blob: 629d35ea07128058d45b48855e5b8eea7ab6b968 [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)
Travis Sheltone34d0e32024-07-30 21:08:56 +020040" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010041" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000042" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010043" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000044" Permission is hereby granted to use and distribute this code,
45" with or without modifications, provided that this copyright
46" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000047" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000048" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000049" expressed or implied. By using this plugin, you agree that
50" in no event will the copyright holder be liable for any damages
51" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010052"
53" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
54" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
55"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020056"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000057"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000058" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000059" (James 1:22 RSV)
60" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000061" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000062if &cp || exists("g:loaded_netrw")
63 finish
64endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020065
66" Check that vim has patches that netrw requires.
67" Patches needed for v7.4: 1557, and 213.
68" (netrw will benefit from vim's having patch#656, too)
69let s:needspatches=[1557,213]
70if exists("s:needspatches")
71 for ptch in s:needspatches
72 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
73 if !exists("s:needpatch{ptch}")
74 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
75 endif
76 let s:needpatch{ptch}= 1
77 finish
78 endif
79 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020080endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020081
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010082let g:loaded_netrw = "v173"
Bram Moolenaar446cb832008-06-24 21:56:24 +000083
Bram Moolenaar1afcace2005-11-25 19:54:28 +000084let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010085setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020086"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010087"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010088"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000089
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000090" ======================
91" Netrw Variables: {{{1
92" ======================
93
Bram Moolenaar071d4272004-06-13 20:20:40 +000094" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020095" netrw#ErrorMsg: {{{2
96" 0=note = s:NOTE
97" 1=warning = s:WARNING
98" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010099" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
100" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
101" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +0100102" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200103fun! netrw#ErrorMsg(level,msg,errnum)
104" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
105
106 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200107" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200108 return
109 endif
110
111 if a:level == 1
112 let level= "**warning** (netrw) "
113 elseif a:level == 2
114 let level= "**error** (netrw) "
115 else
116 let level= "**note** (netrw) "
117 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100118" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200119
Damienb4d11642024-08-15 22:00:45 +0200120 if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200121 " use popup window
122 if type(a:msg) == 3
123 let msg = [level]+a:msg
124 else
125 let msg= level.a:msg
126 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200127 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200128 let s:popuperr_text= ""
129 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200130 " (default) netrw creates a one-line window to show error/warning
131 " messages (reliably displayed)
132
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100133 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200134 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100135" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200136
137 " getting messages out reliably is just plain difficult!
138 " This attempt splits the current window, creating a one line window.
139 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100140" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200141 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100142" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200143 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100144 if type(a:msg) == 3
145 for msg in a:msg
146 NetrwKeepj call setline(line("$")+1,level.msg)
147 endfor
148 else
149 NetrwKeepj call setline(line("$")+1,level.a:msg)
150 endif
151 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200152 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100153" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200154 bo 1split
155 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200156 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200157 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100158 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100159" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200160 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100161 if type(a:msg) == 3
162 for msg in a:msg
163 NetrwKeepj call setline(line("$")+1,level.msg)
164 endfor
165 else
166 NetrwKeepj call setline(line("$"),level.a:msg)
167 endif
168 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200169 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100170" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200171 if &fo !~ '[ta]'
172 syn clear
173 syn match netrwMesgNote "^\*\*note\*\*"
174 syn match netrwMesgWarning "^\*\*warning\*\*"
175 syn match netrwMesgError "^\*\*error\*\*"
176 hi link netrwMesgWarning WarningMsg
177 hi link netrwMesgError Error
178 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100179" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200180 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200181
182 else
183 " (optional) netrw will show messages using echomsg. Even if the
184 " message doesn't appear, at least it'll be recallable via :messages
185" redraw!
186 if a:level == s:WARNING
187 echohl WarningMsg
188 elseif a:level == s:ERROR
189 echohl Error
190 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100191
192 if type(a:msg) == 3
193 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100194 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100195 endfor
196 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100197 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100198 endif
199
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100200" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200201 echohl None
202 endif
203
204" call Dret("netrw#ErrorMsg")
205endfun
206
207" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100208" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100209" Loosely, varname = value.
210fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100211" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100212 if !exists(a:varname)
213 if type(a:value) == 0
214 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200215 elseif type(a:value) == 1 && a:value =~ '^[{[]'
216 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100217 elseif type(a:value) == 1
218 exe "let ".a:varname."="."'".a:value."'"
219 else
220 exe "let ".a:varname."=".a:value
221 endif
222 endif
223endfun
224
225" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000226" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200227call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000228if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100229 call s:NetrwInit("s:THINLIST",0)
230 call s:NetrwInit("s:LONGLIST",1)
231 call s:NetrwInit("s:WIDELIST",2)
232 call s:NetrwInit("s:TREELIST",3)
233 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000234endif
235
Damien7c754112024-08-15 21:58:57 +0200236let s:NOTE = 0
237let s:WARNING = 1
238let s:ERROR = 2
239call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
240
Bram Moolenaar9964e462007-05-05 17:54:07 +0000241" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200242" Default option values: {{{2
243let g:netrw_localcopycmdopt = ""
244let g:netrw_localcopydircmdopt = ""
245let g:netrw_localmkdiropt = ""
246let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200247
248" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000249" Default values for netrw's global protocol variables {{{2
Damienb4d11642024-08-15 22:00:45 +0200250if exists("*popup_atcursor")
251\ && has("syntax")
252\ && exists("g:syntax_on")
253\ && has("mouse")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200254 call s:NetrwInit("g:netrw_use_errorwindow",2)
255else
256 call s:NetrwInit("g:netrw_use_errorwindow",1)
257endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200258
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000259if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100260 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000261 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100262 elseif executable("curl")
263 let g:netrw_dav_cmd = "curl"
264 else
265 let g:netrw_dav_cmd = ""
266 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000267endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000268if !exists("g:netrw_fetch_cmd")
269 if executable("fetch")
270 let g:netrw_fetch_cmd = "fetch -o"
271 else
272 let g:netrw_fetch_cmd = ""
273 endif
274endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100275if !exists("g:netrw_file_cmd")
276 if executable("elinks")
277 call s:NetrwInit("g:netrw_file_cmd","elinks")
278 elseif executable("links")
279 call s:NetrwInit("g:netrw_file_cmd","links")
280 endif
281endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000282if !exists("g:netrw_ftp_cmd")
283 let g:netrw_ftp_cmd = "ftp"
284endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200285let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200286if !exists("g:netrw_ftp_options")
287 let g:netrw_ftp_options= "-i -n"
288endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000289if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100290 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100291 let g:netrw_http_cmd = "wget"
292 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100293 elseif executable("curl")
294 let g:netrw_http_cmd = "curl"
295 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200296 elseif executable("elinks")
297 let g:netrw_http_cmd = "elinks"
298 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000299 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100300 let g:netrw_http_cmd = "fetch"
301 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200302 elseif executable("links")
303 let g:netrw_http_cmd = "links"
304 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000305 else
306 let g:netrw_http_cmd = ""
307 endif
308endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100309call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100310call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100311call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
312call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200313call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200314if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200315 if executable("scp")
316 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
317 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200318 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200319 else
320 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
321 endif
322endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100323call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
324call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000325
Nir Lichtman1e34b952024-05-08 19:19:34 +0200326if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000327 \ && exists("g:netrw_use_nt_rcp")
328 \ && g:netrw_use_nt_rcp
329 \ && executable( $SystemRoot .'/system32/rcp.exe')
330 let s:netrw_has_nt_rcp = 1
331 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000332else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000333 let s:netrw_has_nt_rcp = 0
334 let s:netrw_rcpmode = ''
335endif
336
337" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000338" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000339" Cygwin Detection ------- {{{3
340if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200341 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
342 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000343 else
344 let g:netrw_cygwin= 0
345 endif
346endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000347" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100348call s:NetrwInit("g:netrw_alto" , &sb)
349call s:NetrwInit("g:netrw_altv" , &spr)
350call s:NetrwInit("g:netrw_banner" , 1)
351call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200352call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100353call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200354call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100355call s:NetrwInit("g:netrw_compress" , "gzip")
356call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200357if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
358 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
359 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000360endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200361call s:NetrwInit("g:netrw_cursor" , 2)
362let s:netrw_usercul = &cursorline
363let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200364"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100365call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000366" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200367call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200368call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Christian Brabandtcacfccf2024-11-23 13:28:01 +0100369let s:xz_opt = has('unix') ? "XZ_OPT=-T0" :
370 \ (has("win32") && &shell =~? '\vcmd(\.exe)?$' ?
371 \ "setx XZ_OPT=-T0 &&" : "")
372call s:NetrwInit("g:netrw_decompress ", "{"
373 \ .."'.lz4': 'lz4 -d',"
374 \ .."'.lzo': 'lzop -d',"
375 \ .."'.lz': 'lzip -dk',"
376 \ .."'.7z': '7za x',"
377 \ .."'.001': '7za x',"
378 \ .."'.zip': 'unzip',"
379 \ .."'.bz': 'bunzip2 -k',"
380 \ .."'.bz2': 'bunzip2 -k',"
381 \ .."'.gz': 'gunzip -k',"
382 \ .."'.lzma': 'unlzma -T0 -k',"
383 \ .."'.xz': 'unxz -T0 -k',"
384 \ .."'.zst': 'zstd -T0 -d',"
385 \ .."'.Z': 'uncompress -k',"
386 \ .."'.tar': 'tar -xvf',"
387 \ .."'.tar.bz': 'tar -xvjf',"
388 \ .."'.tar.bz2': 'tar -xvjf',"
389 \ .."'.tbz': 'tar -xvjf',"
390 \ .."'.tbz2': 'tar -xvjf',"
391 \ .."'.tar.gz': 'tar -xvzf',"
392 \ .."'.tgz': 'tar -xvzf',"
393 \ .."'.tar.lzma': '"..s:xz_opt.." tar -xvf --lzma',"
394 \ .."'.tlz': '"..s:xz_opt.." tar -xvf --lzma',"
395 \ .."'.tar.xz': '"..s:xz_opt.." tar -xvfJ',"
396 \ .."'.txz': '"..s:xz_opt.." tar -xvfJ',"
397 \ .."'.tar.zst': '"..s:xz_opt.." tar -xvf --use-compress-program=unzstd',"
398 \ .."'.tzst': '"..s:xz_opt.." tar -xvf --use-compress-program=unzstd',"
399 \ .."'.rar': '"..(executable("unrar")?"unrar x -ad":"rar x -ad").."'"
400 \ .."}")
401unlet s:xz_opt
Bram Moolenaar5c736222010-01-06 20:54:52 +0100402call s:NetrwInit("g:netrw_dirhistmax" , 10)
403call s:NetrwInit("g:netrw_fastbrowse" , 1)
404call 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 +0000405if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000406 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
407 let g:netrw_ftp_list_cmd = "ls -lF"
408 let g:netrw_ftp_timelist_cmd = "ls -tlF"
409 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000410 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000411 let g:netrw_ftp_list_cmd = "dir"
412 let g:netrw_ftp_timelist_cmd = "dir"
413 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000414 endif
415endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100416call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000417" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100418call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000419if !exists("g:netrw_ignorenetrc")
420 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
421 let g:netrw_ignorenetrc= 1
422 else
423 let g:netrw_ignorenetrc= 0
424 endif
425endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100426call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000427if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000428 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100429 if exists("g:netrw_list_cmd_options")
430 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
431 else
432 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
433 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000434 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200435 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100436 if exists("g:netrw_list_cmd_options")
437 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
438 else
439 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
440 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000441 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100442" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000443 let g:netrw_list_cmd= ""
444 endif
445endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100446call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000447" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200448if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200449 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200450 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
451endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100452if !exists("g:netrw_localcmdshell")
453 let g:netrw_localcmdshell= ""
454endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000455if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200456 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000457 if g:netrw_cygwin
458 let g:netrw_localcopycmd= "cp"
459 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000460 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200461 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000462 endif
463 elseif has("unix") || has("macunix")
464 let g:netrw_localcopycmd= "cp"
465 else
466 let g:netrw_localcopycmd= ""
467 endif
468endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100469if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200470 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100471 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200472 let g:netrw_localcopydircmd = "cp"
473 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100474 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000475 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200476 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100477 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200478 elseif has("unix")
479 let g:netrw_localcopydircmd = "cp"
480 let g:netrw_localcopydircmdopt= " -R"
481 elseif has("macunix")
482 let g:netrw_localcopydircmd = "cp"
483 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100484 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200485 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100486 endif
487endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200488if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100489 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200490 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
491endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200492if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200493 if g:netrw_cygwin
494 call s:NetrwInit("g:netrw_localmkdir","mkdir")
495 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000496 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200497 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200498 endif
499else
500 call s:NetrwInit("g:netrw_localmkdir","mkdir")
501endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200502call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200503if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200504 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200505 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
506endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000507if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200508 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000509 if g:netrw_cygwin
510 let g:netrw_localmovecmd= "mv"
511 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000512 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200513 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000514 endif
515 elseif has("unix") || has("macunix")
516 let g:netrw_localmovecmd= "mv"
517 else
518 let g:netrw_localmovecmd= ""
519 endif
520endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100521" following serves as an example for how to insert a version&patch specific test
522"if v:version < 704 || (v:version == 704 && !has("patch1107"))
523"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100524call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
525" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000526if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000527 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000528endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000529if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000530 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
531endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000532" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100533call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
534call s:NetrwInit("g:netrw_maxfilenamelen", 32)
535call s:NetrwInit("g:netrw_menu" , 1)
536call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200537call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100538call s:NetrwInit("g:netrw_retmap" , 0)
539if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
540 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200541elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100542 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
543else
544 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000545endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100546call s:NetrwInit("g:netrw_preview" , 0)
547call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100548call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100549call s:NetrwInit("g:netrw_sshport" , "-p")
550call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
551call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
552call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100553call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
554" Default values - q-s ---------- {{{3
555call s:NetrwInit("g:netrw_quickhelp",0)
556let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100557 \ "(create new) %:file d:directory",
558 \ "(windows split&open) o:horz v:vert p:preview",
559 \ "i:style qf:file info O:obtain r:reverse",
560 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
561 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
562 \ "(history) qb:list u:go up U:go down",
563 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100564" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
565call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100566if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
567 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
568else
569 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
570endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100571call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
572call s:NetrwInit("g:netrw_sort_options" , "")
573call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000574if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100575 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200576 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100577 else
578 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000579 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000580endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100581call s:NetrwInit("g:netrw_special_syntax" , 0)
582call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaara6878372014-03-22 21:02:50 +0100583call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100584call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000585" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100586call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200587if !exists("g:netrw_xstrlen")
588 if exists("g:Align_xstrlen")
589 let g:netrw_xstrlen= g:Align_xstrlen
590 elseif exists("g:drawit_xstrlen")
591 let g:netrw_xstrlen= g:drawit_xstrlen
592 elseif &enc == "latin1" || !has("multi_byte")
593 let g:netrw_xstrlen= 0
594 else
595 let g:netrw_xstrlen= 1
596 endif
597endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100598call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200599call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100600call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200601if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000602" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000603" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100604call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200605if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200606 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200607else
Bram Moolenaarff034192013-04-24 18:51:19 +0200608 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200609endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200610call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100611call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
612call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100613if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100614 let s:treedepthstring= "│ "
615else
616 let s:treedepthstring= "| "
617endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200618call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000619
620" BufEnter event ignored by decho when following variable is true
621" Has a side effect that doau BufReadPost doesn't work, so
622" files read by network transfer aren't appropriately highlighted.
623"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000624
Bram Moolenaaradc21822011-04-01 18:03:16 +0200625" ======================
626" Netrw Initialization: {{{1
627" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200628if 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 +0100629" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100630 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200631" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100632 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100633 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
634 au VimEnter * let s:initbeval= &beval
635"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100636" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
637" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
638" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
639" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
640" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
641" 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 +0200642endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200643au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200644
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200645if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100646 com! -nargs=* NetrwKeepj keepj <args>
647else
648 let g:netrw_keepj= ""
649 com! -nargs=* NetrwKeepj <args>
650endif
651
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000652" ==============================
653" Netrw Utility Functions: {{{1
654" ==============================
655
Bram Moolenaaradc21822011-04-01 18:03:16 +0200656" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100657" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100658if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100659" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100660 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100661 if &ft != "netrw"
662 return ""
663 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200664 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
665 " popup error window is still showing
666 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
667 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
668 " text under mouse hasn't changed; only close window when it changes
669 call popup_close(s:popuperr_id)
670 unlet s:popuperr_text
671 else
672 let s:popuperr_text= v:beval_text
673 endif
674 let mesg= ""
675 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 +0100676 let mesg= ""
677 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
678 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
679 elseif getline(v:beval_lnum) =~ '^"\s*/'
680 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
681 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100682 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100683 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
684 let mesg = "S: edit sorting sequence"
685 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
686 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
687 elseif v:beval_text == "Quick" || v:beval_text == "Help"
688 let mesg = "Help: press <F1>"
689 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
690 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
691 else
692 let mesg= ""
693 endif
694 return mesg
695 endfun
696"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100697" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
698" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
699" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
700" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
701" 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 +0200702endif
703
Bram Moolenaar071d4272004-06-13 20:20:40 +0000704" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200705" netrw#Explore: launch the local browser in the directory of the current file {{{2
706" indx: == -1: Nexplore
707" == -2: Pexplore
708" == +: this is overloaded:
709" * If Nexplore/Pexplore is in use, then this refers to the
710" indx'th item in the w:netrw_explore_list[] of items which
711" matched the */pattern **/pattern *//pattern **//pattern
712" * If Hexplore or Vexplore, then this will override
713" g:netrw_winsize to specify the qty of rows or columns the
714" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100715" 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 +0200716" dosplit==1: the window will be split before running the local browser
717" style == 0: Explore style == 1: Explore!
718" == 2: Hexplore style == 3: Hexplore!
719" == 4: Vexplore style == 5: Vexplore!
720" == 6: Texplore
721fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaarff034192013-04-24 18:51:19 +0200722 if !exists("b:netrw_curdir")
723 let b:netrw_curdir= getcwd()
Bram Moolenaarff034192013-04-24 18:51:19 +0200724 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100725
726 " record current file for Rexplore's benefit
727 if &ft != "netrw"
728 let w:netrw_rexfile= expand("%:p")
729 endif
730
731 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200732 let curdir = simplify(b:netrw_curdir)
733 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200734 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200735 let curdir= substitute(curdir,'\','/','g')
736 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100737
738 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
739 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
740 " try Explore again.
741 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100742 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200743 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
744 if a1 != a:1
745 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
746 return
747 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100748 endif
749 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200750
751 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200752 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100753" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100754 sil! let keepregstar = @*
755 sil! let keepregplus = @+
756 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200757 sil! let keepregslash= @/
758
Bram Moolenaar8d043172014-01-23 14:24:41 +0100759 " if dosplit
760 " -or- file has been modified AND file not hidden when abandoned
761 " -or- Texplore used
762 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaarff034192013-04-24 18:51:19 +0200763 call s:SaveWinVars()
764 let winsz= g:netrw_winsize
765 if a:indx > 0
766 let winsz= a:indx
767 endif
768
769 if a:style == 0 " Explore, Sexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200770 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200771 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200772 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200773
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200774 elseif a:style == 1 " Explore!, Sexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200775 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200776 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200777 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200778
779 elseif a:style == 2 " Hexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200780 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200781 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200782 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200783
784 elseif a:style == 3 " Hexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200785 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200786 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200787 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200788
789 elseif a:style == 4 " Vexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200790 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200791 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200792 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200793
794 elseif a:style == 5 " Vexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200795 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200796 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200797 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200798
799 elseif a:style == 6 " Texplore
800 call s:SaveBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200801 exe "keepalt tabnew ".fnameescape(curdir)
802 call s:RestoreBufVars()
803 endif
804 call s:RestoreWinVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200805 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100806 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200807
808 if a:0 > 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200809 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaarff034192013-04-24 18:51:19 +0200810 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaarff034192013-04-24 18:51:19 +0200811 elseif a:1 == '.'
Bram Moolenaarff034192013-04-24 18:51:19 +0200812 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
813 if dirname !~ '/$'
814 let dirname= dirname."/"
815 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200816 elseif a:1 =~ '\$'
Bram Moolenaarff034192013-04-24 18:51:19 +0200817 let dirname= simplify(expand(a:1))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200818 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaarff034192013-04-24 18:51:19 +0200819 let dirname= simplify(a:1)
Bram Moolenaarff034192013-04-24 18:51:19 +0200820 else
Bram Moolenaarff034192013-04-24 18:51:19 +0200821 let dirname= a:1
822 endif
823 else
824 " clear explore
Bram Moolenaarff034192013-04-24 18:51:19 +0200825 call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200826 return
827 endif
828
Bram Moolenaarff034192013-04-24 18:51:19 +0200829 if dirname =~ '\.\./\=$'
830 let dirname= simplify(fnamemodify(dirname,':p:h'))
831 elseif dirname =~ '\.\.' || dirname == '.'
832 let dirname= simplify(fnamemodify(dirname,':p'))
833 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200834
835 if dirname =~ '^\*//'
836 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200837 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
838 let starpat= 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200839 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
840
841 elseif dirname =~ '^\*\*//'
842 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200843 let pattern= substitute(dirname,'^\*\*//','','')
844 let starpat= 2
Bram Moolenaarff034192013-04-24 18:51:19 +0200845
846 elseif dirname =~ '/\*\*/'
847 " handle .../**/.../filepat
Bram Moolenaarff034192013-04-24 18:51:19 +0200848 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200849 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200850 let b:netrw_curdir = prefixdir
851 else
852 let b:netrw_curdir= getcwd().'/'.prefixdir
853 endif
854 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
855 let starpat= 4
Bram Moolenaarff034192013-04-24 18:51:19 +0200856
857 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200858 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200859 let starpat= 3
Bram Moolenaarff034192013-04-24 18:51:19 +0200860
861 elseif dirname=~ '^\*\*/'
862 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
863 let starpat= 4
Bram Moolenaarff034192013-04-24 18:51:19 +0200864
865 else
866 let starpat= 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200867 endif
868
869 if starpat == 0 && a:indx >= 0
870 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaarff034192013-04-24 18:51:19 +0200871 if dirname == ""
872 let dirname= curfiledir
Bram Moolenaarff034192013-04-24 18:51:19 +0200873 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200874 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200875 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200876 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200877 if dirname == ""
878 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200879 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100880 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100881 " depending on whether backslashes have been converted to forward slashes by earlier code).
882 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200883 let dirname= b:netrw_curdir."/".dirname
884 endif
885 elseif dirname !~ '^/'
886 let dirname= b:netrw_curdir."/".dirname
887 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200888 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200889 endif
890 if exists("w:netrw_bannercnt")
891 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
892 " If one wants to return the same place in the netrw window, use :Rex instead.
893 exe w:netrw_bannercnt
894 endif
895
Bram Moolenaarff034192013-04-24 18:51:19 +0200896
897 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
898 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
899 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
900 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
901 elseif a:indx <= 0
902 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaarff034192013-04-24 18:51:19 +0200903 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaarff034192013-04-24 18:51:19 +0200904 let s:didstarstar= 1
905 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
906 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
907 endif
908
909 if has("path_extra")
Bram Moolenaarff034192013-04-24 18:51:19 +0200910 if !exists("w:netrw_explore_indx")
911 let w:netrw_explore_indx= 0
912 endif
913
914 let indx = a:indx
Bram Moolenaarff034192013-04-24 18:51:19 +0200915
916 if indx == -1
917 " Nexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200918 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100919 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 +0200920 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100921 if @* != keepregstar | sil! let @* = keepregstar | endif
922 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100923 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200924 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200925 return
926 endif
927 let indx= w:netrw_explore_indx
928 if indx < 0 | let indx= 0 | endif
929 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
930 let curfile= w:netrw_explore_list[indx]
Bram Moolenaarff034192013-04-24 18:51:19 +0200931 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
932 let indx= indx + 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200933 endwhile
934 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200935
936 elseif indx == -2
937 " Pexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200938 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100939 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 +0200940 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100941 if @* != keepregstar | sil! let @* = keepregstar | endif
942 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100943 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200944 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200945 return
946 endif
947 let indx= w:netrw_explore_indx
948 if indx < 0 | let indx= 0 | endif
949 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
950 let curfile= w:netrw_explore_list[indx]
Bram Moolenaarff034192013-04-24 18:51:19 +0200951 while indx >= 0 && curfile == w:netrw_explore_list[indx]
952 let indx= indx - 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200953 endwhile
954 if indx < 0 | let indx= 0 | endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200955
956 else
957 " Explore -- initialize
958 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100959 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200960 let w:netrw_explore_indx= 0
961 if !exists("b:netrw_curdir")
962 let b:netrw_curdir= getcwd()
963 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200964
965 " switch on starpat to build the w:netrw_explore_list of files
966 if starpat == 1
967 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200968 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100969 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200970 catch /^Vim\%((\a\+)\)\=:E480/
971 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +0200972 return
973 endtry
974 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
975 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
976
977 elseif starpat == 2
978 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200979 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100980 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200981 catch /^Vim\%((\a\+)\)\=:E480/
982 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
983 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200984 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100985 if @* != keepregstar | sil! let @* = keepregstar | endif
986 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100987 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200988 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200989 return
990 endtry
991 let s:netrw_curdir = b:netrw_curdir
992 let w:netrw_explore_list = getqflist()
993 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
994 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
995
996 elseif starpat == 3
997 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200998 let filepat= substitute(dirname,'^\*/','','')
999 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaarff034192013-04-24 18:51:19 +02001000 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1001 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1002
1003 elseif starpat == 4
1004 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +02001005 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1006 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1007 endif " switch on starpat to build w:netrw_explore_list
1008
1009 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaarff034192013-04-24 18:51:19 +02001010
1011 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001012 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001013 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001014 if @* != keepregstar | sil! let @* = keepregstar | endif
1015 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001016 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001017 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +02001018 return
1019 endif
1020 endif " if indx ... endif
1021
1022 " NetrwStatusLine support - for exploring support
1023 let w:netrw_explore_indx= indx
Bram Moolenaarff034192013-04-24 18:51:19 +02001024
1025 " wrap the indx around, but issue a note
1026 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaarff034192013-04-24 18:51:19 +02001027 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1028 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001029 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001030 endif
1031
1032 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaarff034192013-04-24 18:51:19 +02001033 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaarff034192013-04-24 18:51:19 +02001034
Bram Moolenaarff034192013-04-24 18:51:19 +02001035 call netrw#LocalBrowseCheck(newdir)
1036 if !exists("w:netrw_liststyle")
1037 let w:netrw_liststyle= g:netrw_liststyle
1038 endif
1039 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001040 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001041 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001042 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001043 endif
1044 let w:netrw_explore_mtchcnt = indx + 1
1045 let w:netrw_explore_bufnr = bufnr("%")
1046 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001047 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaarff034192013-04-24 18:51:19 +02001048
1049 else
Bram Moolenaarff034192013-04-24 18:51:19 +02001050 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001051 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 +02001052 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001053 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001054 if @* != keepregstar | sil! let @* = keepregstar | endif
1055 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001056 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001057 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +02001058 return
1059 endif
1060
1061 else
Bram Moolenaarff034192013-04-24 18:51:19 +02001062 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1063 sil! unlet w:netrw_treedict
1064 sil! unlet w:netrw_treetop
1065 endif
1066 let newdir= dirname
1067 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001068 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001069 else
Tom Benham64a536d2024-11-07 21:15:03 +01001070 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir,0))
Bram Moolenaarff034192013-04-24 18:51:19 +02001071 endif
1072 endif
1073
1074 " visual display of **/ **// */ Exploration files
Bram Moolenaarff034192013-04-24 18:51:19 +02001075 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaarff034192013-04-24 18:51:19 +02001076 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001077 " only update match list when current directory isn't the same as before
Bram Moolenaarff034192013-04-24 18:51:19 +02001078 let s:explore_prvdir = b:netrw_curdir
1079 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001080 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001081 if b:netrw_curdir !~ '/$'
1082 let dirlen= dirlen + 1
1083 endif
1084 let prvfname= ""
1085 for fname in w:netrw_explore_list
Bram Moolenaarff034192013-04-24 18:51:19 +02001086 if fname =~ '^'.b:netrw_curdir
1087 if s:explore_match == ""
1088 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1089 else
1090 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1091 endif
1092 elseif fname !~ '^/' && fname != prvfname
1093 if s:explore_match == ""
1094 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1095 else
1096 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1097 endif
1098 endif
1099 let prvfname= fname
1100 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02001101 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1102 exe "2match netrwMarkFile /".s:explore_match."/"
1103 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001104 endif
1105 echo "<s-up>==Pexplore <s-down>==Nexplore"
1106 else
1107 2match none
1108 if exists("s:explore_match") | unlet s:explore_match | endif
1109 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001110 endif
1111
Bram Moolenaara6878372014-03-22 21:02:50 +01001112 " since Explore may be used to initialize netrw's browser,
1113 " there's no danger of a late FocusGained event on initialization.
1114 " Consequently, set s:netrw_events to 2.
1115 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001116 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001117 if @* != keepregstar | sil! let @* = keepregstar | endif
1118 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001119 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001120 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +02001121endfun
1122
1123" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001124" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001125" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1126" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1127" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1128" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1129" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001130fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001131" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001132 let curwin= winnr()
1133
Bram Moolenaara6878372014-03-22 21:02:50 +01001134 if a:0 > 0 && a:1 != ""
1135 " if a netrw window is already on the left-side of the tab
1136 " and a directory has been specified, explore with that
1137 " directory.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001138 let a1 = expand(a:1)
Bram Moolenaara6878372014-03-22 21:02:50 +01001139 exe "1wincmd w"
1140 if &ft == "netrw"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001141 exe "Explore ".fnameescape(a1)
1142 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001143 let s:lexplore_win= curwin
1144 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001145 if exists("t:netrw_lexposn")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001146 unlet t:netrw_lexposn
1147 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001148 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001149 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001150 exe curwin."wincmd w"
1151 else
1152 let a1= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01001153 endif
1154
Bram Moolenaar8d043172014-01-23 14:24:41 +01001155 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001156 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001157 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001158 else
1159 let lexwinnr= 0
1160 endif
1161
1162 if lexwinnr > 0
1163 " close down netrw explorer window
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001164 exe lexwinnr."wincmd w"
1165 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001166 let t:netrw_lexposn = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001167 close
1168 if lexwinnr < curwin
1169 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001170 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001171 if lexwinnr != curwin
1172 exe curwin."wincmd w"
1173 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001174 unlet t:netrw_lexbufnr
1175
1176 else
1177 " open netrw explorer window
1178 exe "1wincmd w"
1179 let keep_altv = g:netrw_altv
1180 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001181 if a:count != 0
1182 let netrw_winsize = g:netrw_winsize
1183 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001184 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001185 let curfile= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001186 exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
1187 if a:0 > 0 && a1 != ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001188 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001189 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001190 elseif curfile =~ '^\a\{3,}://'
Bram Moolenaar85850f32019-07-19 22:05:51 +02001191 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001192 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02001193 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001194 endif
1195 if a:count != 0
1196 let g:netrw_winsize = netrw_winsize
1197 endif
1198 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001199 let g:netrw_altv = keep_altv
1200 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001201 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1202 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001203 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001204 set bh=wipe
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001205 if exists("t:netrw_lexposn")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001206 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001207 unlet t:netrw_lexposn
1208 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001209 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001210
1211 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001212 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001213 if a:rightside
1214 let g:netrw_chgwin= 1
1215 else
1216 let g:netrw_chgwin= 2
1217 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001218 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001219
Bram Moolenaar8d043172014-01-23 14:24:41 +01001220endfun
1221
1222" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001223" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001224" supports :NetrwClean -- remove netrw from first directory on runtimepath
1225" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001226fun! netrw#Clean(sys)
1227" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001228
1229 if a:sys
1230 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1231 else
1232 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1233 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001234" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001235 let diddel= 0
1236 let diddir= ""
1237
1238 if choice == 1
1239 for dir in split(&rtp,',')
1240 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001241" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001242 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1243 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1244 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1245 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1246 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1247 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 +00001248 let diddir= dir
1249 let diddel= diddel + 1
1250 if !a:sys|break|endif
1251 endif
1252 endfor
1253 endif
1254
1255 echohl WarningMsg
1256 if diddel == 0
1257 echomsg "netrw is either not installed or not removable"
1258 elseif diddel == 1
1259 echomsg "removed one copy of netrw from <".diddir.">"
1260 else
1261 echomsg "removed ".diddel." copies of netrw"
1262 endif
1263 echohl None
1264
Bram Moolenaara6878372014-03-22 21:02:50 +01001265" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001266endfun
1267
Bram Moolenaar5c736222010-01-06 20:54:52 +01001268" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001269" netrw#MakeTgt: make a target out of the directory name provided {{{2
1270fun! netrw#MakeTgt(dname)
1271" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1272 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001273 let svpos = winsaveview()
1274" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001275 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1276" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001277 if s:netrwmftgt_islocal
1278 let netrwmftgt= simplify(a:dname)
1279 else
1280 let netrwmftgt= a:dname
1281 endif
1282 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1283 " re-selected target, so just clear it
1284 unlet s:netrwmftgt s:netrwmftgt_islocal
1285 else
1286 let s:netrwmftgt= netrwmftgt
1287 endif
1288 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001289 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001290 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001291" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1292 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001293" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001294endfun
1295
Bram Moolenaara6878372014-03-22 21:02:50 +01001296" ---------------------------------------------------------------------
1297" netrw#Obtain: {{{2
1298" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001299" islocal=0 obtain from remote source
1300" =1 obtain from local source
1301" fname : a filename or a list of filenames
1302" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001303fun! netrw#Obtain(islocal,fname,...)
1304" 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 +02001305 " NetrwStatusLine support - for obtaining support
1306
1307 if type(a:fname) == 1
1308 let fnamelist= [ a:fname ]
1309 elseif type(a:fname) == 3
1310 let fnamelist= a:fname
1311 else
1312 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 +01001313" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001314 return
1315 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001316" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001317 if a:0 > 0
1318 let tgtdir= a:1
1319 else
1320 let tgtdir= getcwd()
1321 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001322" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001323
1324 if exists("b:netrw_islocal") && b:netrw_islocal
1325 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001326" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001327 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1328 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001329 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001330 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001331" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001332 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001333" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001334 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001335 if v:shell_error != 0
1336 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 +01001337" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001338 return
1339 endif
1340 endfor
1341 else
1342 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001343" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1344 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1345" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001346 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001347 if v:shell_error != 0
1348 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 +01001349" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001350 return
1351 endif
1352 endif
1353 elseif !exists("b:netrw_curdir")
1354 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1355 else
1356 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1357 endif
1358
1359 else
1360 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001361" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001362 if type(a:fname) == 1
1363 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1364 endif
1365 call s:NetrwMethod(b:netrw_curdir)
1366
1367 if b:netrw_method == 4
1368 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001369" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001370 if exists("g:netrw_port") && g:netrw_port != ""
1371 let useport= " ".g:netrw_scpport." ".g:netrw_port
1372 else
1373 let useport= ""
1374 endif
1375 if b:netrw_fname =~ '/'
1376 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1377 else
1378 let path= ""
1379 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001380 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001381 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 +02001382
1383 elseif b:netrw_method == 2
1384 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001385" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001386 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001387 let tmpbufnr= bufnr("%")
1388 setl ff=unix
1389 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001390 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001391" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001392 endif
1393
1394 if exists("b:netrw_fname") && b:netrw_fname != ""
1395 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001396" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001397 endif
1398
1399 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001400 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001401" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001402 endif
1403 for fname in fnamelist
1404 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001405" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001406 endfor
1407 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001408 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 +02001409 else
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))
Bram Moolenaarff034192013-04-24 18:51:19 +02001411 endif
1412 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1413 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1414 let debugkeep= &debug
1415 setl debug=msg
1416 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1417 let &debug= debugkeep
1418 endif
1419
1420 elseif b:netrw_method == 3
1421 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001422" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001423 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001424 let tmpbufnr= bufnr("%")
1425 setl ff=unix
1426
1427 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001428 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001429" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001430 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001431 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001432" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001433 endif
1434
1435 if exists("g:netrw_uid") && g:netrw_uid != ""
1436 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001437 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001438" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001439 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001440 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001441 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001442" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001443 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001444 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001445" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001446 endif
1447 endif
1448
1449 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001450 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001451" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001452 endif
1453
1454 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001455 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001456" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001457 endif
1458
1459 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001460 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001461" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001462 endif
1463
1464 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001465 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001466" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001467 endif
1468 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001469 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001470 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001471" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001472
1473 " perform ftp:
1474 " -i : turns off interactive prompting from ftp
1475 " -n unix : DON'T use <.netrc>, even though it exists
1476 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001477 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1478 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001479 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001480 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1481 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001482" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001483 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001484 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001485 endif
1486 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001487
1488 elseif b:netrw_method == 9
1489 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001490" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001491 if a:fname =~ '/'
1492 let localfile= substitute(a:fname,'^.*/','','')
1493 else
1494 let localfile= a:fname
1495 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001496 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 +02001497
Bram Moolenaarff034192013-04-24 18:51:19 +02001498 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001499 " probably a badly formed url; protocol not recognized
1500" call Dret("netrw#Obtain : unsupported method")
1501 return
1502
1503 else
1504 " protocol recognized but not supported for Obtain (yet?)
1505 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001506 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001507 endif
1508" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001509 return
1510 endif
1511
1512 " restore status line
1513 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001514 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001515 endif
1516
1517 endif
1518
1519 " cleanup
1520 if exists("tmpbufnr")
1521 if bufnr("%") != tmpbufnr
1522 exe tmpbufnr."bw!"
1523 else
1524 q!
1525 endif
1526 endif
1527
Bram Moolenaara6878372014-03-22 21:02:50 +01001528" call Dret("netrw#Obtain")
1529endfun
1530
1531" ---------------------------------------------------------------------
1532" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1533fun! netrw#Nread(mode,fname)
1534" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001535 let svpos= winsaveview()
1536" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001537 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001538" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1539 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001540
1541 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1542 if exists("w:netrw_bannercnt")
1543 " start with cursor just after the banner
1544 exe w:netrw_bannercnt
1545 endif
1546 endif
1547" call Dret("netrw#Nread")
1548endfun
1549
1550" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001551" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1552" Options get restored by s:NetrwOptionsRestore()
1553"
1554" Option handling:
1555" * save user's options (s:NetrwOptionsSave)
1556" * set netrw-safe options (s:NetrwOptionsSafe)
1557" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1558" * restore user's options (s:netrwOPtionsRestore)
1559" - restore a user option when != safe option (s:NetrwRestoreSetting)
1560" vt: (variable type) normally its either "w:" or "s:"
1561fun! s:NetrwOptionsSave(vt)
1562" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1563" 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 +02001564" 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>"))
1565" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001566
1567 if !exists("{a:vt}netrw_optionsave")
1568 let {a:vt}netrw_optionsave= 1
1569 else
1570" call Dret("s:NetrwOptionsSave : options already saved")
1571 return
1572 endif
1573" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1574
1575 " Save current settings and current directory
1576" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1577 let s:yykeep = @@
1578 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1579 let {a:vt}netrw_aikeep = &l:ai
1580 let {a:vt}netrw_awkeep = &l:aw
1581 let {a:vt}netrw_bhkeep = &l:bh
1582 let {a:vt}netrw_blkeep = &l:bl
1583 let {a:vt}netrw_btkeep = &l:bt
1584 let {a:vt}netrw_bombkeep = &l:bomb
1585 let {a:vt}netrw_cedit = &cedit
1586 let {a:vt}netrw_cikeep = &l:ci
1587 let {a:vt}netrw_cinkeep = &l:cin
1588 let {a:vt}netrw_cinokeep = &l:cino
1589 let {a:vt}netrw_comkeep = &l:com
1590 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001591 let {a:vt}netrw_cuckeep = &l:cuc
1592 let {a:vt}netrw_culkeep = &l:cul
1593" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001594 let {a:vt}netrw_diffkeep = &l:diff
1595 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001596 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1597 let {a:vt}netrw_ffkeep = &l:ff
1598 endif
1599 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1600 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001601 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001602 let {a:vt}netrw_hidkeep = &l:hidden
1603 let {a:vt}netrw_imkeep = &l:im
1604 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001605 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001606 let {a:vt}netrw_lskeep = &l:ls
1607 let {a:vt}netrw_makeep = &l:ma
1608 let {a:vt}netrw_magickeep = &l:magic
1609 let {a:vt}netrw_modkeep = &l:mod
1610 let {a:vt}netrw_nukeep = &l:nu
1611 let {a:vt}netrw_rnukeep = &l:rnu
1612 let {a:vt}netrw_repkeep = &l:report
1613 let {a:vt}netrw_rokeep = &l:ro
1614 let {a:vt}netrw_selkeep = &l:sel
1615 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001616 if !g:netrw_use_noswf
1617 let {a:vt}netrw_swfkeep = &l:swf
1618 endif
1619 let {a:vt}netrw_tskeep = &l:ts
1620 let {a:vt}netrw_twkeep = &l:tw " textwidth
1621 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1622 let {a:vt}netrw_wrapkeep = &l:wrap
1623 let {a:vt}netrw_writekeep = &l:write
1624
1625 " save a few selected netrw-related variables
1626" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1627 if g:netrw_keepdir
1628 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001629" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001630 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001631 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001632 sil! let {a:vt}netrw_starkeep = @*
1633 sil! let {a:vt}netrw_pluskeep = @+
1634 endif
1635 sil! let {a:vt}netrw_slashkeep= @/
1636
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001637" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001638" 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>"))
1639" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1640endfun
1641
1642" ---------------------------------------------------------------------
1643" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1644" Use s:NetrwSaveOptions() to save user settings
1645" Use s:NetrwOptionsRestore() to restore user settings
1646fun! s:NetrwOptionsSafe(islocal)
1647" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1648" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1649" 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>"))
1650 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1651 call s:NetrwSetSafeSetting("&l:ai",0)
1652 call s:NetrwSetSafeSetting("&l:aw",0)
1653 call s:NetrwSetSafeSetting("&l:bl",0)
1654 call s:NetrwSetSafeSetting("&l:bomb",0)
1655 if a:islocal
1656 call s:NetrwSetSafeSetting("&l:bt","nofile")
1657 else
1658 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1659 endif
1660 call s:NetrwSetSafeSetting("&l:ci",0)
1661 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001662 if g:netrw_fastbrowse > a:islocal
1663 call s:NetrwSetSafeSetting("&l:bh","hide")
1664 else
1665 call s:NetrwSetSafeSetting("&l:bh","delete")
1666 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001667 call s:NetrwSetSafeSetting("&l:cino","")
1668 call s:NetrwSetSafeSetting("&l:com","")
1669 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1670 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1671 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001672 if &go =~ 'a' | set go-=a | endif
1673 if &go =~ 'A' | set go-=A | endif
1674 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001675 call s:NetrwSetSafeSetting("&l:hid",0)
1676 call s:NetrwSetSafeSetting("&l:im",0)
1677 setl isk+=@ isk+=* isk+=/
1678 call s:NetrwSetSafeSetting("&l:magic",1)
1679 if g:netrw_use_noswf
1680 call s:NetrwSetSafeSetting("swf",0)
1681 endif
1682 call s:NetrwSetSafeSetting("&l:report",10000)
1683 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1684 call s:NetrwSetSafeSetting("&l:spell",0)
1685 call s:NetrwSetSafeSetting("&l:tw",0)
1686 call s:NetrwSetSafeSetting("&l:wig","")
1687 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001688
1689 " set up cuc and cul based on g:netrw_cursor and listing style
1690 " COMBAK -- cuc cul related
1691 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001692
1693 " allow the user to override safe options
1694" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1695 if &ft == "netrw"
1696" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1697 keepalt NetrwKeepj doau FileType netrw
1698 endif
1699
1700" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1701" 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>"))
1702" call Dret("s:NetrwOptionsSafe")
1703endfun
1704
1705" ---------------------------------------------------------------------
1706" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1707fun! s:NetrwOptionsRestore(vt)
Bram Moolenaara6878372014-03-22 21:02:50 +01001708 if !exists("{a:vt}netrw_optionsave")
Christian Brabandtaa2ce6f2024-10-30 18:27:03 +01001709 " filereadable() returns zero for remote files (e.g. scp://user@localhost//etc/fstab)
1710 " Note: @ may not be in 'isfname', so '^\w\+://\f\+/' may not match
1711 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+'
Bram Moolenaar71badf92023-04-22 22:40:14 +01001712 filetype detect
Bram Moolenaar71badf92023-04-22 22:40:14 +01001713 else
1714 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001715 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001716 return
1717 endif
1718 unlet {a:vt}netrw_optionsave
1719
1720 if exists("+acd")
1721 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara6878372014-03-22 21:02:50 +01001722 let curdir = getcwd()
1723 let &l:acd = {a:vt}netrw_acdkeep
1724 unlet {a:vt}netrw_acdkeep
1725 if &l:acd
1726 call s:NetrwLcd(curdir)
1727 endif
1728 endif
1729 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001730 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1731 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1732 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1733 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1734 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
1735 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1736 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1737 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1738 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1739 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
1740 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1741 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1742 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1743 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1744 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001745 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001746 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1747 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001748 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001749 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001750 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1751 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001752 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001753 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1754 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001755 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001756 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1757 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001758 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1759 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1760 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1761 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001762 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001763 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1764 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1765 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001766 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
1767 call s:NetrwRestoreSetting("s:yykeep","@@")
1768 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1769 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1770 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1771 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1772
Bram Moolenaara6878372014-03-22 21:02:50 +01001773 if exists("{a:vt}netrw_swfkeep")
1774 if &directory == ""
1775 " user hasn't specified a swapfile directory;
1776 " netrw will temporarily set the swapfile directory
1777 " to the current directory as returned by getcwd().
1778 let &l:directory= getcwd()
1779 sil! let &l:swf = {a:vt}netrw_swfkeep
1780 setl directory=
1781 unlet {a:vt}netrw_swfkeep
1782 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001783 if !g:netrw_use_noswf
1784 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1785 sil! let &l:swf= {a:vt}netrw_swfkeep
1786 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001787 unlet {a:vt}netrw_swfkeep
1788 endif
1789 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001790 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001791 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1792 if exists("{a:vt}netrw_dirkeep")
1793 call s:NetrwLcd(dirkeep)
1794 unlet {a:vt}netrw_dirkeep
1795 endif
1796 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001797 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001798 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1799 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001800 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001801 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001802
Bram Moolenaara6878372014-03-22 21:02:50 +01001803 " Moved the filetype detect here from NetrwGetFile() because remote files
1804 " were having their filetype detect-generated settings overwritten by
1805 " NetrwOptionRestore.
1806 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001807 filetype detect
Bram Moolenaara6878372014-03-22 21:02:50 +01001808 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001809endfun
1810
1811" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001812" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1813" but only when the options' value and the safe setting differ
1814" Doing this means that netrw will not come up as having changed a
1815" setting last when it really didn't actually change it.
1816"
1817" Called from s:NetrwOptionsSafe
1818" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1819fun! s:NetrwSetSafeSetting(setting,safesetting)
1820" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001821
Bram Moolenaar85850f32019-07-19 22:05:51 +02001822 if a:setting =~ '^&'
1823" call Decho("fyi: a:setting starts with &")
1824 exe "let settingval= ".a:setting
1825" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001826
Bram Moolenaar85850f32019-07-19 22:05:51 +02001827 if settingval != a:safesetting
1828" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1829 if type(a:safesetting) == 0
1830 exe "let ".a:setting."=".a:safesetting
1831 elseif type(a:safesetting) == 1
1832 exe "let ".a:setting."= '".a:safesetting."'"
1833 else
1834 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1835 endif
1836 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001837 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001838
Bram Moolenaar85850f32019-07-19 22:05:51 +02001839" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001840endfun
1841
1842" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001843" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1844" but only if the setting value differs from the associated keepvar.
1845" Doing this means that netrw will not come up as having changed a
1846" setting last when it really didn't actually change it.
1847"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001848" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001849" keepvars are set up by s:NetrwOptionsSave
1850fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001851""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001852
Bram Moolenaar85850f32019-07-19 22:05:51 +02001853 " typically called from s:NetrwOptionsRestore
1854 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1855 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001856 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001857 if exists(a:keepvar)
1858 exe "let keepvarval= ".a:keepvar
1859 exe "let setting= ".a:setting
1860
1861"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1862"" call Decho("fyi: keepvarval=".keepvarval)
1863"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1864
1865 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001866"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001867 if type(a:setting) == 0
1868 exe "let ".a:setting."= ".keepvarval
1869 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001870 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001871 else
1872 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1873 endif
1874 endif
1875
1876 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001877 endif
1878
Bram Moolenaar85850f32019-07-19 22:05:51 +02001879"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001880endfun
1881
1882" ---------------------------------------------------------------------
1883" NetrwStatusLine: {{{2
1884fun! NetrwStatusLine()
1885
1886" vvv NetrwStatusLine() debugging vvv
1887" let g:stlmsg=""
1888" if !exists("w:netrw_explore_bufnr")
1889" let g:stlmsg="!X<explore_bufnr>"
1890" elseif w:netrw_explore_bufnr != bufnr("%")
1891" let g:stlmsg="explore_bufnr!=".bufnr("%")
1892" endif
1893" if !exists("w:netrw_explore_line")
1894" let g:stlmsg=" !X<explore_line>"
1895" elseif w:netrw_explore_line != line(".")
1896" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
1897" endif
1898" if !exists("w:netrw_explore_list")
1899" let g:stlmsg=" !X<explore_list>"
1900" endif
1901" ^^^ NetrwStatusLine() debugging ^^^
1902
1903 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")
1904 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09001905 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02001906 let &laststatus = s:netrw_users_ls
1907 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
1908 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
1909 return ""
1910 else
1911 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
1912 endif
1913endfun
1914
Bram Moolenaar85850f32019-07-19 22:05:51 +02001915" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001916" Netrw Transfer Functions: {{{1
1917" ===============================
1918
Bram Moolenaar071d4272004-06-13 20:20:40 +00001919" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001920" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001921" mode: =0 read remote file and insert before current line
1922" =1 read remote file and insert after current line
1923" =2 replace with remote file
1924" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001925fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02001926" 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 +00001927
Bram Moolenaar5c736222010-01-06 20:54:52 +01001928 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02001929 call s:NetrwOptionsSave("w:")
1930 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001931 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001932 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
1933 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
1934 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02001935" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001936
Bram Moolenaar5c736222010-01-06 20:54:52 +01001937 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001938 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001939 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001940 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001941 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001942 elseif a:mode == 2 " replace with remote file
1943 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00001944 elseif a:mode == 3 " skip read of file (leave as temporary)
1945 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001946 else
1947 exe a:mode
1948 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001949 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001950 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001951" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001952
Bram Moolenaar5c736222010-01-06 20:54:52 +01001953 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00001954 let tmpfile= s:GetTempfile("")
1955 if tmpfile == ""
1956" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001957 return
1958 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001959
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001960 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001961
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001962 " attempt to repeat with previous host-file-etc
1963 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001964" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001965 let choice = b:netrw_lastfile
1966 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001967
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001968 else
1969 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001970" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001971
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001972 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001973 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001974 echomsg 'NetRead Usage:'
1975 echomsg ':Nread machine:path uses rcp'
1976 echomsg ':Nread "machine path" uses ftp with <.netrc>'
1977 echomsg ':Nread "machine id password path" uses ftp'
1978 echomsg ':Nread dav://machine[:port]/path uses cadaver'
1979 echomsg ':Nread fetch://machine/path uses fetch'
1980 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
1981 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001982 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01001983 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001984 echomsg ':Nread rcp://[user@]machine/path uses rcp'
1985 echomsg ':Nread rsync://machine[:port]/path uses rsync'
1986 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
1987 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00001988 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001989 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001990
Bram Moolenaar9964e462007-05-05 17:54:07 +00001991 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001992 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001993" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00001994 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001995 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02001996 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001997 else
1998 " case "... ... ..."
1999 let choice = strpart(choice,1,strlen(choice)-1)
2000 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002001
Bram Moolenaar9964e462007-05-05 17:54:07 +00002002 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002003 let wholechoice = wholechoice . " " . choice
2004 let ichoice = ichoice + 1
2005 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002006 if !exists("g:netrw_quiet")
2007 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2008 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002009" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002010 return
2011 endif
2012 let choice= a:{ichoice}
2013 endwhile
2014 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2015 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002016 endif
2017 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002018
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002019" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002020 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002021
Bram Moolenaar5c736222010-01-06 20:54:52 +01002022 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002023 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002024 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002025" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002026 return
2027 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002028 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002029
Bram Moolenaar8d043172014-01-23 14:24:41 +01002030 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002031" 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 +02002032 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002033" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002034 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002035" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002036 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002037 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002038
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002039 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002040 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002041 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002042 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2043 echo "(netrw) Processing your read request..."
2044 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002045
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002046 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002047 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002048 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002049" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002050 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002051 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002052 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002053 " ER: the tmpfile is full path: rcp sees C:\... as host C
2054 if s:netrw_has_nt_rcp == 1
2055 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2056 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2057 else
2058 " Any way needed it machine contains a '.'
2059 let uid_machine = g:netrw_machine .'.'. $USERNAME
2060 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002061 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002062 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2063 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2064 else
2065 let uid_machine = g:netrw_machine
2066 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002067 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002068 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 +00002069 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002070 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002071
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002072 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002073 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002074 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002075" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002076 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002077 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002078 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002079 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002080 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002081" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002082 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002083 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002084" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002085 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002086 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002087" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002088 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002089 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 +00002090 else
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))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002092 endif
2093 " 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 +00002094 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002095 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002096 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002097 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002098 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002099 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002100 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002101 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002102 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2103 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002104 q!
2105 endif
2106 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002107 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002108 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002109
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002110 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002111 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002112 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2113 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002114" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002115 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002116 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002117 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002118 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002119 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002120 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002121" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002122 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002123 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002124" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002125 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002126
Bram Moolenaar97d62492012-11-15 21:28:22 +01002127 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002128 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002129 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002130" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002131 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002132 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002133 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002134" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002135 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002136 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002137" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002138 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002139 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002140
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002141 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002142 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002143" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002144 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002145 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002146 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002147" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002148 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002149 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002150" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002151
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002152 " perform ftp:
2153 " -i : turns off interactive prompting from ftp
2154 " -n unix : DON'T use <.netrc>, even though it exists
2155 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002156 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002157 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002158 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2159 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002160" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002161 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002162 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002163 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002164 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002165 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002166 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002167 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002168
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002169 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002170 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002171 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002172" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002173 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002174 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002175 else
2176 let useport= ""
2177 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002178 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2179 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002180 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002181 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2182 else
2183 let tmpfile_get = tmpfile
2184 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002185 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 +00002186 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002187 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002188
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002189 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002190 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002191 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002192" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002193 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002194 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002195 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002196 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002197" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002198 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002199 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002200
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002201 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2202 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002203" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002204 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002205 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 +00002206 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002207 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 +00002208 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002209 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002210
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002211 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002212 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002213" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002214 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2215 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002216" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2217" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2218 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 +00002219 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002220" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002221 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002222 endif
2223 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002224" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002225 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002226
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002227 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002228 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002229 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002230" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002231
Bram Moolenaar5c736222010-01-06 20:54:52 +01002232 if !executable(g:netrw_dav_cmd)
2233 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2234" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2235 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002236 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002237 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002238 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 +01002239 else
2240 " Construct execution string (four lines) which will be passed through filter
2241 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2242 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002243 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002244 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002245 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002246 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002247 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002248 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002249 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002250 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002251 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002252 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2253 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002254
Bram Moolenaar5c736222010-01-06 20:54:52 +01002255 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002256 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002257 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002258 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002259 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002260 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002261 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002262
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002263 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002264 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002265 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002266" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002267 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 +00002268 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002269 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002270
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002271 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002272 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002273 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002274 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002275" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002276 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002277 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002278 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002279 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002280" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002281 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002282 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002283 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002284 let netrw_option= "http"
2285 else
2286 let netrw_option= "ftp"
2287 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002288" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002289
Bram Moolenaar446cb832008-06-24 21:56:24 +00002290 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002291 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 +00002292 else
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_machine."/".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002294 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002295
Bram Moolenaar446cb832008-06-24 21:56:24 +00002296 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002297 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002298" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002299 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002300
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002301 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002302 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002303 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002304" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2305 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 +00002306 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002307 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002308
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002309 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002310 " NetRead: (file) NetRead Method #10 {{{3
2311 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002312" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2313 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002314 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2315 let b:netrw_lastfile = choice
2316
2317 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002318 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002319 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002320 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002321 endif
2322 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002323
Bram Moolenaar5c736222010-01-06 20:54:52 +01002324 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002325 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002326" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002327 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002328 unlet b:netrw_fname
2329 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002330 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 +01002331" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002332 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002333 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002334 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002335
Bram Moolenaar9964e462007-05-05 17:54:07 +00002336" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002337endfun
2338
2339" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002340" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002341fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002342" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002343
Bram Moolenaar5c736222010-01-06 20:54:52 +01002344 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002345 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002346 call s:NetrwOptionsSave("w:")
2347 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002348
Bram Moolenaar5c736222010-01-06 20:54:52 +01002349 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002350 let tmpfile= s:GetTempfile("")
2351 if tmpfile == ""
2352" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002353 return
2354 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002355
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002356 if a:0 == 0
2357 let ichoice = 0
2358 else
2359 let ichoice = 1
2360 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002361
Bram Moolenaar9964e462007-05-05 17:54:07 +00002362 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002363" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002364 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002365 " For binary writes, always write entire file.
2366 " (line numbers don't really make sense for that).
2367 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002368" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002369 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002370 elseif g:netrw_cygwin
2371 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002372 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002373" 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 +01002374 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002375 else
2376 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002377" 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 +01002378 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002379 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002380
Bram Moolenaar9964e462007-05-05 17:54:07 +00002381 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002382 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002383 " on the temporary file's name. Deletion of the temporary file during
2384 " cleanup then causes an error message.
2385 0file!
2386 endif
2387
Bram Moolenaar5c736222010-01-06 20:54:52 +01002388 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002389 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002390
Bram Moolenaar9964e462007-05-05 17:54:07 +00002391 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002392 " attempt to repeat with previous host-file-etc
2393 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002394" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002395 let choice = b:netrw_lastfile
2396 let ichoice= ichoice + 1
2397 else
2398 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002399
Bram Moolenaar8d043172014-01-23 14:24:41 +01002400 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002401 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002402 echomsg 'NetWrite Usage:"'
2403 echomsg ':Nwrite machine:path uses rcp'
2404 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2405 echomsg ':Nwrite "machine id password path" uses ftp'
2406 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2407 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2408 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2409 echomsg ':Nwrite rcp://machine/path uses rcp'
2410 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2411 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2412 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002413 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002414 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002415
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002416 elseif match(choice,"^\"") != -1
2417 if match(choice,"\"$") != -1
2418 " case "..."
2419 let choice=strpart(choice,1,strlen(choice)-2)
2420 else
2421 " case "... ... ..."
2422 let choice = strpart(choice,1,strlen(choice)-1)
2423 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002424
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002425 while match(choice,"\"$") == -1
2426 let wholechoice= wholechoice . " " . choice
2427 let ichoice = ichoice + 1
2428 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002429 if !exists("g:netrw_quiet")
2430 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2431 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002432" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002433 return
2434 endif
2435 let choice= a:{ichoice}
2436 endwhile
2437 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2438 endif
2439 endif
2440 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002441 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002442" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002443
Bram Moolenaar9964e462007-05-05 17:54:07 +00002444 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002445 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002446 if !exists("b:netrw_method") || b:netrw_method < 0
2447" call Dfunc("netrw#NetWrite : unsupported method")
2448 return
2449 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002450
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002451 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002452 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002453 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002454 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2455 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002456" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002457 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002458
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002459 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002460 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002461 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002462" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002463 if s:netrw_has_nt_rcp == 1
2464 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2465 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2466 else
2467 let uid_machine = g:netrw_machine .'.'. $USERNAME
2468 endif
2469 else
2470 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2471 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2472 else
2473 let uid_machine = g:netrw_machine
2474 endif
2475 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002476 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 +00002477 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002478
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002479 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002480 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002481 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002482" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002483 let netrw_fname = b:netrw_fname
2484
2485 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2486 let bhkeep = &l:bh
2487 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002488 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002489 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002490
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002491" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002492 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002493 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002494" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002495 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002496 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002497" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002498 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002499 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002500" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002501 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002502 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 +00002503 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002504" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2505 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506 endif
2507 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2508 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002509 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002510 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002511 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002512 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002514
2515 " remove enew buffer (quietly)
2516 let filtbuf= bufnr("%")
2517 exe curbuf."b!"
2518 let &l:bh = bhkeep
2519 exe filtbuf."bw!"
2520
Bram Moolenaar071d4272004-06-13 20:20:40 +00002521 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002522
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002523 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002524 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002525 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002526 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002527" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002528 let netrw_fname = b:netrw_fname
2529 let bhkeep = &l:bh
2530
2531 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2532 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002533 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002534 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002535 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002536
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002537 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002538 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002539" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002540 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002541 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002542" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002543 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002544 if exists("g:netrw_uid") && g:netrw_uid != ""
2545 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002546 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002547" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002548 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002549 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002550 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002551" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002552 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002553 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002554" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002555 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002556 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002557 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002558" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002559 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002560 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002561" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002562 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002563 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002564" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002565 " save choice/id/password for future use
2566 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002567
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002568 " perform ftp:
2569 " -i : turns off interactive prompting from ftp
2570 " -n unix : DON'T use <.netrc>, even though it exists
2571 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002572 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002573 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002574 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2575 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002576 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002577 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002578 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002579 let mod=1
2580 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002581
2582 " remove enew buffer (quietly)
2583 let filtbuf= bufnr("%")
2584 exe curbuf."b!"
2585 let &l:bh= bhkeep
2586 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002587
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002588 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002589 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002590 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002591" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002592 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002593 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002594 else
2595 let useport= ""
2596 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002597 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 +00002598 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002599
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002600 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002601 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002602 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002603" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002604 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2605 if executable(curl)
2606 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002607 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 +01002608 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002609 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002610 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002611
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002612 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002613 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002614 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002615" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002616
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002617 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002618 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2619 let bhkeep = &l:bh
2620
2621 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2622 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002623 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002624 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002625
Bram Moolenaarff034192013-04-24 18:51:19 +02002626 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002627 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002628 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002629 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002630 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002631 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002632 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002633 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002634 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002635 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002636
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002637 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002638 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002639 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002640
2641 " remove enew buffer (quietly)
2642 let filtbuf= bufnr("%")
2643 exe curbuf."b!"
2644 let &l:bh = bhkeep
2645 exe filtbuf."bw!"
2646
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002647 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002648
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002649 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002650 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002651 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002652" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002653 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 +00002654 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002655
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002656 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002657 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002658 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002659" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002660 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2662 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2663 else
2664 let uid_machine = g:netrw_machine
2665 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002666
2667 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2668 let bhkeep = &l:bh
2669 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002670 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002671 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002672
Bram Moolenaarff034192013-04-24 18:51:19 +02002673 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002674 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002675" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002676 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002677 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002678 let filtbuf= bufnr("%")
2679 exe curbuf."b!"
2680 let &l:bh = bhkeep
2681 exe filtbuf."bw!"
2682 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002683
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002684 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002685 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002686 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002687 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002688 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002689 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002690 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002691
Bram Moolenaar5c736222010-01-06 20:54:52 +01002692 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002693" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002694 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002695" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002696 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002697 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002698 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002699
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002700 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002701 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002702 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002703" 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 +02002704 elseif !exists("leavemod")
2705 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002706" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002707 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002708" 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 +00002709 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002710
Bram Moolenaar9964e462007-05-05 17:54:07 +00002711" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002712endfun
2713
2714" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002715" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002716" uses NetRead to get a copy of the file into a temporarily file,
2717" then sources that file,
2718" then removes that file.
2719fun! netrw#NetSource(...)
2720" call Dfunc("netrw#NetSource() a:0=".a:0)
2721 if a:0 > 0 && a:1 == '?'
2722 " give help
2723 echomsg 'NetSource Usage:'
2724 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2725 echomsg ':Nsource fetch://machine/path uses fetch'
2726 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002727 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002728 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2729 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2730 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2731 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2732 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002733 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002734 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002735 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002736 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002737" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002738 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002739" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002740 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002741" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002742 if delete(s:netrw_tmpfile)
2743 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2744 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002745 unlet s:netrw_tmpfile
2746 else
2747 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2748 endif
2749 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002750 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002751 endif
2752" call Dret("netrw#NetSource")
2753endfun
2754
Bram Moolenaar8d043172014-01-23 14:24:41 +01002755" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002756" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2757" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002758fun! netrw#SetTreetop(iscmd,...)
Bram Moolenaara6878372014-03-22 21:02:50 +01002759
Bram Moolenaar85850f32019-07-19 22:05:51 +02002760 " iscmd==0: netrw#SetTreetop called using gn mapping
2761 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
Bram Moolenaar8d043172014-01-23 14:24:41 +01002762 " clear out the current tree
2763 if exists("w:netrw_treetop")
2764 let inittreetop= w:netrw_treetop
2765 unlet w:netrw_treetop
2766 endif
2767 if exists("w:netrw_treedict")
2768 unlet w:netrw_treedict
2769 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002770
Bram Moolenaar85850f32019-07-19 22:05:51 +02002771 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002772 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaar8d043172014-01-23 14:24:41 +01002773 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002774 if isdirectory(s:NetrwFile(a:1))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002775 let treedir = a:1
2776 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002777 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002778 let treedir = b:netrw_curdir."/".a:1
2779 let s:netrw_treetop = treedir
Bram Moolenaar8d043172014-01-23 14:24:41 +01002780 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002781 " normally the cursor is left in the message window.
2782 " However, here this results in the directory being listed in the message window, which is not wanted.
2783 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002784 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002785 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002786 let treedir = "."
2787 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002788 endif
2789 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002790
2791 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002792 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar85850f32019-07-19 22:05:51 +02002793
2794 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002795 if islocal
Tom Benham64a536d2024-11-07 21:15:03 +01002796 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir,0))
Bram Moolenaara6878372014-03-22 21:02:50 +01002797 else
Tom Benham64a536d2024-11-07 21:15:03 +01002798 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir,0))
Bram Moolenaara6878372014-03-22 21:02:50 +01002799 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002800
Bram Moolenaar8d043172014-01-23 14:24:41 +01002801endfun
2802
Bram Moolenaar9964e462007-05-05 17:54:07 +00002803" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002804" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002805" readcmd == %r : replace buffer with newly read file
2806" == 0r : read file at top of buffer
2807" == r : read file after current line
2808" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002809fun! s:NetrwGetFile(readcmd, tfile, method)
2810" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002811
2812 " readcmd=='t': simply do nothing
2813 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002814" 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 +01002815" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002816 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002817 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002818
Bram Moolenaar9964e462007-05-05 17:54:07 +00002819 " get name of remote filename (ie. url and all)
2820 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002821" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002822
Bram Moolenaar9964e462007-05-05 17:54:07 +00002823 if exists("*NetReadFixup")
2824 " for the use of NetReadFixup (not otherwise used internally)
2825 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002826 endif
2827
Bram Moolenaar9964e462007-05-05 17:54:07 +00002828 if a:readcmd[0] == '%'
2829 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002830" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002831
2832 " rename the current buffer to the temp file (ie. tfile)
2833 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002834 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002835 else
2836 let tfile= a:tfile
2837 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002838 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002839
2840 " edit temporary file (ie. read the temporary file in)
2841 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002842" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002843 call zip#Browse(tfile)
2844 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002845" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002846 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002847 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002848" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002849 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002850 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002851" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002852 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002853 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002854" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002855 call tar#Browse(tfile)
2856 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002857" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002858 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002859 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002860" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002861 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002862 endif
2863
2864 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002865 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002866
Bram Moolenaar71badf92023-04-22 22:40:14 +01002867 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002868 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002869 " Note that isk must not include a "/" for scripts.vim
2870 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002871" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2872" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002873" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002874" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
2875 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01002876 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01002877 filetype detect
2878" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09002879 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02002880" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002881 let line1 = 1
2882 let line2 = line("$")
2883
Bram Moolenaar8d043172014-01-23 14:24:41 +01002884 elseif !&ma
2885 " 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 +01002886 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002887" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002888 return
2889
Bram Moolenaar9964e462007-05-05 17:54:07 +00002890 elseif s:FileReadable(a:tfile)
2891 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002892" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002893 let curline = line(".")
2894 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002895" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002896 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002897 let line1= curline + 1
2898 let line2= line("$") - lastline + 1
2899
2900 else
2901 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002902" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
2903" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002904 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002905" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002906 return
2907 endif
2908
2909 " User-provided (ie. optional) fix-it-up command
2910 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002911" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002912 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002913" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002914" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002915 endif
2916
Bram Moolenaaradc21822011-04-01 18:03:16 +02002917 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00002918 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002919 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00002920 endif
2921
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002922" 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 +00002923
2924 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00002925" redraw!
2926
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002927" 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 +00002928" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002929endfun
2930
Bram Moolenaar9964e462007-05-05 17:54:07 +00002931" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002932" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01002933" Input:
2934" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
2935" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002936" b:netrw_method= 1: rcp
2937" 2: ftp + <.netrc>
2938" 3: ftp + machine, id, password, and [path]filename
2939" 4: scp
2940" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002941" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002942" 7: rsync
2943" 8: fetch
2944" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002945" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01002946" g:netrw_machine= hostname
2947" b:netrw_fname = filename
2948" g:netrw_port = optional port number (for ftp)
2949" g:netrw_choice = copy of input url (choice)
2950fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002951" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002952
Bram Moolenaar251e1912011-06-19 05:09:16 +02002953 " sanity check: choice should have at least three slashes in it
2954 if strlen(substitute(a:choice,'[^/]','','g')) < 3
2955 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
2956 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02002957" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02002958 return
2959 endif
2960
Bram Moolenaar5c736222010-01-06 20:54:52 +01002961 " record current g:netrw_machine, if any
2962 " curmachine used if protocol == ftp and no .netrc
2963 if exists("g:netrw_machine")
2964 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002965" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002966 else
2967 let curmachine= "N O T A HOST"
2968 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002969 if exists("g:netrw_port")
2970 let netrw_port= g:netrw_port
2971 endif
2972
2973 " insure that netrw_ftp_cmd starts off every method determination
2974 " with the current g:netrw_ftp_cmd
2975 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01002976
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002977 " initialization
2978 let b:netrw_method = 0
2979 let g:netrw_machine = ""
2980 let b:netrw_fname = ""
2981 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002982 let g:netrw_choice = a:choice
2983
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002984 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002985 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00002986 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
2987 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002988 " rcpurm : rcp://[user@]host/filename Use rcp
2989 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002990 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02002991 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01002992 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002993 " rsyncurm : rsync://host[:port]/path Use rsync
2994 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
2995 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002996 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002997 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
2998 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02002999 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3000 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003001 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003002 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003003 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003004 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003005 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003006 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003007 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003008 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003009
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003010" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003011 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003012 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003013 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003014" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003015 let b:netrw_method = 1
3016 let userid = substitute(a:choice,rcpurm,'\1',"")
3017 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3018 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003019 if userid != ""
3020 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003021 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003022
Bram Moolenaaradc21822011-04-01 18:03:16 +02003023 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003024 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003025" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003026 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003027 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3028 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3029 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003030
Bram Moolenaar15146672011-10-20 22:22:38 +02003031 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003032 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003033" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003034 let b:netrw_method = 5
3035 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3036 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003037 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003038
Bram Moolenaaradc21822011-04-01 18:03:16 +02003039 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003040 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003041" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003042 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003043 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003044 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3045 else
3046 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3047 endif
3048 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003049
Bram Moolenaaradc21822011-04-01 18:03:16 +02003050 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003051 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003052" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003053 let b:netrw_method = 7
3054 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3055 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003056
Bram Moolenaaradc21822011-04-01 18:03:16 +02003057 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003058 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003059" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003060 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003061 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3062 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3063 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003064" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003065 if userid != ""
3066 let g:netrw_uid= userid
3067 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003068
Bram Moolenaaradc21822011-04-01 18:03:16 +02003069 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003070 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003071 call NetUserPass("ftp:".g:netrw_machine)
3072 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003073 " if there's a change in hostname, require password re-entry
3074 unlet s:netrw_passwd
3075 endif
3076 if exists("netrw_port")
3077 unlet netrw_port
3078 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003079 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003080
Bram Moolenaar446cb832008-06-24 21:56:24 +00003081 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003082 let b:netrw_method = 3
3083 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003084 let host= substitute(g:netrw_machine,'\..*$','','')
3085 if exists("s:netrw_hup[host]")
3086 call NetUserPass("ftp:".host)
3087
Nir Lichtman1e34b952024-05-08 19:19:34 +02003088 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003089" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3090" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003091 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003092 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003093" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003094 endif
3095 let b:netrw_method= 2
3096 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003097" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003098 let b:netrw_method= 2
3099 else
3100 if !exists("g:netrw_uid") || g:netrw_uid == ""
3101 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003102 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003103 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003104 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003105 endif
3106 let b:netrw_method= 3
3107 endif
3108 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003109
Bram Moolenaaradc21822011-04-01 18:03:16 +02003110 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003111 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003112" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003113 let b:netrw_method = 8
3114 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3115 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3116 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3117 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003118
Bram Moolenaaradc21822011-04-01 18:03:16 +02003119 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003120 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003121" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003122 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003123 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3124 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003125 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003126 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003127 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003128
Bram Moolenaaradc21822011-04-01 18:03:16 +02003129 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003130 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003131" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003132 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003133 let b:netrw_method = 3
3134 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3135 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003136
Bram Moolenaar9964e462007-05-05 17:54:07 +00003137 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003138 let b:netrw_method = 2
3139 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3140 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3141 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003142
Bram Moolenaaradc21822011-04-01 18:03:16 +02003143 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003144 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003145" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003146 let b:netrw_method = 9
3147 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3148 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003149
Bram Moolenaaradc21822011-04-01 18:03:16 +02003150 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003151 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003152" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003153 let b:netrw_method = 1
3154 let userid = substitute(a:choice,rcphf,'\2',"")
3155 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3156 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003157" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3158" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3159" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3160" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003161 if userid != ""
3162 let g:netrw_uid= userid
3163 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003164
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003165 " Method#10: file://user@hostname/...path-to-file {{{3
3166 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003167" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003168 let b:netrw_method = 10
3169 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003170" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003171
Bram Moolenaaradc21822011-04-01 18:03:16 +02003172 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003173 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003174 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003175 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003176 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003177 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003178 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003179 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003180
Bram Moolenaar81695252004-12-29 20:58:21 +00003181 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003182 " remove any leading [:#] from port number
3183 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3184 elseif exists("netrw_port")
3185 " retain port number as implicit for subsequent ftp operations
3186 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003187 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003188
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003189" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3190" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3191" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3192" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003193" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003194" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003195" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003196" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003197" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003198" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003199" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003200" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202
Bram Moolenaar9964e462007-05-05 17:54:07 +00003203" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003204" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003205" Usage: :call NetUserPass() -- will prompt for userid and password
3206" :call NetUserPass("uid") -- will prompt for password
3207" :call NetUserPass("uid","password") -- sets global userid and password
3208" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3209" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003210fun! NetUserPass(...)
3211
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003212" call Dfunc("NetUserPass() a:0=".a:0)
3213
3214 if !exists('s:netrw_hup')
3215 let s:netrw_hup= {}
3216 endif
3217
Bram Moolenaar071d4272004-06-13 20:20:40 +00003218 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003219 " case: no input arguments
3220
3221 " change host and username if not previously entered; get new password
3222 if !exists("g:netrw_machine")
3223 let g:netrw_machine= input('Enter hostname: ')
3224 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003225 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003226 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227 let g:netrw_uid= input('Enter username: ')
3228 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003229 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003230 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003231
3232 " set up hup database
3233 let host = substitute(g:netrw_machine,'\..*$','','')
3234 if !exists('s:netrw_hup[host]')
3235 let s:netrw_hup[host]= {}
3236 endif
3237 let s:netrw_hup[host].uid = g:netrw_uid
3238 let s:netrw_hup[host].passwd = s:netrw_passwd
3239
3240 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003241 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003242
3243 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003244 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003245 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003246" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003247 let host = substitute(a:1,'^ftp:','','')
3248 let host = substitute(host,'\..*','','')
3249 if exists("s:netrw_hup[host]")
3250 let g:netrw_uid = s:netrw_hup[host].uid
3251 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003252" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3253" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003254 else
3255 let g:netrw_uid = input("Enter UserId: ")
3256 let s:netrw_passwd = inputsecret("Enter Password: ")
3257 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003258
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003259 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003260 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003261" 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 +02003262 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003263 if g:netrw_machine =~ '[0-9.]\+'
3264 let host= g:netrw_machine
3265 else
3266 let host= substitute(g:netrw_machine,'\..*$','','')
3267 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003268 else
3269 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003270 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003271 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003272" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003273 if exists("g:netrw_passwd")
3274 " ask for password if one not previously entered
3275 let s:netrw_passwd= g:netrw_passwd
3276 else
3277 let s:netrw_passwd = inputsecret("Enter Password: ")
3278 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003279 endif
3280
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003281" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003282 if exists("host")
3283 if !exists('s:netrw_hup[host]')
3284 let s:netrw_hup[host]= {}
3285 endif
3286 let s:netrw_hup[host].uid = g:netrw_uid
3287 let s:netrw_hup[host].passwd = s:netrw_passwd
3288 endif
3289
3290 elseif a:0 == 2
3291 let g:netrw_uid = a:1
3292 let s:netrw_passwd = a:2
3293
3294 elseif a:0 == 3
3295 " enter hostname, user-id, and password into the hup dictionary
3296 let host = substitute(a:1,'^\a\+:','','')
3297 let host = substitute(host,'\..*$','','')
3298 if !exists('s:netrw_hup[host]')
3299 let s:netrw_hup[host]= {}
3300 endif
3301 let s:netrw_hup[host].uid = a:2
3302 let s:netrw_hup[host].passwd = a:3
3303 let g:netrw_uid = s:netrw_hup[host].uid
3304 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003305" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3306" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003307 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003308
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003309" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003310endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311
Bram Moolenaar85850f32019-07-19 22:05:51 +02003312" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003313" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003314" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003315
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003316" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003317" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3318fun! s:ExplorePatHls(pattern)
3319" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3320 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003321" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003322 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003323" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003324 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3325" call Dret("s:ExplorePatHls repat<".repat.">")
3326 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003327endfun
3328
3329" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003330" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003331" 0: (user: <mb>) bookmark current directory
3332" 1: (user: <gb>) change to the bookmarked directory
3333" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003334" 3: (browsing) records current directory history
3335" 4: (user: <u>) go up (previous) directory, using history
3336" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003337" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003338fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003339" 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 +02003340 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3341" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3342 return
3343 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003344
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003345 let ykeep = @@
3346 let curbufnr = bufnr("%")
3347
Bram Moolenaar9964e462007-05-05 17:54:07 +00003348 if a:chg == 0
3349 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003350" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003351 if exists("s:netrwmarkfilelist_{curbufnr}")
3352 call s:NetrwBookmark(0)
3353 echo "bookmarked marked files"
3354 else
3355 call s:MakeBookmark(a:curdir)
3356 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003357 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003358
KSR-Yasudaf4498252023-10-06 03:34:17 +09003359 try
3360 call s:NetrwBookHistSave()
3361 catch
3362 endtry
3363
Bram Moolenaar9964e462007-05-05 17:54:07 +00003364 elseif a:chg == 1
3365 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003366" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003367 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003368" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003369 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003370 else
3371 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3372 endif
3373
3374 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003375" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003376 let didwork= 0
3377 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003378" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003379 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003380" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003381 let cnt= 1
3382 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003383" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003384 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003385 let didwork = 1
3386 let cnt = cnt + 1
3387 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003388 endif
3389
3390 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003391 " Note: history is saved only when PerformListing is done;
3392 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3393 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003394 let first = 1
3395 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003396 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003397 while ( first || cnt != g:netrw_dirhistcnt )
3398" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003399 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003400" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003401 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003402 let didwork= 1
3403 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003404 let histcnt = histcnt + 1
3405 let first = 0
3406 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003407 if cnt < 0
3408 let cnt= cnt + g:netrw_dirhistmax
3409 endif
3410 endwhile
3411 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003412 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003413 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003414 if didwork
3415 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3416 endif
3417
3418 elseif a:chg == 3
3419 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003420" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003421 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 +02003422 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003423 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3424 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003425 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003426" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003427 endif
3428
3429 elseif a:chg == 4
3430 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003431" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003432 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003433 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3434 if g:netrw_dirhistcnt < 0
3435 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003436 endif
3437 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003438 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003439 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003440 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3441" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003442 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003443 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003444" call Decho("setl ma noro",'~'.expand("<slnum>"))
3445 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003446 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003447" call Decho("setl nomod",'~'.expand("<slnum>"))
3448" 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 +00003449 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003450" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3451 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003452 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003453 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003454 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003455 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003456 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003457 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003458 echo "Sorry, no predecessor directory exists yet"
3459 endif
3460
3461 elseif a:chg == 5
3462 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003463" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003464 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003465 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3466 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3467" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003468 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003469" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003470 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003471 sil! NetrwKeepj %d _
3472" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3473" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003474 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003475" 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 +02003476 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003477" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3478 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003479 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003480 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3481 if g:netrw_dirhistcnt < 0
3482 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003483 endif
3484 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003485 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003486 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003487 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003488 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003489 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003490
3491 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003492" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003493 if exists("s:netrwmarkfilelist_{curbufnr}")
3494 call s:NetrwBookmark(1)
3495 echo "removed marked files from bookmarks"
3496 else
3497 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003498 let iremove = v:count
3499 let dremove = g:netrw_bookmarklist[iremove - 1]
3500" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003501 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003502" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3503 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3504 echo "removed ".dremove." from g:netrw_bookmarklist"
3505" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003506 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003507" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003508
3509 try
3510 call s:NetrwBookHistSave()
3511 catch
3512 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003513 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003514 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003515 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003516 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003517" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003518endfun
3519
3520" ---------------------------------------------------------------------
3521" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003522" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003523" Sister function: s:NetrwBookHistSave()
3524fun! s:NetrwBookHistRead()
3525" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003526 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003527" 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 +02003528 return
3529 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003530 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003531
3532 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003533 if !exists("s:netrw_initbookhist")
3534 let home = s:NetrwHome()
3535 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003536 if filereadable(s:NetrwFile(savefile))
3537" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003538 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003539 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003540
3541 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003542 if g:netrw_dirhistmax > 0
3543 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003544 if filereadable(s:NetrwFile(savefile))
3545" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003546 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003547 endif
3548 let s:netrw_initbookhist= 1
3549 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003550 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003551 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003552
Bram Moolenaar97d62492012-11-15 21:28:22 +01003553 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003554" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3555" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003556" call Dret("s:NetrwBookHistRead")
3557endfun
3558
3559" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003560" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003561" Sister function: s:NetrwBookHistRead()
3562" I used to do this via viminfo but that appears to
3563" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003564" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3565" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003566" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003567fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003568" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003569 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003570" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003571 return
3572 endif
3573
Bram Moolenaar5c736222010-01-06 20:54:52 +01003574 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003575" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003576 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003577
3578 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003579 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003580" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003581 if g:netrw_use_noswf
3582 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3583 else
3584 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3585 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003586 setl nocin noai noci magic nospell nohid wig= noaw
3587 setl ma noro write
3588 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003589 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003590
Bram Moolenaar85850f32019-07-19 22:05:51 +02003591 " rename enew'd file: .netrwhist -- no attempt to merge
3592 " record dirhistmax and current dirhistcnt
3593 " save history
3594" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003595 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003596 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003597 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3598 if g:netrw_dirhistmax > 0
3599 let lastline = line("$")
3600 let cnt = g:netrw_dirhistcnt
3601 let first = 1
3602 while ( first || cnt != g:netrw_dirhistcnt )
3603 let lastline= lastline + 1
3604 if exists("g:netrw_dirhist_{cnt}")
3605 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3606" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3607 endif
3608 let first = 0
3609 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3610 if cnt < 0
3611 let cnt= cnt + g:netrw_dirhistmax
3612 endif
3613 endwhile
3614 exe "sil! w! ".savefile
3615" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3616 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003617
Bram Moolenaar85850f32019-07-19 22:05:51 +02003618 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003619 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003620 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003621" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003622 " merge and write .netrwbook
3623 let savefile= s:NetrwHome()."/.netrwbook"
3624
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003625 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003626 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003627 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003628 for bdm in booklist
3629 if index(g:netrw_bookmarklist,bdm) == -1
3630 call add(g:netrw_bookmarklist,bdm)
3631 endif
3632 endfor
3633 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003634 endif
3635
3636 " construct and save .netrwbook
3637 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003638 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003639" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003640 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003641
3642 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003643 let bgone= bufnr("%")
3644 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003645 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003646
3647" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003648endfun
3649
3650" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003651" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3652" list of the contents of a local or remote directory. It is assumed that the
3653" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3654" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003655" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003656fun! s:NetrwBrowse(islocal,dirname)
3657 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaara6878372014-03-22 21:02:50 +01003658
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003659 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3660 " This is useful when one edits a local file, then :e ., then :Rex
3661 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3662 let w:netrw_rexfile= bufname("#")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003663 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003664
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003665 " s:NetrwBrowse : initialize history {{{3
3666 if !exists("s:netrw_initbookhist")
3667 NetrwKeepj call s:NetrwBookHistRead()
3668 endif
3669
3670 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003671 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003672 let dirname= simplify(a:dirname)
3673 else
3674 let dirname= a:dirname
3675 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003676
Bram Moolenaar85850f32019-07-19 22:05:51 +02003677 " repoint t:netrw_lexbufnr if appropriate
3678 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02003679 let repointlexbufnr= 1
3680 endif
3681
3682 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003683 if exists("s:netrw_skipbrowse")
3684 unlet s:netrw_skipbrowse
Bram Moolenaar446cb832008-06-24 21:56:24 +00003685 return
3686 endif
3687 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003688 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003689 return
3690 endif
3691 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003692 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003693 return
3694 endif
3695
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003696 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003697 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003698
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003699 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003700 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3701 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaar85850f32019-07-19 22:05:51 +02003702 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3703 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003704 endif
3705
3706 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003707 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003708 if s:NetrwLcd(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003709 return
3710 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003711
Bram Moolenaar5c736222010-01-06 20:54:52 +01003712 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003713 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003714 if bufname(dirname) != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003715 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003716 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003717 " attempt transfer of remote regular file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003718
3719 " remove any filetype indicator from end of dirname, except for the
3720 " "this is a directory" indicator (/).
3721 " There shouldn't be one of those here, anyway.
3722 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003723 call s:RemotePathAnalysis(dirname)
3724
3725 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3726 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003727 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003728 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003729 let b:netrw_curdir = dirname
3730 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003731 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003732 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3733 sil call netrw#NetRead(2,url)
3734 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003735 if s:path =~ '.bz2'
3736 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3737 elseif s:path =~ '.gz'
3738 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3739 elseif s:path =~ '.gz'
3740 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3741 else
3742 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3743 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003744 endif
3745
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003746 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003747 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003748 call s:NetrwOptionsRestore("w:")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003749 setl ma nomod noro
Bram Moolenaar446cb832008-06-24 21:56:24 +00003750 return
3751 endif
3752
Bram Moolenaaradc21822011-04-01 18:03:16 +02003753 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003754 call s:UseBufWinVars()
3755
3756 " set up some variables {{{3
3757 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003758 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003759 let s:last_sort_by = g:netrw_sort_by
3760
3761 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003762 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003763
Bram Moolenaar97d62492012-11-15 21:28:22 +01003764 " get/set-up buffer {{{3
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003765 let svpos = winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01003766
3767 " NetrwGetBuffer might change buffers but s:rexposn_X was set for the
3768 " previous buffer
3769 let prevbufnr = bufnr('%')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003770 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Tom Benham64a536d2024-11-07 21:15:03 +01003771 if exists("s:rexposn_".prevbufnr)
3772 let s:rexposn_{bufnr('%')} = s:rexposn_{prevbufnr}
3773 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003774
Bram Moolenaar446cb832008-06-24 21:56:24 +00003775 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003776 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3777 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02003778 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3779 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003780 2match none
3781 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003782 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003783 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003784 call s:NetrwOptionsRestore("w:")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003785 setl noma nomod nowrap
Bram Moolenaar446cb832008-06-24 21:56:24 +00003786 return
3787 endif
3788
3789 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003790 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003791 if b:netrw_curdir =~ '[/\\]$'
3792 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3793 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003794 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003795 let b:netrw_curdir= b:netrw_curdir."/"
3796 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003797 if b:netrw_curdir == ''
3798 if has("amiga")
3799 " On the Amiga, the empty string connotes the current directory
3800 let b:netrw_curdir= getcwd()
3801 else
3802 " under unix, when the root directory is encountered, the result
3803 " from the preceding substitute is an empty string.
3804 let b:netrw_curdir= '/'
3805 endif
3806 endif
3807 if !a:islocal && b:netrw_curdir !~ '/$'
3808 let b:netrw_curdir= b:netrw_curdir.'/'
3809 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003810
3811 " ------------
3812 " (local only) {{{3
3813 " ------------
3814 if a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00003815 " Set up ShellCmdPost handling. Append current buffer to browselist
3816 call s:LocalFastBrowser()
3817
3818 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3819 if !g:netrw_keepdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003820 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003821 if s:NetrwLcd(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003822 return
3823 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003824 endif
3825 endif
3826
3827 " --------------------------------
3828 " remote handling: {{{3
3829 " --------------------------------
3830 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00003831
Bram Moolenaar97d62492012-11-15 21:28:22 +01003832 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003833 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003834 let dirname= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003835 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3836 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3837 if dirname !~ '/$'
3838 let dirname= dirname.'/'
3839 endif
3840 let b:netrw_curdir = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003841 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003842 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003843 endif
3844
3845 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
3846 if dirname !~ dirpat
3847 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003848 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003849 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003850 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003851 setl noma nomod nowrap
Bram Moolenaar446cb832008-06-24 21:56:24 +00003852 return
3853 endif
3854 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003855 endif " (additional remote handling)
3856
Bram Moolenaar85850f32019-07-19 22:05:51 +02003857 " -------------------------------
3858 " Perform Directory Listing: {{{3
3859 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003860 NetrwKeepj call s:NetrwMaps(a:islocal)
3861 NetrwKeepj call s:NetrwCommands(a:islocal)
3862 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003863
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003864 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003865 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003866
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003867 " If there is a rexposn: restore position with rexposn
3868 " Otherwise : set rexposn
3869 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003870 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
3871 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
3872 NetrwKeepj exe w:netrw_bannercnt
3873 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003874 else
3875 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
3876 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02003877 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01003878 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara6878372014-03-22 21:02:50 +01003879 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02003880 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003881
Bram Moolenaar85850f32019-07-19 22:05:51 +02003882 " repoint t:netrw_lexbufnr if appropriate
3883 if exists("repointlexbufnr")
3884 let t:netrw_lexbufnr= bufnr("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02003885 endif
3886
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003887 " restore position
3888 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003889 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003890 endif
3891
Bram Moolenaara6878372014-03-22 21:02:50 +01003892 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003893 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
3894 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaar446cb832008-06-24 21:56:24 +00003895 return
3896endfun
3897
3898" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003899" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
3900" may not apply correctly; ie. netrw's idea of the current directory may
3901" differ from vim's. This function insures that netrw's idea of the current
3902" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003903" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003904fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003905" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
3906" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
3907" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
3908" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
3909" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003910
3911 " clean up any leading treedepthstring
3912 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
3913 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02003914" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003915 else
3916 let fname= a:fname
3917 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003918
3919 if g:netrw_keepdir
3920 " vim's idea of the current directory possibly may differ from netrw's
3921 if !exists("b:netrw_curdir")
3922 let b:netrw_curdir= getcwd()
3923 endif
3924
Nir Lichtman1e34b952024-05-08 19:19:34 +02003925 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003926 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003927 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003928 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003929" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003930 else
3931 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003932 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003933" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003934 endif
3935
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003936 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003937 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003938 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003939" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003940 else
3941 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003942 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003943" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003944 endif
3945 else
3946 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003947 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003948" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
3949" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
3950" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003951 endif
3952
Bram Moolenaar85850f32019-07-19 22:05:51 +02003953" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003954 return ret
3955endfun
3956
3957" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003958" s:NetrwFileInfo: supports qf (query for file information) {{{2
3959fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01003960" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01003961 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00003962 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003963 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003964 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003965 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003966 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003967 let lsopt= "-lsadh --si"
3968 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02003969" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003970 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003971
3972 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003973 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003974" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003975
Bram Moolenaara6878372014-03-22 21:02:50 +01003976 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003977 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003978" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003979
3980 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003981 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003982" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003983
Bram Moolenaar446cb832008-06-24 21:56:24 +00003984 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003985" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003986 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003987" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003988 endif
3989 else
3990 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003991" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
3992 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003993 let fname= substitute(a:fname,".$","","")
3994 else
3995 let fname= a:fname
3996 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003997 let t = getftime(s:NetrwFile(fname))
3998 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003999 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004000 let sz= s:NetrwHumanReadable(sz)
4001 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004002 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4003" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004004 endif
4005 else
4006 echo "sorry, \"qf\" not supported yet for remote files"
4007 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004008 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004009" call Dret("s:NetrwFileInfo")
4010endfun
4011
4012" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004013" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4014fun! s:NetrwFullPath(filename)
4015" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4016 let filename= a:filename
4017 if filename !~ '^/'
4018 let filename= resolve(getcwd().'/'.filename)
4019 endif
4020 if filename != "/" && filename =~ '/$'
4021 let filename= substitute(filename,'/$','','')
4022 endif
4023" " call Dret("s:NetrwFullPath <".filename.">")
4024 return filename
4025endfun
4026
4027" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004028" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004029" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004030" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004031" 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 +00004032fun! s:NetrwGetBuffer(islocal,dirname)
4033" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004034" 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 +02004035" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4036" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004037 let dirname= a:dirname
4038
4039 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004040" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004041 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004042" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004043 let s:netrwbuf= {}
4044 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004045" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4046" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4047
4048 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4049 let bufnum = -1
4050
4051 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4052 if has_key(s:netrwbuf,"NetrwTreeListing")
4053 let bufnum= s:netrwbuf["NetrwTreeListing"]
4054 else
4055 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4056 endif
4057" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4058 if !bufexists(bufnum)
Peter Aronoffbe551da2024-09-22 11:29:40 +02004059 call remove(s:netrwbuf,"NetrwTreeListing")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004060 let bufnum= -1
4061 endif
4062 elseif bufnr("NetrwTreeListing") != -1
4063 let bufnum= bufnr("NetrwTreeListing")
4064" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4065 else
4066" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4067 let bufnum= -1
4068 endif
4069
4070 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004071 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004072" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004073 if !bufexists(bufnum)
4074 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4075 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004076 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004077
Bram Moolenaar446cb832008-06-24 21:56:24 +00004078 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004079" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004080 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004081 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004082" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4083
Bram Moolenaar71badf92023-04-22 22:40:14 +01004084 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004085 " IF the buffer already has the desired name
4086 " AND it is empty
4087 let curbuf = bufname("%")
4088 if curbuf == '.'
4089 let curbuf = getcwd()
4090 endif
4091" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004092" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004093" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4094" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4095" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4096" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4097 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004098" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4099 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004100 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004101" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004102 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004103 " 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 +00004104
4105 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004106 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004107" 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 +00004108 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004109" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004110 " name the buffer
4111 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4112 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004113" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004114 let w:netrw_treebufnr = bufnr("%")
4115 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004116 if g:netrw_use_noswf
4117 setl nobl bt=nofile noswf
4118 else
4119 setl nobl bt=nofile
4120 endif
4121 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4122 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4123 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4124 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004125" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004126 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004127 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004128 " enter the new buffer into the s:netrwbuf dictionary
4129 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4130" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4131" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004132 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004133" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004134
4135 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004136" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004137 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004138 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004139 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004140
4141 if &ft == "netrw"
4142" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4143 exe "sil! NetrwKeepj noswapfile b ".bufnum
4144" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004145 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004146" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4147 call s:NetrwEditBuf(bufnum)
4148" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004149 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004150" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004151 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004152 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004153 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004154
4155 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004156 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004157
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004158 if line("$") <= 1 && getline(1) == ""
4159 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004160 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004161" 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>"))
4162" 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 +01004163" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4164 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004165
Bram Moolenaar97d62492012-11-15 21:28:22 +01004166 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004167" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004168 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004169 sil NetrwKeepj %d _
4170" 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>"))
4171" 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 +01004172" 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 +00004173 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004174
Bram Moolenaar446cb832008-06-24 21:56:24 +00004175 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004176" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4177" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004178 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004179 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004180 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004181" 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>"))
4182" 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 +01004183" 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 +00004184 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004185
Bram Moolenaar446cb832008-06-24 21:56:24 +00004186 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004187" 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>"))
4188" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4189" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004190 return 1
4191 endif
4192 endif
4193
4194 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4195 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4196 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4197 " med 1 D H
4198 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004199" 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 +00004200 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004201 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004202 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004203
4204 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004205" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4206" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4207 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004208
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004209" 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>"))
4210" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4211" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004212 return 0
4213endfun
4214
4215" ---------------------------------------------------------------------
4216" s:NetrwGetcwd: get the current directory. {{{2
4217" Change backslashes to forward slashes, if any.
4218" If doesc is true, escape certain troublesome characters
4219fun! s:NetrwGetcwd(doesc)
4220" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4221 let curdir= substitute(getcwd(),'\\','/','ge')
4222 if curdir !~ '[\/]$'
4223 let curdir= curdir.'/'
4224 endif
4225 if a:doesc
4226 let curdir= fnameescape(curdir)
4227 endif
4228" call Dret("NetrwGetcwd <".curdir.">")
4229 return curdir
4230endfun
4231
4232" ---------------------------------------------------------------------
4233" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4234fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004235" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4236" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4237 let keepsol= &l:sol
4238 setl nosol
4239
Bram Moolenaar446cb832008-06-24 21:56:24 +00004240 call s:UseBufWinVars()
4241
4242 " insure that w:netrw_liststyle is set up
4243 if !exists("w:netrw_liststyle")
4244 if exists("g:netrw_liststyle")
4245 let w:netrw_liststyle= g:netrw_liststyle
4246 else
4247 let w:netrw_liststyle= s:THINLIST
4248 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004249" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004250 endif
4251
4252 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4253 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004254" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004255 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004256 let dirname= "./"
4257 let curline= getline('.')
4258
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004259 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004260 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004261 let s:netrw_skipbrowse= 1
4262 echo 'Pressing "s" also works'
4263
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004264 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004265 let s:netrw_skipbrowse= 1
4266 echo 'Press "S" to edit sorting sequence'
4267
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004268 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004269 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004270 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004271
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004272 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004273 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004274 let s:netrw_skipbrowse= 1
4275 echo 'Pressing "a" also works'
4276
4277 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004278 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004279 endif
4280
4281 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004282" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004283 NetrwKeepj norm! 0
4284 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004285
4286 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004287" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004288 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004289 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4290
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004291 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004292" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004293 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004294 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004295
4296 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004297" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004298 let dirname= getline('.')
4299
4300 if !exists("b:netrw_cpf")
4301 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004302 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 +01004303 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004304" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004305 endif
4306
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004307" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004308 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004309" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4310" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004311 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004312 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004313 else
4314 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004315 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004316 endif
Enno3146d632024-07-04 19:44:42 +02004317
4318 let dict={}
4319 " save the unnamed register and register 0-9 and a
4320 let dict.a=[getreg('a'), getregtype('a')]
4321 for i in range(0, 9)
4322 let dict[i] = [getreg(i), getregtype(i)]
4323 endfor
4324 let dict.unnamed = [getreg(''), getregtype('')]
4325
Bram Moolenaarc236c162008-07-13 17:41:49 +00004326 let eofname= filestart + b:netrw_cpf + 1
4327 if eofname <= col("$")
4328 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004329 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004330 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004331 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004332 endif
Enno3146d632024-07-04 19:44:42 +02004333
Bram Moolenaar446cb832008-06-24 21:56:24 +00004334 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004335 call s:RestoreRegister(dict)
4336
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004337" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004338 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004339" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004340 endif
4341
4342 " symlinks are indicated by a trailing "@". Remove it before further processing.
4343 let dirname= substitute(dirname,"@$","","")
4344
4345 " executables are indicated by a trailing "*". Remove it before further processing.
4346 let dirname= substitute(dirname,"\*$","","")
4347
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004348 let &l:sol= keepsol
4349
Bram Moolenaar446cb832008-06-24 21:56:24 +00004350" call Dret("s:NetrwGetWord <".dirname.">")
4351 return dirname
4352endfun
4353
4354" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004355" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4356" g:netrw_bufsettings will be used after the listing is produced.
4357" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004358fun! s:NetrwListSettings(islocal)
4359" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004360" 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 +00004361 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004362" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4363 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4364 setl bt=nofile nobl ma nonu nowrap noro nornu
4365 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004366 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004367 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004368 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004369" call Dredir("ls!","s:NetrwListSettings")
4370" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004371 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004372 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004373 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004374 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004375 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004376 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004377 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004378" 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 +00004379" call Dret("s:NetrwListSettings")
4380endfun
4381
4382" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004383" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004384" islocal=0: remote browsing
4385" =1: local browsing
4386fun! s:NetrwListStyle(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004387 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004388 let fname = s:NetrwGetWord()
4389 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004390 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004391 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00004392
Bram Moolenaar85850f32019-07-19 22:05:51 +02004393 " repoint t:netrw_lexbufnr if appropriate
4394 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02004395 let repointlexbufnr= 1
4396 endif
4397
Bram Moolenaar446cb832008-06-24 21:56:24 +00004398 if w:netrw_liststyle == s:THINLIST
4399 " use one column listing
Bram Moolenaar446cb832008-06-24 21:56:24 +00004400 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4401
4402 elseif w:netrw_liststyle == s:LONGLIST
4403 " use long list
Bram Moolenaar446cb832008-06-24 21:56:24 +00004404 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4405
4406 elseif w:netrw_liststyle == s:WIDELIST
4407 " give wide list
Bram Moolenaar446cb832008-06-24 21:56:24 +00004408 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4409
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004410 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00004411 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4412
4413 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004414 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004415 let g:netrw_liststyle = s:THINLIST
4416 let w:netrw_liststyle = g:netrw_liststyle
4417 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4418 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004419 setl ma noro
Bram Moolenaar446cb832008-06-24 21:56:24 +00004420
4421 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004422 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004423 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004424 setl nomod
Bram Moolenaar446cb832008-06-24 21:56:24 +00004425
4426 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01004427 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004428 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004429
Bram Moolenaar85850f32019-07-19 22:05:51 +02004430 " repoint t:netrw_lexbufnr if appropriate
4431 if exists("repointlexbufnr")
4432 let t:netrw_lexbufnr= bufnr("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004433 endif
4434
Bram Moolenaar13600302014-05-22 18:26:40 +02004435 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004436" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4437 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004438 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004439
Bram Moolenaar446cb832008-06-24 21:56:24 +00004440endfun
4441
4442" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004443" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4444fun! s:NetrwBannerCtrl(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004445 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004446 " toggle the banner (enable/suppress)
4447 let g:netrw_banner= !g:netrw_banner
4448
4449 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004450 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01004451 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004452
4453 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004454 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4455 let fname= s:NetrwGetWord()
4456 sil NetrwKeepj $
4457 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4458" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4459 if result <= 0 && exists("w:netrw_bannercnt")
4460 exe "NetrwKeepj ".w:netrw_bannercnt
4461 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004462 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004463 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004464" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4465endfun
4466
4467" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004468" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4469"
4470" No bang: enters files/directories into Netrw's bookmark system
4471" No argument and in netrw buffer:
4472" if there are marked files: bookmark marked files
4473" otherwise : bookmark file/directory under cursor
4474" No argument and not in netrw buffer: bookmarks current open file
4475" Has arguments: globs them individually and bookmarks them
4476"
4477" With bang: deletes files/directories from Netrw's bookmark system
4478fun! s:NetrwBookmark(del,...)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004479 if a:0 == 0
4480 if &ft == "netrw"
4481 let curbufnr = bufnr("%")
4482
4483 if exists("s:netrwmarkfilelist_{curbufnr}")
4484 " for every filename in the marked list
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004485 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004486 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004487 for fname in s:netrwmarkfilelist_{curbufnr}
4488 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4489 endfor
4490 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4491 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01004492 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004493 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004494 else
4495 let fname= s:NetrwGetWord()
4496 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4497 endif
4498
4499 else
4500 " bookmark currently open file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004501 let fname= expand("%")
4502 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4503 endif
4504
4505 else
4506 " bookmark specified files
4507 " attempts to infer if working remote or local
4508 " by deciding if the current file begins with an url
4509 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004510 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004511 let i = 1
4512 while i <= a:0
4513 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004514 if v:version > 704 || (v:version == 704 && has("patch656"))
4515 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004516 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004517 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004518 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004519 else
4520 let mbfiles= [a:{i}]
4521 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004522 for mbfile in mbfiles
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004523 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4524 endfor
4525 let i= i + 1
4526 endwhile
4527 endif
4528
4529 " update the menu
4530 call s:NetrwBookmarkMenu()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004531endfun
4532
4533" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004534" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4535" .2.[cnt] for bookmarks, and
4536" .3.[cnt] for history
4537" (see s:NetrwMenu())
4538fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004539 if !exists("s:netrw_menucnt")
4540 return
4541 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004542" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004543
4544 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004545 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004546 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004547" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004548 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4549 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004550 endif
4551 if !exists("s:netrw_initbookhist")
4552 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004553 endif
4554
4555 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004556 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004557 let cnt= 1
4558 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004559" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004560 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004561
4562 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004563 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004564
4565 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004566 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 +01004567 let cnt= cnt + 1
4568 endfor
4569
4570 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004571
4572 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004573 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004574 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004575 let first = 1
4576 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004577 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004578 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004579 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004580 if exists("g:netrw_dirhist_{cnt}")
4581 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004582" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004583 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4584 endif
4585 let first = 0
4586 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4587 if cnt < 0
4588 let cnt= cnt + g:netrw_dirhistmax
4589 endif
4590 endwhile
4591 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004592
Bram Moolenaar9964e462007-05-05 17:54:07 +00004593 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004594" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004595endfun
4596
4597" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004598" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4599" directory and a new directory name. Also, if the
4600" "new directory name" is actually a file,
4601" NetrwBrowseChgDir() edits the file.
Tom Benham64a536d2024-11-07 21:15:03 +01004602" cursor=0: newdir is relative to b:netrw_curdir
4603" =1: newdir is relative to the path to the word under the cursor in
4604" tree view
4605fun! s:NetrwBrowseChgDir(islocal,newdir,cursor,...)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004606 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004607 if !exists("b:netrw_curdir")
4608 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4609 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004610 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004611 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004612 endif
4613
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004614 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02004615 call s:SavePosn(s:netrw_posn)
4616 NetrwKeepj call s:NetrwOptionsSave("s:")
4617 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Tom Benham64a536d2024-11-07 21:15:03 +01004618
4619 let newdir = a:newdir
4620 if a:cursor && exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treetop")
4621 " dirname is the path to the word under the cursor
4622 let dirname = s:NetrwTreePath(w:netrw_treetop)
Christian Brabandt5b63b232024-11-10 20:22:34 +01004623 " newdir resolves to a directory and points to a directory in dirname
4624 " /tmp/test/folder_symlink/ -> /tmp/test/original_folder/
4625 if a:islocal && fnamemodify(dirname, ':t') == newdir && isdirectory(resolve(dirname)) && resolve(dirname) == resolve(newdir)
4626 let dirname = fnamemodify(resolve(dirname), ':p:h:h')
4627 let newdir = fnamemodify(resolve(newdir), ':t')
4628 endif
Tom Benham64a536d2024-11-07 21:15:03 +01004629 " Remove trailing "/"
4630 let dirname = substitute(dirname, "/$", "", "")
4631
4632 " If the word under the cursor is a directory (except for ../), NetrwTreePath
4633 " returns the full path, including the word under the cursor, remove it
4634 if newdir =~ "/$" && newdir != "../"
4635 let dirname = fnamemodify(dirname, ":h")
4636 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004637 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004638 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004639 endif
Tom Benham64a536d2024-11-07 21:15:03 +01004640 if has("win32")
4641 let dirname = substitute(dirname,'\\','/','ge')
4642 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004643 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004644 let dorestore = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01004645
4646 " ignore <cr>s when done in the banner
4647 if g:netrw_banner
Bram Moolenaara6878372014-03-22 21:02:50 +01004648 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004649 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +01004650 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaar13600302014-05-22 18:26:40 +02004651 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004652 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004653 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004654 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara6878372014-03-22 21:02:50 +01004655 endif
4656 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004657 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004658
Bram Moolenaar446cb832008-06-24 21:56:24 +00004659 " set up o/s-dependent directory recognition pattern
4660 if has("amiga")
4661 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004662 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004663 let dirpat= '[\/]$'
4664 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004665
4666 if dirname !~ dirpat
4667 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004668 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004669 let dirname= dirname.'/'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004670 endif
4671
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004672 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004673 " ------------------------------
4674 " NetrwBrowseChgDir: edit a file {{{3
4675 " ------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004676
Bram Moolenaar97d62492012-11-15 21:28:22 +01004677 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004678 let s:rexposn_{bufnr("%")}= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01004679
Bram Moolenaar446cb832008-06-24 21:56:24 +00004680 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004681 if dirname =~ '/$'
4682 let dirname= dirname.newdir
4683 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004684 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004685 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004686 elseif newdir =~ '^\(/\|\a:\)'
4687 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004688 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004689 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004690 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004691 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004692 if a:0 < 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004693 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004694 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004695 if !exists("s:didsplit")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004696 if type(g:netrw_browse_split) == 3
4697 " open file in server
4698 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004699 call s:NetrwServerEdit(a:islocal,dirname)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004700 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004701
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004702 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004703 " horizontally splitting the window first
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004704 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4705 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004706 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004707 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004708 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004709 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004710
Bram Moolenaar446cb832008-06-24 21:56:24 +00004711 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004712 " vertically splitting the window first
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004713 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4714 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004715 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004716 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004717 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004718 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004719
Bram Moolenaar446cb832008-06-24 21:56:24 +00004720 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004721 " open file in new tab
Bram Moolenaarff034192013-04-24 18:51:19 +02004722 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004723 if !exists("b:netrw_curdir")
4724 let b:netrw_curdir= getcwd()
4725 endif
4726 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004727
Bram Moolenaar446cb832008-06-24 21:56:24 +00004728 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004729 " act like "P" (ie. open previous window)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004730 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004731 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004732 return
4733 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004734 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004735
Bram Moolenaar9964e462007-05-05 17:54:07 +00004736 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004737 " handling a file, didn't split, so remove menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00004738 call s:NetrwMenu(0)
4739 " optional change to window
4740 if g:netrw_chgwin >= 1
Bram Moolenaar13600302014-05-22 18:26:40 +02004741 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004742 " if g:netrw_chgwin is set to one more than the last window, then
4743 " vertically split the last window to make that window available.
4744 let curwin= winnr()
4745 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4746 vs
4747 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004748 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004749 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004750 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004751 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004752 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004753
Bram Moolenaar9964e462007-05-05 17:54:07 +00004754 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004755
Bram Moolenaar446cb832008-06-24 21:56:24 +00004756 " the point where netrw actually edits the (local) file
4757 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004758 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004759 if !&mod
4760 " if e the new file would fail due to &mod, then don't change any of the flags
4761 let dolockout= 1
4762 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004763 if a:islocal
Bram Moolenaar8d043172014-01-23 14:24:41 +01004764 " some like c-^ to return to the last edited file
4765 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004766 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4767 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01004768 call s:NetrwEditFile("e","",dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004769 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02004770 if &hidden || &bufhidden == "hide"
4771 " file came from vim's hidden storage. Don't "restore" options with it.
4772 let dorestore= 0
4773 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004774 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00004775 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004776
4777 " handle g:Netrw_funcref -- call external-to-netrw functions
4778 " This code will handle g:Netrw_funcref as an individual function reference
4779 " or as a list of function references. It will ignore anything that's not
4780 " a function reference. See :help Funcref for information about function references.
4781 if exists("g:Netrw_funcref")
4782 if type(g:Netrw_funcref) == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004783 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004784 elseif type(g:Netrw_funcref) == 3
4785 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004786 if type(Fncref) == 2
4787 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004788 endif
4789 endfor
4790 endif
4791 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004792 endif
4793
4794 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004795 " ----------------------------------------------------
4796 " NetrwBrowseChgDir: just go to the new directory spec {{{3
4797 " ----------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004798 let dirname = newdir
4799 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004800 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004801 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004802
4803 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004804 " ---------------------------------------------
4805 " NetrwBrowseChgDir: refresh the directory list {{{3
4806 " ---------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004807 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004808 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004809
4810 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004811 " --------------------------------------
4812 " NetrwBrowseChgDir: go up one directory {{{3
4813 " --------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004814
4815 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
4816 " force a refresh
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004817 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004818 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004819 endif
4820
4821 if has("amiga")
4822 " amiga
Bram Moolenaar446cb832008-06-24 21:56:24 +00004823 if a:islocal
4824 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
4825 let dirname= substitute(dirname,'/$','','')
4826 else
4827 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
4828 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004829
Nir Lichtman1e34b952024-05-08 19:19:34 +02004830 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004831 " windows
4832 if a:islocal
4833 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4834 if dirname == ""
4835 let dirname= '/'
4836 endif
4837 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004838 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01004839 endif
4840 if dirname =~ '^\a:$'
4841 let dirname= dirname.'/'
4842 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01004843
Bram Moolenaar446cb832008-06-24 21:56:24 +00004844 else
4845 " unix or cygwin
Bram Moolenaar446cb832008-06-24 21:56:24 +00004846 if a:islocal
4847 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4848 if dirname == ""
4849 let dirname= '/'
4850 endif
4851 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004852 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004853 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004854 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004855 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004856 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004857
4858 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004859 " --------------------------------------
4860 " NetrwBrowseChgDir: Handle Tree Listing {{{3
4861 " --------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004862 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004863 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004864 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004865 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004866 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004867 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004868 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004869 let haskey = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004870
4871 " search treedict for tree dir as-is
4872 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004873 let haskey= 1
4874 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004875 endif
4876
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004877 " search treedict for treedir with a [/@] appended
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004878 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004879 if has_key(w:netrw_treedict,treedir."/")
4880 let treedir= treedir."/"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004881 let haskey = 1
4882 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004883 endif
4884 endif
4885
4886 " search treedict for treedir with any trailing / elided
4887 if !haskey && treedir =~ '/$'
4888 let treedir= substitute(treedir,'/$','','')
4889 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004890 let haskey = 1
4891 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004892 endif
4893 endif
4894
4895 if haskey
4896 " close tree listing for selected subdirectory
Bram Moolenaar446cb832008-06-24 21:56:24 +00004897 call remove(w:netrw_treedict,treedir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004898 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00004899 else
4900 " go down one directory
4901 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004902 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004903 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004904 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004905
4906 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01004907 " ----------------------------------------
4908 " NetrwBrowseChgDir: Go down one directory {{{3
4909 " ----------------------------------------
4910 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004911 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004912 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00004913 endif
4914
Bram Moolenaar97d62492012-11-15 21:28:22 +01004915 " --------------------------------------
4916 " NetrwBrowseChgDir: Restore and Cleanup {{{3
4917 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02004918 if dorestore
4919 " dorestore is zero'd when a local file was hidden or bufhidden;
4920 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004921 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02004922 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02004923 if dolockout && dorestore
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004924 if filewritable(dirname)
Bram Moolenaar13600302014-05-22 18:26:40 +02004925 setl ma noro nomod
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004926 else
Bram Moolenaar13600302014-05-22 18:26:40 +02004927 setl ma ro nomod
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004928 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004929 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004930 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004931 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004932
Bram Moolenaar446cb832008-06-24 21:56:24 +00004933 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00004934endfun
4935
4936" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004937" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
4938" for thin, long, and wide: cursor placed just after banner
4939" for tree, keeps cursor on current filename
4940fun! s:NetrwBrowseUpDir(islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004941 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
4942 " this test needed because occasionally this function seems to be incorrectly called
4943 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004944 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004945 " directories.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004946 return
4947 endif
4948
Bram Moolenaara6878372014-03-22 21:02:50 +01004949 norm! 0
4950 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara6878372014-03-22 21:02:50 +01004951 let curline= getline(".")
4952 let swwline= winline() - 1
4953 if exists("w:netrw_treetop")
4954 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02004955 elseif exists("b:netrw_curdir")
4956 let w:netrw_treetop= b:netrw_curdir
4957 else
4958 let w:netrw_treetop= getcwd()
4959 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01004960 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004961 let curfile = getline(".")
4962 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01004963 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01004964 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004965 else
Tom Benham64a536d2024-11-07 21:15:03 +01004966 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004967 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004968 if w:netrw_treetop == '/'
4969 keepj call search('^\M'.curfile,"w")
4970 elseif curfile == '../'
4971 keepj call search('^\M'.curfile,"wb")
4972 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004973 while 1
4974 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
4975 let treepath= s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004976 if treepath == curpath
4977 break
4978 endif
4979 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01004980 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004981
Bram Moolenaara6878372014-03-22 21:02:50 +01004982 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004983 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004984 if exists("b:netrw_curdir")
4985 let curdir= b:netrw_curdir
4986 else
4987 let curdir= expand(getcwd())
4988 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004989 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01004990 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004991 else
Tom Benham64a536d2024-11-07 21:15:03 +01004992 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004993 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004994 call s:RestorePosn(s:netrw_posn)
4995 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01004996 let curdir= '\<'. escape(curdir, '~'). '/'
4997 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01004998 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004999endfun
5000
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005001func s:redir()
5002 " set up redirection (avoids browser messages)
5003 " by default if not set, g:netrw_suppress_gx_mesg is true
5004 if get(g:, 'netrw_suppress_gx_mesg', 1)
5005 if &srr =~# "%s"
5006 return printf(&srr, has("win32") ? "nul" : "/dev/null")
5007 else
5008 return &srr .. (has("win32") ? "nul" : "/dev/null")
5009 endif
5010 endif
5011 return ''
5012endfunc
5013
5014if has('unix')
5015 if has('win32unix')
5016 " Cygwin provides cygstart
5017 if executable('cygstart')
5018 fun! netrw#Launch(args)
5019 exe 'silent ! cygstart --hide' a:args s:redir() | redraw!
5020 endfun
5021 elseif !empty($MSYSTEM) && executable('start')
5022 " MSYS2/Git Bash comes by default without cygstart; see
5023 " https://www.msys2.org/wiki/How-does-MSYS2-differ-from-Cygwin
5024 " Instead it provides /usr/bin/start script running `cmd.exe //c start`
5025 " Adding "" //b` sets void title, hides cmd window and blocks path conversion
5026 " of /b to \b\ " by MSYS2; see https://www.msys2.org/docs/filesystem-paths/
5027 fun! netrw#Launch(args)
5028 exe 'silent !start "" //b' a:args s:redir() | redraw!
5029 endfun
5030 else
5031 " imitate /usr/bin/start script for other environments and hope for the best
5032 fun! netrw#Launch(args)
5033 exe 'silent !cmd //c start "" //b' a:args s:redir() | redraw!
5034 endfun
5035 endif
5036 elseif exists('$WSL_DISTRO_NAME') " use cmd.exe to start GUI apps in WSL
5037 fun! netrw#Launch(args)
5038 let args = a:args
5039 exe 'silent !' ..
5040 \ ((args =~? '\v<\f+\.(exe|com|bat|cmd)>') ?
Konfekt460799d2024-11-14 21:42:27 +01005041 \ 'cmd.exe /c start /b ' .. args :
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005042 \ 'nohup ' .. args .. ' ' .. s:redir() .. ' &')
5043 \ | redraw!
5044 endfun
5045 else
5046 fun! netrw#Launch(args)
5047 exe ':silent ! nohup' a:args s:redir() '&' | redraw!
5048 endfun
5049 endif
5050elseif has('win32')
5051 fun! netrw#Launch(args)
5052 exe 'silent !' .. (&shell =~? '\<cmd\.exe\>' ? '' : 'cmd.exe /c')
5053 \ 'start "" /b' a:args s:redir() | redraw!
5054 endfun
5055else
5056 fun! netrw#Launch(dummy)
5057 echom 'No common launcher found'
5058 endfun
5059endif
5060
5061" Git Bash
5062if has('win32unix')
5063 " (cyg)start suffices
5064 let s:os_viewer = ''
5065" Windows / WSL
5066elseif executable('explorer.exe')
5067 let s:os_viewer = 'explorer.exe'
5068" Linux / BSD
5069elseif executable('xdg-open')
5070 let s:os_viewer = 'xdg-open'
5071" MacOS
5072elseif executable('open')
5073 let s:os_viewer = 'open'
5074endif
5075
5076fun! s:viewer()
5077 if exists('g:netrw_browsex_viewer') && executable(g:netrw_browsex_viewer)
5078 " extract any viewing options. Assumes that they're set apart by spaces.
5079 " call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
5080 if g:netrw_browsex_viewer =~ '\s'
5081 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5082 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5083 let oviewer = ''
5084 let cnt = 1
5085 while !executable(viewer) && viewer != oviewer
5086 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5087 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5088 let cnt = cnt + 1
5089 let oviewer = viewer
5090 " call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
5091 endwhile
5092 else
5093 let viewer = g:netrw_browsex_viewer
5094 let viewopt = ""
5095 endif
5096 " call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
5097 return viewer .. ' ' .. viewopt
5098 else
5099 if !exists('s:os_viewer')
5100 call netrw#ErrorMsg(s:ERROR,"No program to open this path found. See :help Open for more information.",106)
5101 else
5102 return s:os_viewer
5103 endif
5104 endif
5105endfun
5106
5107fun! netrw#Open(file) abort
5108 call netrw#Launch(s:viewer() .. ' ' .. shellescape(a:file, 1))
5109endf
5110
5111if !exists('g:netrw_regex_url')
5112 let g:netrw_regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}'
5113endif
5114
Bram Moolenaara6878372014-03-22 21:02:50 +01005115" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005116" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005117" given filename; typically this means given their extension.
5118" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005119fun! netrw#BrowseX(fname,remote)
Konfekt460799d2024-11-14 21:42:27 +01005120 if a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
Bram Moolenaar91359012019-11-30 17:57:03 +01005121 " remote directory, not a webpage access, looks like an attempt to do a directory listing
Bram Moolenaar91359012019-11-30 17:57:03 +01005122 norm! gf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005123 endif
5124
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005125 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5126 let remote = a:remote
5127 else
5128 let remote = 0
5129 endif
5130
Bram Moolenaar97d62492012-11-15 21:28:22 +01005131 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005132 let screenposn = winsaveview()
Bram Moolenaar97d62492012-11-15 21:28:22 +01005133
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005134 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5135 let awkeep = &aw
5136 set noaw
5137
Bram Moolenaar5c736222010-01-06 20:54:52 +01005138 " special core dump handler
5139 if a:fname =~ '/core\(\.\d\+\)\=$'
5140 if exists("g:Netrw_corehandler")
5141 if type(g:Netrw_corehandler) == 2
5142 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005143 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005144 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005145 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005146 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005147 if type(Fncref) == 2
5148 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005149 endif
5150 endfor
5151 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005152 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005153 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005154 let &aw= awkeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005155 return
5156 endif
5157 endif
5158
Bram Moolenaar446cb832008-06-24 21:56:24 +00005159 " set up the filename
5160 " (lower case the extension, make a local copy of a remote file)
5161 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005162 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005163 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005164 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005165 if exten =~ "[\\/]"
5166 let exten= ""
5167 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005168
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005169 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005170 " create a local copy
Bram Moolenaarff034192013-04-24 18:51:19 +02005171 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005172 call netrw#NetRead(3,a:fname)
5173 " attempt to rename tempfile
5174 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005175 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02005176 if s:netrw_tmpfile != newname && newname != ""
5177 if rename(s:netrw_tmpfile,newname) == 0
5178 " renaming succeeded
Bram Moolenaar85850f32019-07-19 22:05:51 +02005179 let fname= newname
5180 else
5181 " renaming failed
Bram Moolenaar85850f32019-07-19 22:05:51 +02005182 let fname= s:netrw_tmpfile
5183 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005184 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005185 let fname= s:netrw_tmpfile
5186 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005187 else
5188 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005189 " special ~ handler for local
5190 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005191 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005192 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005193 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005194
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005195 " although shellescape(..., 1) is used in netrw#Open(), it's insufficient
5196 call netrw#Open(escape(fname, '#%'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005197
Bram Moolenaar446cb832008-06-24 21:56:24 +00005198 " cleanup: remove temporary file,
5199 " delete current buffer if success with handler,
5200 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005201 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005202 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005203" if remote == 1 && fname != a:fname
Bram Moolenaarc236c162008-07-13 17:41:49 +00005204" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005205" endif
5206
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005207 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005208 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005209 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005210 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005211 endif
Christian Brabandt9f320692024-10-30 18:36:20 +01005212 exe "sil! NetrwKeepj norm! \<c-o>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005213 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005214 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005215 let @@ = ykeep
5216 let &aw= awkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005217endfun
5218
5219" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005220" netrw#GX: gets word under cursor for gx support {{{2
5221" See also: netrw#BrowseXVis
5222" netrw#BrowseX
5223fun! netrw#GX()
5224" call Dfunc("netrw#GX()")
5225 if &ft == "netrw"
5226 let fname= s:NetrwGetWord()
5227 else
Konfekt3d7e5672024-10-27 22:16:49 +01005228 let fname= exists("g:netrw_gx")? expand(g:netrw_gx) : s:GetURL()
Bram Moolenaar85850f32019-07-19 22:05:51 +02005229 endif
5230" call Dret("netrw#GX <".fname.">")
5231 return fname
5232endfun
5233
Konfekt3d7e5672024-10-27 22:16:49 +01005234fun! s:GetURL() abort
5235 let URL = ''
5236 if exists('*Netrw_get_URL_' .. &filetype)
5237 let URL = call('Netrw_get_URL_' .. &filetype, [])
5238 endif
5239 if !empty(URL) | return URL | endif
5240 " URLs end in letter, digit or forward slash
5241 let URL = matchstr(expand("<cWORD>"), '\<' .. g:netrw_regex_url .. '\ze[^A-Za-z0-9/]*$')
5242 if !empty(URL) | return URL | endif
5243
5244 " Is it a file in the current work dir ...
5245 let file = expand("<cfile>")
5246 if filereadable(file) | return file | endif
5247 " ... or in that of the current buffer?
5248 let path = fnamemodify(expand('%'), ':p')
5249 if isdirectory(path)
5250 let dir = path
5251 elseif filereadable(path)
5252 let dir = fnamemodify(path, ':h')
5253 endif
5254 if exists('dir') && filereadable(dir..'/'..file) | return dir..'/'..file | endif
5255
5256 return ''
5257endf
5258
Bram Moolenaar85850f32019-07-19 22:05:51 +02005259" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005260" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5261fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005262 let dict={}
5263 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005264 norm! gv"ay
5265 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005266 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005267 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005268endfun
5269
5270" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005271" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5272" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5273" to become an unlisted buffer, so in that case don't bwipe it.
5274fun! s:NetrwBufRename(newname)
5275" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5276" call Dredir("ls!","s:NetrwBufRename (before rename)")
5277 let oldbufname= bufname(bufnr("%"))
5278" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5279
5280 if oldbufname != a:newname
5281" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5282 let b:junk= 1
5283" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5284 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005285" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005286 let oldbufnr= bufnr(oldbufname)
5287" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5288" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5289 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5290" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5291 exe "bwipe! ".oldbufnr
5292" else " Decho
5293" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005294" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5295" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5296" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005297 endif
5298" call Dredir("ls!","s:NetrwBufRename (after rename)")
5299" else " Decho
5300" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5301 endif
5302
5303" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5304endfun
5305
5306" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005307" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005308fun! netrw#CheckIfRemote(...)
5309" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5310 if a:0 > 0
5311 let curfile= a:1
5312 else
5313 let curfile= expand("%")
5314 endif
5315" call Decho("curfile<".curfile.">")
5316 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005317" call Dret("netrw#CheckIfRemote 1")
5318 return 1
5319 else
5320" call Dret("netrw#CheckIfRemote 0")
5321 return 0
5322 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005323endfun
5324
5325" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005326" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5327fun! s:NetrwChgPerm(islocal,curdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005328 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005329 call inputsave()
5330 let newperm= input("Enter new permission: ")
5331 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005332 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5333 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005334 call system(chgperm)
5335 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005336 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005337 endif
5338 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01005339 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005340 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005341 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005342endfun
5343
5344" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005345" s:CheckIfKde: checks if kdeinit is running {{{2
5346" Returns 0: kdeinit not running
5347" 1: kdeinit is running
5348fun! s:CheckIfKde()
5349" call Dfunc("s:CheckIfKde()")
5350 " seems kde systems often have gnome-open due to dependencies, even though
5351 " gnome-open's subsidiary display tools are largely absent. Kde systems
5352 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5353 if !exists("s:haskdeinit")
5354 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005355 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005356 if v:shell_error
5357 let s:haskdeinit = 0
5358 endif
5359 else
5360 let s:haskdeinit= 0
5361 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005362" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005363 endif
5364
5365" call Dret("s:CheckIfKde ".s:haskdeinit)
5366 return s:haskdeinit
5367endfun
5368
5369" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005370" s:NetrwClearExplore: clear explore variables (if any) {{{2
5371fun! s:NetrwClearExplore()
5372" call Dfunc("s:NetrwClearExplore()")
5373 2match none
5374 if exists("s:explore_match") |unlet s:explore_match |endif
5375 if exists("s:explore_indx") |unlet s:explore_indx |endif
5376 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5377 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5378 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5379 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5380 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5381 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5382 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5383" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005384" call Dret("s:NetrwClearExplore")
5385endfun
5386
5387" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005388" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5389fun! s:NetrwEditBuf(bufnum)
5390" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5391 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5392" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5393 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5394 else
5395" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005396 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005397 endif
5398" call Dret("s:NetrwEditBuf")
5399endfun
5400
5401" ---------------------------------------------------------------------
5402" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5403" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5404fun! s:NetrwEditFile(cmd,opt,fname)
5405" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5406 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5407" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5408 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5409 else
5410" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005411 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5412 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5413 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005414 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5415 endif
5416" call Dret("s:NetrwEditFile")
5417endfun
5418
5419" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005420" s:NetrwExploreListUniq: {{{2
5421fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005422 " this assumes that the list is already sorted
5423 let newexplist= []
5424 for member in a:explist
5425 if !exists("uniqmember") || member != uniqmember
5426 let uniqmember = member
5427 let newexplist = newexplist + [ member ]
5428 endif
5429 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01005430 return newexplist
5431endfun
5432
5433" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005434" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5435fun! s:NetrwForceChgDir(islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005436 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005437 if a:newdir !~ '/$'
5438 " ok, looks like force is needed to get directory-style treatment
5439 if a:newdir =~ '@$'
5440 let newdir= substitute(a:newdir,'@$','/','')
5441 elseif a:newdir =~ '[*=|\\]$'
5442 let newdir= substitute(a:newdir,'.$','/','')
5443 else
5444 let newdir= a:newdir.'/'
5445 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005446 else
5447 " should already be getting treatment as a directory
5448 let newdir= a:newdir
5449 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005450 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir,0)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005451 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005452 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005453endfun
5454
5455" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005456" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005457" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5458" expr : this is the expression to follow the directory. Will use s:ComposePath()
5459" pare =1: remove the current directory from the resulting glob() filelist
5460" =0: leave the current directory in the resulting glob() filelist
5461fun! s:NetrwGlob(direntry,expr,pare)
5462" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005463 if netrw#CheckIfRemote()
5464 keepalt 1sp
5465 keepalt enew
5466 let keep_liststyle = w:netrw_liststyle
5467 let w:netrw_liststyle = s:THINLIST
5468 if s:NetrwRemoteListing() == 0
5469 keepj keepalt %s@/@@
5470 let filelist= getline(1,$)
5471 q!
5472 else
5473 " remote listing error -- leave treedict unchanged
5474 let filelist= w:netrw_treedict[a:direntry]
5475 endif
5476 let w:netrw_liststyle= keep_liststyle
5477 else
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005478 let path= s:ComposePath(fnameescape(a:direntry), a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005479 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005480 " escape [ so it is not detected as wildcard character, see :h wildcard
5481 let path= substitute(path, '[', '[[]', 'g')
5482 endif
5483 if v:version > 704 || (v:version == 704 && has("patch656"))
5484 let filelist= glob(path,0,1,1)
5485 else
5486 let filelist= glob(path,0,1)
5487 endif
5488 if a:pare
5489 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5490 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005491 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005492 return filelist
5493endfun
5494
5495" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005496" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5497fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005498 if a:newfile =~ '[/@*=|\\]$'
5499 let newfile= substitute(a:newfile,'.$','','')
5500 else
5501 let newfile= a:newfile
5502 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005503 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01005504 call s:NetrwBrowseChgDir(a:islocal,newfile,0)
Bram Moolenaarff034192013-04-24 18:51:19 +02005505 else
Tom Benham64a536d2024-11-07 21:15:03 +01005506 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile,0))
Bram Moolenaarff034192013-04-24 18:51:19 +02005507 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005508endfun
5509
5510" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005511" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5512" and switches the hiding mode. The actual hiding is done by
5513" s:NetrwListHide().
5514" g:netrw_hide= 0: show all
5515" 1: show not-hidden files
5516" 2: show hidden files only
5517fun! s:NetrwHide(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005518 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005519 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005520
5521 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005522
5523 " hide the files in the markfile list
5524 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00005525 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5526 " remove fname from hiding list
5527 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5528 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5529 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005530 else
5531 " append fname to hiding list
5532 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5533 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5534 else
5535 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5536 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005537 endif
5538 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005539 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005540 let g:netrw_hide= 1
5541
5542 else
5543
5544 " switch between show-all/show-not-hidden/show-hidden
5545 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005546 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005547 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005548 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005549 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005550 return
5551 endif
5552 endif
5553
Tom Benham64a536d2024-11-07 21:15:03 +01005554 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005555 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005556 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005557endfun
5558
5559" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005560" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5561fun! s:NetrwHideEdit(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005562 let ykeep= @@
5563 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005564 let svpos= winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005565
5566 " get new hiding list from user
5567 call inputsave()
5568 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5569 call inputrestore()
5570 let g:netrw_list_hide= newhide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005571
5572 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01005573 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./",0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005574
5575 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005576 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005577 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005578endfun
5579
5580" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005581" s:NetrwHidden: invoked by "gh" {{{2
5582fun! s:NetrwHidden(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005583 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005584 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005585 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005586
5587 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005588 " remove .file pattern from hiding list
Bram Moolenaar446cb832008-06-24 21:56:24 +00005589 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005590 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005591 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5592 else
5593 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5594 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005595 if g:netrw_list_hide =~ '^,'
5596 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5597 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005598
5599 " refresh screen and return to saved position
Tom Benham64a536d2024-11-07 21:15:03 +01005600 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005601 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005602 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005603endfun
5604
5605" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005606" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5607fun! s:NetrwHome()
5608 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005609 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005610 else
5611 " go to vim plugin home
5612 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005613 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005614 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005615 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005616 let home= basehome."/.vim"
5617 break
5618 endif
5619 endfor
5620 if home == ""
5621 " just pick the first directory
5622 let home= substitute(&rtp,',.*$','','')
5623 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005624 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005625 let home= substitute(home,'/','\\','g')
5626 endif
5627 endif
5628 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005629 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005630" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005631 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005632" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005633 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005634 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005635" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005636 call mkdir(home)
5637 endif
5638 endif
5639 let g:netrw_home= home
5640 return home
5641endfun
5642
5643" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005644" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5645fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005646 if exists("s:netrwdrag")
5647 return
5648 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005649 if &ft != "netrw"
5650 return
5651 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005652
Bram Moolenaar97d62492012-11-15 21:28:22 +01005653 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005654 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005655 while getchar(0) != 0
5656 "clear the input stream
5657 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005658 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005659 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005660 let mouse_lnum = v:mouse_lnum
5661 let wlastline = line('w$')
5662 let lastline = line('$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005663 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5664 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005665 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005666 return
5667 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005668 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005669 " 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 +01005670 " without this test when its disabled.
5671 " 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 +01005672 if v:mouse_col > virtcol('.')
5673 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005674 return
5675 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005676
Bram Moolenaar446cb832008-06-24 21:56:24 +00005677 if a:islocal
5678 if exists("b:netrw_curdir")
Tom Benham64a536d2024-11-07 21:15:03 +01005679 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005680 endif
5681 else
5682 if exists("b:netrw_curdir")
Tom Benham64a536d2024-11-07 21:15:03 +01005683 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005684 endif
5685 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005686 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005687endfun
5688
5689" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005690" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
5691fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005692 if &ft != "netrw"
5693 return
5694 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005695 call s:NetrwMarkFileTgt(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005696endfun
5697
5698" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005699" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
5700" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02005701" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005702" a:islocal=2 : <c-r> used, remote
5703" a:islocal=3 : <c-r> used, local
5704fun! s:NetrwServerEdit(islocal,fname)
5705" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
5706 let islocal = a:islocal%2 " =0: remote =1: local
5707 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
5708
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005709 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005710 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005711 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005712 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005713 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005714 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5715 unlet s:netrw_browse_split_{winnr()}
5716 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005717 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname,0))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005718 return
5719 endif
5720
5721 if has("clientserver") && executable("gvim")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005722
5723 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005724 let srvrname = g:netrw_browse_split[0]
5725 let tabnum = g:netrw_browse_split[1]
5726 let winnum = g:netrw_browse_split[2]
5727
5728 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005729 if !ctrlr
5730 " user must have closed the server window and the user did not use <c-r>, but
5731 " used something like <cr>.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005732 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09005733 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005734 endif
5735 let g:netrw_browse_split= 0
5736 if exists("s:netrw_browse_split_".winnr())
5737 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5738 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005739 call s:NetrwBrowseChgDir(islocal,a:fname,0)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005740 return
5741
5742 elseif has("win32") && executable("start")
5743 " start up remote netrw server under windows
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005744 call system("start gvim --servername ".srvrname)
5745
5746 else
5747 " start up remote netrw server under linux
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005748 call system("gvim --servername ".srvrname)
5749 endif
5750 endif
5751
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005752 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
5753 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005754 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005755 else
5756
5757 if serverlist() !~ '\<'.g:netrw_servername.'\>'
5758
5759 if !ctrlr
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005760 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09005761 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005762 endif
5763 let g:netrw_browse_split= 0
Tom Benham64a536d2024-11-07 21:15:03 +01005764 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname,0))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005765 return
5766
5767 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005768 if has("win32") && executable("start")
5769 " start up remote netrw server under windows
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005770 call system("start gvim --servername ".g:netrw_servername)
5771 else
5772 " start up remote netrw server under linux
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005773 call system("gvim --servername ".g:netrw_servername)
5774 endif
5775 endif
5776 endif
5777
5778 while 1
5779 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005780 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005781 break
5782 catch /^Vim\%((\a\+)\)\=:E241/
5783 sleep 200m
5784 endtry
5785 endwhile
5786
5787 if exists("g:netrw_browse_split")
5788 if type(g:netrw_browse_split) != 3
5789 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
5790 endif
5791 unlet g:netrw_browse_split
5792 endif
5793 let g:netrw_browse_split= [g:netrw_servername,1,1]
5794 endif
5795
5796 else
5797 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
5798 endif
5799
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005800endfun
5801
5802" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005803" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
5804fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005805 if &ft != "netrw"
5806 return
5807 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005808" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005809
Bram Moolenaar8d043172014-01-23 14:24:41 +01005810 let s:ngw= s:NetrwGetWord()
5811 call s:NetrwMarkFile(a:islocal,s:ngw)
5812
5813" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02005814endfun
5815
5816" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005817" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
5818" Used to mark multiple files.
5819fun! s:NetrwSLeftdrag(islocal)
5820" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
5821 if !exists("s:netrwdrag")
5822 let s:netrwdrag = winnr()
5823 if a:islocal
5824 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005825 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01005826 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005827 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005828 endif
5829 let ngw = s:NetrwGetWord()
5830 if !exists("s:ngw") || s:ngw != ngw
5831 call s:NetrwMarkFile(a:islocal,ngw)
5832 endif
5833 let s:ngw= ngw
5834" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5835endfun
5836
5837" ---------------------------------------------------------------------
5838" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
5839fun! s:NetrwSLeftrelease(islocal)
5840" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5841 if exists("s:netrwdrag")
5842 nunmap <s-leftrelease>
5843 let ngw = s:NetrwGetWord()
5844 if !exists("s:ngw") || s:ngw != ngw
5845 call s:NetrwMarkFile(a:islocal,ngw)
5846 endif
5847 if exists("s:ngw")
5848 unlet s:ngw
5849 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005850 unlet s:netrwdrag
5851 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005852" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02005853endfun
5854
5855" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01005856" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
5857" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00005858fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005859" 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 +02005860" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005861 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005862
5863 " 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 +02005864 " How-it-works: take the hiding command, convert it into a range.
5865 " Duplicate characters don't matter.
5866 " Remove all such characters from the '/~@#...890' string.
5867 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005868" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005869 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01005870 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005871" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005872
5873 while listhide != ""
5874 if listhide =~ ','
5875 let hide = substitute(listhide,',.*$','','e')
5876 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
5877 else
5878 let hide = listhide
5879 let listhide = ""
5880 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005881" 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 +01005882 if g:netrw_sort_by =~ '^[ts]'
5883 if hide =~ '^\^'
5884" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
5885 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
5886 elseif hide =~ '^\\(\^'
5887 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
5888 endif
5889" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
5890 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005891
5892 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005893" 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 +00005894 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005895" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005896 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005897 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005898" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005899 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005900 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005901" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005902 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02005903
Bram Moolenaar446cb832008-06-24 21:56:24 +00005904 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005905 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005906" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005907 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005908" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005909 endif
5910
Bram Moolenaaradc21822011-04-01 18:03:16 +02005911 " remove any blank lines that have somehow remained.
5912 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005913 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02005914
Bram Moolenaar97d62492012-11-15 21:28:22 +01005915 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005916" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005917endfun
5918
5919" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005920" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005921" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005922fun! s:NetrwMakeDir(usrhost)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005923
Bram Moolenaar97d62492012-11-15 21:28:22 +01005924 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005925 " get name of new directory from user. A bare <CR> will skip.
5926 " if its currently a directory, also request will be skipped, but with
5927 " a message.
5928 call inputsave()
5929 let newdirname= input("Please give directory name: ")
5930 call inputrestore()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005931
5932 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01005933 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005934 return
5935 endif
5936
5937 if a:usrhost == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005938
5939 " Local mkdir:
5940 " sanity checks
5941 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005942 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005943 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005944 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005945 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005946 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005947 return
5948 endif
5949 if s:FileReadable(fullnewdir)
5950 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005951 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005952 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005953 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005954 return
5955 endif
5956
5957 " requested new local directory is neither a pre-existing file or
5958 " directory, so make it!
5959 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005960 if has("unix")
5961 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
5962 else
5963 call mkdir(fullnewdir,"p")
5964 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005965 else
5966 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005967 if s:NetrwLcd(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005968 return
5969 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005970 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005971 if v:shell_error != 0
5972 let @@= ykeep
5973 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 +01005974 return
5975 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005976 if !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02005977 if s:NetrwLcd(netrw_origdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005978 return
5979 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005980 endif
5981 endif
5982
5983 if v:shell_error == 0
5984 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005985 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01005986 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005987 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005988 elseif !exists("g:netrw_quiet")
5989 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
5990 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005991
5992 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01005993 " Remote mkdir: using ssh
Bram Moolenaar446cb832008-06-24 21:56:24 +00005994 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
5995 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005996 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005997 if v:shell_error == 0
5998 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005999 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01006000 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006001 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006002 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006003 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006004 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006005
6006 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006007 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006008 let svpos= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01006009 if exists("b:netrw_fname")
Bram Moolenaara6878372014-03-22 21:02:50 +01006010 let remotepath= b:netrw_fname
6011 else
6012 let remotepath= ""
6013 endif
6014 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Tom Benham64a536d2024-11-07 21:15:03 +01006015 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006016 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006017
Bram Moolenaar446cb832008-06-24 21:56:24 +00006018 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006019 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006020 let svpos= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01006021 if exists("b:netrw_fname")
Bram Moolenaara6878372014-03-22 21:02:50 +01006022 let remotepath= b:netrw_fname
6023 else
6024 let remotepath= ""
6025 endif
6026 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Tom Benham64a536d2024-11-07 21:15:03 +01006027 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006028 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006029 endif
6030
Bram Moolenaar97d62492012-11-15 21:28:22 +01006031 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006032endfun
6033
6034" ---------------------------------------------------------------------
6035" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6036fun! s:TreeSqueezeDir(islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01006037 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6038 " its a tree-listing style
6039 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006040 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006041 let depth = strchars(substitute(curdepth,' ','','g'))
6042 let srch = -1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006043 if depth >= 2
6044 NetrwKeepj norm! 0
6045 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6046 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006047 elseif depth == 1
6048 NetrwKeepj norm! 0
6049 let treedepthchr= substitute(s:treedepthstring,' ','','')
6050 let srch = search('^[^'.treedepthchr.']','bW',stopline)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006051 endif
6052 if srch > 0
Tom Benham64a536d2024-11-07 21:15:03 +01006053 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord(),1))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006054 exe srch
6055 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006056 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006057endfun
6058
6059" ---------------------------------------------------------------------
6060" s:NetrwMaps: {{{2
6061fun! s:NetrwMaps(islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01006062
Bram Moolenaar85850f32019-07-19 22:05:51 +02006063 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006064 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006065" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006066 if !hasmapto("<Plug>NetrwReturn")
6067 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006068 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6069 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006070 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6071 endif
6072 endif
6073 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006074 endif
6075
Bram Moolenaar85850f32019-07-19 22:05:51 +02006076 " generate default <Plug> maps {{{3
6077 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006078 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006079 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6080 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6081 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6082 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6083 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6084 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6085 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6086 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6087 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6088 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006089
Bram Moolenaara6878372014-03-22 21:02:50 +01006090 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02006091 " local normal-mode maps {{{3
6092 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6093 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6094 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6095 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6096 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6097 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6098 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006099 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006100 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6101 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6102 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6103" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006104 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6105 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6106 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006107 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006108 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006109 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6110 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6111 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6112 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006113 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6114 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6115 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6116 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6117 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6118 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6119 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6120 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6121 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6122 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6123 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6124 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6125 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006126 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006127 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006128 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6129 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6130 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6131 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6132 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006133 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006134 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006135 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 +01006136 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006137 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6138 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6139 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006140 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006141 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006142 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6143 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006144 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006145 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006146 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6147 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6148 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006149 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 +01006150 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006151
Tom Benham64a536d2024-11-07 21:15:03 +01006152 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 +01006153 if !hasmapto('<Plug>NetrwHideEdit')
6154 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006155 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006156 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006157 if !hasmapto('<Plug>NetrwRefresh')
6158 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006159 endif
Tom Benham64a536d2024-11-07 21:15:03 +01006160 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 +01006161 if s:didstarstar || !mapcheck("<s-down>","n")
6162 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006163 endif
6164 if s:didstarstar || !mapcheck("<s-up>","n")
6165 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006166 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006167 if !hasmapto('<Plug>NetrwTreeSqueeze')
6168 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006169 endif
6170 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006171 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6172 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006173 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6174 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6175 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6176 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6177 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6178 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6179 imap <buffer> <leftmouse> <Plug>ILeftmouse
6180 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006181 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6182 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6183 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6184 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6185 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006186 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006187 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6188 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006189 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006190 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6191 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6192 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6193 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6194 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6195 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6196 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006197 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6198
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006199 " support user-specified maps
6200 call netrw#UserMaps(1)
6201
Bram Moolenaar85850f32019-07-19 22:05:51 +02006202 else
6203 " remote normal-mode maps {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006204 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006205 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6206 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6207 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6208 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6209 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6210 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6211 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006212 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./',0))<cr>
6213 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 +02006214 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6215 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6216" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006217 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6218 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6219 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6220 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6221 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6222 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6223 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6224 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006225 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006226 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006227 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6228 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6229 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6230 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6231 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6232 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6233 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6234 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6235 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6236 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6237 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006238 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006239 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006240 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6241 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6242 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6243 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6244 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006245 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6246 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006247 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 +01006248 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006249 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006250 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6251 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006252 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006253 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 +01006254 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6255 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6256 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6257 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6258 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6259 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6260 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6261 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006262 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord(),1),1)<cr>
Konfekt3d7e5672024-10-27 22:16:49 +01006263 nmap <buffer> <nowait> gx x
Bram Moolenaara6878372014-03-22 21:02:50 +01006264 if !hasmapto('<Plug>NetrwHideEdit')
6265 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006266 endif
6267 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6268 if !hasmapto('<Plug>NetrwRefresh')
6269 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006270 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006271 if !hasmapto('<Plug>NetrwTreeSqueeze')
6272 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006273 endif
6274 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006275
6276 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006277 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006278
Tom Benham64a536d2024-11-07 21:15:03 +01006279 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./',0))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006280 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006281 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006282 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006283 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006284 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006285 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006286 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006287 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006288 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006289 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006290 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006291 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6292 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6293 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006294 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006295 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006296 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6297 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006298 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006299 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6300 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6301 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6302 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6303 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6304 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6305 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006306 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006307
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006308 " support user-specified maps
6309 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006310 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006311endfun
6312
6313" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006314" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006315" If -buffer, the command is only available from within netrw buffers
6316" Otherwise, the command is available from any window, so long as netrw
6317" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006318fun! s:NetrwCommands(islocal)
6319" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6320
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006321 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6322 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006323 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 +01006324 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006325 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006326 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006327 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006328 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006329 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006330
6331" call Dret("s:NetrwCommands")
6332endfun
6333
6334" ---------------------------------------------------------------------
6335" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6336" glob()ing only works with local files
6337fun! s:NetrwMarkFiles(islocal,...)
6338" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006339 let curdir = s:NetrwGetCurdir(a:islocal)
6340 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006341 while i <= a:0
6342 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006343 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006344 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006345 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006346 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006347 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006348 else
6349 let mffiles= [a:{i}]
6350 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006351" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006352 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006353" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006354 call s:NetrwMarkFile(a:islocal,mffile)
6355 endfor
6356 let i= i + 1
6357 endwhile
6358" call Dret("s:NetrwMarkFiles")
6359endfun
6360
6361" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006362" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006363fun! s:NetrwMarkTarget(...)
Bram Moolenaara6878372014-03-22 21:02:50 +01006364 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006365 let curdir = s:NetrwGetCurdir(1)
6366 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006367 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006368 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6369 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006370 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006371 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006372 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6373 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006374 let svpos = winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01006375 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006376 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006377endfun
6378
6379" ---------------------------------------------------------------------
6380" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6381" mark and unmark files. If a markfile list exists,
6382" then the rename and delete functions will use it instead
6383" of whatever may happen to be under the cursor at that
6384" moment. When the mouse and gui are available,
6385" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006386"
6387" Creates two lists
6388" s:netrwmarkfilelist -- holds complete paths to all marked files
6389" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6390"
6391" Creates a marked file match string
6392" s:netrwmarfilemtch_# -- used with 2match to display marked files
6393"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006394" Creates a buffer version of islocal
6395" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006396fun! s:NetrwMarkFile(islocal,fname)
6397" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006398" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006399
6400 " sanity check
6401 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006402" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006403 return
6404 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006405 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006406
Bram Moolenaar97d62492012-11-15 21:28:22 +01006407 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006408 let curbufnr= bufnr("%")
yasudac18a9d52024-09-19 18:09:51 +02006409 let leader= '\%(^\|\s\)\zs'
Bram Moolenaara6878372014-03-22 21:02:50 +01006410 if a:fname =~ '\a$'
6411 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6412 else
6413 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6414 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006415
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006416 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006417 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006418" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6419" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6420" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006421 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006422
6423 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006424 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006425" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006426 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006427 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006428
6429 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006430 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006431" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006432 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6433 if s:netrwmarkfilelist_{curbufnr} == []
6434 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006435" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006436 call s:NetrwUnmarkList(curbufnr,curdir)
6437 else
6438 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006439" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006440 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006441 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006442 for fname in s:netrwmarkfilelist_{curbufnr}
6443 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006444 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006445 else
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 endif
6448 let first= 0
6449 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006450" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006451 endif
6452 endif
6453
6454 else
6455 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006456" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006457
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006458" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006459 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006460 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6461" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006462
6463 " build initial markfile matching pattern
6464 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006465 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006466 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006467 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006468 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006469" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006470 endif
6471
6472 " handle global markfilelist
6473 if exists("s:netrwmarkfilelist")
6474 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6475 if index(s:netrwmarkfilelist,dname) == -1
6476 " append new filename to global markfilelist
6477 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006478" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006479 else
6480 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006481" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6482" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006483 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006484" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006485 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006486" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006487 unlet s:netrwmarkfilelist
6488 endif
6489 endif
6490 else
6491 " initialize new global-directory markfilelist
6492 let s:netrwmarkfilelist= []
6493 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006494" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006495 endif
6496
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006497 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006498 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6499 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6500" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6501 if exists("g:did_drchip_netrwlist_syntax")
6502 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6503 endif
6504 else
6505" " call Decho("2match none",'~'.expand("<slnum>"))
6506 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006507 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006508 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006509 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006510" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6511" 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 +00006512endfun
6513
6514" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006515" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6516" mA: move the argument list to marked file list (tomflist=1)
6517" Uses the global marked file list
6518fun! s:NetrwMarkFileArgList(islocal,tomflist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006519 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006520 let curdir = s:NetrwGetCurdir(a:islocal)
6521 let curbufnr = bufnr("%")
6522
6523 if a:tomflist
6524 " mA: move argument list to marked file list
6525 while argc()
6526 let fname= argv(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006527 exe "argdel ".fnameescape(fname)
6528 call s:NetrwMarkFile(a:islocal,fname)
6529 endwhile
6530
6531 else
6532 " ma: move marked file list to argument list
6533 if exists("s:netrwmarkfilelist")
6534
6535 " for every filename in the marked list
6536 for fname in s:netrwmarkfilelist
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006537 exe "argadd ".fnameescape(fname)
6538 endfor " for every file in the marked list
6539
6540 " unmark list and refresh
6541 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01006542 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006543 NetrwKeepj call winrestview(svpos)
6544 endif
6545 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006546endfun
6547
6548" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006549" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
6550" compress/decompress files using the programs
6551" in g:netrw_compress and g:netrw_uncompress,
6552" using g:netrw_compress_suffix to know which to
6553" do. By default:
6554" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006555" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00006556fun! s:NetrwMarkFileCompress(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006557 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006558 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006559 let curbufnr = bufnr("%")
6560
Bram Moolenaarff034192013-04-24 18:51:19 +02006561 " sanity check
6562 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006563 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006564 return
6565 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006566
Bram Moolenaar446cb832008-06-24 21:56:24 +00006567 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02006568
6569 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00006570 for fname in s:netrwmarkfilelist_{curbufnr}
Christian Brabandtcacfccf2024-11-23 13:28:01 +01006571 let sfx= substitute(fname,'^.\{-}\(\.[[:alnum:]]\+\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02006572 if exists("g:netrw_decompress['".sfx."']")
6573 " fname has a suffix indicating that its compressed; apply associated decompression routine
6574 let exe= g:netrw_decompress[sfx]
Bram Moolenaarff034192013-04-24 18:51:19 +02006575 let exe= netrw#WinPath(exe)
6576 if a:islocal
6577 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006578 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006579 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006580 call system(exe." ".fname)
6581 if v:shell_error
6582 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01006583 endif
6584 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006585 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
6586 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01006587 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006588
Bram Moolenaarff034192013-04-24 18:51:19 +02006589 endif
6590 unlet sfx
6591
Bram Moolenaar446cb832008-06-24 21:56:24 +00006592 if exists("exe")
6593 unlet exe
6594 elseif a:islocal
6595 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006596 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006597 if v:shell_error
6598 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
6599 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006600 else
6601 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006602 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006603 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006604 endfor " for every file in the marked list
6605
Bram Moolenaar446cb832008-06-24 21:56:24 +00006606 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01006607 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006608 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006609 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006610endfun
6611
6612" ---------------------------------------------------------------------
6613" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
6614" If no marked files, then set up directory as the
6615" target. Currently does not support copying entire
6616" directories. Uses the local-buffer marked file list.
6617" Returns 1=success (used by NetrwMarkFileMove())
6618" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006619fun! s:NetrwMarkFileCopy(islocal,...)
6620" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
6621
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006622 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006623 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006624 if b:netrw_curdir !~ '/$'
6625 if !exists("b:netrw_curdir")
6626 let b:netrw_curdir= curdir
6627 endif
6628 let b:netrw_curdir= b:netrw_curdir."/"
6629 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006630
Bram Moolenaarff034192013-04-24 18:51:19 +02006631 " sanity check
6632 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006633 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006634" call Dret("s:NetrwMarkFileCopy")
6635 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006636 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006637" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006638
Bram Moolenaar446cb832008-06-24 21:56:24 +00006639 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006640 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006641" call Dret("s:NetrwMarkFileCopy 0")
6642 return 0
6643 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006644" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006645
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006646 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006647 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006648" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006649 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006650 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
6651" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
6652 return
6653 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006654
6655 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02006656 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006657 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
6658 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006659" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006660 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006661 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
6662 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006663" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006664 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006665 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006666 let oldname = a:1
6667 else
6668 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006669" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006670 let s:recursive= 1
6671 for oldname in s:netrwmarkfilelist_{bufnr("%")}
6672 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
6673 if ret == 0
6674 break
6675 endif
6676 endfor
6677 unlet s:recursive
6678 call s:NetrwUnmarkList(curbufnr,curdir)
6679" call Dret("s:NetrwMarkFileCopy ".ret)
6680 return ret
6681 endif
6682
6683 call inputsave()
6684 let newname= input("Copy ".oldname." to : ",oldname,"file")
6685 call inputrestore()
6686 if newname == ""
6687" call Dret("s:NetrwMarkFileCopy 0")
6688 return 0
6689 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006690 let args= s:ShellEscape(oldname)
6691 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006692 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006693 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
6694 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006695 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02006696 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02006697 let args= substitute(args,'/','\\','g')
6698 let tgt = substitute(tgt, '/','\\','g')
6699 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006700 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
6701 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
6702 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
6703 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
6704" call Decho("args <".args.">",'~'.expand("<slnum>"))
6705" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006706 if isdirectory(s:NetrwFile(args))
6707" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006708 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006709" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02006710 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006711 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
6712 " contents to a target. One must append the source directory name to the target to get xcopy to
6713 " do the right thing.
6714 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006715" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006716 endif
6717 else
6718 let copycmd= g:netrw_localcopycmd
6719 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006720 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006721 let copycmd = substitute(copycmd,'\s.*$','','')
6722 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02006723 let copycmd = netrw#WinPath(copycmd).copycmdargs
6724 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006725 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02006726 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006727" call Decho("args <".args.">",'~'.expand("<slnum>"))
6728" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
6729" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
6730" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006731 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01006732 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02006733 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02006734 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 +01006735 else
6736 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
6737 endif
6738" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006739 return 0
6740 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006741
6742 elseif a:islocal && !s:netrwmftgt_islocal
6743 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006744" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006745 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006746
6747 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006748 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006749" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006750 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006751
6752 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006753 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006754" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006755 let curdir = getcwd()
6756 let tmpdir = s:GetTempfile("")
6757 if tmpdir !~ '/'
6758 let tmpdir= curdir."/".tmpdir
6759 endif
6760 if exists("*mkdir")
6761 call mkdir(tmpdir)
6762 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006763 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006764 if v:shell_error != 0
6765 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 +01006766" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01006767 return
6768 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006769 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006770 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006771 if s:NetrwLcd(tmpdir)
6772" call Dret("s:NetrwMarkFileCopy : lcd failure")
6773 return
6774 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006775 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006776 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006777 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006778 if getcwd() == tmpdir
6779 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006780 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006781 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02006782 if s:NetrwLcd(curdir)
6783" call Dret("s:NetrwMarkFileCopy : lcd failure")
6784 return
6785 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01006786 if delete(tmpdir,"d")
6787 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006788 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006789 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006790 if s:NetrwLcd(curdir)
6791" call Dret("s:NetrwMarkFileCopy : lcd failure")
6792 return
6793 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006794 endif
6795 endif
6796 endif
6797
6798 " -------
6799 " cleanup
6800 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006801" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006802 " remove markings from local buffer
6803 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006804" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
6805" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
6806" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
6807" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
6808" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
6809" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
6810 if exists("s:recursive")
6811" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
6812 else
6813" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006814 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006815 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01006816 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006817 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006818 else
6819 " refresh local and targets for fast browsing
6820 if !exists("s:recursive")
6821 " remove markings from local buffer
6822" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
6823 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
6824 endif
6825
6826 " refresh buffers
6827 if s:netrwmftgt_islocal
6828" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
6829 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
6830 endif
6831 if a:islocal && s:netrwmftgt != curdir
6832" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
6833 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
6834 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01006835 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006836
Bram Moolenaar446cb832008-06-24 21:56:24 +00006837" call Dret("s:NetrwMarkFileCopy 1")
6838 return 1
6839endfun
6840
6841" ---------------------------------------------------------------------
6842" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
6843" invoke vim's diff mode on the marked files.
6844" Either two or three files can be so handled.
6845" Uses the global marked file list.
6846fun! s:NetrwMarkFileDiff(islocal)
6847" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6848 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006849
Bram Moolenaarff034192013-04-24 18:51:19 +02006850 " sanity check
6851 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006852 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006853" call Dret("s:NetrwMarkFileDiff")
6854 return
6855 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006856 let curdir= s:NetrwGetCurdir(a:islocal)
6857" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006858
Bram Moolenaara6878372014-03-22 21:02:50 +01006859 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006860 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00006861 for fname in s:netrwmarkfilelist
6862 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006863 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006864" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006865 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006866 diffthis
6867 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09006868 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006869" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006870 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006871 diffthis
6872 else
6873 break
6874 endif
6875 endfor
6876 call s:NetrwUnmarkList(curbufnr,curdir)
6877 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006878
Bram Moolenaar446cb832008-06-24 21:56:24 +00006879" call Dret("s:NetrwMarkFileDiff")
6880endfun
6881
6882" ---------------------------------------------------------------------
6883" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
6884" Uses global markfilelist
6885fun! s:NetrwMarkFileEdit(islocal)
6886" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
6887
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006888 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006889 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02006890
6891 " sanity check
6892 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006893 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006894" call Dret("s:NetrwMarkFileEdit")
6895 return
6896 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006897" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006898
Bram Moolenaar446cb832008-06-24 21:56:24 +00006899 if exists("s:netrwmarkfilelist_{curbufnr}")
6900 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006901 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006902 " unmark markedfile list
6903" call s:NetrwUnmarkList(curbufnr,curdir)
6904 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006905" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02006906 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00006907 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006908 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006909
Bram Moolenaar446cb832008-06-24 21:56:24 +00006910" call Dret("s:NetrwMarkFileEdit")
6911endfun
6912
6913" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006914" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02006915fun! s:NetrwMarkFileQFEL(islocal,qfel)
6916" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
6917 call s:NetrwUnmarkAll()
6918 let curbufnr= bufnr("%")
6919
6920 if !empty(a:qfel)
6921 for entry in a:qfel
6922 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006923" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006924 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006925" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006926 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
6927 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
6928 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
6929 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006930" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006931 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
6932 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006933" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006934 endif
6935 endfor
6936 echo "(use me to edit marked files)"
6937 else
6938 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
6939 endif
6940
6941" call Dret("s:NetrwMarkFileQFEL")
6942endfun
6943
6944" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006945" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
6946" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
6947" mX enbloc=1: Uses the global marked-file list, applies command to entire list
6948fun! s:NetrwMarkFileExe(islocal,enbloc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006949 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006950 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006951 let curbufnr = bufnr("%")
6952
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006953 if a:enbloc == 0
6954 " individually apply command to files, one at a time
6955 " sanity check
6956 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6957 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006958 return
6959 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006960
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006961 if exists("s:netrwmarkfilelist_{curbufnr}")
6962 " get the command
6963 call inputsave()
6964 let cmd= input("Enter command: ","","file")
6965 call inputrestore()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006966 if cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006967 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006968 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006969
6970 " apply command to marked files, individually. Substitute: filename -> %
6971 " If no %, then append a space and the filename to the command
6972 for fname in s:netrwmarkfilelist_{curbufnr}
6973 if a:islocal
6974 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09006975 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006976 endif
6977 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006978 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006979 endif
6980 if cmd =~ '%'
6981 let xcmd= substitute(cmd,'%',fname,'g')
6982 else
6983 let xcmd= cmd.' '.fname
6984 endif
6985 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006986 let ret= system(xcmd)
6987 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006988 let ret= s:RemoteSystem(xcmd)
6989 endif
6990 if v:shell_error < 0
6991 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
6992 break
6993 else
yasudac75dad02024-08-22 21:06:32 +02006994 if ret !=# ''
6995 echo "\n"
6996 " skip trailing new line
6997 echo ret[0:-2]
6998 else
6999 echo ret
7000 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007001 endif
7002 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007003
7004 " unmark marked file list
7005 call s:NetrwUnmarkList(curbufnr,curdir)
7006
7007 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007008 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007009 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007010 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007011 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007012 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007013
7014 else " apply command to global list of files, en bloc
7015
7016 call inputsave()
7017 let cmd= input("Enter command: ","","file")
7018 call inputrestore()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007019 if cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007020 return
7021 endif
7022 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007023 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007024 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007025 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007026 endif
7027 if a:islocal
7028 call system(cmd)
7029 if v:shell_error < 0
7030 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7031 endif
7032 else
7033 let ret= s:RemoteSystem(cmd)
7034 endif
7035 call s:NetrwUnmarkAll()
7036
7037 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007038 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007039 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007040
7041 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007042endfun
7043
7044" ---------------------------------------------------------------------
7045" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7046" as the marked file(s) (toggles suffix presence)
7047" Uses the local marked file list.
7048fun! s:NetrwMarkHideSfx(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007049 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007050 let curbufnr = bufnr("%")
7051
7052 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7053 if exists("s:netrwmarkfilelist_{curbufnr}")
7054
7055 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007056 " construct suffix pattern
7057 if fname =~ '\.'
7058 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7059 else
7060 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7061 endif
7062 " determine if its in the hiding list or not
7063 let inhidelist= 0
7064 if g:netrw_list_hide != ""
7065 let itemnum = 0
7066 let hidelist= split(g:netrw_list_hide,',')
7067 for hidepat in hidelist
7068 if sfxpat == hidepat
7069 let inhidelist= 1
7070 break
7071 endif
7072 let itemnum= itemnum + 1
7073 endfor
7074 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007075 if inhidelist
7076 " remove sfxpat from list
7077 call remove(hidelist,itemnum)
7078 let g:netrw_list_hide= join(hidelist,",")
7079 elseif g:netrw_list_hide != ""
7080 " append sfxpat to non-empty list
7081 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7082 else
7083 " set hiding list to sfxpat
7084 let g:netrw_list_hide= sfxpat
7085 endif
7086 endfor
7087
7088 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007089 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007090 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007091 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007092 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007093 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007094endfun
7095
7096" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007097" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007098" Uses the local marked-file list.
7099fun! s:NetrwMarkFileVimCmd(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007100 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007101 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007102 let curbufnr = bufnr("%")
7103
Bram Moolenaarff034192013-04-24 18:51:19 +02007104 " sanity check
7105 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007106 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007107 return
7108 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007109
Bram Moolenaar15146672011-10-20 22:22:38 +02007110 if exists("s:netrwmarkfilelist_{curbufnr}")
7111 " get the command
7112 call inputsave()
7113 let cmd= input("Enter vim command: ","","file")
7114 call inputrestore()
Bram Moolenaar15146672011-10-20 22:22:38 +02007115 if cmd == ""
Bram Moolenaar15146672011-10-20 22:22:38 +02007116 return
7117 endif
7118
7119 " apply command to marked files. Substitute: filename -> %
7120 " If no %, then append a space and the filename to the command
7121 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar15146672011-10-20 22:22:38 +02007122 if a:islocal
7123 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007124 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaar15146672011-10-20 22:22:38 +02007125 exe cmd
7126 exe "sil! keepalt wq!"
7127 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007128 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007129 endif
7130 endfor
7131
7132 " unmark marked file list
7133 call s:NetrwUnmarkList(curbufnr,curdir)
7134
7135 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007136 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007137 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007138 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007139 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007140 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007141endfun
7142
7143" ---------------------------------------------------------------------
7144" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7145" as the marked file(s) (toggles suffix presence)
7146" Uses the local marked file list.
7147fun! s:NetrwMarkHideSfx(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007148 let svpos = winsaveview()
Bram Moolenaar15146672011-10-20 22:22:38 +02007149 let curbufnr = bufnr("%")
7150
7151 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7152 if exists("s:netrwmarkfilelist_{curbufnr}")
7153
7154 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar15146672011-10-20 22:22:38 +02007155 " construct suffix pattern
7156 if fname =~ '\.'
7157 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7158 else
7159 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7160 endif
7161 " determine if its in the hiding list or not
7162 let inhidelist= 0
7163 if g:netrw_list_hide != ""
7164 let itemnum = 0
7165 let hidelist= split(g:netrw_list_hide,',')
7166 for hidepat in hidelist
7167 if sfxpat == hidepat
7168 let inhidelist= 1
7169 break
7170 endif
7171 let itemnum= itemnum + 1
7172 endfor
7173 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007174 if inhidelist
7175 " remove sfxpat from list
7176 call remove(hidelist,itemnum)
7177 let g:netrw_list_hide= join(hidelist,",")
7178 elseif g:netrw_list_hide != ""
7179 " append sfxpat to non-empty list
7180 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7181 else
7182 " set hiding list to sfxpat
7183 let g:netrw_list_hide= sfxpat
7184 endif
7185 endfor
7186
7187 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007188 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007189 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007190 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007191 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007192 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007193endfun
7194
7195" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007196" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7197" Uses the global markfilelist
7198fun! s:NetrwMarkFileGrep(islocal)
7199" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007200 let svpos = winsaveview()
7201" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007202 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007203 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007204
7205 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007206" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007207 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007208" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007209 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007210 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007211" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007212 let netrwmarkfilelist= "*"
7213 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007214
Bram Moolenaarff034192013-04-24 18:51:19 +02007215 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007216" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007217 call inputsave()
7218 let pat= input("Enter pattern: ","")
7219 call inputrestore()
7220 let patbang = ""
7221 if pat =~ '^!'
7222 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007223 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007224 endif
7225 if pat =~ '^\i'
7226 let pat = escape(pat,'/')
7227 let pat = '/'.pat.'/'
7228 else
7229 let nonisi = pat[0]
7230 endif
7231
7232 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007233" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007234 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007235 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007236 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007237 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007238" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7239 return
7240 endtry
7241 echo "(use :cn, :cp to navigate, :Rex to return)"
7242
7243 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007244" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7245 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007246
7247 if exists("nonisi")
7248 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007249" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007250 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007251 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007252 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007253 endif
7254
7255" call Dret("s:NetrwMarkFileGrep")
7256endfun
7257
7258" ---------------------------------------------------------------------
7259" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7260" uses the global marked file list
7261" s:netrwmfloc= 0: target directory is remote
7262" = 1: target directory is local
7263fun! s:NetrwMarkFileMove(islocal)
7264" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007265 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007266 let curbufnr = bufnr("%")
7267
7268 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007269 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007270 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007271" call Dret("s:NetrwMarkFileMove")
7272 return
7273 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007274" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007275
Bram Moolenaar446cb832008-06-24 21:56:24 +00007276 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007277 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007278" call Dret("s:NetrwMarkFileCopy 0")
7279 return 0
7280 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007281" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007282
7283 if a:islocal && s:netrwmftgt_islocal
7284 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007285" call Decho("move from local to local",'~'.expand("<slnum>"))
7286" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007287 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007288 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7289" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7290 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007291 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007292 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007293" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007294 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007295 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007296" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007297 if g:netrw_localmovecmd =~ '\s'
7298 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7299 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7300 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007301" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007302 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007303 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007304" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007305 endif
7306 else
7307 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007308" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007309 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007310 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007311 if g:netrw_keepdir
7312 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7313 let fname= b:netrw_curdir."/".fname
7314 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007315 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007316 let fname= substitute(fname,'/','\\','g')
7317 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007318" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007319 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007320 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007321 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007322 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 +01007323 else
7324 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7325 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007326 break
7327 endif
7328 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007329
7330 elseif a:islocal && !s:netrwmftgt_islocal
7331 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007332" call Decho("move from local to remote",'~'.expand("<slnum>"))
7333" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007334 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007335 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007336" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007337 for fname in mflist
7338 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7339 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7340 endfor
7341 unlet mflist
7342
7343 elseif !a:islocal && s:netrwmftgt_islocal
7344 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007345" call Decho("move from remote to local",'~'.expand("<slnum>"))
7346" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007347 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007348 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007349" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007350 for fname in mflist
7351 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7352 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7353 endfor
7354 unlet mflist
7355
7356 elseif !a:islocal && !s:netrwmftgt_islocal
7357 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007358" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7359" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007360 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007361 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007362" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007363 for fname in mflist
7364 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7365 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7366 endfor
7367 unlet mflist
7368 endif
7369
7370 " -------
7371 " cleanup
7372 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007373" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007374
7375 " remove markings from local buffer
7376 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7377
7378 " refresh buffers
7379 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007380" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007381 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007382 endif
7383 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007384" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007385 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007386 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007387 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007388" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007389 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007390 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007391
Bram Moolenaar446cb832008-06-24 21:56:24 +00007392" call Dret("s:NetrwMarkFileMove")
7393endfun
7394
7395" ---------------------------------------------------------------------
7396" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7397" using the hardcopy command. Local marked-file list only.
7398fun! s:NetrwMarkFilePrint(islocal)
7399" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7400 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007401
7402 " sanity check
7403 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007404 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007405" call Dret("s:NetrwMarkFilePrint")
7406 return
7407 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007408" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7409 let curdir= s:NetrwGetCurdir(a:islocal)
7410
Bram Moolenaar446cb832008-06-24 21:56:24 +00007411 if exists("s:netrwmarkfilelist_{curbufnr}")
7412 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007413 call s:NetrwUnmarkList(curbufnr,curdir)
7414 for fname in netrwmarkfilelist
7415 if a:islocal
7416 if g:netrw_keepdir
7417 let fname= s:ComposePath(curdir,fname)
7418 endif
7419 else
7420 let fname= curdir.fname
7421 endif
7422 1split
7423 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007424" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007425 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007426" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007427 hardcopy
7428 q
7429 endfor
7430 2match none
7431 endif
7432" call Dret("s:NetrwMarkFilePrint")
7433endfun
7434
7435" ---------------------------------------------------------------------
7436" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7437" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007438" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007439fun! s:NetrwMarkFileRegexp(islocal)
7440" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7441
7442 " get the regular expression
7443 call inputsave()
7444 let regexp= input("Enter regexp: ","","file")
7445 call inputrestore()
7446
7447 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007448 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007449" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007450 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007451" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007452 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007453 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007454 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007455 else
7456 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007457 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007458 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007459" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007460
7461 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007462 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007463 if fname =~ '^'.fnameescape(curdir)
7464" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7465 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7466 else
7467" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7468 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7469 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007470 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007471
7472 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007473" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007474
7475 " convert displayed listing into a filelist
7476 let eikeep = &ei
7477 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007478 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007479 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007480" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007481 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007482 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02007483 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007484 sil NetrwKeepj norm! "ap
7485 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007486 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007487 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007488 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007489 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007490 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007491 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007492 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007493 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007494 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007495 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007496 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7497 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007498 call histdel("/",-1)
7499 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007500 endif
7501 " convert regexp into the more usual glob-style format
7502 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007503" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007504 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01007505 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007506 let filelist= getline(1,line("$"))
7507 q!
7508 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007509 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007510 endfor
7511 unlet filelist
7512 let @a = areg
7513 let &ei = eikeep
7514 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007515 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007516
7517" call Dret("s:NetrwMarkFileRegexp")
7518endfun
7519
7520" ---------------------------------------------------------------------
7521" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
7522" Uses the local marked file list.
7523fun! s:NetrwMarkFileSource(islocal)
7524" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
7525 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007526
7527 " sanity check
7528 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007529 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007530" call Dret("s:NetrwMarkFileSource")
7531 return
7532 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007533" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7534 let curdir= s:NetrwGetCurdir(a:islocal)
7535
Bram Moolenaar446cb832008-06-24 21:56:24 +00007536 if exists("s:netrwmarkfilelist_{curbufnr}")
7537 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007538 call s:NetrwUnmarkList(curbufnr,curdir)
7539 for fname in netrwmarkfilelist
7540 if a:islocal
7541 if g:netrw_keepdir
7542 let fname= s:ComposePath(curdir,fname)
7543 endif
7544 else
7545 let fname= curdir.fname
7546 endif
7547 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007548" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007549 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007550 endfor
7551 2match none
7552 endif
7553" call Dret("s:NetrwMarkFileSource")
7554endfun
7555
7556" ---------------------------------------------------------------------
7557" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
7558" Uses the global markfilelist
7559fun! s:NetrwMarkFileTag(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007560 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007561 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007562 let curbufnr = bufnr("%")
7563
Bram Moolenaarff034192013-04-24 18:51:19 +02007564 " sanity check
7565 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007566 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007567 return
7568 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007569
Bram Moolenaar446cb832008-06-24 21:56:24 +00007570 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007571 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007572 call s:NetrwUnmarkAll()
7573
7574 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02007575
Bram Moolenaar85850f32019-07-19 22:05:51 +02007576 call system(g:netrw_ctags." ".netrwmarkfilelist)
7577 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00007578 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
7579 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007580
Bram Moolenaar446cb832008-06-24 21:56:24 +00007581 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00007582 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01007583 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007584 let curdir= b:netrw_curdir
7585 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007586 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00007587 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007588 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01007589 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007590 wq!
7591 endif
7592 2match none
Tom Benham64a536d2024-11-07 21:15:03 +01007593 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007594 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007595 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007596endfun
7597
7598" ---------------------------------------------------------------------
7599" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007600" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02007601" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00007602" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02007603" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00007604fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007605 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007606 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007607 let hadtgt = exists("s:netrwmftgt")
7608 if !exists("w:netrw_bannercnt")
7609 let w:netrw_bannercnt= b:netrw_bannercnt
7610 endif
7611
7612 " set up target
7613 if line(".") < w:netrw_bannercnt
Bram Moolenaarff034192013-04-24 18:51:19 +02007614 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
7615 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaarff034192013-04-24 18:51:19 +02007616 unlet s:netrwmftgt s:netrwmftgt_islocal
7617 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007618 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02007619 endif
Tom Benham64a536d2024-11-07 21:15:03 +01007620 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007621 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007622 return
7623 else
7624 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaarff034192013-04-24 18:51:19 +02007625 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007626
7627 else
7628 " get word under cursor.
7629 " * If directory, use it for the target.
7630 " * If file, use b:netrw_curdir for the target
7631 let curword= s:NetrwGetWord()
7632 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007633 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007634 let s:netrwmftgt = tgtdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007635 elseif !a:islocal && tgtdir =~ '/$'
7636 let s:netrwmftgt = tgtdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007637 else
7638 let s:netrwmftgt = curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007639 endif
7640 endif
7641 if a:islocal
7642 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
7643 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007644 endif
7645 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007646 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007647 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
7648 endif
7649 let s:netrwmftgt_islocal= a:islocal
7650
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007651 " need to do refresh so that the banner will be updated
7652 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01007653 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007654 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007655 endif
Tom Benham64a536d2024-11-07 21:15:03 +01007656" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007657 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Tom Benham64a536d2024-11-07 21:15:03 +01007658 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop,0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007659 else
Tom Benham64a536d2024-11-07 21:15:03 +01007660 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007661 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007662 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007663 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007664 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00007665 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007666endfun
7667
7668" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007669" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
7670fun! s:NetrwGetCurdir(islocal)
7671" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
7672
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007673 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007674 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
7675" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
7676 elseif !exists("b:netrw_curdir")
7677 let b:netrw_curdir= getcwd()
7678" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
7679 endif
7680
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007681" 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 +01007682 if b:netrw_curdir !~ '\<\a\{3,}://'
7683 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007684" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007685 if g:netrw_keepdir == 0
7686 call s:NetrwLcd(curdir)
7687 endif
7688 endif
7689
7690" call Dret("s:NetrwGetCurdir <".curdir.">")
7691 return b:netrw_curdir
7692endfun
7693
7694" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00007695" s:NetrwOpenFile: query user for a filename and open it {{{2
7696fun! s:NetrwOpenFile(islocal)
7697" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007698 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00007699 call inputsave()
7700 let fname= input("Enter filename: ")
7701 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02007702" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
7703
7704 " determine if Lexplore is in use
7705 if exists("t:netrw_lexbufnr")
7706 " check if t:netrw_lexbufnr refers to a netrw window
7707" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
7708 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
7709 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
7710" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
7711 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
7712 exe "NetrwKeepj e ".fnameescape(fname)
7713 let @@= ykeep
7714" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
7715 endif
7716 endif
7717
7718 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00007719 if fname !~ '[/\\]'
7720 if exists("b:netrw_curdir")
7721 if exists("g:netrw_quiet")
7722 let netrw_quiet_keep = g:netrw_quiet
7723 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007724 let g:netrw_quiet = 1
7725 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007726 let s:rexposn_{bufnr("%")}= winsaveview()
7727" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007728 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007729 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007730 else
7731 exe "e ".fnameescape(b:netrw_curdir."/".fname)
7732 endif
7733 if exists("netrw_quiet_keep")
7734 let g:netrw_quiet= netrw_quiet_keep
7735 else
7736 unlet g:netrw_quiet
7737 endif
7738 endif
7739 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007740 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007741 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007742 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00007743" call Dret("s:NetrwOpenFile")
7744endfun
7745
7746" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007747" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
7748" For the mapping to this function be made via
7749" netrwPlugin, you'll need to have had
7750" g:netrw_usetab set to non-zero.
7751fun! netrw#Shrink()
7752" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
7753 let curwin = winnr()
7754 let wiwkeep = &wiw
7755 set wiw=1
7756
7757 if &ft == "netrw"
7758 if winwidth(0) > g:netrw_wiw
7759 let t:netrw_winwidth= winwidth(0)
7760 exe "vert resize ".g:netrw_wiw
7761 wincmd l
7762 if winnr() == curwin
7763 wincmd h
7764 endif
7765" call Decho("vert resize 0",'~'.expand("<slnum>"))
7766 else
7767 exe "vert resize ".t:netrw_winwidth
7768" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
7769 endif
7770
7771 elseif exists("t:netrw_lexbufnr")
7772 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
7773 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
7774 let t:netrw_winwidth= winwidth(0)
7775 exe "vert resize ".g:netrw_wiw
7776 wincmd l
7777 if winnr() == curwin
7778 wincmd h
7779 endif
7780" call Decho("vert resize 0",'~'.expand("<slnum>"))
7781 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
7782 exe "vert resize ".t:netrw_winwidth
7783" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01007784 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007785 call netrw#Lexplore(0,0)
7786 endif
7787
7788 else
7789 call netrw#Lexplore(0,0)
7790 endif
7791 let wiw= wiwkeep
7792
7793" call Dret("netrw#Shrink")
7794endfun
7795
7796" ---------------------------------------------------------------------
7797" s:NetSortSequence: allows user to edit the sorting sequence {{{2
7798fun! s:NetSortSequence(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007799 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007800 let svpos= winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007801 call inputsave()
7802 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
7803 call inputrestore()
7804
7805 " refresh the listing
7806 let g:netrw_sort_sequence= newsortseq
Tom Benham64a536d2024-11-07 21:15:03 +01007807 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007808 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007809 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007810endfun
7811
7812" ---------------------------------------------------------------------
7813" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
7814" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02007815" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00007816fun! s:NetrwUnmarkList(curbufnr,curdir)
7817" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
7818
7819 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007820 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007821 for mfile in s:netrwmarkfilelist_{a:curbufnr}
7822 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
7823 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
7824 call remove(s:netrwmarkfilelist,idx) " remove from global list
7825 endfor
7826 if s:netrwmarkfilelist == []
7827 unlet s:netrwmarkfilelist
7828 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007829
Bram Moolenaar446cb832008-06-24 21:56:24 +00007830 " getting rid of the local marked-file lists is easy
7831 unlet s:netrwmarkfilelist_{a:curbufnr}
7832 endif
7833 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
7834 unlet s:netrwmarkfilemtch_{a:curbufnr}
7835 endif
7836 2match none
7837" call Dret("s:NetrwUnmarkList")
7838endfun
7839
7840" ---------------------------------------------------------------------
7841" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
7842fun! s:NetrwUnmarkAll()
7843" call Dfunc("s:NetrwUnmarkAll()")
7844 if exists("s:netrwmarkfilelist")
7845 unlet s:netrwmarkfilelist
7846 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02007847 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007848 2match none
7849" call Dret("s:NetrwUnmarkAll")
7850endfun
7851
7852" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02007853" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007854fun! s:NetrwUnmarkAll2()
7855" call Dfunc("s:NetrwUnmarkAll2()")
7856 redir => netrwmarkfilelist_let
7857 let
7858 redir END
7859 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007860 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00007861 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
7862 for flist in netrwmarkfilelist_list
7863 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
7864 unlet s:netrwmarkfilelist_{curbufnr}
7865 unlet s:netrwmarkfilemtch_{curbufnr}
7866 endfor
7867" call Dret("s:NetrwUnmarkAll2")
7868endfun
7869
7870" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007871" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
7872"
7873" Marked files are in two types of lists:
7874" s:netrwmarkfilelist -- holds complete paths to all marked files
7875" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
7876"
7877" Marked files suitable for use with 2match are in:
7878" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00007879fun! s:NetrwUnMarkFile(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007880 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007881 let curbufnr = bufnr("%")
7882
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007883 " unmark marked file list
7884 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
7885 if exists("s:netrwmarkfilelist")
7886" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007887 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007888 endif
7889
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007890 let ibuf= 1
7891 while ibuf < bufnr("$")
7892 if exists("s:netrwmarkfilelist_".ibuf)
7893 unlet s:netrwmarkfilelist_{ibuf}
7894 unlet s:netrwmarkfilemtch_{ibuf}
7895 endif
7896 let ibuf = ibuf + 1
7897 endwhile
7898 2match none
7899
Tom Benham64a536d2024-11-07 21:15:03 +01007900" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007901call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007902endfun
7903
7904" ---------------------------------------------------------------------
7905" s:NetrwMenu: generates the menu for gvim and netrw {{{2
7906fun! s:NetrwMenu(domenu)
7907
7908 if !exists("g:NetrwMenuPriority")
7909 let g:NetrwMenuPriority= 80
7910 endif
7911
Bram Moolenaaradc21822011-04-01 18:03:16 +02007912 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00007913" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
7914
7915 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007916" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007917 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02007918 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
7919 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
7920 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
7921 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
7922 if g:netrw_dirhistmax > 0
7923 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
7924 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
7925 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
7926 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
7927 else
7928 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
7929 endif
7930 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
7931 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
7932 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
7933 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
7934 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
7935 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
7936 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
7937 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
7938 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
7939 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
7940 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
7941 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
7942 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
7943 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
7944 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 +01007945 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 +02007946 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
7947 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
7948 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
7949 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
7950 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
7951 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
7952 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
7953 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
7954 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
7955 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
7956 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
7957 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
7958 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
7959 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
7960 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
7961 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
7962 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
7963 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
7964 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
7965 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
7966 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
7967 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
7968 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
7969 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
7970 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
7971 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
7972 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
7973 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
7974 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
7975 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>'
7976 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>'
7977 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>'
7978 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
7979 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>'
7980 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>'
7981 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 +01007982 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 +02007983 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
7984 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00007985 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02007986 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
7987 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00007988
7989 elseif !a:domenu
7990 let s:netrwcnt = 0
7991 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007992 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007993 exe curwin."wincmd w"
7994
7995 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007996" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007997 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007998" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007999 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008000 endif
8001 endif
8002" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008003 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008004 endif
8005
8006endfun
8007
8008" ---------------------------------------------------------------------
8009" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8010" Used by the O maps (as <SID>NetrwObtain())
8011fun! s:NetrwObtain(islocal)
8012" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8013
Bram Moolenaar97d62492012-11-15 21:28:22 +01008014 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008015 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008016 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008017 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008018 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8019 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008020 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008021 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008022 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008023
8024" call Dret("NetrwObtain")
8025endfun
8026
8027" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008028" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8029" If there's only one window, then the window will first be split.
8030" Returns:
8031" choice = 0 : didn't have to choose
8032" choice = 1 : saved modified file in window first
8033" choice = 2 : didn't save modified file, opened window
8034" choice = 3 : cancel open
8035fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008036 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008037 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008038 let curdir = b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008039
8040 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008041 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008042 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008043 let curword = s:NetrwGetWord()
8044 let choice = 0
8045 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 +01008046 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01008047 let curdir = s:treedir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008048
Bram Moolenaar8d043172014-01-23 14:24:41 +01008049 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008050 if lastwinnr == 1
8051 " if only one window, open a new one first
Bram Moolenaar85850f32019-07-19 22:05:51 +02008052 " g:netrw_preview=0: preview window shown in a horizontally split window
8053 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008054 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008055 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008056 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar15146672011-10-20 22:22:38 +02008057 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008058 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008059 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008060 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar15146672011-10-20 22:22:38 +02008061 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008062 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008063 let didsplit = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00008064
8065 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008066 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008067 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01008068 setl ei=all
Bram Moolenaar446cb832008-06-24 21:56:24 +00008069 wincmd p
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01008070
Bram Moolenaar71badf92023-04-22 22:40:14 +01008071 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8072 " whoops -- user trying to open file in the Lexplore window.
8073 " Use Lexplore's opening-file window instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01008074" exe g:netrw_chgwin."wincmd w"
8075 wincmd p
Tom Benham64a536d2024-11-07 21:15:03 +01008076 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008077 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008078
8079 " prevwinnr: the window number of the "prev" window
8080 " prevbufnr: the buffer number of the buffer in the "prev" window
8081 " bnrcnt : the qty of windows open on the "prev" buffer
8082 let prevwinnr = winnr()
8083 let prevbufnr = bufnr("%")
8084 let prevbufname = bufname("%")
8085 let prevmod = &mod
8086 let bnrcnt = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008087 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008088
8089 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008090 " and it doesn't appear in any other extant window, then ask the
8091 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008092 if prevmod
Bram Moolenaar8d043172014-01-23 14:24:41 +01008093 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008094 exe prevwinnr."wincmd w"
8095
8096 if bnrcnt == 1 && &hidden == 0
8097 " only one copy of the modified buffer in a window, and
8098 " hidden not set, so overwriting will lose the modified file. Ask first...
8099 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008100 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008101
8102 if choice == 1
8103 " Yes -- write file & then browse
8104 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008105 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008106 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008107 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008108 exe origwin."wincmd w"
8109 let &ei = eikeep
8110 let @@ = ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008111 return choice
8112 endif
8113
8114 elseif choice == 2
8115 " No -- don't worry about changed file, just browse anyway
Bram Moolenaar8d043172014-01-23 14:24:41 +01008116 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008117
8118 else
8119 " Cancel -- don't do this
Bram Moolenaar8d043172014-01-23 14:24:41 +01008120 exe origwin."wincmd w"
8121 let &ei= eikeep
8122 let @@ = ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008123 return choice
8124 endif
8125 endif
8126 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008127 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008128 endif
8129
8130 " restore b:netrw_curdir (window split/enew may have lost it)
8131 let b:netrw_curdir= curdir
8132 if a:islocal < 2
8133 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01008134 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword,0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008135 else
Tom Benham64a536d2024-11-07 21:15:03 +01008136 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword,0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008137 endif
8138 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008139 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008140 return choice
8141endfun
8142
8143" ---------------------------------------------------------------------
8144" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8145" Always assumed to be local -> remote
8146" call s:NetrwUpload(filename, target)
8147" call s:NetrwUpload(filename, target, fromdirectory)
8148fun! s:NetrwUpload(fname,tgt,...)
8149" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8150
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008151 if a:tgt =~ '^\a\{3,}://'
8152 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008153 else
8154 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8155 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008156" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008157
8158 if a:0 > 0
8159 let fromdir= a:1
8160 else
8161 let fromdir= getcwd()
8162 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008163" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008164
8165 if type(a:fname) == 1
8166 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008167" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008168 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008169" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8170 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8171" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008172 if a:tgt =~ '/$'
8173 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008174" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008175 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008176 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008177" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008178 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008179" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008180 endif
8181 q!
8182
8183 elseif type(a:fname) == 3
8184 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008185" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008186 let curdir= getcwd()
8187 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008188 if s:NetrwLcd(fromdir)
8189" call Dret("s:NetrwUpload : lcd failure")
8190 return
8191 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008192 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008193 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008194 if exists("g:netrw_port") && g:netrw_port != ""
8195 let useport= " ".g:netrw_scpport." ".g:netrw_port
8196 else
8197 let useport= ""
8198 endif
8199 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8200 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008201 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 +02008202 if s:NetrwLcd(curdir)
8203" call Dret("s:NetrwUpload : lcd failure")
8204 return
8205 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008206
8207 elseif a:tgt =~ '^ftp:'
8208 call s:NetrwMethod(a:tgt)
8209
8210 if b:netrw_method == 2
8211 " handle uploading a list of files via ftp+.netrc
8212 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008213 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008214" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008215
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008216 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008217" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008218
8219 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008220 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008221" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008222 endif
8223
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008224 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008225" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008226
Bram Moolenaaradc21822011-04-01 18:03:16 +02008227 if tgtdir == ""
8228 let tgtdir= '/'
8229 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008230 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008231" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008232
8233 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008234 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8235" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008236 endfor
8237
8238 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008239 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 +00008240 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008241" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8242 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008243 endif
8244 " 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 +01008245 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008246 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008247 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8248 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8249 else
8250 bw!|q
8251 endif
8252
8253 elseif b:netrw_method == 3
8254 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8255 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008256 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008257 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008258 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008259
8260 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008261 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008262" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008263 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008264 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008265" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008266 endif
8267
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008268 if exists("g:netrw_uid") && g:netrw_uid != ""
8269 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008270 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008271" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008272 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008273 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008274 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008275" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008276 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008277 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008278" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008279 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008280 endif
8281
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008282 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008283" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008284
8285 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008286 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008287" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008288 endif
8289
8290 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008291 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008292" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008293 endif
8294
8295 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008296 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008297" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008298 endfor
8299
8300 " perform ftp:
8301 " -i : turns off interactive prompting from ftp
8302 " -n unix : DON'T use <.netrc>, even though it exists
8303 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008304 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008305 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008306 " 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 +01008307 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008308 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008309 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8310 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008311 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008312 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8313 let &debug = debugkeep
8314 let mod = 1
8315 else
8316 bw!|q
8317 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008318 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008319" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008320 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008321 endif
8322 else
8323 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8324 endif
8325 endif
8326
8327" call Dret("s:NetrwUpload")
8328endfun
8329
8330" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008331" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008332fun! s:NetrwPreview(path) range
8333" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008334" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8335" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008336 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008337 NetrwKeepj call s:NetrwOptionsSave("s:")
8338 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8339 NetrwKeepj call s:NetrwOptionsSafe(1)
8340 else
8341 NetrwKeepj call s:NetrwOptionsSafe(0)
8342 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008343 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008344" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008345 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008346" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8347 if g:netrw_preview
8348 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008349 let pvhkeep = &pvh
8350 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8351 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008352" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8353 else
8354 " horizontal split
8355 let pvhkeep = &pvh
8356 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8357 let &pvh = winheight(0) - winsz
8358" 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 +02008359 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008360 " g:netrw_preview g:netrw_alto
8361 " 1 : vert 1: top -- preview window is vertically split off and on the left
8362 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8363 " 0 : 1: top -- preview window is horizontally split off and on the top
8364 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8365 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008366 " 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 +02008367 " the BufEnter event set up in netrwPlugin.vim
8368" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8369 let eikeep = &ei
8370 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008371 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008372 let &ei= eikeep
8373" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008374 if exists("pvhkeep")
8375 let &pvh= pvhkeep
8376 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008377 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008378 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008379 endif
8380 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008381 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 +00008382 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008383 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008384 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008385" call Dret("NetrwPreview")
8386endfun
8387
8388" ---------------------------------------------------------------------
8389" s:NetrwRefresh: {{{2
8390fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008391" 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 +00008392 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008393 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008394" call Decho("setl ma noro",'~'.expand("<slnum>"))
8395" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008396 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008397 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8398 if !exists("w:netrw_treetop")
8399 if exists("b:netrw_curdir")
8400 let w:netrw_treetop= b:netrw_curdir
8401 else
8402 let w:netrw_treetop= getcwd()
8403 endif
8404 endif
8405 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
8406 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008407
8408 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008409 let screenposn = winsaveview()
8410" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008411
8412" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
8413" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
8414 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008415 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008416 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008417 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008418 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008419 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008420
8421 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008422" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
8423 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008424
8425 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02008426 if has("syntax") && exists("g:syntax_on") && g:syntax_on
8427 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8428" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
8429 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8430 else
8431" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
8432 2match none
8433 endif
8434 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008435
Bram Moolenaar97d62492012-11-15 21:28:22 +01008436" restore
8437 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008438" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008439endfun
8440
8441" ---------------------------------------------------------------------
8442" s:NetrwRefreshDir: refreshes a directory by name {{{2
8443" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008444" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008445fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008446 if g:netrw_fastbrowse == 0
8447 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008448 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008449
8450 if tgtwin > 0
8451 " tgtwin is being displayed, so refresh it
8452 let curwin= winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008453 exe tgtwin."wincmd w"
Tom Benham64a536d2024-11-07 21:15:03 +01008454 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008455 exe curwin."wincmd w"
8456
8457 elseif bufnr(a:dirname) > 0
8458 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008459 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00008460 endif
8461
8462 elseif g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008463 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008464 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008465endfun
8466
8467" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02008468" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
8469" window number to do its editing in.
8470" Supports [count]C where the count, if present, is used to specify
8471" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008472fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02008473" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008474 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008475" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008476 if a:1 == "" " :NetrwC win#
8477 let g:netrw_chgwin= winnr()
8478 else " :NetrwC
8479 let g:netrw_chgwin= a:1
8480 endif
8481 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02008482 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008483 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02008484 let g:netrw_chgwin= winnr()
8485 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008486 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008487" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02008488endfun
8489
8490" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008491" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
8492" What this function does is to compute a priority for the patterns
8493" in the g:netrw_sort_sequence. It applies a substitute to any
8494" "files" that satisfy each pattern, putting the priority / in
8495" front. An "*" pattern handles the default priority.
8496fun! s:NetrwSetSort()
8497" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008498 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008499 if w:netrw_liststyle == s:LONGLIST
8500 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
8501 else
8502 let seqlist = g:netrw_sort_sequence
8503 endif
8504 " sanity check -- insure that * appears somewhere
8505 if seqlist == ""
8506 let seqlist= '*'
8507 elseif seqlist !~ '\*'
8508 let seqlist= seqlist.',*'
8509 endif
8510 let priority = 1
8511 while seqlist != ""
8512 if seqlist =~ ','
8513 let seq = substitute(seqlist,',.*$','','e')
8514 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
8515 else
8516 let seq = seqlist
8517 let seqlist = ""
8518 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008519 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01008520 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008521 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01008522 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008523 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01008524 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008525 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008526" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008527
8528 " sanity check
8529 if w:netrw_bannercnt > line("$")
8530 " apparently no files were left after a Hiding pattern was used
8531" call Dret("SetSort : no files left after hiding")
8532 return
8533 endif
8534 if seq == '*'
8535 let starpriority= spriority
8536 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008537 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008538 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008539 " sometimes multiple sorting patterns will match the same file or directory.
8540 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008541 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
8542 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008543 endif
8544 let priority = priority + 1
8545 endwhile
8546 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008547 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
8548 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008549 endif
8550
8551 " Following line associated with priority -- items that satisfy a priority
8552 " pattern get prefixed by ###/ which permits easy sorting by priority.
8553 " Sometimes files can satisfy multiple priority patterns -- only the latest
8554 " priority pattern needs to be retained. So, at this point, these excess
8555 " priority prefixes need to be removed, but not directories that happen to
8556 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008557 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
8558 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008559 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008560
8561" call Dret("SetSort")
8562endfun
8563
Bram Moolenaarff034192013-04-24 18:51:19 +02008564" ---------------------------------------------------------------------
8565" s:NetrwSetTgt: sets the target to the specified choice index {{{2
8566" Implements [count]Tb (bookhist<b>)
8567" [count]Th (bookhist<h>)
8568" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008569fun! s:NetrwSetTgt(islocal,bookhist,choice)
8570" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02008571
8572 if a:bookhist == 'b'
8573 " supports choosing a bookmark as a target using a qb-generated list
8574 let choice= a:choice - 1
8575 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01008576 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02008577 else
8578 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
8579 endif
8580
8581 elseif a:bookhist == 'h'
8582 " supports choosing a history stack entry as a target using a qb-generated list
8583 let choice= (a:choice % g:netrw_dirhistmax) + 1
8584 if exists("g:netrw_dirhist_".choice)
8585 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01008586 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02008587 else
8588 echomsg "Sorry, history#".a:choice." not available!"
8589 endif
8590 endif
8591
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008592 " refresh the display
8593 if !exists("b:netrw_curdir")
8594 let b:netrw_curdir= getcwd()
8595 endif
8596 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
8597
Bram Moolenaarff034192013-04-24 18:51:19 +02008598" call Dret("s:NetrwSetTgt")
8599endfun
8600
Bram Moolenaar446cb832008-06-24 21:56:24 +00008601" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02008602" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008603fun! s:NetrwSortStyle(islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008604 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008605 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008606
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008607 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 +01008608 NetrwKeepj norm! 0
Tom Benham64a536d2024-11-07 21:15:03 +01008609 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008610 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008611endfun
8612
8613" ---------------------------------------------------------------------
8614" s:NetrwSplit: mode {{{2
8615" =0 : net and o
8616" =1 : net and t
8617" =2 : net and v
8618" =3 : local and o
8619" =4 : local and t
8620" =5 : local and v
8621fun! s:NetrwSplit(mode)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008622
Bram Moolenaar97d62492012-11-15 21:28:22 +01008623 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008624 call s:SaveWinVars()
8625
8626 if a:mode == 0
8627 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02008628 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008629 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008630 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008631 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008632 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008633 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008634 unlet s:didsplit
8635
8636 elseif a:mode == 1
8637 " remote and t
Tom Benham64a536d2024-11-07 21:15:03 +01008638 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008639 tabnew
8640 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008641 NetrwKeepj call s:RestoreWinVars()
8642 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008643 unlet s:didsplit
8644
8645 elseif a:mode == 2
8646 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02008647 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008648 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008649 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008650 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008651 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008652 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008653 unlet s:didsplit
8654
8655 elseif a:mode == 3
8656 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02008657 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008658 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008659 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008660 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008661 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008662 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008663 unlet s:didsplit
8664
8665 elseif a:mode == 4
8666 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00008667 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008668 let eikeep = &ei
8669 let netrw_winnr = winnr()
8670 let netrw_line = line(".")
8671 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008672 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01008673 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01008674 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008675 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
8676 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008677 let &ei = eikeep
8678 let netrw_curdir = s:NetrwTreeDir(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008679 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01008680 let b:netrw_curdir = netrw_curdir
8681 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008682 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008683 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword,0))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008684 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01008685 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008686 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
8687 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01008688 let &ei= eikeep
8689 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008690 unlet s:didsplit
8691
8692 elseif a:mode == 5
8693 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02008694 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008695 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008696 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008697 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008698 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008699 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008700 unlet s:didsplit
8701
8702 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008703 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008704 endif
8705
Bram Moolenaar97d62492012-11-15 21:28:22 +01008706 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008707endfun
8708
8709" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008710" s:NetrwTgtMenu: {{{2
8711fun! s:NetrwTgtMenu()
8712 if !exists("s:netrw_menucnt")
8713 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008714 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008715" call Dfunc("s:NetrwTgtMenu()")
8716
8717 " the following test assures that gvim is running, has menus available, and has menus enabled.
8718 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
8719 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008720" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008721 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
8722 endif
8723 if !exists("s:netrw_initbookhist")
8724 call s:NetrwBookHistRead()
8725 endif
8726
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008727 " try to cull duplicate entries
8728 let tgtdict={}
8729
Bram Moolenaarff034192013-04-24 18:51:19 +02008730 " target bookmarked places
8731 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008732" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008733 let cnt= 1
8734 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008735 if has_key(tgtdict,bmd)
8736 let cnt= cnt + 1
8737 continue
8738 endif
8739 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02008740 let ebmd= escape(bmd,g:netrw_menu_escape)
8741 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008742" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008743 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 +02008744 let cnt= cnt + 1
8745 endfor
8746 endif
8747
8748 " target directory browsing history
8749 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008750" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008751 let histcnt = 1
8752 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02008753 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02008754 if exists("g:netrw_dirhist_{histcnt}")
8755 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008756 if has_key(tgtdict,histentry)
8757 let histcnt = histcnt + 1
8758 continue
8759 endif
8760 let tgtdict[histentry] = histcnt
8761 let ehistentry = escape(histentry,g:netrw_menu_escape)
8762" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008763 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 +02008764 endif
8765 let histcnt = histcnt + 1
8766 endwhile
8767 endif
8768 endif
8769" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008770endfun
8771
8772" ---------------------------------------------------------------------
8773" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
8774" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008775fun! s:NetrwTreeDir(islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008776
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008777 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008778 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
8779 let treedir= s:treedir
8780 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008781 unlet s:prevwinopen
Bram Moolenaar8d043172014-01-23 14:24:41 +01008782 return treedir
8783 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008784 if exists("s:prevwinopen")
8785 unlet s:prevwinopen
8786 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008787
Bram Moolenaar8d043172014-01-23 14:24:41 +01008788 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
8789 let b:netrw_curdir= getcwd()
8790 endif
8791 let treedir = b:netrw_curdir
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008792 let s:treecurpos= winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008793
8794 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar5c736222010-01-06 20:54:52 +01008795
8796 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008797 let curline= substitute(getline('.'),"\t -->.*$",'','')
8798 if curline =~ '/$'
Bram Moolenaar8d043172014-01-23 14:24:41 +01008799 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008800 elseif curline =~ '@$'
Tom Benham64a536d2024-11-07 21:15:03 +01008801 let potentialdir= resolve(s:NetrwTreePath(w:netrw_treetop))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008802 else
8803 let treedir= ""
8804 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008805
8806 " detect user attempting to close treeroot
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008807 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008808 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008809 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008810 return b:netrw_curdir
8811 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008812
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008813 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
8814" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
8815" let newdir = w:netrw_treetop.'/'.potentialdir
Christian Brabandt56b7da32024-02-29 17:48:14 +01008816 if a:islocal && curline =~ '@$'
8817 if isdirectory(s:NetrwFile(potentialdir))
Tom Benham64a536d2024-11-07 21:15:03 +01008818 let treedir = potentialdir
Christian Brabandt56b7da32024-02-29 17:48:14 +01008819 let w:netrw_treetop = treedir
8820 endif
8821 else
8822 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
8823 let treedir = s:NetrwTreePath(w:netrw_treetop)
8824 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008825 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008826
8827 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00008828 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008829 return treedir
8830endfun
8831
8832" ---------------------------------------------------------------------
8833" s:NetrwTreeDisplay: recursive tree display {{{2
8834fun! s:NetrwTreeDisplay(dir,depth)
Tom Benham64a536d2024-11-07 21:15:03 +01008835 " ensure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02008836 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00008837
8838 " install ../ and shortdir
8839 if a:depth == ""
8840 call setline(line("$")+1,'../')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008841 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008842 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008843 if a:dir == w:netrw_treetop
8844 let shortdir= a:dir
8845 else
8846 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
8847 endif
8848 call setline(line("$")+1,a:depth.shortdir)
8849 else
8850 let shortdir= substitute(a:dir,'^.*/','','e')
8851 call setline(line("$")+1,a:depth.shortdir.'/')
8852 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008853 " append a / to dir if its missing one
8854 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008855
8856 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008857 let depth= s:treedepthstring.a:depth
Bram Moolenaar446cb832008-06-24 21:56:24 +00008858
Bram Moolenaar85850f32019-07-19 22:05:51 +02008859 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
8860 if g:netrw_hide == 1
8861 " hide given patterns
8862 let listhide= split(g:netrw_list_hide,',')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008863 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02008864 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008865 endfor
8866
8867 elseif g:netrw_hide == 2
8868 " show given patterns (only)
8869 let listhide= split(g:netrw_list_hide,',')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008870 let entries=[]
8871 for entry in w:netrw_treedict[dir]
8872 for pat in listhide
8873 if entry =~ pat
8874 call add(entries,entry)
8875 break
8876 endif
8877 endfor
8878 endfor
8879 let w:netrw_treedict[dir]= entries
8880 endif
8881 if depth != ""
8882 " always remove "." and ".." entries when there's depth
8883 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
Tom Benham64a536d2024-11-07 21:15:03 +01008884 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\./$"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008885 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 endif
8888
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008889 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008890 if dir =~ '/$'
8891 let direntry= substitute(dir.entry,'[@/]$','','e')
8892 else
8893 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
8894 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008895 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008896 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008897 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008898 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
8899 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
Tom Benham64a536d2024-11-07 21:15:03 +01008900 NetrwKeepj call s:NetrwTreeDisplay(direntry.'@',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008901 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008902 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008903 endif
8904 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008905endfun
8906
8907" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008908" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
8909fun! s:NetrwRefreshTreeDict(dir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008910 if !exists("w:netrw_treedict")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008911 return
8912 endif
8913
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008914 for entry in w:netrw_treedict[a:dir]
8915 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008916
8917 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008918 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Tom Benham64a536d2024-11-07 21:15:03 +01008919 let filelist = s:NetrwLocalListingList(direntry,0)
8920 let w:netrw_treedict[direntry] = sort(filelist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008921
8922 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008923 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Tom Benham64a536d2024-11-07 21:15:03 +01008924 let filelist = s:NetrwLocalListingList(direntry.'/',0)
8925 let w:netrw_treedict[direntry] = sort(filelist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008926
8927 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008928 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008929 let liststar = s:NetrwGlob(direntry.'/','*',1)
8930 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008931
8932 else
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008933 endif
8934 endfor
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008935endfun
8936
8937" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008938" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008939" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008940fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008941 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00008942
8943 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00008944 if !exists("w:netrw_treetop")
8945 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008946 let s:netrw_treetop= w:netrw_treetop
Tom Benham4d618002024-10-31 10:47:23 +01008947 " use \V in case the directory contains specials chars like '$' or '~'
8948 elseif (w:netrw_treetop =~ ('^'.'\V'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop))
8949 \ || a:dirname !~ ('^'.'\V'.w:netrw_treetop)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008950 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008951 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00008952 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008953 if exists("w:netrw_treetop")
8954 let s:netrw_treetop= w:netrw_treetop
8955 else
8956 let w:netrw_treetop= getcwd()
8957 let s:netrw_treetop= w:netrw_treetop
8958 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008959
Bram Moolenaar446cb832008-06-24 21:56:24 +00008960 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008961 " insure that we have a treedict, albeit empty
Bram Moolenaar446cb832008-06-24 21:56:24 +00008962 let w:netrw_treedict= {}
8963 endif
8964
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008965 " update the dictionary for the current directory
Christian Brabandta063b222024-11-07 14:30:30 +01008966 exe "sil! NetrwKeepj keepp ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008967 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008968 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008969
8970 " if past banner, record word
8971 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
8972 let fname= expand("<cword>")
8973 else
8974 let fname= ""
8975 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008976
8977 " display from treetop on down
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008978 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008979
8980 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
8981 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaar8d043172014-01-23 14:24:41 +01008982 1d
8983 endwhile
8984
Bram Moolenaar13600302014-05-22 18:26:40 +02008985 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00008986
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008987 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008988 endif
8989endfun
8990
8991" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008992" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01008993" Normally, treetop is w:netrw_treetop, but a
8994" user of the function ( netrw#SetTreetop() )
8995" wipes that out prior to calling this function
8996fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008997" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
8998 if line(".") < w:netrw_bannercnt + 2
8999 let treedir= a:treetop
9000 if treedir !~ '/$'
9001 let treedir= treedir.'/'
9002 endif
9003" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9004 return treedir
9005 endif
9006
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009007 let svpos = winsaveview()
9008" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009009 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009010" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009011 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009012" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9013 let curline= getline('.')
9014" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9015 if curline =~ '/$'
9016" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9017 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9018" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9019 elseif curline =~ '@\s\+-->'
9020" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9021 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9022 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9023" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009024 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009025" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009026 let treedir= ""
9027 endif
9028 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009029" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9030" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009031 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9032 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9033 let treedir= dirname.treedir
9034 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009035" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009036 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009037" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009038 if a:treetop =~ '/$'
9039 let treedir= a:treetop.treedir
9040 else
9041 let treedir= a:treetop.'/'.treedir
9042 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009043" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009044 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009045" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009046" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9047 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009048" call Dret("s:NetrwTreePath <".treedir.">")
9049 return treedir
9050endfun
9051
9052" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009053" s:NetrwWideListing: {{{2
9054fun! s:NetrwWideListing()
9055
9056 if w:netrw_liststyle == s:WIDELIST
9057" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9058 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009059 " cpf: characters per filename
9060 " fpl: filenames per line
9061 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009062 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009063 let dict={}
9064 " save the unnamed register and register 0-9 and a
9065 let dict.a=[getreg('a'), getregtype('a')]
9066 for i in range(0, 9)
9067 let dict[i] = [getreg(i), getregtype(i)]
9068 endfor
9069 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009070" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009071 let b:netrw_cpf= 0
9072 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009073 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009074 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9075 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009076 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009077 " restore stored registers
9078 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009079" call Dret("NetrwWideListing")
9080 return
9081 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009082 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009083 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009084" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009085
9086 " determine qty files per line (fpl)
9087 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9088 if w:netrw_fpl <= 0
9089 let w:netrw_fpl= 1
9090 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009091" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009092
9093 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009094 " fpc: files per column of wide listing
9095 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009096 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009097 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9098 let newcolstart = w:netrw_bannercnt + fpc
9099 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009100" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009101 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009102" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009103 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009104 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009105 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009106 while line("$") >= newcolstart
9107 if newcolend > line("$") | let newcolend= line("$") | endif
9108 let newcolqty= newcolend - newcolstart
9109 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009110 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009111 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009112 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009113 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009114 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009115 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009116 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009117 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009118 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009119 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009120" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009121 if @* != keepregstar | sil! let @* = keepregstar | endif
9122 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009123 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009124 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9125 NetrwKeepj call histdel("/",-1)
9126 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9127 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009128" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009129 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009130 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009131" 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 +00009132" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009133 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009134 else
9135 if hasmapto("w","n")
9136 sil! nunmap <buffer> w
9137 endif
9138 if hasmapto("b","n")
9139 sil! nunmap <buffer> b
9140 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009141 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009142endfun
9143
9144" ---------------------------------------------------------------------
9145" s:PerformListing: {{{2
9146fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009147" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9148" 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 +02009149" 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>"))
9150 sil! NetrwKeepj %d _
9151" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009152
Bram Moolenaar15146672011-10-20 22:22:38 +02009153 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009154" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009155 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009156
Bram Moolenaar85850f32019-07-19 22:05:51 +02009157 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009158 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009159" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009160
9161" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009162" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009163" endif " Decho
9164
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009165" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009166 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9167 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009168" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9169 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009170 endif
9171
9172 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009173 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009174
9175 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009176 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009177" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009178 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009179 if exists("g:netrw_pchk")
9180 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9181 " failure detections.
9182 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009183 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009184 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9185 endif
9186 if exists("g:netrw_pchk")
9187 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9188 else
9189 let curdir= b:netrw_curdir
9190 endif
9191 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9192 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9193 else
9194 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009195 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009196 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009197 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009198 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009199" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009200 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009201 let w:netrw_bannercnt= 1
9202 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009203" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9204" 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 +00009205
Bram Moolenaar85850f32019-07-19 22:05:51 +02009206 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009207 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009208 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009209 let sortby= sortby." reversed"
9210 endif
9211
9212 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009213 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009214" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009215 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009216" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009217 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009218 NetrwKeepj put ='\" Sorted by '.sortby
9219 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009220 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9221 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009222" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009223 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009224 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009225 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9226 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009227 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009228" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009229" 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 +00009230 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009231
Bram Moolenaar85850f32019-07-19 22:05:51 +02009232 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009233 if g:netrw_banner
9234 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009235" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009236 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009237 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009238 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009239 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009240 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009241 endif
9242 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009243 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009244" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009245 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009246 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009247 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009248
9249 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009250 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009251" 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 +01009252 if g:netrw_list_hide != "" && g:netrw_hide
9253 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009254 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009255 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009256 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009257 endif
9258 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009259 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009260 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009261
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009262" 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 +01009263 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009264" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009265 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009266" 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 +01009267 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009268 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009269" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009270" 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 +00009271 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009272
9273 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009274 if g:netrw_banner
9275 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009276 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009277" 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 +01009278" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009279" 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 +01009280 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009281
Bram Moolenaar446cb832008-06-24 21:56:24 +00009282 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009283" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009284 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009285 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009286 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009287 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009288 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009289" 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 +01009290" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9291 return
9292 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009293 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009294
9295 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009296 if !exists("w:netrw_bannercnt")
9297 let w:netrw_bannercnt= 0
9298 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009299" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
9300" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
9301" 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 +01009302
Bram Moolenaar5c736222010-01-06 20:54:52 +01009303 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009304" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009305" 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 +00009306 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009307 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009308 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009309 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009310" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009311
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009312 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009313 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +02009314" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009315 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009316
Bram Moolenaar5c736222010-01-06 20:54:52 +01009317 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009318" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009319 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +02009320 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009321 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009322 else
9323 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009324 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009325 endif
9326 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009327
Bram Moolenaar446cb832008-06-24 21:56:24 +00009328 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009329" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009330 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
9331 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009332
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009333 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +02009334 " exten: sort by extension
9335 " The histdel(...,-1) calls remove the last search from the search history
9336" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009337 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
9338 NetrwKeepj call histdel("/",-1)
9339 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
9340 NetrwKeepj call histdel("/",-1)
9341 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
9342 NetrwKeepj call histdel("/",-1)
9343 if !g:netrw_banner || w:netrw_bannercnt < line("$")
9344" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009345 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009346 " normal direction sorting
9347 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
9348 else
9349 " reverse direction sorting
9350 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
9351 endif
9352 endif
9353 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
9354 NetrwKeepj call histdel("/",-1)
9355
Bram Moolenaar446cb832008-06-24 21:56:24 +00009356 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01009357 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009358" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009359 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009360" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009361 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009362 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009363" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009364 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009365 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009366" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009367 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
9368 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009369 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009370 endif
9371
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009372 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009373" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009374 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009375 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009376 call histdel("/",-1)
9377 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009378 endif
9379 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009380" 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 +00009381
9382 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009383" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
9384" 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 +01009385 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009386" 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 +01009387 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
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#3)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009389
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009390 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009391 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009392" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Christian Brabandta063b222024-11-07 14:30:30 +01009393 sil! keepp g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009394 endif
9395
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009396 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009397 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009398" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
9399 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009400 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009401" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
9402 else
9403" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
9404" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
9405" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
9406" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009407 endif
9408
9409 " record previous current directory
9410 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009411" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009412
9413 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009414" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
9415" 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 +01009416 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009417" 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 +02009418 NetrwKeepj call s:NetrwOptionsRestore("w:")
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#6)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009420
9421 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009422" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02009423 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009424" 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 +01009425 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009426" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009427 exe "setl ts=".(g:netrw_maxfilenamelen+1)
9428 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009429" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009430" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009431
Bram Moolenaar8d043172014-01-23 14:24:41 +01009432 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009433" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
9434" 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 +01009435" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
9436 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009437 unlet s:treecurpos
9438 endif
9439
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009440" 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>"))
9441" 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 +00009442" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
9443endfun
9444
9445" ---------------------------------------------------------------------
9446" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00009447fun! s:SetupNetrwStatusLine(statline)
9448" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
9449
9450 if !exists("s:netrw_setup_statline")
9451 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009452" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00009453
9454 if !exists("s:netrw_users_stl")
9455 let s:netrw_users_stl= &stl
9456 endif
9457 if !exists("s:netrw_users_ls")
9458 let s:netrw_users_ls= &laststatus
9459 endif
9460
9461 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +02009462 let dict={}
9463 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +00009464 redir @a
9465 try
9466 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009467 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +00009468 if &bg == "dark"
9469 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
9470 else
9471 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
9472 endif
9473 endtry
9474 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +02009475 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +00009476 endif
9477
9478 " set up status line (may use User9 highlighting)
9479 " insure that windows have a statusline
9480 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +09009481 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +02009482 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009483" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009484 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +00009485
9486" call Dret("SetupNetrwStatusLine : stl=".&stl)
9487endfun
9488
Bram Moolenaar85850f32019-07-19 22:05:51 +02009489" =========================================
9490" Remote Directory Browsing Support: {{{1
9491" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00009492
9493" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01009494" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
9495" This function assumes that a long listing will be received. Size, time,
9496" and reverse sorts will be requested of the server but not otherwise
9497" enforced here.
9498fun! s:NetrwRemoteFtpCmd(path,listcmd)
9499" 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 +01009500" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009501 " sanity check: {{{3
9502 if !exists("w:netrw_method")
9503 if exists("b:netrw_method")
9504 let w:netrw_method= b:netrw_method
9505 else
9506 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
9507" call Dret("NetrwRemoteFtpCmd")
9508 return
9509 endif
9510 endif
9511
9512 " WinXX ftp uses unix style input, so set ff to unix " {{{3
9513 let ffkeep= &ff
9514 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009515" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009516
9517 " clear off any older non-banner lines " {{{3
9518 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009519" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
9520 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +01009521
9522 ".........................................
9523 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
9524 " ftp + <.netrc>: Method #2
9525 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009526 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009527 endif
9528 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009529 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009530" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009531 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009532 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009533" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +01009534 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009535" 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>"))
9536 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 +01009537 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009538" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
9539 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 +01009540 endif
9541
9542 ".........................................
9543 elseif w:netrw_method == 3 " {{{3
9544 " ftp + machine,id,passwd,filename: Method #3
9545 setl ff=unix
9546 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009547 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +01009548 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009549 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +01009550 endif
9551
9552 " handle userid and password
9553 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009554" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009555 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
9556 call NetUserPass("ftp:".host)
9557 endif
9558 if exists("g:netrw_uid") && g:netrw_uid != ""
9559 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009560 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +01009561 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009562 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009563 endif
9564 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009565 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009566 endif
9567 endif
9568
9569 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009570 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009571 endif
9572 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009573 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009574" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009575 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009576 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +01009577
9578 " perform ftp:
9579 " -i : turns off interactive prompting from ftp
9580 " -n unix : DON'T use <.netrc>, even though it exists
9581 " -n win32: quit being obnoxious about password
9582 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009583" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009584 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +01009585" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009586" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
9587" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009588 endif
9589
9590 ".........................................
9591 elseif w:netrw_method == 9 " {{{3
9592 " sftp username@machine: Method #9
9593 " s:netrw_sftp_cmd
9594 setl ff=unix
9595
9596 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +09009597 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +01009598" call Dret("NetrwRemoteFtpCmd")
9599 return
9600
9601 ".........................................
9602 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009603 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +01009604 endif
9605
9606 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +02009607 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009608 sil! NetrwKeepj %s/\r$//e
9609 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009610 endif
9611 if a:listcmd == "dir"
9612 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009613 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
9614 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
9615 NetrwKeepj call histdel("/",-1)
9616 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009617 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 +01009618 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
9619 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009620 endif
9621 endif
9622
9623 " ftp's listing doesn't seem to include ./ or ../ " {{{3
9624 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009625 exe 'NetrwKeepj '.w:netrw_bannercnt
9626 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +01009627 endif
9628 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009629 exe 'NetrwKeepj '.w:netrw_bannercnt
9630 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +01009631 endif
9632
9633 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +09009634 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +01009635" call Dret("NetrwRemoteFtpCmd")
9636endfun
9637
9638" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009639" s:NetrwRemoteListing: {{{2
9640fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009641" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00009642
Bram Moolenaara6878372014-03-22 21:02:50 +01009643 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
9644 let w:netrw_bannercnt= s:bannercnt
9645 endif
9646 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +09009647 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009648 endif
9649
Bram Moolenaar446cb832008-06-24 21:56:24 +00009650 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009651
Bram Moolenaar446cb832008-06-24 21:56:24 +00009652 " sanity check:
9653 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009654" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009655 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009656" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009657 if !exists("g:netrw_quiet")
9658 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
9659 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009660 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009661" call Dret("s:NetrwRemoteListing -1")
9662 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00009663 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009664
Bram Moolenaar8d043172014-01-23 14:24:41 +01009665 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009666" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009667 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009668 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009669 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 +00009670 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009671 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 +00009672 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009673 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009674
Bram Moolenaar85850f32019-07-19 22:05:51 +02009675 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009676" call Dret("s:NetrwRemoteListing -1")
9677 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009678 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009679" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009680
Bram Moolenaar446cb832008-06-24 21:56:24 +00009681 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009682" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009683 let w:netrw_method= b:netrw_method
9684 endif
9685
Bram Moolenaar13600302014-05-22 18:26:40 +02009686 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +02009687 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009688" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009689 let s:method = "ftp"
9690 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009691 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009692 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009693 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009694 let listcmd= g:netrw_ftp_sizelist_cmd
9695 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009696" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009697 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009698" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009699
Bram Moolenaara6878372014-03-22 21:02:50 +01009700 " report on missing file or directory messages
9701 if search('[Nn]o such file or directory\|Failed to change directory')
9702 let mesg= getline(".")
9703 if exists("w:netrw_bannercnt")
9704 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009705 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +01009706 setl noma
9707 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009708 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009709 call netrw#ErrorMsg(s:WARNING,mesg,96)
9710" call Dret("s:NetrwRemoteListing : -1")
9711 return -1
9712 endif
9713
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009714 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 +00009715 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009716" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009717 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009718
9719 " cleanup
9720 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009721 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
9722 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009723 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009724 sil! NetrwKeepj %s/\r$//e
9725 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009726
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009727 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +00009728 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009729 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +01009730 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009731" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009732 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009733" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009734 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009735 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009736 exe "sil! NetrwKeepj ".line1
9737 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009738
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009739" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009740 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009741" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009742 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
9743 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009744 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009745" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009746 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
9747 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
9748 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
9749 NetrwKeepj call histdel("/",-1)
9750 NetrwKeepj call histdel("/",-1)
9751 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009752 endif
9753 endif
9754
Bram Moolenaar13600302014-05-22 18:26:40 +02009755 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00009756 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009757" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009758 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009759" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009760 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009761" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
9762 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009763 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009764 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
9765 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
9766 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
9767 NetrwKeepj call histdel("/",-1)
9768 NetrwKeepj call histdel("/",-1)
9769 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009770 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009771 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
9772 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009773 endif
9774 else
9775 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009776" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009777 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00009778 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009779" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
9780 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
9781" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009782 endif
9783 endif
9784
9785 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +01009786 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009787" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009788 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
9789 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009790 endif
9791 endif
9792
9793 if w:netrw_liststyle == s:LONGLIST
9794 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009795" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009796
9797 if s:method == "ftp"
9798 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009799 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009800 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009801 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +00009802 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009803 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +00009804 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009805 sil! NetrwKeepj 1
9806 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009807 let line2= line(".")
9808 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009809 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009810 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009811 endif
9812 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009813 exe "sil! NetrwKeepj ".line1
9814 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009815 endif
9816
9817 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009818" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009819 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 +00009820 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009821" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009822 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009823 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009824 exe 'sil NetrwKeepj '.w:netrw_bannercnt
9825 NetrwKeepj call histdel("/",-1)
9826 NetrwKeepj call histdel("/",-1)
9827 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009828 endif
9829 endif
9830
9831" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009832" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009833" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01009834
9835" call Dret("s:NetrwRemoteListing 0")
9836 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009837endfun
9838
Bram Moolenaar446cb832008-06-24 21:56:24 +00009839" ---------------------------------------------------------------------
9840" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
9841fun! s:NetrwRemoteRm(usrhost,path) range
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009842 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009843
9844 let all= 0
9845 if exists("s:netrwmarkfilelist_{bufnr('%')}")
9846 " remove all marked files
9847 for fname in s:netrwmarkfilelist_{bufnr("%")}
9848 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009849 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009850 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009851 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009852 let all= 1
9853 endif
9854 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01009855 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009856
9857 else
9858 " remove files specified by range
9859
9860 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009861 let keepsol = &l:sol
9862 setl nosol
9863 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +00009864
9865 " remove multiple files and directories
9866 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009867 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009868 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009869 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009870 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009871 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009872 let all= 1
9873 endif
9874 let ctr= ctr + 1
9875 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009876 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +00009877 endif
9878
9879 " refresh the (remote) directory listing
Tom Benham64a536d2024-11-07 21:15:03 +01009880 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009881 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009882endfun
9883
9884" ---------------------------------------------------------------------
9885" s:NetrwRemoteRmFile: {{{2
9886fun! s:NetrwRemoteRmFile(path,rmfile,all)
9887" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
9888
9889 let all= a:all
9890 let ok = ""
9891
9892 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
9893 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009894" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009895 if !all
9896 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009897" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009898 call inputsave()
9899 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
9900 call inputrestore()
9901 echohl NONE
9902 if ok == ""
9903 let ok="no"
9904 endif
9905 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009906 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009907 let all= 1
9908 endif
9909 endif
9910
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009911 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009912" 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 +00009913 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009914" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009915 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009916 if path =~ '^\a\{3,}://'
9917 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009918 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009919 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009920 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
9921 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009922" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009923 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009924" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009925 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009926 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009927 let ok="q"
9928 else
MiguelBarroc46c21b2024-01-31 20:07:17 +01009929 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009930" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
9931" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
9932" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009933 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009934 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009935 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009936 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009937 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009938" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009939 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009940 if v:shell_error != 0
9941 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09009942 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 +01009943 else
9944 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
9945 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009946 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009947 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009948 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009949" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009950 endif
9951 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009952 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009953" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009954 endif
9955
9956 else
9957 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009958" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009959 if !all
9960 call inputsave()
9961 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
9962 call inputrestore()
9963 if ok == ""
9964 let ok="no"
9965 endif
9966 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009967 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009968 let all= 1
9969 endif
9970 endif
9971
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009972 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00009973 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009974 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009975 else
9976 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009977 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
9978" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00009979 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009980" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009981
9982 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009983" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
9984 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
9985" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00009986 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009987" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009988
9989 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009990 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009991 endif
9992 endif
9993 endif
9994
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009995 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009996" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009997 endif
9998 endif
9999
10000" call Dret("s:NetrwRemoteRmFile ".ok)
10001 return ok
10002endfun
10003
10004" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010005" s:NetrwRemoteRename: rename a remote file or directory {{{2
10006fun! s:NetrwRemoteRename(usrhost,path) range
Bram Moolenaar446cb832008-06-24 21:56:24 +000010007
10008 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010009 let svpos = winsaveview()
10010" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010011 let ctr = a:firstline
10012 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10013
10014 " rename files given by the markfilelist
10015 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10016 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +000010017 if exists("subfrom")
10018 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010019 else
10020 call inputsave()
10021 let newname= input("Moving ".oldname." to : ",oldname)
10022 call inputrestore()
10023 if newname =~ '^s/'
10024 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10025 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10026 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010027 endif
10028 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010029
Bram Moolenaar446cb832008-06-24 21:56:24 +000010030 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010031 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010032 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010033 let oldname= s:ShellEscape(a:path.oldname)
10034 let newname= s:ShellEscape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010035 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010036 endif
10037
10038 endfor
10039 call s:NetrwUnMarkFile(1)
10040
10041 else
10042
10043 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010044 let keepsol= &l:sol
10045 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010046 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010047 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010048
10049 let oldname= s:NetrwGetWord()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010050
10051 call inputsave()
10052 let newname= input("Moving ".oldname." to : ",oldname)
10053 call inputrestore()
10054
10055 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10056 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10057 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010058 let oldname= s:ShellEscape(a:path.oldname)
10059 let newname= s:ShellEscape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010060 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010061 endif
10062
10063 let ctr= ctr + 1
10064 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010065 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010066 endif
10067
10068 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010069 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010070 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010071endfun
10072
Bram Moolenaar85850f32019-07-19 22:05:51 +020010073" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010074" Local Directory Browsing Support: {{{1
10075" ==========================================
10076
10077" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010078" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010079" Should accept: file://localhost/etc/fstab
10080" file:///etc/fstab
10081" file:///c:/WINDOWS/clock.avi
10082" file:///c|/WINDOWS/clock.avi
10083" file://localhost/c:/WINDOWS/clock.avi
10084" file://localhost/c|/WINDOWS/clock.avi
10085" file://c:/foo.txt
10086" file:///c:/foo.txt
10087" 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 +020010088fun! netrw#FileUrlEdit(fname)
10089" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010090 let fname = a:fname
10091 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010092" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010093 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010094" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010095 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010096 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010097 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010098" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010099 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010100" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010101 endif
10102 endif
10103 let fname2396 = netrw#RFC2396(fname)
10104 let fname2396e= fnameescape(fname2396)
10105 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010106 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010107" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010108 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010109" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010110 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10111 endif
10112 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010113
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010114" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10115" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010116 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010117 exe 'NetrwKeepj keepalt edit '.plainfname
10118 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10119
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010120" 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 +020010121" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010122 exe "sil doau BufReadPost ".fname2396e
10123endfun
10124
10125" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010126" netrw#LocalBrowseCheck: {{{2
10127fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010128 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010129 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10130 "
10131 " unfortunate interaction -- split window debugging can't be used here, must use
10132 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10133 " another call to LocalBrowseCheck() when attempts to write
10134 " to the DBG buffer are made.
10135 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010136 " The &ft == "netrw" test was installed because the BufEnter event
10137 " would hit when re-entering netrw windows, creating unexpected
10138 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010139" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010140" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010141" 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 +010010142 " getting E930: Cannot use :redir inside execute
10143"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010144" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10145" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010146
Bram Moolenaar97d62492012-11-15 21:28:22 +010010147 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010148 if isdirectory(s:NetrwFile(a:dirname))
10149" 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 +010010150
Bram Moolenaar97d62492012-11-15 21:28:22 +010010151 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010152" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10153" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010154 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010155
Bram Moolenaar446cb832008-06-24 21:56:24 +000010156 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010157" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010158 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010159
Bram Moolenaar5c736222010-01-06 20:54:52 +010010160 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010161" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010162 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010163 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010164 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010165" 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 +010010166" call Dret("netrw#LocalBrowseCheck")
10167 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010168 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010169
Bram Moolenaar85850f32019-07-19 22:05:51 +020010170 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010171 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10172 " AND IF the listing style is not a tree listing
10173 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010174" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010175 let ibuf = 1
10176 let buflast = bufnr("$")
10177 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010178 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10179 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010180 endif
10181 let ibuf= ibuf + 1
10182 endwhile
10183 endif
10184 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010185" 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>"))
10186" 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 +000010187 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010188" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010189endfun
10190
10191" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010192" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010193" performed any shell command. The idea is to cause all local-browsing
10194" buffers to be refreshed after a user has executed some shell command,
10195" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010196fun! s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010197 " determine which buffers currently reside in a tab
10198 if !exists("s:netrw_browselist")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010199 return
10200 endif
10201 if !exists("w:netrw_bannercnt")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010202 return
10203 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010204 if !empty(getcmdwintype())
10205 " cannot move away from cmdline window, see :h E11
10206 return
10207 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010208 if exists("s:netrw_events") && s:netrw_events == 1
10209 " s:LocalFastBrowser gets called (indirectly) from a
10210 let s:netrw_events= 2
Bram Moolenaara6878372014-03-22 21:02:50 +010010211 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010212 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010213 let itab = 1
10214 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010215 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010216 while itab <= tabpagenr("$")
10217 let buftablist = buftablist + tabpagebuflist()
10218 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010219 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010220 endwhile
Bram Moolenaar446cb832008-06-24 21:56:24 +000010221 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10222 " | refresh any netrw window
10223 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010224 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010225 let ibl = 0
10226 for ibuf in s:netrw_browselist
Bram Moolenaar446cb832008-06-24 21:56:24 +000010227 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10228 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010229 " (ibuf not shown in a current window AND
10230 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010231 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010232 call remove(s:netrw_browselist,ibl)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010233 continue
10234 elseif index(tabpagebuflist(),ibuf) != -1
10235 " refresh any netrw buffer
Bram Moolenaar446cb832008-06-24 21:56:24 +000010236 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010237 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010238 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10239 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10240 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10241 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010242 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10243 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10244 endif
Tom Benham64a536d2024-11-07 21:15:03 +010010245 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010246 endif
10247 let ibl= ibl + 1
10248 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010249 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010250 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010251endfun
10252
10253" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010254" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10255"
10256" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010257" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010258" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10259" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010260" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010261"
10262" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
10263" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010010264" (re-using a buffer may not be as accurate)
10265"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010266" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010010267" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
10268" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
10269" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
10270" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010271fun! s:LocalFastBrowser()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010272
10273 " initialize browselist, a list of buffer numbers that the local browser has used
10274 if !exists("s:netrw_browselist")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010275 let s:netrw_browselist= []
10276 endif
10277
10278 " append current buffer to fastbrowse list
10279 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaar97d62492012-11-15 21:28:22 +010010280 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010281 endif
10282
10283 " enable autocmd events to handle refreshing/removing local browser buffers
10284 " If local browse buffer is currently showing: refresh it
10285 " If local browse buffer is currently hidden : wipe it
10286 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
10287 " =1 : medium speed, re-use directory listing for remote only
10288 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010010289 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
10290 let s:netrw_events= 1
10291 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010292 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020010293 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010010294 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010295 else
Bram Moolenaara6878372014-03-22 21:02:50 +010010296 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010297 endif
10298 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010010299
10300 " user must have changed fastbrowse to its fast setting, so remove
10301 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010010302 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara6878372014-03-22 21:02:50 +010010303 unlet s:netrw_events
10304 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010305 au!
10306 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010010307 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010308 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010309endfun
10310
Tom Benham64a536d2024-11-07 21:15:03 +010010311fun! s:NetrwLocalListingList(dirname,setmaxfilenamelen)
Bram Moolenaara6878372014-03-22 21:02:50 +010010312 " get the list of files contained in the current directory
Tom Benham64a536d2024-11-07 21:15:03 +010010313 let dirname = a:dirname
10314 let dirnamelen = strlen(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010315 let filelist = s:NetrwGlob(dirname,"*",0)
10316 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara6878372014-03-22 21:02:50 +010010317
Nir Lichtman1e34b952024-05-08 19:19:34 +020010318 if g:netrw_cygwin == 0 && has("win32")
Tom Benham64a536d2024-11-07 21:15:03 +010010319 elseif index(filelist,'..') == -1 && dirname !~ '/'
Bram Moolenaara6878372014-03-22 21:02:50 +010010320 " include ../ in the glob() entry if its missing
Tom Benham64a536d2024-11-07 21:15:03 +010010321 let filelist= filelist+[s:ComposePath(dirname,"../")]
Bram Moolenaara6878372014-03-22 21:02:50 +010010322 endif
10323
Tom Benham64a536d2024-11-07 21:15:03 +010010324 if a:setmaxfilenamelen && get(g:, 'netrw_dynamic_maxfilenamelen', 0)
Bram Moolenaara6878372014-03-22 21:02:50 +010010325 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
10326 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara6878372014-03-22 21:02:50 +010010327 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010328
Tom Benham64a536d2024-11-07 21:15:03 +010010329 let resultfilelist = []
Bram Moolenaara6878372014-03-22 21:02:50 +010010330 for filename in filelist
Bram Moolenaara6878372014-03-22 21:02:50 +010010331
10332 if getftype(filename) == "link"
10333 " indicate a symbolic link
Bram Moolenaara6878372014-03-22 21:02:50 +010010334 let pfile= filename."@"
10335
10336 elseif getftype(filename) == "socket"
10337 " indicate a socket
Bram Moolenaara6878372014-03-22 21:02:50 +010010338 let pfile= filename."="
10339
10340 elseif getftype(filename) == "fifo"
10341 " indicate a fifo
Bram Moolenaara6878372014-03-22 21:02:50 +010010342 let pfile= filename."|"
10343
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010344 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010345 " indicate a directory
Bram Moolenaara6878372014-03-22 21:02:50 +010010346 let pfile= filename."/"
10347
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010348 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020010349 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010010350 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
10351 " indicate an executable
Bram Moolenaara6878372014-03-22 21:02:50 +010010352 let pfile= filename."*"
10353 else
10354 " normal file
10355 let pfile= filename
10356 endif
10357 elseif executable(filename)
10358 " indicate an executable
Bram Moolenaara6878372014-03-22 21:02:50 +010010359 let pfile= filename."*"
10360 else
10361 " normal file
10362 let pfile= filename
10363 endif
10364
10365 else
10366 " normal file
10367 let pfile= filename
10368 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010369
10370 if pfile =~ '//$'
10371 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara6878372014-03-22 21:02:50 +010010372 endif
10373 let pfile= strpart(pfile,dirnamelen)
10374 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara6878372014-03-22 21:02:50 +010010375
10376 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090010377 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
10378 let sz = getfsize(filename)
10379 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
10380 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010010381
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010382 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010383 let sz= s:NetrwHumanReadable(sz)
10384 endif
K.Takata8750e3c2023-11-22 18:20:01 +090010385 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090010386 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010387 endif
10388
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010389 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010010390 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010010391 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaara6878372014-03-22 21:02:50 +010010392 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090010393 let ft = printf("%018d",t)
Bram Moolenaara6878372014-03-22 21:02:50 +010010394 let ftpfile= ft.'/'.pfile
Tom Benham64a536d2024-11-07 21:15:03 +010010395 let resultfilelist += [ftpfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010396
10397 elseif g:netrw_sort_by =~ "^s"
10398 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaara6878372014-03-22 21:02:50 +010010399 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090010400 let fsz = printf("%018d",sz)
Bram Moolenaara6878372014-03-22 21:02:50 +010010401 let fszpfile= fsz.'/'.pfile
Tom Benham64a536d2024-11-07 21:15:03 +010010402 let resultfilelist += [fszpfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010403
10404 else
10405 " sort by name
Tom Benham64a536d2024-11-07 21:15:03 +010010406 let resultfilelist += [pfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010407 endif
Tom Benham64a536d2024-11-07 21:15:03 +010010408 endfor
10409
10410 return resultfilelist
10411endfun
10412
10413" ---------------------------------------------------------------------
10414" s:LocalListing: does the job of "ls" for local directories {{{2
10415fun! s:LocalListing()
10416
10417 let filelist = s:NetrwLocalListingList(b:netrw_curdir, 1)
10418 for filename in filelist
10419 sil! NetrwKeepj put =filename
Bram Moolenaara6878372014-03-22 21:02:50 +010010420 endfor
10421
10422 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010423 sil! NetrwKeepj g/^$/d
10424 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010010425 call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010426 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010427endfun
10428
10429" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010430" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
10431fun! s:NetrwLocalExecute(cmd)
10432" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
10433 let ykeep= @@
10434 " sanity check
10435 if !executable(a:cmd)
10436 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
10437 let @@= ykeep
10438" call Dret("s:NetrwLocalExecute")
10439 return
10440 endif
10441
10442 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010443" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010444 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010445" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010446
10447 " strip any ansi escape sequences off
10448 let result = substitute(result,"\e\\[[0-9;]*m","","g")
10449
10450 " show user the result(s)
10451 echomsg result
10452 let @@= ykeep
10453
10454" call Dret("s:NetrwLocalExecute")
10455endfun
10456
10457" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010458" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010459fun! s:NetrwLocalRename(path) range
Bram Moolenaar97d62492012-11-15 21:28:22 +010010460
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010461 if !exists("w:netrw_bannercnt")
10462 let w:netrw_bannercnt= b:netrw_bannercnt
10463 endif
10464
Bram Moolenaar97d62492012-11-15 21:28:22 +010010465 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010010466 let ykeep = @@
10467 let ctr = a:firstline
10468 let svpos = winsaveview()
10469 let all = 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010010470
10471 " rename files given by the markfilelist
10472 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10473 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar97d62492012-11-15 21:28:22 +010010474 if exists("subfrom")
10475 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaar97d62492012-11-15 21:28:22 +010010476 else
10477 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010478 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010479 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010480 if newname =~ ''
10481 " two ctrl-x's : ignore all of string preceding the ctrl-x's
10482 let newname = substitute(newname,'^.*','','')
10483 elseif newname =~ ''
10484 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
10485 let newname = substitute(newname,'[^/]*','','')
10486 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010487 if newname =~ '^s/'
10488 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10489 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaar97d62492012-11-15 21:28:22 +010010490 let newname = substitute(oldname,subfrom,subto,'')
10491 endif
10492 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010010493 if !all && filereadable(newname)
10494 call inputsave()
10495 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
10496 call inputrestore()
10497 if response == "all"
10498 let all= 1
10499 elseif response != "y" && response != "yes"
10500 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010501 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaar29634562020-01-09 21:46:04 +010010502 NetrwKeepj call winrestview(svpos)
10503 let @@= ykeep
Bram Moolenaar29634562020-01-09 21:46:04 +010010504 return
10505 endif
10506 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010507 call rename(oldname,newname)
10508 endfor
10509 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010510
Bram Moolenaar97d62492012-11-15 21:28:22 +010010511 else
10512
10513 " attempt to rename files/directories
10514 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010515 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010010516
10517 " sanity checks
10518 if line(".") < w:netrw_bannercnt
10519 let ctr= ctr + 1
10520 continue
10521 endif
10522 let curword= s:NetrwGetWord()
10523 if curword == "./" || curword == "../"
10524 let ctr= ctr + 1
10525 continue
10526 endif
10527
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010528 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010010529 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010530
10531 call inputsave()
10532 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
10533 call inputrestore()
10534
10535 call rename(oldname,newname)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010536 let ctr= ctr + 1
10537 endwhile
10538 endif
10539
10540 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010541 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010542 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010543 let @@= ykeep
Bram Moolenaar97d62492012-11-15 21:28:22 +010010544endfun
10545
10546" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010547" s:NetrwLocalRm: {{{2
10548fun! s:NetrwLocalRm(path) range
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010549 if !exists("w:netrw_bannercnt")
10550 let w:netrw_bannercnt= b:netrw_bannercnt
10551 endif
10552
Bram Moolenaar446cb832008-06-24 21:56:24 +000010553 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010010554 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010555 let ret = 0
10556 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010557 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010558
10559 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10560 " remove all marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +000010561 for fname in s:netrwmarkfilelist_{bufnr("%")}
10562 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010563 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010564 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010565 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010566 let all= 1
10567 endif
10568 endfor
10569 call s:NetrwUnMarkFile(1)
10570
10571 else
10572 " remove (multiple) files and directories
Bram Moolenaar446cb832008-06-24 21:56:24 +000010573
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010574 let keepsol= &l:sol
10575 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010576 let ctr = a:firstline
10577 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010578 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010579
10580 " sanity checks
10581 if line(".") < w:netrw_bannercnt
10582 let ctr= ctr + 1
10583 continue
10584 endif
10585 let curword= s:NetrwGetWord()
10586 if curword == "./" || curword == "../"
10587 let ctr= ctr + 1
10588 continue
10589 endif
10590 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010591 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010592 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010593 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010594 let all= 1
10595 endif
10596 let ctr= ctr + 1
10597 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010598 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010599 endif
10600
10601 " refresh the directory
Bram Moolenaar446cb832008-06-24 21:56:24 +000010602 if bufname("%") != "NetrwMessage"
Tom Benham64a536d2024-11-07 21:15:03 +010010603 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010604 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010605 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010606 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010607endfun
10608
10609" ---------------------------------------------------------------------
10610" s:NetrwLocalRmFile: remove file fname given the path {{{2
10611" Give confirmation prompt unless all==1
10612fun! s:NetrwLocalRmFile(path,fname,all)
10613" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010614
Bram Moolenaar446cb832008-06-24 21:56:24 +000010615 let all= a:all
10616 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010617 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020010618 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010619" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010620
10621 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
10622 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010623" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010624 if !all
10625 echohl Statement
10626 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020010627 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010628 call inputrestore()
10629 echohl NONE
10630 if ok == ""
10631 let ok="no"
10632 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010633" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010634 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010635" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010636 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010637 let all= 1
10638 endif
10639 endif
10640
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010641 if all || ok =~# '^y\%[es]$' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000010642 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010643" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010644 endif
10645
10646 else
10647 " attempt to remove directory
10648 if !all
10649 echohl Statement
10650 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020010651 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010652 call inputrestore()
10653 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
10654 if ok == ""
10655 let ok="no"
10656 endif
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010657 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010658 let all= 1
10659 endif
10660 endif
10661 let rmfile= substitute(rmfile,'[\/]$','','e')
10662
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010663 if all || ok =~# '^y\%[es]$' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020010664 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010010665 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010666 endif
10667 endif
10668 endif
10669
10670" call Dret("s:NetrwLocalRmFile ".ok)
10671 return ok
10672endfun
10673
Bram Moolenaar85850f32019-07-19 22:05:51 +020010674" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010675" Support Functions: {{{1
10676
Bram Moolenaar488c6512005-08-11 20:09:58 +000010677" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010678" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
10679" 0: marked file list of current buffer
10680" 1: marked file target
10681fun! netrw#Access(ilist)
10682 if a:ilist == 0
10683 if exists("s:netrwmarkfilelist_".bufnr('%'))
10684 return s:netrwmarkfilelist_{bufnr('%')}
10685 else
10686 return "no-list-buf#".bufnr('%')
10687 endif
10688 elseif a:ilist == 1
10689 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020010690 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010691endfun
10692
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010693" ---------------------------------------------------------------------
10694" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
10695fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010696 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010697endfun
10698
Bram Moolenaara6878372014-03-22 21:02:50 +010010699" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010700" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
10701" I expect this function to be used in
10702" :PChkAssert netrw#Expose("netrwmarkfilelist")
10703" for example.
10704fun! netrw#Expose(varname)
10705" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010706 if exists("s:".a:varname)
10707 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010708" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010709 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010710" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010711 if type(retval) == 3
10712 let retval = copy(retval)
10713 let i = 0
10714 while i < len(retval)
10715 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
10716 let i = i + 1
10717 endwhile
10718 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010719" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010720 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010721 else
10722" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010723 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010724 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010725" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010726 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010727 endif
10728
10729" call Dret("netrw#Expose ".string(retval))
10730 return retval
10731endfun
10732
10733" ---------------------------------------------------------------------
10734" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
10735fun! netrw#Modify(varname,newvalue)
10736" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
10737 exe "let s:".a:varname."= ".string(a:newvalue)
10738" call Dret("netrw#Modify")
10739endfun
10740
10741" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010742" netrw#RFC2396: converts %xx into characters {{{2
10743fun! netrw#RFC2396(fname)
10744" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090010745 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010010746" call Dret("netrw#RFC2396 ".fname)
10747 return fname
10748endfun
10749
10750" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010751" netrw#UserMaps: supports user-specified maps {{{2
10752" see :help function()
10753"
10754" g:Netrw_UserMaps is a List with members such as:
10755" [[keymap sequence, function reference],...]
10756"
10757" The referenced function may return a string,
10758" refresh : refresh the display
10759" -other- : this string will be executed
10760" or it may return a List of strings.
10761"
10762" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020010763" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010764" Related functions:
10765" netrw#Expose(varname) -- see s:varname variables
10766" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
10767" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
10768fun! netrw#UserMaps(islocal)
10769" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
10770" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
10771
10772 " set up usermaplist
10773 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
10774" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
10775 for umap in g:Netrw_UserMaps
10776" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
10777" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
10778 " if umap[0] is a string and umap[1] is a string holding a function name
10779 if type(umap[0]) == 1 && type(umap[1]) == 1
10780" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
10781 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
10782 else
10783 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
10784 endif
10785 endfor
10786 endif
10787" call Dret("netrw#UserMaps")
10788endfun
10789
10790" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010791" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
10792fun! netrw#WinPath(path)
10793" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010794 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010795 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010010796 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010797 " remove trailing slash (Win95)
10798 let path = substitute(path, '\(\\\|/\)$', '', 'g')
10799 " remove escaped spaces
10800 let path = substitute(path, '\ ', ' ', 'g')
10801 " convert slashes to backslashes
10802 let path = substitute(path, '/', '\', 'g')
10803 else
10804 let path= a:path
10805 endif
10806" call Dret("netrw#WinPath <".path.">")
10807 return path
10808endfun
10809
10810" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020010811" s:StripTrailingSlash: removes trailing slashes from a path {{{2
10812fun! s:StripTrailingSlash(path)
10813 " remove trailing slash
10814 return substitute(a:path, '[/\\]$', '', 'g')
10815endfun
10816
Travis Sheltone34d0e32024-07-30 21:08:56 +020010817" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010818" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
10819" cb : bl2mf=0 add marked files to buffer list
10820" cB : bl2mf=1 use bufferlist to mark files
10821" (mnemonic: cb = copy (marked files) to buffer list)
10822fun! s:NetrwBadd(islocal,bl2mf)
10823" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
10824 if a:bl2mf
10825 " cB: add buffer list to marked files
10826 redir => bufl
10827 ls
10828 redir END
10829 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
10830 for fname in bufl
10831 call s:NetrwMarkFile(a:islocal,fname)
10832 endfor
10833 else
10834 " cb: add marked files to buffer list
10835 for fname in s:netrwmarkfilelist_{bufnr("%")}
10836" " call Decho("badd ".fname,'~'.expand("<slnum>"))
10837 exe "badd ".fnameescape(fname)
10838 endfor
10839 let curbufnr = bufnr("%")
10840 let curdir = s:NetrwGetCurdir(a:islocal)
10841 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
10842 endif
10843" call Dret("s:NetrwBadd")
10844endfun
10845
10846" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000010847" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
10848fun! s:ComposePath(base,subdir)
10849" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
10850
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010851 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010852" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010853 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000010854 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010855 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000010856 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010857 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000010858 endif
10859
Bram Moolenaar85850f32019-07-19 22:05:51 +020010860 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020010861 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010862" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010863 let ret= a:subdir
10864
Nir Lichtman1e34b952024-05-08 19:19:34 +020010865 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010866" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010867 if a:base =~ '[/\\]$'
10868 let ret= a:base.a:subdir
10869 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010870 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010010871 endif
10872
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010873 elseif a:base =~ '^\a\{3,}://'
10874" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010875 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
10876 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
10877 if a:subdir == '../'
10878 if curpath =~ '[^/]/[^/]\+/$'
10879 let curpath= substitute(curpath,'[^/]\+/$','','')
10880 else
10881 let curpath=""
10882 endif
10883 let ret= urlbase.curpath
10884 else
10885 let ret= urlbase.curpath.a:subdir
10886 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010887" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
10888" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
10889" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010890
10891 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010892" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010893 let ret = substitute(a:base."/".a:subdir,"//","/","g")
10894 if a:base =~ '^//'
10895 " keeping initial '//' for the benefit of network share listing support
10896 let ret= '/'.ret
10897 endif
10898 let ret= simplify(ret)
10899 endif
10900
10901" call Dret("s:ComposePath ".ret)
10902 return ret
10903endfun
10904
10905" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010906" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
10907" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
10908fun! s:DeleteBookmark(fname)
10909" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
10910 call s:MergeBookmarks()
10911
10912 if exists("g:netrw_bookmarklist")
10913 let indx= index(g:netrw_bookmarklist,a:fname)
10914 if indx == -1
10915 let indx= 0
10916 while indx < len(g:netrw_bookmarklist)
10917 if g:netrw_bookmarklist[indx] =~ a:fname
10918 call remove(g:netrw_bookmarklist,indx)
10919 let indx= indx - 1
10920 endif
10921 let indx= indx + 1
10922 endwhile
10923 else
10924 " remove exact match
10925 call remove(g:netrw_bookmarklist,indx)
10926 endif
10927 endif
10928
10929" call Dret("s:DeleteBookmark")
10930endfun
10931
10932" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000010933" s:FileReadable: o/s independent filereadable {{{2
10934fun! s:FileReadable(fname)
10935" call Dfunc("s:FileReadable(fname<".a:fname.">)")
10936
10937 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010938 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010939 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010940 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010941 endif
10942
10943" call Dret("s:FileReadable ".ret)
10944 return ret
10945endfun
10946
10947" ---------------------------------------------------------------------
10948" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
10949" Places correct suffix on end of temporary filename,
10950" using the suffix provided with fname
10951fun! s:GetTempfile(fname)
10952" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
10953
10954 if !exists("b:netrw_tmpfile")
10955 " get a brand new temporary filename
10956 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010957" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010958
Bram Moolenaarc236c162008-07-13 17:41:49 +000010959 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010960" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010961
Bram Moolenaar9964e462007-05-05 17:54:07 +000010962 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010963 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
10964" 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 +010010965 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010966" call Dret("s:GetTempfile getcwd<".getcwd().">")
10967 return ""
10968 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010969
Bram Moolenaar9964e462007-05-05 17:54:07 +000010970 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010971 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010972" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010973
Bram Moolenaar9964e462007-05-05 17:54:07 +000010974 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000010975 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010010976 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020010977 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010978 if !exists("+shellslash") || !&ssl
10979 let tmpfile = substitute(tmpfile,'/','\','g')
10980 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010981 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010982 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000010983 endif
10984 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010985" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010986 else
10987 " re-use temporary filename
10988 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010989" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010990 endif
10991
10992 " use fname's suffix for the temporary file
10993 if a:fname != ""
10994 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010995" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010996 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000010997 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010998 elseif a:fname =~ '.txz$'
10999 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011000 else
11001 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11002 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011003" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011004 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011005" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011006 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011007" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011008 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11009 endif
11010 endif
11011
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011012" 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 +000011013" call Dret("s:GetTempfile <".tmpfile.">")
11014 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011015endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011016
11017" ---------------------------------------------------------------------
11018" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011019" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011020fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011021" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011022 if s:user == ""
11023 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11024 else
11025 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11026 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011027 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011028 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011029 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011030 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011031 else
11032 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11033 endif
11034" call Dret("s:MakeSshCmd <".sshcmd.">")
11035 return sshcmd
11036endfun
11037
11038" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011039" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11040fun! s:MakeBookmark(fname)
11041" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11042
11043 if !exists("g:netrw_bookmarklist")
11044 let g:netrw_bookmarklist= []
11045 endif
11046
11047 if index(g:netrw_bookmarklist,a:fname) == -1
11048 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011049 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011050 call add(g:netrw_bookmarklist,a:fname.'/')
11051 elseif a:fname !~ '/'
11052 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11053 else
11054 call add(g:netrw_bookmarklist,a:fname)
11055 endif
11056 call sort(g:netrw_bookmarklist)
11057 endif
11058
11059" call Dret("s:MakeBookmark")
11060endfun
11061
11062" ---------------------------------------------------------------------
11063" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11064fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011065" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011066 " get bookmarks from .netrwbook file
11067 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011068 if filereadable(s:NetrwFile(savefile))
11069" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011070 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011071" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011072 NetrwKeepj call delete(savefile)
11073 endif
11074" call Dret("s:MergeBookmarks")
11075endfun
11076
11077" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011078" s:NetrwBMShow: {{{2
11079fun! s:NetrwBMShow()
11080" call Dfunc("s:NetrwBMShow()")
11081 redir => bmshowraw
11082 menu
11083 redir END
11084 let bmshowlist = split(bmshowraw,'\n')
11085 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011086 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011087 if bmshowfuncs != []
11088 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011089 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011090 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011091 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011092 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011093 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011094" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11095endfun
11096
11097" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011098" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011099fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011100 if !exists("w:netrw_liststyle")
11101 let w:netrw_liststyle= g:netrw_liststyle
11102 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011103" 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 +020011104
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011105" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11106
Bram Moolenaaradc21822011-04-01 18:03:16 +020011107 if &ft != "netrw"
11108 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11109 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011110" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011111
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011112 elseif g:netrw_cursor == 8
11113 if w:netrw_liststyle == s:WIDELIST
11114 setl cursorline
11115 setl cursorcolumn
11116 else
11117 setl cursorline
11118 endif
11119 elseif g:netrw_cursor == 7
11120 setl cursorline
11121 elseif g:netrw_cursor == 6
11122 if w:netrw_liststyle == s:WIDELIST
11123 setl cursorline
11124 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011125 elseif g:netrw_cursor == 4
11126 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011127" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011128 setl cursorline
11129 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011130
11131 elseif g:netrw_cursor == 3
11132 " thin-long-tree: cursorline, user's cursorcolumn
11133 " wide : cursorline, cursorcolumn
11134 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011135" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011136 setl cursorline
11137 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011138 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011139" 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 +020011140 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011141 endif
11142
11143 elseif g:netrw_cursor == 2
11144 " thin-long-tree: cursorline, user's cursorcolumn
11145 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011146" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011147 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011148
11149 elseif g:netrw_cursor == 1
11150 " thin-long-tree: user's cursorline, user's cursorcolumn
11151 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011152 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011153" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011154 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011155 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011156" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011157 endif
11158
11159 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011160 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011161" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011162 let &l:cursorline = s:netrw_usercul
11163 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011164 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011165
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011166" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011167" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011168endfun
11169
11170" ---------------------------------------------------------------------
11171" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11172fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011173" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011174 if exists("s:netrw_usercul")
11175 let &l:cursorline = s:netrw_usercul
11176 endif
11177 if exists("s:netrw_usercuc")
11178 let &l:cursorcolumn = s:netrw_usercuc
11179 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011180" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011181" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11182endfun
11183
Christian Brabandt62f7b552024-06-23 20:23:40 +020011184" s:RestoreRegister: restores all registers given in the dict {{{2
11185fun! s:RestoreRegister(dict)
11186 for [key, val] in items(a:dict)
11187 if key == 'unnamed'
11188 let key = ''
11189 endif
11190 call setreg(key, val[0], val[1])
11191 endfor
11192endfun
11193
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011194" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011195" s:NetrwDelete: Deletes a file. {{{2
11196" Uses Steve Hall's idea to insure that Windows paths stay
11197" acceptable. No effect on Unix paths.
11198" Examples of use: let result= s:NetrwDelete(path)
11199fun! s:NetrwDelete(path)
11200" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11201
Bram Moolenaar5c736222010-01-06 20:54:52 +010011202 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011203 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000011204 if exists("+shellslash")
11205 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011206 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011207 let result = delete(path)
11208 let &shellslash = sskeep
11209 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011210" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011211 let result= delete(path)
11212 endif
11213 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011214" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011215 let result= delete(path)
11216 endif
11217 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011218 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011219 endif
11220
11221" call Dret("s:NetrwDelete ".result)
11222 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000011223endfun
11224
11225" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011226" s:NetrwBufRemover: removes a buffer that: {{{2s
11227" has buffer-id > 1
11228" is unlisted
11229" is unnamed
11230" does not appear in any window
11231fun! s:NetrwBufRemover(bufid)
11232" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
11233" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
11234" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
11235" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
11236" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
11237
yasuda4dbb2662023-10-04 20:50:35 +020011238 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011239" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020011240 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011241 endif
11242
11243" call Dret("s:NetrwBufRemover")
11244endfun
11245
11246" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011247" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010011248fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011249" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011250" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011251
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011252 " Clean out the last buffer:
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011253 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
11254 " If so, delete it.
11255 call s:NetrwBufRemover(bufnr("$"))
11256
Bram Moolenaar446cb832008-06-24 21:56:24 +000011257 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011258" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011259 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
11260 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
11261 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
11262 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
11263 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11264 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
11265 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
11266 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
11267 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
11268 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11269 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
11270 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
11271 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
11272 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
11273 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
11274 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
11275
Bram Moolenaar85850f32019-07-19 22:05:51 +020011276 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011277" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011278 " when tree listing uses file TreeListing... a new buffer is made.
11279 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011280 " COMBAK: this causes a problem, see P43
11281" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011282 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010011283 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011284 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011285" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020011286 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011287
Bram Moolenaar446cb832008-06-24 21:56:24 +000011288 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011289" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011290 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
11291 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
11292 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
11293 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
11294 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
11295 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
11296 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
11297 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
11298 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
11299 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
11300 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
11301 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
11302 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
11303 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
11304 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
11305 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
11306
Bram Moolenaar5c736222010-01-06 20:54:52 +010011307 if a:0 > 0
11308 let b:netrw_curdir= a:1
11309 if b:netrw_curdir =~ '/$'
11310 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011311 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010011312 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011313 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020011314 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
11315 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010011316 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011317 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010011318 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011319 endif
11320 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011321 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
11322 let &l:bexpr = "netrw#BalloonHelp()"
11323 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011324
Bram Moolenaar8d043172014-01-23 14:24:41 +010011325" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011326endfun
11327
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011328" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011329" s:NetrwExe: executes a string using "!" {{{2
11330fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011331" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Konfekt3d7e5672024-10-27 22:16:49 +010011332 if has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +020011333" call Decho("using win32:",expand("<slnum>"))
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
Bram Moolenaar85850f32019-07-19 22:05:51 +020011343" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011344 exe a:cmd
11345 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011346 if v:shell_error
11347 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
11348 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011349" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011350endfun
11351
11352" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011353" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
11354fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011355 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011356" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011357 let curbuf = bufnr("%")
11358 let curwin = winnr()
11359 let iwin = 1
11360 while iwin <= winnr("$")
11361 exe iwin."wincmd w"
11362 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
11363 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
11364 let winvars= w:
11365 break
11366 endif
11367 let iwin= iwin + 1
11368 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020011369 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011370 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011371" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011372 for k in keys(winvars)
11373 let w:{k}= winvars[k]
11374 endfor
11375 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011376" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011377 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011378endfun
11379
Bram Moolenaara6878372014-03-22 21:02:50 +010011380" ---------------------------------------------------------------------
11381" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020011382" Returns: 0=success
11383" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010011384fun! s:NetrwLcd(newdir)
11385" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011386" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011387
Bram Moolenaar85850f32019-07-19 22:05:51 +020011388 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011389 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011390 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010011391 catch /^Vim\%((\a\+)\)\=:E344/
11392 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
11393 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011394 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010011395 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
11396 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020011397 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010011398 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
11399 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090011400 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010011401 endif
11402 endif
11403 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020011404 let err472= 1
11405 endtry
11406
11407 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010011408 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
11409 if exists("w:netrw_prvdir")
11410 let a:newdir= w:netrw_prvdir
11411 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011412 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011413" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020011414 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011415" 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 +010011416 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010011417 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011418" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
11419 return -1
11420 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011421
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011422" call Decho("getcwd <".getcwd().">")
11423" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020011424" call Dret("s:NetrwLcd 0")
11425 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011426endfun
11427
Bram Moolenaar9964e462007-05-05 17:54:07 +000011428" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011429" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
11430" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
11431fun! s:NetrwSaveWordPosn()
11432" call Dfunc("NetrwSaveWordPosn()")
11433 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
11434" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
11435endfun
11436
11437" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011438" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
11439" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
11440fun! s:NetrwHumanReadable(sz)
11441" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
11442
11443 if g:netrw_sizestyle == 'h'
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011444 if a:sz >= 1000000000
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011445 let sz = printf("%.1f",a:sz/1000000000.0)."g"
11446 elseif a:sz >= 10000000
11447 let sz = printf("%d",a:sz/1000000)."m"
11448 elseif a:sz >= 1000000
11449 let sz = printf("%.1f",a:sz/1000000.0)."m"
11450 elseif a:sz >= 10000
11451 let sz = printf("%d",a:sz/1000)."k"
11452 elseif a:sz >= 1000
11453 let sz = printf("%.1f",a:sz/1000.0)."k"
11454 else
11455 let sz= a:sz
11456 endif
11457
11458 elseif g:netrw_sizestyle == 'H'
11459 if a:sz >= 1073741824
11460 let sz = printf("%.1f",a:sz/1073741824.0)."G"
11461 elseif a:sz >= 10485760
11462 let sz = printf("%d",a:sz/1048576)."M"
11463 elseif a:sz >= 1048576
11464 let sz = printf("%.1f",a:sz/1048576.0)."M"
11465 elseif a:sz >= 10240
11466 let sz = printf("%d",a:sz/1024)."K"
11467 elseif a:sz >= 1024
11468 let sz = printf("%.1f",a:sz/1024.0)."K"
11469 else
11470 let sz= a:sz
11471 endif
11472
11473 else
11474 let sz= a:sz
11475 endif
11476
11477" call Dret("s:NetrwHumanReadable ".sz)
11478 return sz
11479endfun
11480
11481" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011482" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
11483" changed sorting, etc. Also see s:NetrwSaveWordPosn().
11484fun! s:NetrwRestoreWordPosn()
11485" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020011486 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000011487" call Dret("NetrwRestoreWordPosn")
11488endfun
11489
11490" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011491" s:RestoreBufVars: {{{2
11492fun! s:RestoreBufVars()
11493" call Dfunc("s:RestoreBufVars()")
11494
11495 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
11496 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
11497 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
11498 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
11499 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
11500 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
11501
11502" call Dret("s:RestoreBufVars")
11503endfun
11504
11505" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011506" s:RemotePathAnalysis: {{{2
11507fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020011508" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011509
Bram Moolenaara6878372014-03-22 21:02:50 +010011510 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010011511 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011512 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010011513 let s:user = substitute(a:dirname,dirpat,'\3','')
11514 let s:machine = substitute(a:dirname,dirpat,'\4','')
11515 let s:port = substitute(a:dirname,dirpat,'\5','')
11516 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020011517 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010011518 if s:machine =~ '@'
11519 let dirpat = '^\(.*\)@\(.\{-}\)$'
11520 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
11521 let s:machine = substitute(s:machine,dirpat,'\2','')
11522 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011523
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011524" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
11525" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
11526" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
11527" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
11528" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
11529" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011530
11531" call Dret("s:RemotePathAnalysis")
11532endfun
11533
11534" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011535" s:RemoteSystem: runs a command on a remote host using ssh {{{2
11536" Returns status
11537" Runs system() on
11538" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011539" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000011540fun! s:RemoteSystem(cmd)
11541" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
11542 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011543 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 +000011544 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011545 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011546 else
11547 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
11548 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
11549 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011550 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000011551 else
11552 let cmd= cmd.' '
11553 endif
11554 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011555" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011556 let ret= system(cmd)
11557 endif
11558" call Dret("s:RemoteSystem ".ret)
11559 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000011560endfun
11561
11562" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011563" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000011564fun! s:RestoreWinVars()
11565" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000011566 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011567 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
11568 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
11569 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
11570 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
11571 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
11572 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
11573 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
11574 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
11575 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
11576 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
11577 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
11578 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000011579 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
11580 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011581 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
11582 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
11583 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
11584" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000011585endfun
11586
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011587" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011588" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
11589"
11590" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
11591" is true) and a command, :Rexplore, which call this function.
11592"
Bram Moolenaar85850f32019-07-19 22:05:51 +020011593" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011594"
11595" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000011596fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020011597 if exists("s:netrwdrag")
11598 return
11599 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011600" 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 +010011601" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
11602" 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 +010011603
11604 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011605 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011606" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011607 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011608 unlet w:netrw_rexfile
11609" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020011610 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011611" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011612" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
11613" 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 +020011614 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011615
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011616 " ---------------------------
11617 " :Rex issued while in a file
11618 " ---------------------------
11619
Bram Moolenaara6878372014-03-22 21:02:50 +010011620 " record current file so :Rex can return to it from netrw
11621 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011622" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011623
11624 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011625" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010011626 return
11627 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011628" 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 +020011629 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011630 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011631 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011632 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011633 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011634 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010011635 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020011636 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011637 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011638" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
11639 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011640" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
11641 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011642 if exists("s:rexposn_".bufnr('%'))
11643 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011644 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011645 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011646" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011647 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011648
Bram Moolenaar85850f32019-07-19 22:05:51 +020011649 if has("syntax") && exists("g:syntax_on") && g:syntax_on
11650 if exists("s:explore_match")
11651 exe "2match netrwMarkFile /".s:explore_match."/"
11652 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010011653 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011654
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011655" 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 +010011656" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011657endfun
11658
11659" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010011660" s:SaveBufVars: save selected b: variables to s: variables {{{2
11661" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000011662fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011663" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011664
11665 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
11666 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
11667 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
11668 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
11669 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
11670 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
11671
11672" call Dret("s:SaveBufVars")
11673endfun
11674
11675" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011676" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
11677fun! s:SavePosn(posndict)
11678" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
11679
Bram Moolenaar85850f32019-07-19 22:05:51 +020011680 if !exists("a:posndict[bufnr('%')]")
11681 let a:posndict[bufnr("%")]= []
11682 endif
11683" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11684 call add(a:posndict[bufnr("%")],winsaveview())
11685" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011686
11687" call Dret("s:SavePosn posndict")
11688 return a:posndict
11689endfun
11690
11691" ---------------------------------------------------------------------
11692" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
11693fun! s:RestorePosn(posndict)
11694" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020011695 if exists("a:posndict")
11696 if has_key(a:posndict,bufnr("%"))
11697" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11698 let posnlen= len(a:posndict[bufnr("%")])
11699 if posnlen > 0
11700 let posnlen= posnlen - 1
11701" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
11702 call winrestview(a:posndict[bufnr("%")][posnlen])
11703 call remove(a:posndict[bufnr("%")],posnlen)
11704" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11705 endif
11706 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011707 endif
11708" call Dret("s:RestorePosn")
11709endfun
11710
11711" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011712" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000011713fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011714" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000011715 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
11716 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
11717 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
11718 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
11719 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
11720 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
11721 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
11722 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
11723 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
11724 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
11725 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
11726 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
11727 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
11728 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
11729 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
11730 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
11731 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
11732 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
11733" call Dret("s:SaveWinVars")
11734endfun
11735
11736" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011737" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011738" To allow separate windows to have their own activities, such as
11739" Explore **/pattern, several variables have been made window-oriented.
11740" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011741" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011742" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011743fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011744" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000011745 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
11746 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
11747 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
11748 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
11749 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
11750 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
11751 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
11752 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
11753 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
11754 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
11755" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011756endfun
11757
11758" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011759" s:SetRexDir: set directory for :Rexplore {{{2
11760fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011761" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011762 let w:netrw_rexdir = a:dirname
11763 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011764 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011765" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
11766" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011767" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011768" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011769" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011770endfun
11771
11772" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011773" s:ShowLink: used to modify thin and tree listings to show links {{{2
11774fun! s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011775 if exists("b:netrw_curdir")
11776 norm! $?\a
Tom Benham64a536d2024-11-07 21:15:03 +010011777 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treetop")
11778 let basedir = s:NetrwTreePath(w:netrw_treetop)
11779 else
11780 let basedir = b:netrw_curdir.'/'
11781 endif
11782 let fname = basedir.s:NetrwGetWord()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011783 let resname = resolve(fname)
Tom Benham64a536d2024-11-07 21:15:03 +010011784 if resname =~ '^\M'.basedir
11785 let dirlen = strlen(basedir)
11786 let resname = strpart(resname,dirlen)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011787 endif
11788 let modline = getline(".")."\t --> ".resname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011789 setl noro ma
11790 call setline(".",modline)
11791 setl ro noma nomod
11792 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011793endfun
11794
11795" ---------------------------------------------------------------------
11796" s:ShowStyle: {{{2
11797fun! s:ShowStyle()
11798 if !exists("w:netrw_liststyle")
11799 let liststyle= g:netrw_liststyle
11800 else
11801 let liststyle= w:netrw_liststyle
11802 endif
11803 if liststyle == s:THINLIST
11804 return s:THINLIST.":thin"
11805 elseif liststyle == s:LONGLIST
11806 return s:LONGLIST.":long"
11807 elseif liststyle == s:WIDELIST
11808 return s:WIDELIST.":wide"
11809 elseif liststyle == s:TREELIST
11810 return s:TREELIST.":tree"
11811 else
11812 return 'n/a'
11813 endif
11814endfun
11815
11816" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010011817" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
11818" Solution from Nicolai Weibull, vim docs (:help strlen()),
11819" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000011820fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011821" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
11822
11823 if v:version >= 703 && exists("*strdisplaywidth")
11824 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011825
Bram Moolenaar8d043172014-01-23 14:24:41 +010011826 elseif type(g:Align_xstrlen) == 1
11827 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
11828 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011829
Bram Moolenaar8d043172014-01-23 14:24:41 +010011830 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000011831 " number of codepoints (Latin a + combining circumflex is two codepoints)
11832 " (comment from TM, solution from NW)
11833 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011834
Bram Moolenaar8d043172014-01-23 14:24:41 +010011835 elseif g:Align_xstrlen == 2
11836 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000011837 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
11838 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011839 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011840
Bram Moolenaar8d043172014-01-23 14:24:41 +010011841 elseif g:Align_xstrlen == 3
11842 " virtual length (counting, for instance, tabs as anything between 1 and
11843 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000011844 " preceded by lam, one otherwise, etc.)
11845 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011846 let modkeep= &l:mod
11847 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011848 call setline(line("."),a:x)
11849 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010011850 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011851 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010011852 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011853
Bram Moolenaar446cb832008-06-24 21:56:24 +000011854 else
11855 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010011856 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011857 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010011858" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011859 return ret
11860endfun
11861
11862" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011863" s:ShellEscape: shellescape(), or special windows handling {{{2
11864fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011865 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011866 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011867 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011868 let f = a:0 > 0 ? a:1 : 0
11869 return shellescape(a:s, f)
11870endfun
11871
11872" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011873" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000011874fun! s:TreeListMove(dir)
11875" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011876 let curline = getline('.')
11877 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
11878 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
11879 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
11880 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
11881 let treedepthchr = substitute(s:treedepthstring,' ','','g')
11882 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
11883" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
11884" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
11885" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
11886" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
11887" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
11888 " COMBAK : need to handle when on a directory
11889 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000011890 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011891 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011892 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011893 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011894" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011895 elseif a:dir == '[]' && nxtline != ''
11896 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011897" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011898 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
11899 if nl != 0
11900 NetrwKeepj norm! k
11901 else
11902 NetrwKeepj norm! G
11903 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011904" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011905 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011906 endif
11907
11908" call Dret("s:TreeListMove")
11909endfun
11910
11911" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011912" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
11913" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
11914" can't be called except via emenu. But due to locale, that menu line may not be called
11915" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
11916fun! s:UpdateBuffersMenu()
11917" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020011918 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000011919 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020011920 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000011921 catch /^Vim\%((\a\+)\)\=:E/
11922 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011923 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000011924 endtry
11925 endif
11926" call Dret("s:UpdateBuffersMenu")
11927endfun
11928
11929" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011930" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020011931" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011932fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000011933" call Dfunc("s:UseBufWinVars()")
11934 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011935 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
11936 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
11937 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
11938 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
11939 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
11940 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11941 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11942 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
11943 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 +000011944" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011945endfun
11946
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011947" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011948" s:UserMaps: supports user-defined UserMaps {{{2
11949" * calls a user-supplied funcref(islocal,curdir)
11950" * interprets result
11951" See netrw#UserMaps()
11952fun! s:UserMaps(islocal,funcname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011953 if !exists("b:netrw_curdir")
11954 let b:netrw_curdir= getcwd()
11955 endif
11956 let Funcref = function(a:funcname)
11957 let result = Funcref(a:islocal)
11958
11959 if type(result) == 1
11960 " if result from user's funcref is a string...
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011961 if result == "refresh"
Tom Benham64a536d2024-11-07 21:15:03 +010011962 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011963 elseif result != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011964 exe result
11965 endif
11966
11967 elseif type(result) == 3
11968 " if result from user's funcref is a List...
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011969 for action in result
11970 if action == "refresh"
Tom Benham64a536d2024-11-07 21:15:03 +010011971 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011972 elseif action != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011973 exe action
11974 endif
11975 endfor
11976 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011977endfun
11978
Bram Moolenaar85850f32019-07-19 22:05:51 +020011979" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011980" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020011981" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000011982let &cpo= s:keepcpo
11983unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000011984
Bram Moolenaar85850f32019-07-19 22:05:51 +020011985" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000011986" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020011987" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000011988" vim:ts=8 fdm=marker