blob: b90a8d672f165ed108634ca0ad27c68594419733 [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" netrw.vim: Handles file transfer and remote directory listing across
2" AUTOLOAD SECTION
Christian Brabandtf9ca1392024-02-19 20:37:11 +01003" Maintainer: This runtime file is looking for a new maintainer.
4" Date: May 03, 2023
Christian Brabandtcb0c1132023-11-21 18:48:16 +00005" Version: 173a
Travis Sheltone34d0e32024-07-30 21:08:56 +02006" Last Change: {{{1
Luca Saccarolaa7d45612024-10-21 21:27:03 +02007" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
8" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
Christian Brabandt8fad5d52024-02-29 18:12:30 +01009" 2024 Feb 19 by Vim Project: (announce adoption)
10" 2024 Feb 29 by Vim Project: handle symlinks in tree mode correctly
Christian Brabandt08d24012024-04-03 22:44:27 +020011" 2024 Apr 03 by Vim Project: detect filetypes for remote edited files
Nir Lichtman1e34b952024-05-08 19:19:34 +020012" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
Nir Lichtmance2ad9f2024-05-09 20:20:36 +020013" 2024 May 09 by Vim Project: remove hard-coded private.ppk
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020014" 2024 May 10 by Vim Project: recursively delete directories by default
Christian Brabandt43f2edc2024-05-13 20:56:43 +020015" 2024 May 13 by Vim Project: prefer scp over pscp
Christian Brabandt98b73eb2024-06-04 18:15:57 +020016" 2024 Jun 04 by Vim Project: set bufhidden if buffer changed, nohidden is set and buffer shall be switched (#14915)
Christian Brabandt14879472024-06-13 21:25:35 +020017" 2024 Jun 13 by Vim Project: glob() on Windows fails when a directory name contains [] (#14952)
Enno3146d632024-07-04 19:44:42 +020018" 2024 Jun 23 by Vim Project: save ad restore registers when liststyle = WIDELIST (#15077, #15114)
Damien9d57ea52024-07-22 20:23:48 +020019" 2024 Jul 22 by Vim Project: avoid endless recursion (#15318)
Christian Brabandt581d4a72024-07-23 21:14:06 +020020" 2024 Jul 23 by Vim Project: escape filename before trying to delete it (#15330)
Travis Sheltone34d0e32024-07-30 21:08:56 +020021" 2024 Jul 30 by Vim Project: handle mark-copy to same target directory (#12112)
Ivan Shapovalovc527d902024-08-02 19:43:12 +020022" 2024 Aug 02 by Vim Project: honor g:netrw_alt{o,v} for :{S,H,V}explore (#15417)
Damien7c754112024-08-15 21:58:57 +020023" 2024 Aug 15 by Vim Project: style changes, prevent E121 (#15501)
yasuda38cfa2b2024-08-22 20:54:47 +020024" 2024 Aug 22 by Vim Project: fix mf-selection highlight (#15551)
yasudac75dad02024-08-22 21:06:32 +020025" 2024 Aug 22 by Vim Project: adjust echo output of mx command (#15550)
Christian Brabandt0f5effb2024-09-15 19:17:23 +020026" 2024 Sep 15 by Vim Project: more strict confirmation dialog (#15680)
yasudac18a9d52024-09-19 18:09:51 +020027" 2024 Sep 19 by Vim Project: mf-selection highlight uses wrong pattern (#15700)
Peter Aronoffbe551da2024-09-22 11:29:40 +020028" 2024 Sep 21 by Vim Project: remove extraneous closing bracket (#15718)
Luca Saccarolaa7d45612024-10-21 21:27:03 +020029" 2024 Oct 21 by Vim Project: remove netrwFileHandlers (#15895)
Konfekt3d7e5672024-10-27 22:16:49 +010030" 2024 Oct 27 by Vim Project: clean up gx mapping (#15721)
Christian Brabandtaa2ce6f2024-10-30 18:27:03 +010031" 2024 Oct 30 by Vim Project: fix filetype detection for remote files (#15961)
Christian Brabandt9f320692024-10-30 18:36:20 +010032" 2024 Oct 30 by Vim Project: fix x mapping on cygwin (#13687)
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010033" 2024 Oct 31 by Vim Project: add netrw#Launch() and netrw#Open() (#15962)
Tom Benham4d618002024-10-31 10:47:23 +010034" 2024 Oct 31 by Vim Project: fix E874 when browsing remote dir (#15964)
Christian Brabandta063b222024-11-07 14:30:30 +010035" 2024 Nov 07 by Vim Project: use keeppatterns to prevent polluting the search history
Tom Benham64a536d2024-11-07 21:15:03 +010036" 2024 Nov 07 by Vim Project: fix a few issues with netrw tree listing (#15996)
Christian Brabandt5b63b232024-11-10 20:22:34 +010037" 2024 Nov 10 by Vim Project: directory symlink not resolved in tree view (#16020)
Konfekt460799d2024-11-14 21:42:27 +010038" 2024 Nov 14 by Vim Project: small fixes to netrw#BrowseX (#16056)
Christian Brabandtcacfccf2024-11-23 13:28:01 +010039" 2024 Nov 23 by Vim Project: update decompress defaults (#16104)
GuyBrushd7745ac2024-11-23 14:13:10 +010040" 2024 Nov 23 by Vim Project: fix powershell escaping issues (#16094)
Konfekteda923e2024-12-04 20:12:44 +010041" 2024 Dec 04 by Vim Project: do not detach for gvim (#16168)
Christian Brabandt92b36662024-12-08 09:52:37 +010042" 2024 Dec 08 by Vim Project: check the first arg of netrw_browsex_viewer for being executable (#16185)
Travis Sheltone34d0e32024-07-30 21:08:56 +020043" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010044" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000045" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010046" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000047" Permission is hereby granted to use and distribute this code,
48" with or without modifications, provided that this copyright
49" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000050" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000051" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000052" expressed or implied. By using this plugin, you agree that
53" in no event will the copyright holder be liable for any damages
54" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010055"
56" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
57" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
58"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020059"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000060"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000061" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000062" (James 1:22 RSV)
63" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000064" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000065if &cp || exists("g:loaded_netrw")
66 finish
67endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020068
69" Check that vim has patches that netrw requires.
70" Patches needed for v7.4: 1557, and 213.
71" (netrw will benefit from vim's having patch#656, too)
72let s:needspatches=[1557,213]
73if exists("s:needspatches")
74 for ptch in s:needspatches
75 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
76 if !exists("s:needpatch{ptch}")
77 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
78 endif
79 let s:needpatch{ptch}= 1
80 finish
81 endif
82 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020083endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020084
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010085let g:loaded_netrw = "v173"
Bram Moolenaar446cb832008-06-24 21:56:24 +000086
Bram Moolenaar1afcace2005-11-25 19:54:28 +000087let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010088setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020089"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010090"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010091"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000092
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000093" ======================
94" Netrw Variables: {{{1
95" ======================
96
Bram Moolenaar071d4272004-06-13 20:20:40 +000097" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020098" netrw#ErrorMsg: {{{2
99" 0=note = s:NOTE
100" 1=warning = s:WARNING
101" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100102" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
103" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
104" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +0100105" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200106fun! netrw#ErrorMsg(level,msg,errnum)
107" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
108
109 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200110" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200111 return
112 endif
113
114 if a:level == 1
115 let level= "**warning** (netrw) "
116 elseif a:level == 2
117 let level= "**error** (netrw) "
118 else
119 let level= "**note** (netrw) "
120 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100121" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200122
Damienb4d11642024-08-15 22:00:45 +0200123 if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200124 " use popup window
125 if type(a:msg) == 3
126 let msg = [level]+a:msg
127 else
128 let msg= level.a:msg
129 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200130 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200131 let s:popuperr_text= ""
132 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200133 " (default) netrw creates a one-line window to show error/warning
134 " messages (reliably displayed)
135
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100136 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200137 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100138" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200139
140 " getting messages out reliably is just plain difficult!
141 " This attempt splits the current window, creating a one line window.
142 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100143" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200144 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100145" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200146 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100147 if type(a:msg) == 3
148 for msg in a:msg
149 NetrwKeepj call setline(line("$")+1,level.msg)
150 endfor
151 else
152 NetrwKeepj call setline(line("$")+1,level.a:msg)
153 endif
154 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200155 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100156" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200157 bo 1split
158 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200159 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200160 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100161 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100162" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200163 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100164 if type(a:msg) == 3
165 for msg in a:msg
166 NetrwKeepj call setline(line("$")+1,level.msg)
167 endfor
168 else
169 NetrwKeepj call setline(line("$"),level.a:msg)
170 endif
171 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200172 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100173" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200174 if &fo !~ '[ta]'
175 syn clear
176 syn match netrwMesgNote "^\*\*note\*\*"
177 syn match netrwMesgWarning "^\*\*warning\*\*"
178 syn match netrwMesgError "^\*\*error\*\*"
179 hi link netrwMesgWarning WarningMsg
180 hi link netrwMesgError Error
181 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100182" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200183 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200184
185 else
186 " (optional) netrw will show messages using echomsg. Even if the
187 " message doesn't appear, at least it'll be recallable via :messages
188" redraw!
189 if a:level == s:WARNING
190 echohl WarningMsg
191 elseif a:level == s:ERROR
192 echohl Error
193 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100194
195 if type(a:msg) == 3
196 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100197 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100198 endfor
199 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100200 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100201 endif
202
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100203" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200204 echohl None
205 endif
206
207" call Dret("netrw#ErrorMsg")
208endfun
209
210" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100211" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100212" Loosely, varname = value.
213fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100214" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100215 if !exists(a:varname)
216 if type(a:value) == 0
217 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200218 elseif type(a:value) == 1 && a:value =~ '^[{[]'
219 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100220 elseif type(a:value) == 1
221 exe "let ".a:varname."="."'".a:value."'"
222 else
223 exe "let ".a:varname."=".a:value
224 endif
225 endif
226endfun
227
228" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000229" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200230call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000231if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100232 call s:NetrwInit("s:THINLIST",0)
233 call s:NetrwInit("s:LONGLIST",1)
234 call s:NetrwInit("s:WIDELIST",2)
235 call s:NetrwInit("s:TREELIST",3)
236 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000237endif
238
Damien7c754112024-08-15 21:58:57 +0200239let s:NOTE = 0
240let s:WARNING = 1
241let s:ERROR = 2
242call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
243
Bram Moolenaar9964e462007-05-05 17:54:07 +0000244" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200245" Default option values: {{{2
246let g:netrw_localcopycmdopt = ""
247let g:netrw_localcopydircmdopt = ""
248let g:netrw_localmkdiropt = ""
249let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200250
251" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000252" Default values for netrw's global protocol variables {{{2
Damienb4d11642024-08-15 22:00:45 +0200253if exists("*popup_atcursor")
254\ && has("syntax")
255\ && exists("g:syntax_on")
256\ && has("mouse")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200257 call s:NetrwInit("g:netrw_use_errorwindow",2)
258else
259 call s:NetrwInit("g:netrw_use_errorwindow",1)
260endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200261
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000262if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100263 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000264 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100265 elseif executable("curl")
266 let g:netrw_dav_cmd = "curl"
267 else
268 let g:netrw_dav_cmd = ""
269 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000270endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000271if !exists("g:netrw_fetch_cmd")
272 if executable("fetch")
273 let g:netrw_fetch_cmd = "fetch -o"
274 else
275 let g:netrw_fetch_cmd = ""
276 endif
277endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100278if !exists("g:netrw_file_cmd")
279 if executable("elinks")
280 call s:NetrwInit("g:netrw_file_cmd","elinks")
281 elseif executable("links")
282 call s:NetrwInit("g:netrw_file_cmd","links")
283 endif
284endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000285if !exists("g:netrw_ftp_cmd")
286 let g:netrw_ftp_cmd = "ftp"
287endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200288let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200289if !exists("g:netrw_ftp_options")
290 let g:netrw_ftp_options= "-i -n"
291endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000292if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100293 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100294 let g:netrw_http_cmd = "wget"
295 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100296 elseif executable("curl")
297 let g:netrw_http_cmd = "curl"
298 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200299 elseif executable("elinks")
300 let g:netrw_http_cmd = "elinks"
301 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000302 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100303 let g:netrw_http_cmd = "fetch"
304 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200305 elseif executable("links")
306 let g:netrw_http_cmd = "links"
307 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000308 else
309 let g:netrw_http_cmd = ""
310 endif
311endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100312call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100313call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100314call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
315call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200316call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200317if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200318 if executable("scp")
319 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
320 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200321 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200322 else
323 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
324 endif
325endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100326call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
327call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000328
Nir Lichtman1e34b952024-05-08 19:19:34 +0200329if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000330 \ && exists("g:netrw_use_nt_rcp")
331 \ && g:netrw_use_nt_rcp
332 \ && executable( $SystemRoot .'/system32/rcp.exe')
333 let s:netrw_has_nt_rcp = 1
334 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000335else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000336 let s:netrw_has_nt_rcp = 0
337 let s:netrw_rcpmode = ''
338endif
339
340" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000341" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000342" Cygwin Detection ------- {{{3
343if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200344 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
345 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000346 else
347 let g:netrw_cygwin= 0
348 endif
349endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000350" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100351call s:NetrwInit("g:netrw_alto" , &sb)
352call s:NetrwInit("g:netrw_altv" , &spr)
353call s:NetrwInit("g:netrw_banner" , 1)
354call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200355call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100356call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200357call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100358call s:NetrwInit("g:netrw_compress" , "gzip")
359call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200360if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
361 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
362 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000363endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200364call s:NetrwInit("g:netrw_cursor" , 2)
365let s:netrw_usercul = &cursorline
366let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200367"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100368call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000369" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200370call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200371call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Christian Brabandtcacfccf2024-11-23 13:28:01 +0100372let s:xz_opt = has('unix') ? "XZ_OPT=-T0" :
373 \ (has("win32") && &shell =~? '\vcmd(\.exe)?$' ?
374 \ "setx XZ_OPT=-T0 &&" : "")
375call s:NetrwInit("g:netrw_decompress ", "{"
376 \ .."'.lz4': 'lz4 -d',"
377 \ .."'.lzo': 'lzop -d',"
378 \ .."'.lz': 'lzip -dk',"
379 \ .."'.7z': '7za x',"
380 \ .."'.001': '7za x',"
381 \ .."'.zip': 'unzip',"
382 \ .."'.bz': 'bunzip2 -k',"
383 \ .."'.bz2': 'bunzip2 -k',"
384 \ .."'.gz': 'gunzip -k',"
385 \ .."'.lzma': 'unlzma -T0 -k',"
386 \ .."'.xz': 'unxz -T0 -k',"
387 \ .."'.zst': 'zstd -T0 -d',"
388 \ .."'.Z': 'uncompress -k',"
389 \ .."'.tar': 'tar -xvf',"
390 \ .."'.tar.bz': 'tar -xvjf',"
391 \ .."'.tar.bz2': 'tar -xvjf',"
392 \ .."'.tbz': 'tar -xvjf',"
393 \ .."'.tbz2': 'tar -xvjf',"
394 \ .."'.tar.gz': 'tar -xvzf',"
395 \ .."'.tgz': 'tar -xvzf',"
396 \ .."'.tar.lzma': '"..s:xz_opt.." tar -xvf --lzma',"
397 \ .."'.tlz': '"..s:xz_opt.." tar -xvf --lzma',"
398 \ .."'.tar.xz': '"..s:xz_opt.." tar -xvfJ',"
399 \ .."'.txz': '"..s:xz_opt.." tar -xvfJ',"
400 \ .."'.tar.zst': '"..s:xz_opt.." tar -xvf --use-compress-program=unzstd',"
401 \ .."'.tzst': '"..s:xz_opt.." tar -xvf --use-compress-program=unzstd',"
402 \ .."'.rar': '"..(executable("unrar")?"unrar x -ad":"rar x -ad").."'"
403 \ .."}")
404unlet s:xz_opt
Bram Moolenaar5c736222010-01-06 20:54:52 +0100405call s:NetrwInit("g:netrw_dirhistmax" , 10)
406call s:NetrwInit("g:netrw_fastbrowse" , 1)
407call 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 +0000408if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000409 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
410 let g:netrw_ftp_list_cmd = "ls -lF"
411 let g:netrw_ftp_timelist_cmd = "ls -tlF"
412 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000413 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000414 let g:netrw_ftp_list_cmd = "dir"
415 let g:netrw_ftp_timelist_cmd = "dir"
416 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000417 endif
418endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100419call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000420" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100421call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000422if !exists("g:netrw_ignorenetrc")
423 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
424 let g:netrw_ignorenetrc= 1
425 else
426 let g:netrw_ignorenetrc= 0
427 endif
428endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100429call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000430if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000431 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100432 if exists("g:netrw_list_cmd_options")
433 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
434 else
435 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
436 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000437 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200438 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100439 if exists("g:netrw_list_cmd_options")
440 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
441 else
442 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
443 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000444 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100445" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000446 let g:netrw_list_cmd= ""
447 endif
448endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100449call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000450" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200451if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200452 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200453 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
454endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100455if !exists("g:netrw_localcmdshell")
456 let g:netrw_localcmdshell= ""
457endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000458if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200459 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000460 if g:netrw_cygwin
461 let g:netrw_localcopycmd= "cp"
462 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000463 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200464 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000465 endif
466 elseif has("unix") || has("macunix")
467 let g:netrw_localcopycmd= "cp"
468 else
469 let g:netrw_localcopycmd= ""
470 endif
471endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100472if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200473 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100474 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200475 let g:netrw_localcopydircmd = "cp"
476 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100477 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000478 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200479 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100480 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200481 elseif has("unix")
482 let g:netrw_localcopydircmd = "cp"
483 let g:netrw_localcopydircmdopt= " -R"
484 elseif has("macunix")
485 let g:netrw_localcopydircmd = "cp"
486 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100487 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200488 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100489 endif
490endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200491if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100492 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200493 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
494endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200495if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200496 if g:netrw_cygwin
497 call s:NetrwInit("g:netrw_localmkdir","mkdir")
498 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000499 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200500 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200501 endif
502else
503 call s:NetrwInit("g:netrw_localmkdir","mkdir")
504endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200505call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200506if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200507 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200508 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
509endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000510if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200511 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000512 if g:netrw_cygwin
513 let g:netrw_localmovecmd= "mv"
514 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000515 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200516 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000517 endif
518 elseif has("unix") || has("macunix")
519 let g:netrw_localmovecmd= "mv"
520 else
521 let g:netrw_localmovecmd= ""
522 endif
523endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100524" following serves as an example for how to insert a version&patch specific test
525"if v:version < 704 || (v:version == 704 && !has("patch1107"))
526"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100527call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
528" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000529if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000530 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000531endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000532if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000533 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
534endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000535" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100536call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
537call s:NetrwInit("g:netrw_maxfilenamelen", 32)
538call s:NetrwInit("g:netrw_menu" , 1)
539call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200540call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100541call s:NetrwInit("g:netrw_retmap" , 0)
542if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
543 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200544elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100545 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
546else
547 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000548endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100549call s:NetrwInit("g:netrw_preview" , 0)
550call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100551call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100552call s:NetrwInit("g:netrw_sshport" , "-p")
553call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
554call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
555call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100556call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
557" Default values - q-s ---------- {{{3
558call s:NetrwInit("g:netrw_quickhelp",0)
559let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100560 \ "(create new) %:file d:directory",
561 \ "(windows split&open) o:horz v:vert p:preview",
562 \ "i:style qf:file info O:obtain r:reverse",
563 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
564 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
565 \ "(history) qb:list u:go up U:go down",
566 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100567" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
568call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100569if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
570 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
571else
572 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
573endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100574call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
575call s:NetrwInit("g:netrw_sort_options" , "")
576call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000577if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100578 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200579 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100580 else
581 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000582 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000583endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100584call s:NetrwInit("g:netrw_special_syntax" , 0)
585call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaara6878372014-03-22 21:02:50 +0100586call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100587call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000588" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100589call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200590if !exists("g:netrw_xstrlen")
591 if exists("g:Align_xstrlen")
592 let g:netrw_xstrlen= g:Align_xstrlen
593 elseif exists("g:drawit_xstrlen")
594 let g:netrw_xstrlen= g:drawit_xstrlen
595 elseif &enc == "latin1" || !has("multi_byte")
596 let g:netrw_xstrlen= 0
597 else
598 let g:netrw_xstrlen= 1
599 endif
600endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100601call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200602call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100603call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200604if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000605" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000606" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100607call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200608if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200609 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200610else
Bram Moolenaarff034192013-04-24 18:51:19 +0200611 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200612endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200613call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100614call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
615call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100616if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100617 let s:treedepthstring= "│ "
618else
619 let s:treedepthstring= "| "
620endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200621call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000622
623" BufEnter event ignored by decho when following variable is true
624" Has a side effect that doau BufReadPost doesn't work, so
625" files read by network transfer aren't appropriately highlighted.
626"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000627
Bram Moolenaaradc21822011-04-01 18:03:16 +0200628" ======================
629" Netrw Initialization: {{{1
630" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200631if 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 +0100632" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100633 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200634" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100635 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100636 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
637 au VimEnter * let s:initbeval= &beval
638"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100639" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
640" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
641" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
642" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
643" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
644" 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 +0200645endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200646au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200647
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200648if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100649 com! -nargs=* NetrwKeepj keepj <args>
650else
651 let g:netrw_keepj= ""
652 com! -nargs=* NetrwKeepj <args>
653endif
654
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000655" ==============================
656" Netrw Utility Functions: {{{1
657" ==============================
658
Bram Moolenaaradc21822011-04-01 18:03:16 +0200659" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100660" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100661if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100662" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100663 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100664 if &ft != "netrw"
665 return ""
666 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200667 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
668 " popup error window is still showing
669 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
670 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
671 " text under mouse hasn't changed; only close window when it changes
672 call popup_close(s:popuperr_id)
673 unlet s:popuperr_text
674 else
675 let s:popuperr_text= v:beval_text
676 endif
677 let mesg= ""
678 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 +0100679 let mesg= ""
680 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
681 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
682 elseif getline(v:beval_lnum) =~ '^"\s*/'
683 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
684 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100685 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100686 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
687 let mesg = "S: edit sorting sequence"
688 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
689 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
690 elseif v:beval_text == "Quick" || v:beval_text == "Help"
691 let mesg = "Help: press <F1>"
692 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
693 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
694 else
695 let mesg= ""
696 endif
697 return mesg
698 endfun
699"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100700" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
701" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
702" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
703" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
704" 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 +0200705endif
706
Bram Moolenaar071d4272004-06-13 20:20:40 +0000707" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200708" netrw#Explore: launch the local browser in the directory of the current file {{{2
709" indx: == -1: Nexplore
710" == -2: Pexplore
711" == +: this is overloaded:
712" * If Nexplore/Pexplore is in use, then this refers to the
713" indx'th item in the w:netrw_explore_list[] of items which
714" matched the */pattern **/pattern *//pattern **//pattern
715" * If Hexplore or Vexplore, then this will override
716" g:netrw_winsize to specify the qty of rows or columns the
717" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100718" 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 +0200719" dosplit==1: the window will be split before running the local browser
720" style == 0: Explore style == 1: Explore!
721" == 2: Hexplore style == 3: Hexplore!
722" == 4: Vexplore style == 5: Vexplore!
723" == 6: Texplore
724fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaarff034192013-04-24 18:51:19 +0200725 if !exists("b:netrw_curdir")
726 let b:netrw_curdir= getcwd()
Bram Moolenaarff034192013-04-24 18:51:19 +0200727 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100728
729 " record current file for Rexplore's benefit
730 if &ft != "netrw"
731 let w:netrw_rexfile= expand("%:p")
732 endif
733
734 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200735 let curdir = simplify(b:netrw_curdir)
736 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200737 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200738 let curdir= substitute(curdir,'\','/','g')
739 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100740
741 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
742 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
743 " try Explore again.
744 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100745 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200746 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
747 if a1 != a:1
748 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
749 return
750 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100751 endif
752 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200753
754 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200755 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100756" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100757 sil! let keepregstar = @*
758 sil! let keepregplus = @+
759 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200760 sil! let keepregslash= @/
761
Bram Moolenaar8d043172014-01-23 14:24:41 +0100762 " if dosplit
763 " -or- file has been modified AND file not hidden when abandoned
764 " -or- Texplore used
765 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaarff034192013-04-24 18:51:19 +0200766 call s:SaveWinVars()
767 let winsz= g:netrw_winsize
768 if a:indx > 0
769 let winsz= a:indx
770 endif
771
772 if a:style == 0 " Explore, Sexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200773 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200774 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200775 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200776
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200777 elseif a:style == 1 " Explore!, Sexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200778 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200779 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200780 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200781
782 elseif a:style == 2 " Hexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200783 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200784 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200785 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200786
787 elseif a:style == 3 " Hexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200788 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200789 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200790 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200791
792 elseif a:style == 4 " Vexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200793 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200794 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200795 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200796
797 elseif a:style == 5 " Vexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200798 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200799 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200800 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200801
802 elseif a:style == 6 " Texplore
803 call s:SaveBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200804 exe "keepalt tabnew ".fnameescape(curdir)
805 call s:RestoreBufVars()
806 endif
807 call s:RestoreWinVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200808 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100809 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200810
811 if a:0 > 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200812 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaarff034192013-04-24 18:51:19 +0200813 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaarff034192013-04-24 18:51:19 +0200814 elseif a:1 == '.'
Bram Moolenaarff034192013-04-24 18:51:19 +0200815 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
816 if dirname !~ '/$'
817 let dirname= dirname."/"
818 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200819 elseif a:1 =~ '\$'
Bram Moolenaarff034192013-04-24 18:51:19 +0200820 let dirname= simplify(expand(a:1))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200821 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaarff034192013-04-24 18:51:19 +0200822 let dirname= simplify(a:1)
Bram Moolenaarff034192013-04-24 18:51:19 +0200823 else
Bram Moolenaarff034192013-04-24 18:51:19 +0200824 let dirname= a:1
825 endif
826 else
827 " clear explore
Bram Moolenaarff034192013-04-24 18:51:19 +0200828 call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200829 return
830 endif
831
Bram Moolenaarff034192013-04-24 18:51:19 +0200832 if dirname =~ '\.\./\=$'
833 let dirname= simplify(fnamemodify(dirname,':p:h'))
834 elseif dirname =~ '\.\.' || dirname == '.'
835 let dirname= simplify(fnamemodify(dirname,':p'))
836 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200837
838 if dirname =~ '^\*//'
839 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200840 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
841 let starpat= 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200842 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
843
844 elseif dirname =~ '^\*\*//'
845 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200846 let pattern= substitute(dirname,'^\*\*//','','')
847 let starpat= 2
Bram Moolenaarff034192013-04-24 18:51:19 +0200848
849 elseif dirname =~ '/\*\*/'
850 " handle .../**/.../filepat
Bram Moolenaarff034192013-04-24 18:51:19 +0200851 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200852 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200853 let b:netrw_curdir = prefixdir
854 else
855 let b:netrw_curdir= getcwd().'/'.prefixdir
856 endif
857 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
858 let starpat= 4
Bram Moolenaarff034192013-04-24 18:51:19 +0200859
860 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200861 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200862 let starpat= 3
Bram Moolenaarff034192013-04-24 18:51:19 +0200863
864 elseif dirname=~ '^\*\*/'
865 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
866 let starpat= 4
Bram Moolenaarff034192013-04-24 18:51:19 +0200867
868 else
869 let starpat= 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200870 endif
871
872 if starpat == 0 && a:indx >= 0
873 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaarff034192013-04-24 18:51:19 +0200874 if dirname == ""
875 let dirname= curfiledir
Bram Moolenaarff034192013-04-24 18:51:19 +0200876 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200877 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200878 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200879 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200880 if dirname == ""
881 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200882 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100883 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100884 " depending on whether backslashes have been converted to forward slashes by earlier code).
885 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200886 let dirname= b:netrw_curdir."/".dirname
887 endif
888 elseif dirname !~ '^/'
889 let dirname= b:netrw_curdir."/".dirname
890 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200891 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200892 endif
893 if exists("w:netrw_bannercnt")
894 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
895 " If one wants to return the same place in the netrw window, use :Rex instead.
896 exe w:netrw_bannercnt
897 endif
898
Bram Moolenaarff034192013-04-24 18:51:19 +0200899
900 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
901 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
902 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
903 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
904 elseif a:indx <= 0
905 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaarff034192013-04-24 18:51:19 +0200906 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaarff034192013-04-24 18:51:19 +0200907 let s:didstarstar= 1
908 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
909 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
910 endif
911
912 if has("path_extra")
Bram Moolenaarff034192013-04-24 18:51:19 +0200913 if !exists("w:netrw_explore_indx")
914 let w:netrw_explore_indx= 0
915 endif
916
917 let indx = a:indx
Bram Moolenaarff034192013-04-24 18:51:19 +0200918
919 if indx == -1
920 " Nexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200921 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100922 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 +0200923 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100924 if @* != keepregstar | sil! let @* = keepregstar | endif
925 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100926 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200927 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200928 return
929 endif
930 let indx= w:netrw_explore_indx
931 if indx < 0 | let indx= 0 | endif
932 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
933 let curfile= w:netrw_explore_list[indx]
Bram Moolenaarff034192013-04-24 18:51:19 +0200934 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
935 let indx= indx + 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200936 endwhile
937 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200938
939 elseif indx == -2
940 " Pexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200941 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100942 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 +0200943 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100944 if @* != keepregstar | sil! let @* = keepregstar | endif
945 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100946 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200947 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200948 return
949 endif
950 let indx= w:netrw_explore_indx
951 if indx < 0 | let indx= 0 | endif
952 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
953 let curfile= w:netrw_explore_list[indx]
Bram Moolenaarff034192013-04-24 18:51:19 +0200954 while indx >= 0 && curfile == w:netrw_explore_list[indx]
955 let indx= indx - 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200956 endwhile
957 if indx < 0 | let indx= 0 | endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200958
959 else
960 " Explore -- initialize
961 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100962 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200963 let w:netrw_explore_indx= 0
964 if !exists("b:netrw_curdir")
965 let b:netrw_curdir= getcwd()
966 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200967
968 " switch on starpat to build the w:netrw_explore_list of files
969 if starpat == 1
970 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200971 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100972 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200973 catch /^Vim\%((\a\+)\)\=:E480/
974 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +0200975 return
976 endtry
977 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
978 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
979
980 elseif starpat == 2
981 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200982 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100983 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200984 catch /^Vim\%((\a\+)\)\=:E480/
985 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
986 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200987 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100988 if @* != keepregstar | sil! let @* = keepregstar | endif
989 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100990 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200991 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200992 return
993 endtry
994 let s:netrw_curdir = b:netrw_curdir
995 let w:netrw_explore_list = getqflist()
996 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
997 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
998
999 elseif starpat == 3
1000 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +02001001 let filepat= substitute(dirname,'^\*/','','')
1002 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaarff034192013-04-24 18:51:19 +02001003 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1004 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1005
1006 elseif starpat == 4
1007 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +02001008 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1009 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1010 endif " switch on starpat to build w:netrw_explore_list
1011
1012 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaarff034192013-04-24 18:51:19 +02001013
1014 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001015 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001016 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001017 if @* != keepregstar | sil! let @* = keepregstar | endif
1018 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001019 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001020 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +02001021 return
1022 endif
1023 endif " if indx ... endif
1024
1025 " NetrwStatusLine support - for exploring support
1026 let w:netrw_explore_indx= indx
Bram Moolenaarff034192013-04-24 18:51:19 +02001027
1028 " wrap the indx around, but issue a note
1029 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaarff034192013-04-24 18:51:19 +02001030 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1031 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001032 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001033 endif
1034
1035 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaarff034192013-04-24 18:51:19 +02001036 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaarff034192013-04-24 18:51:19 +02001037
Bram Moolenaarff034192013-04-24 18:51:19 +02001038 call netrw#LocalBrowseCheck(newdir)
1039 if !exists("w:netrw_liststyle")
1040 let w:netrw_liststyle= g:netrw_liststyle
1041 endif
1042 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001043 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001044 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001045 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001046 endif
1047 let w:netrw_explore_mtchcnt = indx + 1
1048 let w:netrw_explore_bufnr = bufnr("%")
1049 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001050 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaarff034192013-04-24 18:51:19 +02001051
1052 else
Bram Moolenaarff034192013-04-24 18:51:19 +02001053 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001054 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 +02001055 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001056 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001057 if @* != keepregstar | sil! let @* = keepregstar | endif
1058 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001059 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001060 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +02001061 return
1062 endif
1063
1064 else
Bram Moolenaarff034192013-04-24 18:51:19 +02001065 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1066 sil! unlet w:netrw_treedict
1067 sil! unlet w:netrw_treetop
1068 endif
1069 let newdir= dirname
1070 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001071 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001072 else
Tom Benham64a536d2024-11-07 21:15:03 +01001073 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir,0))
Bram Moolenaarff034192013-04-24 18:51:19 +02001074 endif
1075 endif
1076
1077 " visual display of **/ **// */ Exploration files
Bram Moolenaarff034192013-04-24 18:51:19 +02001078 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaarff034192013-04-24 18:51:19 +02001079 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001080 " only update match list when current directory isn't the same as before
Bram Moolenaarff034192013-04-24 18:51:19 +02001081 let s:explore_prvdir = b:netrw_curdir
1082 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001083 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001084 if b:netrw_curdir !~ '/$'
1085 let dirlen= dirlen + 1
1086 endif
1087 let prvfname= ""
1088 for fname in w:netrw_explore_list
Bram Moolenaarff034192013-04-24 18:51:19 +02001089 if fname =~ '^'.b:netrw_curdir
1090 if s:explore_match == ""
1091 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1092 else
1093 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1094 endif
1095 elseif fname !~ '^/' && fname != prvfname
1096 if s:explore_match == ""
1097 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1098 else
1099 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1100 endif
1101 endif
1102 let prvfname= fname
1103 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02001104 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1105 exe "2match netrwMarkFile /".s:explore_match."/"
1106 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001107 endif
1108 echo "<s-up>==Pexplore <s-down>==Nexplore"
1109 else
1110 2match none
1111 if exists("s:explore_match") | unlet s:explore_match | endif
1112 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001113 endif
1114
Bram Moolenaara6878372014-03-22 21:02:50 +01001115 " since Explore may be used to initialize netrw's browser,
1116 " there's no danger of a late FocusGained event on initialization.
1117 " Consequently, set s:netrw_events to 2.
1118 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001119 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001120 if @* != keepregstar | sil! let @* = keepregstar | endif
1121 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001122 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001123 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +02001124endfun
1125
1126" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001127" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001128" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1129" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1130" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1131" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1132" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001133fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001134" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001135 let curwin= winnr()
1136
Bram Moolenaara6878372014-03-22 21:02:50 +01001137 if a:0 > 0 && a:1 != ""
1138 " if a netrw window is already on the left-side of the tab
1139 " and a directory has been specified, explore with that
1140 " directory.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001141 let a1 = expand(a:1)
Bram Moolenaara6878372014-03-22 21:02:50 +01001142 exe "1wincmd w"
1143 if &ft == "netrw"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001144 exe "Explore ".fnameescape(a1)
1145 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001146 let s:lexplore_win= curwin
1147 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001148 if exists("t:netrw_lexposn")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001149 unlet t:netrw_lexposn
1150 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001151 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001152 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001153 exe curwin."wincmd w"
1154 else
1155 let a1= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01001156 endif
1157
Bram Moolenaar8d043172014-01-23 14:24:41 +01001158 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001159 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001160 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001161 else
1162 let lexwinnr= 0
1163 endif
1164
1165 if lexwinnr > 0
1166 " close down netrw explorer window
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001167 exe lexwinnr."wincmd w"
1168 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001169 let t:netrw_lexposn = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001170 close
1171 if lexwinnr < curwin
1172 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001173 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001174 if lexwinnr != curwin
1175 exe curwin."wincmd w"
1176 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001177 unlet t:netrw_lexbufnr
1178
1179 else
1180 " open netrw explorer window
1181 exe "1wincmd w"
1182 let keep_altv = g:netrw_altv
1183 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001184 if a:count != 0
1185 let netrw_winsize = g:netrw_winsize
1186 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001187 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001188 let curfile= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001189 exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
1190 if a:0 > 0 && a1 != ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001191 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001192 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001193 elseif curfile =~ '^\a\{3,}://'
Bram Moolenaar85850f32019-07-19 22:05:51 +02001194 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001195 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02001196 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001197 endif
1198 if a:count != 0
1199 let g:netrw_winsize = netrw_winsize
1200 endif
1201 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001202 let g:netrw_altv = keep_altv
1203 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001204 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1205 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001206 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001207 set bh=wipe
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001208 if exists("t:netrw_lexposn")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001209 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001210 unlet t:netrw_lexposn
1211 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001212 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001213
1214 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001215 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001216 if a:rightside
1217 let g:netrw_chgwin= 1
1218 else
1219 let g:netrw_chgwin= 2
1220 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001221 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001222
Bram Moolenaar8d043172014-01-23 14:24:41 +01001223endfun
1224
1225" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001226" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001227" supports :NetrwClean -- remove netrw from first directory on runtimepath
1228" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001229fun! netrw#Clean(sys)
1230" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001231
1232 if a:sys
1233 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1234 else
1235 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1236 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001237" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001238 let diddel= 0
1239 let diddir= ""
1240
1241 if choice == 1
1242 for dir in split(&rtp,',')
1243 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001244" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001245 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1246 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1247 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1248 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1249 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1250 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 +00001251 let diddir= dir
1252 let diddel= diddel + 1
1253 if !a:sys|break|endif
1254 endif
1255 endfor
1256 endif
1257
1258 echohl WarningMsg
1259 if diddel == 0
1260 echomsg "netrw is either not installed or not removable"
1261 elseif diddel == 1
1262 echomsg "removed one copy of netrw from <".diddir.">"
1263 else
1264 echomsg "removed ".diddel." copies of netrw"
1265 endif
1266 echohl None
1267
Bram Moolenaara6878372014-03-22 21:02:50 +01001268" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001269endfun
1270
Bram Moolenaar5c736222010-01-06 20:54:52 +01001271" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001272" netrw#MakeTgt: make a target out of the directory name provided {{{2
1273fun! netrw#MakeTgt(dname)
1274" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1275 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001276 let svpos = winsaveview()
1277" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001278 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1279" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001280 if s:netrwmftgt_islocal
1281 let netrwmftgt= simplify(a:dname)
1282 else
1283 let netrwmftgt= a:dname
1284 endif
1285 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1286 " re-selected target, so just clear it
1287 unlet s:netrwmftgt s:netrwmftgt_islocal
1288 else
1289 let s:netrwmftgt= netrwmftgt
1290 endif
1291 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001292 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001293 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001294" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1295 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001296" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001297endfun
1298
Bram Moolenaara6878372014-03-22 21:02:50 +01001299" ---------------------------------------------------------------------
1300" netrw#Obtain: {{{2
1301" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001302" islocal=0 obtain from remote source
1303" =1 obtain from local source
1304" fname : a filename or a list of filenames
1305" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001306fun! netrw#Obtain(islocal,fname,...)
1307" 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 +02001308 " NetrwStatusLine support - for obtaining support
1309
1310 if type(a:fname) == 1
1311 let fnamelist= [ a:fname ]
1312 elseif type(a:fname) == 3
1313 let fnamelist= a:fname
1314 else
1315 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 +01001316" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001317 return
1318 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001319" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001320 if a:0 > 0
1321 let tgtdir= a:1
1322 else
1323 let tgtdir= getcwd()
1324 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001325" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001326
1327 if exists("b:netrw_islocal") && b:netrw_islocal
1328 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001329" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001330 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1331 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001332 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001333 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001334" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001335 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001336" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001337 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001338 if v:shell_error != 0
1339 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 +01001340" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001341 return
1342 endif
1343 endfor
1344 else
1345 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001346" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1347 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1348" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001349 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001350 if v:shell_error != 0
1351 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 +01001352" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001353 return
1354 endif
1355 endif
1356 elseif !exists("b:netrw_curdir")
1357 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1358 else
1359 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1360 endif
1361
1362 else
1363 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001364" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001365 if type(a:fname) == 1
1366 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1367 endif
1368 call s:NetrwMethod(b:netrw_curdir)
1369
1370 if b:netrw_method == 4
1371 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001372" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001373 if exists("g:netrw_port") && g:netrw_port != ""
1374 let useport= " ".g:netrw_scpport." ".g:netrw_port
1375 else
1376 let useport= ""
1377 endif
1378 if b:netrw_fname =~ '/'
1379 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1380 else
1381 let path= ""
1382 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001383 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001384 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 +02001385
1386 elseif b:netrw_method == 2
1387 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001388" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001389 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001390 let tmpbufnr= bufnr("%")
1391 setl ff=unix
1392 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001393 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001394" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001395 endif
1396
1397 if exists("b:netrw_fname") && b:netrw_fname != ""
1398 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001399" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001400 endif
1401
1402 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001403 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001404" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001405 endif
1406 for fname in fnamelist
1407 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001408" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001409 endfor
1410 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001411 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 +02001412 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001413 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001414 endif
1415 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1416 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1417 let debugkeep= &debug
1418 setl debug=msg
1419 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1420 let &debug= debugkeep
1421 endif
1422
1423 elseif b:netrw_method == 3
1424 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001425" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001426 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001427 let tmpbufnr= bufnr("%")
1428 setl ff=unix
1429
1430 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001431 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001432" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001433 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001434 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001435" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001436 endif
1437
1438 if exists("g:netrw_uid") && g:netrw_uid != ""
1439 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001440 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001441" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001442 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001443 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001444 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001445" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001446 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001447 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001448" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001449 endif
1450 endif
1451
1452 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001453 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001454" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001455 endif
1456
1457 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001458 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001459" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001460 endif
1461
1462 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001463 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001464" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001465 endif
1466
1467 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001468 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001469" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001470 endif
1471 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001472 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001473 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001474" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001475
1476 " perform ftp:
1477 " -i : turns off interactive prompting from ftp
1478 " -n unix : DON'T use <.netrc>, even though it exists
1479 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001480 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1481 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001482 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001483 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1484 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001485" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001486 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001487 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001488 endif
1489 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001490
1491 elseif b:netrw_method == 9
1492 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001493" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001494 if a:fname =~ '/'
1495 let localfile= substitute(a:fname,'^.*/','','')
1496 else
1497 let localfile= a:fname
1498 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001499 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 +02001500
Bram Moolenaarff034192013-04-24 18:51:19 +02001501 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001502 " probably a badly formed url; protocol not recognized
1503" call Dret("netrw#Obtain : unsupported method")
1504 return
1505
1506 else
1507 " protocol recognized but not supported for Obtain (yet?)
1508 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001509 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001510 endif
1511" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001512 return
1513 endif
1514
1515 " restore status line
1516 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001517 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001518 endif
1519
1520 endif
1521
1522 " cleanup
1523 if exists("tmpbufnr")
1524 if bufnr("%") != tmpbufnr
1525 exe tmpbufnr."bw!"
1526 else
1527 q!
1528 endif
1529 endif
1530
Bram Moolenaara6878372014-03-22 21:02:50 +01001531" call Dret("netrw#Obtain")
1532endfun
1533
1534" ---------------------------------------------------------------------
1535" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1536fun! netrw#Nread(mode,fname)
1537" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001538 let svpos= winsaveview()
1539" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001540 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001541" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1542 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001543
1544 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1545 if exists("w:netrw_bannercnt")
1546 " start with cursor just after the banner
1547 exe w:netrw_bannercnt
1548 endif
1549 endif
1550" call Dret("netrw#Nread")
1551endfun
1552
1553" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001554" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1555" Options get restored by s:NetrwOptionsRestore()
1556"
1557" Option handling:
1558" * save user's options (s:NetrwOptionsSave)
1559" * set netrw-safe options (s:NetrwOptionsSafe)
1560" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1561" * restore user's options (s:netrwOPtionsRestore)
1562" - restore a user option when != safe option (s:NetrwRestoreSetting)
1563" vt: (variable type) normally its either "w:" or "s:"
1564fun! s:NetrwOptionsSave(vt)
1565" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1566" 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 +02001567" 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>"))
1568" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001569
1570 if !exists("{a:vt}netrw_optionsave")
1571 let {a:vt}netrw_optionsave= 1
1572 else
1573" call Dret("s:NetrwOptionsSave : options already saved")
1574 return
1575 endif
1576" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1577
1578 " Save current settings and current directory
1579" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1580 let s:yykeep = @@
1581 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1582 let {a:vt}netrw_aikeep = &l:ai
1583 let {a:vt}netrw_awkeep = &l:aw
1584 let {a:vt}netrw_bhkeep = &l:bh
1585 let {a:vt}netrw_blkeep = &l:bl
1586 let {a:vt}netrw_btkeep = &l:bt
1587 let {a:vt}netrw_bombkeep = &l:bomb
1588 let {a:vt}netrw_cedit = &cedit
1589 let {a:vt}netrw_cikeep = &l:ci
1590 let {a:vt}netrw_cinkeep = &l:cin
1591 let {a:vt}netrw_cinokeep = &l:cino
1592 let {a:vt}netrw_comkeep = &l:com
1593 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001594 let {a:vt}netrw_cuckeep = &l:cuc
1595 let {a:vt}netrw_culkeep = &l:cul
1596" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001597 let {a:vt}netrw_diffkeep = &l:diff
1598 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001599 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1600 let {a:vt}netrw_ffkeep = &l:ff
1601 endif
1602 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1603 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001604 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001605 let {a:vt}netrw_hidkeep = &l:hidden
1606 let {a:vt}netrw_imkeep = &l:im
1607 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001608 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001609 let {a:vt}netrw_lskeep = &l:ls
1610 let {a:vt}netrw_makeep = &l:ma
1611 let {a:vt}netrw_magickeep = &l:magic
1612 let {a:vt}netrw_modkeep = &l:mod
1613 let {a:vt}netrw_nukeep = &l:nu
1614 let {a:vt}netrw_rnukeep = &l:rnu
1615 let {a:vt}netrw_repkeep = &l:report
1616 let {a:vt}netrw_rokeep = &l:ro
1617 let {a:vt}netrw_selkeep = &l:sel
1618 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001619 if !g:netrw_use_noswf
1620 let {a:vt}netrw_swfkeep = &l:swf
1621 endif
1622 let {a:vt}netrw_tskeep = &l:ts
1623 let {a:vt}netrw_twkeep = &l:tw " textwidth
1624 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1625 let {a:vt}netrw_wrapkeep = &l:wrap
1626 let {a:vt}netrw_writekeep = &l:write
1627
1628 " save a few selected netrw-related variables
1629" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1630 if g:netrw_keepdir
1631 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001632" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001633 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001634 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001635 sil! let {a:vt}netrw_starkeep = @*
1636 sil! let {a:vt}netrw_pluskeep = @+
1637 endif
1638 sil! let {a:vt}netrw_slashkeep= @/
1639
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001640" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001641" 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>"))
1642" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1643endfun
1644
1645" ---------------------------------------------------------------------
1646" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1647" Use s:NetrwSaveOptions() to save user settings
1648" Use s:NetrwOptionsRestore() to restore user settings
1649fun! s:NetrwOptionsSafe(islocal)
1650" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1651" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1652" 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>"))
1653 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1654 call s:NetrwSetSafeSetting("&l:ai",0)
1655 call s:NetrwSetSafeSetting("&l:aw",0)
1656 call s:NetrwSetSafeSetting("&l:bl",0)
1657 call s:NetrwSetSafeSetting("&l:bomb",0)
1658 if a:islocal
1659 call s:NetrwSetSafeSetting("&l:bt","nofile")
1660 else
1661 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1662 endif
1663 call s:NetrwSetSafeSetting("&l:ci",0)
1664 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001665 if g:netrw_fastbrowse > a:islocal
1666 call s:NetrwSetSafeSetting("&l:bh","hide")
1667 else
1668 call s:NetrwSetSafeSetting("&l:bh","delete")
1669 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001670 call s:NetrwSetSafeSetting("&l:cino","")
1671 call s:NetrwSetSafeSetting("&l:com","")
1672 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1673 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1674 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001675 if &go =~ 'a' | set go-=a | endif
1676 if &go =~ 'A' | set go-=A | endif
1677 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001678 call s:NetrwSetSafeSetting("&l:hid",0)
1679 call s:NetrwSetSafeSetting("&l:im",0)
1680 setl isk+=@ isk+=* isk+=/
1681 call s:NetrwSetSafeSetting("&l:magic",1)
1682 if g:netrw_use_noswf
1683 call s:NetrwSetSafeSetting("swf",0)
1684 endif
1685 call s:NetrwSetSafeSetting("&l:report",10000)
1686 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1687 call s:NetrwSetSafeSetting("&l:spell",0)
1688 call s:NetrwSetSafeSetting("&l:tw",0)
1689 call s:NetrwSetSafeSetting("&l:wig","")
1690 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001691
1692 " set up cuc and cul based on g:netrw_cursor and listing style
1693 " COMBAK -- cuc cul related
1694 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001695
1696 " allow the user to override safe options
1697" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1698 if &ft == "netrw"
1699" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1700 keepalt NetrwKeepj doau FileType netrw
1701 endif
1702
1703" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1704" 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>"))
1705" call Dret("s:NetrwOptionsSafe")
1706endfun
1707
1708" ---------------------------------------------------------------------
1709" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1710fun! s:NetrwOptionsRestore(vt)
Bram Moolenaara6878372014-03-22 21:02:50 +01001711 if !exists("{a:vt}netrw_optionsave")
Christian Brabandtaa2ce6f2024-10-30 18:27:03 +01001712 " filereadable() returns zero for remote files (e.g. scp://user@localhost//etc/fstab)
1713 " Note: @ may not be in 'isfname', so '^\w\+://\f\+/' may not match
1714 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+'
Bram Moolenaar71badf92023-04-22 22:40:14 +01001715 filetype detect
Bram Moolenaar71badf92023-04-22 22:40:14 +01001716 else
1717 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001718 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001719 return
1720 endif
1721 unlet {a:vt}netrw_optionsave
1722
1723 if exists("+acd")
1724 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara6878372014-03-22 21:02:50 +01001725 let curdir = getcwd()
1726 let &l:acd = {a:vt}netrw_acdkeep
1727 unlet {a:vt}netrw_acdkeep
1728 if &l:acd
1729 call s:NetrwLcd(curdir)
1730 endif
1731 endif
1732 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001733 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1734 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1735 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1736 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1737 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
1738 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1739 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1740 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1741 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1742 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
1743 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1744 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1745 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1746 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1747 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001748 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001749 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1750 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001751 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001752 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001753 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1754 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001755 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001756 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1757 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001758 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001759 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1760 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001761 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1762 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1763 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1764 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001765 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001766 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1767 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1768 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001769 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
1770 call s:NetrwRestoreSetting("s:yykeep","@@")
1771 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1772 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1773 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1774 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1775
Bram Moolenaara6878372014-03-22 21:02:50 +01001776 if exists("{a:vt}netrw_swfkeep")
1777 if &directory == ""
1778 " user hasn't specified a swapfile directory;
1779 " netrw will temporarily set the swapfile directory
1780 " to the current directory as returned by getcwd().
1781 let &l:directory= getcwd()
1782 sil! let &l:swf = {a:vt}netrw_swfkeep
1783 setl directory=
1784 unlet {a:vt}netrw_swfkeep
1785 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001786 if !g:netrw_use_noswf
1787 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1788 sil! let &l:swf= {a:vt}netrw_swfkeep
1789 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001790 unlet {a:vt}netrw_swfkeep
1791 endif
1792 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001793 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001794 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1795 if exists("{a:vt}netrw_dirkeep")
1796 call s:NetrwLcd(dirkeep)
1797 unlet {a:vt}netrw_dirkeep
1798 endif
1799 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001800 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001801 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1802 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001803 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001804 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001805
Bram Moolenaara6878372014-03-22 21:02:50 +01001806 " Moved the filetype detect here from NetrwGetFile() because remote files
1807 " were having their filetype detect-generated settings overwritten by
1808 " NetrwOptionRestore.
1809 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001810 filetype detect
Bram Moolenaara6878372014-03-22 21:02:50 +01001811 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001812endfun
1813
1814" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001815" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1816" but only when the options' value and the safe setting differ
1817" Doing this means that netrw will not come up as having changed a
1818" setting last when it really didn't actually change it.
1819"
1820" Called from s:NetrwOptionsSafe
1821" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1822fun! s:NetrwSetSafeSetting(setting,safesetting)
1823" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001824
Bram Moolenaar85850f32019-07-19 22:05:51 +02001825 if a:setting =~ '^&'
1826" call Decho("fyi: a:setting starts with &")
1827 exe "let settingval= ".a:setting
1828" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001829
Bram Moolenaar85850f32019-07-19 22:05:51 +02001830 if settingval != a:safesetting
1831" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1832 if type(a:safesetting) == 0
1833 exe "let ".a:setting."=".a:safesetting
1834 elseif type(a:safesetting) == 1
1835 exe "let ".a:setting."= '".a:safesetting."'"
1836 else
1837 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1838 endif
1839 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001840 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001841
Bram Moolenaar85850f32019-07-19 22:05:51 +02001842" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001843endfun
1844
1845" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001846" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1847" but only if the setting value differs from the associated keepvar.
1848" Doing this means that netrw will not come up as having changed a
1849" setting last when it really didn't actually change it.
1850"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001851" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001852" keepvars are set up by s:NetrwOptionsSave
1853fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001854""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001855
Bram Moolenaar85850f32019-07-19 22:05:51 +02001856 " typically called from s:NetrwOptionsRestore
1857 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1858 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001859 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001860 if exists(a:keepvar)
1861 exe "let keepvarval= ".a:keepvar
1862 exe "let setting= ".a:setting
1863
1864"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1865"" call Decho("fyi: keepvarval=".keepvarval)
1866"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1867
1868 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001869"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001870 if type(a:setting) == 0
1871 exe "let ".a:setting."= ".keepvarval
1872 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001873 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001874 else
1875 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1876 endif
1877 endif
1878
1879 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001880 endif
1881
Bram Moolenaar85850f32019-07-19 22:05:51 +02001882"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001883endfun
1884
1885" ---------------------------------------------------------------------
1886" NetrwStatusLine: {{{2
1887fun! NetrwStatusLine()
1888
1889" vvv NetrwStatusLine() debugging vvv
1890" let g:stlmsg=""
1891" if !exists("w:netrw_explore_bufnr")
1892" let g:stlmsg="!X<explore_bufnr>"
1893" elseif w:netrw_explore_bufnr != bufnr("%")
1894" let g:stlmsg="explore_bufnr!=".bufnr("%")
1895" endif
1896" if !exists("w:netrw_explore_line")
1897" let g:stlmsg=" !X<explore_line>"
1898" elseif w:netrw_explore_line != line(".")
1899" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
1900" endif
1901" if !exists("w:netrw_explore_list")
1902" let g:stlmsg=" !X<explore_list>"
1903" endif
1904" ^^^ NetrwStatusLine() debugging ^^^
1905
1906 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")
1907 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09001908 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02001909 let &laststatus = s:netrw_users_ls
1910 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
1911 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
1912 return ""
1913 else
1914 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
1915 endif
1916endfun
1917
Bram Moolenaar85850f32019-07-19 22:05:51 +02001918" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001919" Netrw Transfer Functions: {{{1
1920" ===============================
1921
Bram Moolenaar071d4272004-06-13 20:20:40 +00001922" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001923" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001924" mode: =0 read remote file and insert before current line
1925" =1 read remote file and insert after current line
1926" =2 replace with remote file
1927" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001928fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02001929" 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 +00001930
Bram Moolenaar5c736222010-01-06 20:54:52 +01001931 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02001932 call s:NetrwOptionsSave("w:")
1933 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001934 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001935 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
1936 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
1937 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02001938" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001939
Bram Moolenaar5c736222010-01-06 20:54:52 +01001940 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001941 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001942 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001943 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001944 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001945 elseif a:mode == 2 " replace with remote file
1946 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00001947 elseif a:mode == 3 " skip read of file (leave as temporary)
1948 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001949 else
1950 exe a:mode
1951 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001952 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001953 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001954" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001955
Bram Moolenaar5c736222010-01-06 20:54:52 +01001956 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00001957 let tmpfile= s:GetTempfile("")
1958 if tmpfile == ""
1959" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001960 return
1961 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001962
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001963 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001964
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001965 " attempt to repeat with previous host-file-etc
1966 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001967" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001968 let choice = b:netrw_lastfile
1969 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001970
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001971 else
1972 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001973" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001974
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001975 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001976 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001977 echomsg 'NetRead Usage:'
1978 echomsg ':Nread machine:path uses rcp'
1979 echomsg ':Nread "machine path" uses ftp with <.netrc>'
1980 echomsg ':Nread "machine id password path" uses ftp'
1981 echomsg ':Nread dav://machine[:port]/path uses cadaver'
1982 echomsg ':Nread fetch://machine/path uses fetch'
1983 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
1984 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001985 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01001986 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001987 echomsg ':Nread rcp://[user@]machine/path uses rcp'
1988 echomsg ':Nread rsync://machine[:port]/path uses rsync'
1989 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
1990 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00001991 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001992 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001993
Bram Moolenaar9964e462007-05-05 17:54:07 +00001994 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001995 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001996" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00001997 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001998 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02001999 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002000 else
2001 " case "... ... ..."
2002 let choice = strpart(choice,1,strlen(choice)-1)
2003 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002004
Bram Moolenaar9964e462007-05-05 17:54:07 +00002005 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002006 let wholechoice = wholechoice . " " . choice
2007 let ichoice = ichoice + 1
2008 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002009 if !exists("g:netrw_quiet")
2010 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2011 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002012" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002013 return
2014 endif
2015 let choice= a:{ichoice}
2016 endwhile
2017 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2018 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002019 endif
2020 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002021
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002022" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002023 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002024
Bram Moolenaar5c736222010-01-06 20:54:52 +01002025 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002026 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002027 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002028" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002029 return
2030 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002031 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002032
Bram Moolenaar8d043172014-01-23 14:24:41 +01002033 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002034" 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 +02002035 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002036" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002037 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002038" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002039 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002040 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002041
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002042 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002043 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002044 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002045 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2046 echo "(netrw) Processing your read request..."
2047 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002048
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002049 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002050 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002051 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002052" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002053 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002054 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002055 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002056 " ER: the tmpfile is full path: rcp sees C:\... as host C
2057 if s:netrw_has_nt_rcp == 1
2058 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2059 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2060 else
2061 " Any way needed it machine contains a '.'
2062 let uid_machine = g:netrw_machine .'.'. $USERNAME
2063 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002064 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002065 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2066 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2067 else
2068 let uid_machine = g:netrw_machine
2069 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002070 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002071 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 +00002072 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002073 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002074
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002075 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002076 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002077 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002078" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002079 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002080 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002081 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002082 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002083 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002084" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002085 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002086 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002087" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002088 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002089 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002090" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002091 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002092 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 +00002093 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002094 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002095 endif
2096 " 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 +00002097 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002098 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002099 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002100 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002101 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002102 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002103 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002104 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002105 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2106 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002107 q!
2108 endif
2109 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002110 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002111 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002112
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002113 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002114 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002115 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2116 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002117" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002118 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002119 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002120 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002121 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002122 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002123 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002124" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002125 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002126 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002127" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002128 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002129
Bram Moolenaar97d62492012-11-15 21:28:22 +01002130 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002131 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002132 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002133" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002134 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002135 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002136 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002137" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002138 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002139 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002140" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002141 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002142 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002143
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002144 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002145 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002146" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002147 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002148 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002149 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002150" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002151 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002152 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002153" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002154
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002155 " perform ftp:
2156 " -i : turns off interactive prompting from ftp
2157 " -n unix : DON'T use <.netrc>, even though it exists
2158 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002159 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002160 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002161 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2162 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002163" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002164 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002165 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002166 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002167 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002168 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002169 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002170 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002171
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002172 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002173 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002174 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002175" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002176 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002177 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002178 else
2179 let useport= ""
2180 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002181 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2182 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002183 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002184 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2185 else
2186 let tmpfile_get = tmpfile
2187 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002188 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 +00002189 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002190 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002191
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002192 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002193 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002194 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002195" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002196 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002197 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002198 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002199 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002200" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002201 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002202 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002203
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002204 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2205 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002206" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002207 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002208 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 +00002209 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002210 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 +00002211 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002212 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002213
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002214 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002215 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002216" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002217 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2218 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002219" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2220" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2221 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 +00002222 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002223" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002224 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002225 endif
2226 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002227" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002228 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002229
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002230 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002231 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002232 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002233" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002234
Bram Moolenaar5c736222010-01-06 20:54:52 +01002235 if !executable(g:netrw_dav_cmd)
2236 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2237" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2238 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002239 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002240 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002241 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 +01002242 else
2243 " Construct execution string (four lines) which will be passed through filter
2244 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2245 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002246 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002247 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002248 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002249 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002250 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002251 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002252 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002253 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002254 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002255 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2256 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002257
Bram Moolenaar5c736222010-01-06 20:54:52 +01002258 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002259 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002260 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002261 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002262 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002263 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002264 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002265
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002266 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002267 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002268 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002269" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002270 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 +00002271 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002272 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002273
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002274 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002275 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002276 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002277 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002278" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002279 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002280 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002281 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002282 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002283" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002284 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002285 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002286 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002287 let netrw_option= "http"
2288 else
2289 let netrw_option= "ftp"
2290 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002291" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002292
Bram Moolenaar446cb832008-06-24 21:56:24 +00002293 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002294 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 +00002295 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002296 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 +00002297 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002298
Bram Moolenaar446cb832008-06-24 21:56:24 +00002299 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002300 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002301" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002302 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002303
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002304 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002305 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002306 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002307" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2308 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 +00002309 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002310 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002311
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002312 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002313 " NetRead: (file) NetRead Method #10 {{{3
2314 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002315" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2316 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002317 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2318 let b:netrw_lastfile = choice
2319
2320 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002321 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002322 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002323 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002324 endif
2325 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002326
Bram Moolenaar5c736222010-01-06 20:54:52 +01002327 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002328 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002329" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002330 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002331 unlet b:netrw_fname
2332 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002333 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 +01002334" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002335 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002336 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002337 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002338
Bram Moolenaar9964e462007-05-05 17:54:07 +00002339" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002340endfun
2341
2342" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002343" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002344fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002345" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002346
Bram Moolenaar5c736222010-01-06 20:54:52 +01002347 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002348 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002349 call s:NetrwOptionsSave("w:")
2350 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002351
Bram Moolenaar5c736222010-01-06 20:54:52 +01002352 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002353 let tmpfile= s:GetTempfile("")
2354 if tmpfile == ""
2355" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002356 return
2357 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002358
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002359 if a:0 == 0
2360 let ichoice = 0
2361 else
2362 let ichoice = 1
2363 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002364
Bram Moolenaar9964e462007-05-05 17:54:07 +00002365 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002366" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002367 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002368 " For binary writes, always write entire file.
2369 " (line numbers don't really make sense for that).
2370 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002371" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002372 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002373 elseif g:netrw_cygwin
2374 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002375 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002376" 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 +01002377 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002378 else
2379 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002380" 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 +01002381 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002382 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002383
Bram Moolenaar9964e462007-05-05 17:54:07 +00002384 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002385 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002386 " on the temporary file's name. Deletion of the temporary file during
2387 " cleanup then causes an error message.
2388 0file!
2389 endif
2390
Bram Moolenaar5c736222010-01-06 20:54:52 +01002391 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002392 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002393
Bram Moolenaar9964e462007-05-05 17:54:07 +00002394 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002395 " attempt to repeat with previous host-file-etc
2396 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002397" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002398 let choice = b:netrw_lastfile
2399 let ichoice= ichoice + 1
2400 else
2401 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002402
Bram Moolenaar8d043172014-01-23 14:24:41 +01002403 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002404 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002405 echomsg 'NetWrite Usage:"'
2406 echomsg ':Nwrite machine:path uses rcp'
2407 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2408 echomsg ':Nwrite "machine id password path" uses ftp'
2409 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2410 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2411 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2412 echomsg ':Nwrite rcp://machine/path uses rcp'
2413 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2414 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2415 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002416 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002417 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002418
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002419 elseif match(choice,"^\"") != -1
2420 if match(choice,"\"$") != -1
2421 " case "..."
2422 let choice=strpart(choice,1,strlen(choice)-2)
2423 else
2424 " case "... ... ..."
2425 let choice = strpart(choice,1,strlen(choice)-1)
2426 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002427
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002428 while match(choice,"\"$") == -1
2429 let wholechoice= wholechoice . " " . choice
2430 let ichoice = ichoice + 1
2431 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002432 if !exists("g:netrw_quiet")
2433 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2434 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002435" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002436 return
2437 endif
2438 let choice= a:{ichoice}
2439 endwhile
2440 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2441 endif
2442 endif
2443 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002444 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002445" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002446
Bram Moolenaar9964e462007-05-05 17:54:07 +00002447 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002448 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002449 if !exists("b:netrw_method") || b:netrw_method < 0
2450" call Dfunc("netrw#NetWrite : unsupported method")
2451 return
2452 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002453
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002454 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002455 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002456 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002457 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2458 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002459" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002460 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002461
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002462 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002463 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002464 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002465" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002466 if s:netrw_has_nt_rcp == 1
2467 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2468 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2469 else
2470 let uid_machine = g:netrw_machine .'.'. $USERNAME
2471 endif
2472 else
2473 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2474 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2475 else
2476 let uid_machine = g:netrw_machine
2477 endif
2478 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002479 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 +00002480 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002481
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002482 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002483 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002484 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002485" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002486 let netrw_fname = b:netrw_fname
2487
2488 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2489 let bhkeep = &l:bh
2490 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002491 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002492 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002493
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002494" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002495 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002496 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002497" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002498 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002499 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002500" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002501 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002502 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002503" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002504 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002505 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 +00002506 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002507" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2508 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 endif
2510 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2511 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002512 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002513 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002514 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002515 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002516 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002517
2518 " remove enew buffer (quietly)
2519 let filtbuf= bufnr("%")
2520 exe curbuf."b!"
2521 let &l:bh = bhkeep
2522 exe filtbuf."bw!"
2523
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002525
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002526 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002527 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002528 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002529 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002530" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002531 let netrw_fname = b:netrw_fname
2532 let bhkeep = &l:bh
2533
2534 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2535 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002536 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002537 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002538 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002539
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002540 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002541 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002542" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002543 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002544 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002545" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002546 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002547 if exists("g:netrw_uid") && g:netrw_uid != ""
2548 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002549 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002550" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002551 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002552 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002553 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002554" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002555 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002556 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002557" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002558 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002559 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002560 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002561" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002562 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002563 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002564" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002565 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002566 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002567" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002568 " save choice/id/password for future use
2569 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002570
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002571 " perform ftp:
2572 " -i : turns off interactive prompting from ftp
2573 " -n unix : DON'T use <.netrc>, even though it exists
2574 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002575 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002576 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002577 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2578 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002579 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002580 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002581 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002582 let mod=1
2583 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002584
2585 " remove enew buffer (quietly)
2586 let filtbuf= bufnr("%")
2587 exe curbuf."b!"
2588 let &l:bh= bhkeep
2589 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002590
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002591 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002592 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002593 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002594" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002595 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002596 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002597 else
2598 let useport= ""
2599 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002600 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 +00002601 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002602
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002603 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002604 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002605 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002606" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002607 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2608 if executable(curl)
2609 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002610 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 +01002611 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002612 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002613 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002614
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002615 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002616 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002617 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002618" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002619
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002620 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002621 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2622 let bhkeep = &l:bh
2623
2624 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2625 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002626 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002627 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002628
Bram Moolenaarff034192013-04-24 18:51:19 +02002629 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002630 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002631 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002632 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002633 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002634 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002635 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002636 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002637 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002638 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002639
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002640 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002641 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002642 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002643
2644 " remove enew buffer (quietly)
2645 let filtbuf= bufnr("%")
2646 exe curbuf."b!"
2647 let &l:bh = bhkeep
2648 exe filtbuf."bw!"
2649
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002650 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002651
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002652 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002653 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002654 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002655" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002656 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 +00002657 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002658
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002659 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002660 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002661 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002662" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002663 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002664 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2665 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2666 else
2667 let uid_machine = g:netrw_machine
2668 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002669
2670 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2671 let bhkeep = &l:bh
2672 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002673 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002674 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002675
Bram Moolenaarff034192013-04-24 18:51:19 +02002676 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002677 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002678" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002679 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002680 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002681 let filtbuf= bufnr("%")
2682 exe curbuf."b!"
2683 let &l:bh = bhkeep
2684 exe filtbuf."bw!"
2685 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002686
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002687 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002688 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002689 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002690 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002691 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002693 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002694
Bram Moolenaar5c736222010-01-06 20:54:52 +01002695 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002696" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002697 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002698" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002699 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002700 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002701 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002702
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002703 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002704 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002705 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002706" 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 +02002707 elseif !exists("leavemod")
2708 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002709" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002710 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002711" 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 +00002712 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002713
Bram Moolenaar9964e462007-05-05 17:54:07 +00002714" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002715endfun
2716
2717" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002718" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002719" uses NetRead to get a copy of the file into a temporarily file,
2720" then sources that file,
2721" then removes that file.
2722fun! netrw#NetSource(...)
2723" call Dfunc("netrw#NetSource() a:0=".a:0)
2724 if a:0 > 0 && a:1 == '?'
2725 " give help
2726 echomsg 'NetSource Usage:'
2727 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2728 echomsg ':Nsource fetch://machine/path uses fetch'
2729 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002730 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002731 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2732 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2733 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2734 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2735 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002736 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002737 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002738 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002739 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002740" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002741 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002742" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002743 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002744" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002745 if delete(s:netrw_tmpfile)
2746 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2747 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002748 unlet s:netrw_tmpfile
2749 else
2750 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2751 endif
2752 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002753 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002754 endif
2755" call Dret("netrw#NetSource")
2756endfun
2757
Bram Moolenaar8d043172014-01-23 14:24:41 +01002758" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002759" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2760" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002761fun! netrw#SetTreetop(iscmd,...)
Bram Moolenaara6878372014-03-22 21:02:50 +01002762
Bram Moolenaar85850f32019-07-19 22:05:51 +02002763 " iscmd==0: netrw#SetTreetop called using gn mapping
2764 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
Bram Moolenaar8d043172014-01-23 14:24:41 +01002765 " clear out the current tree
2766 if exists("w:netrw_treetop")
2767 let inittreetop= w:netrw_treetop
2768 unlet w:netrw_treetop
2769 endif
2770 if exists("w:netrw_treedict")
2771 unlet w:netrw_treedict
2772 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002773
Bram Moolenaar85850f32019-07-19 22:05:51 +02002774 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002775 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaar8d043172014-01-23 14:24:41 +01002776 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002777 if isdirectory(s:NetrwFile(a:1))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002778 let treedir = a:1
2779 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002780 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002781 let treedir = b:netrw_curdir."/".a:1
2782 let s:netrw_treetop = treedir
Bram Moolenaar8d043172014-01-23 14:24:41 +01002783 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002784 " normally the cursor is left in the message window.
2785 " However, here this results in the directory being listed in the message window, which is not wanted.
2786 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002787 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002788 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002789 let treedir = "."
2790 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002791 endif
2792 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002793
2794 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002795 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar85850f32019-07-19 22:05:51 +02002796
2797 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002798 if islocal
Tom Benham64a536d2024-11-07 21:15:03 +01002799 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir,0))
Bram Moolenaara6878372014-03-22 21:02:50 +01002800 else
Tom Benham64a536d2024-11-07 21:15:03 +01002801 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir,0))
Bram Moolenaara6878372014-03-22 21:02:50 +01002802 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002803
Bram Moolenaar8d043172014-01-23 14:24:41 +01002804endfun
2805
Bram Moolenaar9964e462007-05-05 17:54:07 +00002806" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002807" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002808" readcmd == %r : replace buffer with newly read file
2809" == 0r : read file at top of buffer
2810" == r : read file after current line
2811" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002812fun! s:NetrwGetFile(readcmd, tfile, method)
2813" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002814
2815 " readcmd=='t': simply do nothing
2816 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002817" 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 +01002818" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002819 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002820 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002821
Bram Moolenaar9964e462007-05-05 17:54:07 +00002822 " get name of remote filename (ie. url and all)
2823 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002824" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002825
Bram Moolenaar9964e462007-05-05 17:54:07 +00002826 if exists("*NetReadFixup")
2827 " for the use of NetReadFixup (not otherwise used internally)
2828 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002829 endif
2830
Bram Moolenaar9964e462007-05-05 17:54:07 +00002831 if a:readcmd[0] == '%'
2832 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002833" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002834
2835 " rename the current buffer to the temp file (ie. tfile)
2836 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002837 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002838 else
2839 let tfile= a:tfile
2840 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002841 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002842
2843 " edit temporary file (ie. read the temporary file in)
2844 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002845" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002846 call zip#Browse(tfile)
2847 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002848" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.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\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002851" call Decho("handling remote gzip-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\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002854" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002855 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002856 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002857" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002858 call tar#Browse(tfile)
2859 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002860" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002861 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002862 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002863" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002864 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002865 endif
2866
2867 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002868 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002869
Bram Moolenaar71badf92023-04-22 22:40:14 +01002870 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002871 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002872 " Note that isk must not include a "/" for scripts.vim
2873 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002874" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2875" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002876" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002877" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
2878 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01002879 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01002880 filetype detect
2881" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09002882 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02002883" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002884 let line1 = 1
2885 let line2 = line("$")
2886
Bram Moolenaar8d043172014-01-23 14:24:41 +01002887 elseif !&ma
2888 " 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 +01002889 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002890" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002891 return
2892
Bram Moolenaar9964e462007-05-05 17:54:07 +00002893 elseif s:FileReadable(a:tfile)
2894 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002895" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002896 let curline = line(".")
2897 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002898" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002899 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002900 let line1= curline + 1
2901 let line2= line("$") - lastline + 1
2902
2903 else
2904 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002905" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
2906" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002907 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002908" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002909 return
2910 endif
2911
2912 " User-provided (ie. optional) fix-it-up command
2913 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002914" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002915 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002916" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002917" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002918 endif
2919
Bram Moolenaaradc21822011-04-01 18:03:16 +02002920 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00002921 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002922 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00002923 endif
2924
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002925" 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 +00002926
2927 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00002928" redraw!
2929
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002930" 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 +00002931" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002932endfun
2933
Bram Moolenaar9964e462007-05-05 17:54:07 +00002934" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002935" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01002936" Input:
2937" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
2938" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002939" b:netrw_method= 1: rcp
2940" 2: ftp + <.netrc>
2941" 3: ftp + machine, id, password, and [path]filename
2942" 4: scp
2943" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002944" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002945" 7: rsync
2946" 8: fetch
2947" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002948" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01002949" g:netrw_machine= hostname
2950" b:netrw_fname = filename
2951" g:netrw_port = optional port number (for ftp)
2952" g:netrw_choice = copy of input url (choice)
2953fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002954" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002955
Bram Moolenaar251e1912011-06-19 05:09:16 +02002956 " sanity check: choice should have at least three slashes in it
2957 if strlen(substitute(a:choice,'[^/]','','g')) < 3
2958 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
2959 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02002960" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02002961 return
2962 endif
2963
Bram Moolenaar5c736222010-01-06 20:54:52 +01002964 " record current g:netrw_machine, if any
2965 " curmachine used if protocol == ftp and no .netrc
2966 if exists("g:netrw_machine")
2967 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002968" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002969 else
2970 let curmachine= "N O T A HOST"
2971 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002972 if exists("g:netrw_port")
2973 let netrw_port= g:netrw_port
2974 endif
2975
2976 " insure that netrw_ftp_cmd starts off every method determination
2977 " with the current g:netrw_ftp_cmd
2978 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01002979
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002980 " initialization
2981 let b:netrw_method = 0
2982 let g:netrw_machine = ""
2983 let b:netrw_fname = ""
2984 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002985 let g:netrw_choice = a:choice
2986
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002987 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002988 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00002989 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
2990 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002991 " rcpurm : rcp://[user@]host/filename Use rcp
2992 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002993 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02002994 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01002995 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002996 " rsyncurm : rsync://host[:port]/path Use rsync
2997 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
2998 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002999 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003000 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3001 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003002 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3003 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003004 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003005 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003006 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003007 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003008 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003009 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003010 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003011 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003012
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003013" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003014 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003015 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003016 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003017" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003018 let b:netrw_method = 1
3019 let userid = substitute(a:choice,rcpurm,'\1',"")
3020 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3021 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003022 if userid != ""
3023 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003024 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003025
Bram Moolenaaradc21822011-04-01 18:03:16 +02003026 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003027 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003028" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003029 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003030 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3031 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3032 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003033
Bram Moolenaar15146672011-10-20 22:22:38 +02003034 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003035 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003036" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003037 let b:netrw_method = 5
3038 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3039 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003040 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003041
Bram Moolenaaradc21822011-04-01 18:03:16 +02003042 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003043 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003044" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003045 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003046 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003047 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3048 else
3049 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3050 endif
3051 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003052
Bram Moolenaaradc21822011-04-01 18:03:16 +02003053 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003054 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003055" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003056 let b:netrw_method = 7
3057 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3058 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003059
Bram Moolenaaradc21822011-04-01 18:03:16 +02003060 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003061 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003062" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003063 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003064 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3065 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3066 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003067" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003068 if userid != ""
3069 let g:netrw_uid= userid
3070 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003071
Bram Moolenaaradc21822011-04-01 18:03:16 +02003072 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003073 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003074 call NetUserPass("ftp:".g:netrw_machine)
3075 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003076 " if there's a change in hostname, require password re-entry
3077 unlet s:netrw_passwd
3078 endif
3079 if exists("netrw_port")
3080 unlet netrw_port
3081 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003082 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003083
Bram Moolenaar446cb832008-06-24 21:56:24 +00003084 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003085 let b:netrw_method = 3
3086 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003087 let host= substitute(g:netrw_machine,'\..*$','','')
3088 if exists("s:netrw_hup[host]")
3089 call NetUserPass("ftp:".host)
3090
Nir Lichtman1e34b952024-05-08 19:19:34 +02003091 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003092" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3093" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003094 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003095 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003096" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003097 endif
3098 let b:netrw_method= 2
3099 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003100" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003101 let b:netrw_method= 2
3102 else
3103 if !exists("g:netrw_uid") || g:netrw_uid == ""
3104 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003105 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003106 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003107 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003108 endif
3109 let b:netrw_method= 3
3110 endif
3111 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003112
Bram Moolenaaradc21822011-04-01 18:03:16 +02003113 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003114 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003115" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003116 let b:netrw_method = 8
3117 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3118 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3119 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3120 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003121
Bram Moolenaaradc21822011-04-01 18:03:16 +02003122 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003123 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003124" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003126 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3127 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003128 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003129 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003130 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003131
Bram Moolenaaradc21822011-04-01 18:03:16 +02003132 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003133 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003134" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003135 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003136 let b:netrw_method = 3
3137 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3138 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003139
Bram Moolenaar9964e462007-05-05 17:54:07 +00003140 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003141 let b:netrw_method = 2
3142 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3143 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3144 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003145
Bram Moolenaaradc21822011-04-01 18:03:16 +02003146 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003147 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003148" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003149 let b:netrw_method = 9
3150 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3151 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003152
Bram Moolenaaradc21822011-04-01 18:03:16 +02003153 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003154 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003155" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003156 let b:netrw_method = 1
3157 let userid = substitute(a:choice,rcphf,'\2',"")
3158 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3159 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003160" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3161" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3162" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3163" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003164 if userid != ""
3165 let g:netrw_uid= userid
3166 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003167
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003168 " Method#10: file://user@hostname/...path-to-file {{{3
3169 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003170" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003171 let b:netrw_method = 10
3172 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003173" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003174
Bram Moolenaaradc21822011-04-01 18:03:16 +02003175 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003176 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003177 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003178 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003179 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003180 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003182 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003183
Bram Moolenaar81695252004-12-29 20:58:21 +00003184 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003185 " remove any leading [:#] from port number
3186 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3187 elseif exists("netrw_port")
3188 " retain port number as implicit for subsequent ftp operations
3189 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003190 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003191
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003192" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3193" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3194" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3195" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003196" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003197" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003198" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003199" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003200" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003201" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003202" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003203" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003204endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003205
Bram Moolenaar9964e462007-05-05 17:54:07 +00003206" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003207" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003208" Usage: :call NetUserPass() -- will prompt for userid and password
3209" :call NetUserPass("uid") -- will prompt for password
3210" :call NetUserPass("uid","password") -- sets global userid and password
3211" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3212" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003213fun! NetUserPass(...)
3214
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003215" call Dfunc("NetUserPass() a:0=".a:0)
3216
3217 if !exists('s:netrw_hup')
3218 let s:netrw_hup= {}
3219 endif
3220
Bram Moolenaar071d4272004-06-13 20:20:40 +00003221 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003222 " case: no input arguments
3223
3224 " change host and username if not previously entered; get new password
3225 if !exists("g:netrw_machine")
3226 let g:netrw_machine= input('Enter hostname: ')
3227 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003229 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230 let g:netrw_uid= input('Enter username: ')
3231 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003232 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003233 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003234
3235 " set up hup database
3236 let host = substitute(g:netrw_machine,'\..*$','','')
3237 if !exists('s:netrw_hup[host]')
3238 let s:netrw_hup[host]= {}
3239 endif
3240 let s:netrw_hup[host].uid = g:netrw_uid
3241 let s:netrw_hup[host].passwd = s:netrw_passwd
3242
3243 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003244 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003245
3246 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003247 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003248 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003249" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003250 let host = substitute(a:1,'^ftp:','','')
3251 let host = substitute(host,'\..*','','')
3252 if exists("s:netrw_hup[host]")
3253 let g:netrw_uid = s:netrw_hup[host].uid
3254 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003255" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3256" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003257 else
3258 let g:netrw_uid = input("Enter UserId: ")
3259 let s:netrw_passwd = inputsecret("Enter Password: ")
3260 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003261
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003262 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003263 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003264" 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 +02003265 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003266 if g:netrw_machine =~ '[0-9.]\+'
3267 let host= g:netrw_machine
3268 else
3269 let host= substitute(g:netrw_machine,'\..*$','','')
3270 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003271 else
3272 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003273 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003274 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003275" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003276 if exists("g:netrw_passwd")
3277 " ask for password if one not previously entered
3278 let s:netrw_passwd= g:netrw_passwd
3279 else
3280 let s:netrw_passwd = inputsecret("Enter Password: ")
3281 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003282 endif
3283
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003284" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003285 if exists("host")
3286 if !exists('s:netrw_hup[host]')
3287 let s:netrw_hup[host]= {}
3288 endif
3289 let s:netrw_hup[host].uid = g:netrw_uid
3290 let s:netrw_hup[host].passwd = s:netrw_passwd
3291 endif
3292
3293 elseif a:0 == 2
3294 let g:netrw_uid = a:1
3295 let s:netrw_passwd = a:2
3296
3297 elseif a:0 == 3
3298 " enter hostname, user-id, and password into the hup dictionary
3299 let host = substitute(a:1,'^\a\+:','','')
3300 let host = substitute(host,'\..*$','','')
3301 if !exists('s:netrw_hup[host]')
3302 let s:netrw_hup[host]= {}
3303 endif
3304 let s:netrw_hup[host].uid = a:2
3305 let s:netrw_hup[host].passwd = a:3
3306 let g:netrw_uid = s:netrw_hup[host].uid
3307 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003308" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3309" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003310 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003311
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003312" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003313endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003314
Bram Moolenaar85850f32019-07-19 22:05:51 +02003315" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003316" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003317" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003318
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003319" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003320" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3321fun! s:ExplorePatHls(pattern)
3322" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3323 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003324" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003325 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003326" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003327 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3328" call Dret("s:ExplorePatHls repat<".repat.">")
3329 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003330endfun
3331
3332" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003333" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003334" 0: (user: <mb>) bookmark current directory
3335" 1: (user: <gb>) change to the bookmarked directory
3336" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003337" 3: (browsing) records current directory history
3338" 4: (user: <u>) go up (previous) directory, using history
3339" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003340" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003341fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003342" 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 +02003343 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3344" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3345 return
3346 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003347
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003348 let ykeep = @@
3349 let curbufnr = bufnr("%")
3350
Bram Moolenaar9964e462007-05-05 17:54:07 +00003351 if a:chg == 0
3352 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003353" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003354 if exists("s:netrwmarkfilelist_{curbufnr}")
3355 call s:NetrwBookmark(0)
3356 echo "bookmarked marked files"
3357 else
3358 call s:MakeBookmark(a:curdir)
3359 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003360 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003361
KSR-Yasudaf4498252023-10-06 03:34:17 +09003362 try
3363 call s:NetrwBookHistSave()
3364 catch
3365 endtry
3366
Bram Moolenaar9964e462007-05-05 17:54:07 +00003367 elseif a:chg == 1
3368 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003369" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003370 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003371" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003372 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003373 else
3374 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3375 endif
3376
3377 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003378" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003379 let didwork= 0
3380 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003381" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003382 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003383" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003384 let cnt= 1
3385 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003386" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003387 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003388 let didwork = 1
3389 let cnt = cnt + 1
3390 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003391 endif
3392
3393 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003394 " Note: history is saved only when PerformListing is done;
3395 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3396 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003397 let first = 1
3398 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003399 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003400 while ( first || cnt != g:netrw_dirhistcnt )
3401" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003402 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003403" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003404 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003405 let didwork= 1
3406 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003407 let histcnt = histcnt + 1
3408 let first = 0
3409 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003410 if cnt < 0
3411 let cnt= cnt + g:netrw_dirhistmax
3412 endif
3413 endwhile
3414 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003415 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003416 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003417 if didwork
3418 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3419 endif
3420
3421 elseif a:chg == 3
3422 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003423" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003424 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 +02003425 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003426 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3427 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003428 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003429" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003430 endif
3431
3432 elseif a:chg == 4
3433 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003434" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003435 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003436 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3437 if g:netrw_dirhistcnt < 0
3438 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003439 endif
3440 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003441 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003442 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003443 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3444" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003445 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003446 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003447" call Decho("setl ma noro",'~'.expand("<slnum>"))
3448 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003449 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003450" call Decho("setl nomod",'~'.expand("<slnum>"))
3451" 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 +00003452 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003453" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3454 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003455 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003456 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003457 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003458 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003459 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003460 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003461 echo "Sorry, no predecessor directory exists yet"
3462 endif
3463
3464 elseif a:chg == 5
3465 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003466" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003467 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003468 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3469 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3470" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003471 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003472" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003473 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003474 sil! NetrwKeepj %d _
3475" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3476" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003477 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003478" 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 +02003479 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003480" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3481 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003482 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003483 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3484 if g:netrw_dirhistcnt < 0
3485 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003486 endif
3487 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003488 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003489 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003490 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003491 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003492 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003493
3494 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003495" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003496 if exists("s:netrwmarkfilelist_{curbufnr}")
3497 call s:NetrwBookmark(1)
3498 echo "removed marked files from bookmarks"
3499 else
3500 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003501 let iremove = v:count
3502 let dremove = g:netrw_bookmarklist[iremove - 1]
3503" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003504 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003505" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3506 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3507 echo "removed ".dremove." from g:netrw_bookmarklist"
3508" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003509 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003510" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003511
3512 try
3513 call s:NetrwBookHistSave()
3514 catch
3515 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003516 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003517 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003518 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003519 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003520" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003521endfun
3522
3523" ---------------------------------------------------------------------
3524" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003525" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003526" Sister function: s:NetrwBookHistSave()
3527fun! s:NetrwBookHistRead()
3528" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003529 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003530" 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 +02003531 return
3532 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003533 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003534
3535 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003536 if !exists("s:netrw_initbookhist")
3537 let home = s:NetrwHome()
3538 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003539 if filereadable(s:NetrwFile(savefile))
3540" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003541 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003542 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003543
3544 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003545 if g:netrw_dirhistmax > 0
3546 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003547 if filereadable(s:NetrwFile(savefile))
3548" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003549 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003550 endif
3551 let s:netrw_initbookhist= 1
3552 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003553 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003554 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003555
Bram Moolenaar97d62492012-11-15 21:28:22 +01003556 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003557" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3558" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003559" call Dret("s:NetrwBookHistRead")
3560endfun
3561
3562" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003563" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003564" Sister function: s:NetrwBookHistRead()
3565" I used to do this via viminfo but that appears to
3566" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003567" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3568" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003569" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003570fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003571" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003572 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003573" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003574 return
3575 endif
3576
Bram Moolenaar5c736222010-01-06 20:54:52 +01003577 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003578" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003579 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003580
3581 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003582 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003583" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003584 if g:netrw_use_noswf
3585 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3586 else
3587 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3588 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003589 setl nocin noai noci magic nospell nohid wig= noaw
3590 setl ma noro write
3591 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003592 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003593
Bram Moolenaar85850f32019-07-19 22:05:51 +02003594 " rename enew'd file: .netrwhist -- no attempt to merge
3595 " record dirhistmax and current dirhistcnt
3596 " save history
3597" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003598 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003599 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003600 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3601 if g:netrw_dirhistmax > 0
3602 let lastline = line("$")
3603 let cnt = g:netrw_dirhistcnt
3604 let first = 1
3605 while ( first || cnt != g:netrw_dirhistcnt )
3606 let lastline= lastline + 1
3607 if exists("g:netrw_dirhist_{cnt}")
3608 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3609" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3610 endif
3611 let first = 0
3612 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3613 if cnt < 0
3614 let cnt= cnt + g:netrw_dirhistmax
3615 endif
3616 endwhile
3617 exe "sil! w! ".savefile
3618" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3619 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003620
Bram Moolenaar85850f32019-07-19 22:05:51 +02003621 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003622 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003623 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003624" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003625 " merge and write .netrwbook
3626 let savefile= s:NetrwHome()."/.netrwbook"
3627
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003628 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003629 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003630 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003631 for bdm in booklist
3632 if index(g:netrw_bookmarklist,bdm) == -1
3633 call add(g:netrw_bookmarklist,bdm)
3634 endif
3635 endfor
3636 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003637 endif
3638
3639 " construct and save .netrwbook
3640 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003641 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003642" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003643 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003644
3645 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003646 let bgone= bufnr("%")
3647 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003648 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003649
3650" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003651endfun
3652
3653" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003654" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3655" list of the contents of a local or remote directory. It is assumed that the
3656" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3657" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003658" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003659fun! s:NetrwBrowse(islocal,dirname)
3660 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaara6878372014-03-22 21:02:50 +01003661
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003662 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3663 " This is useful when one edits a local file, then :e ., then :Rex
3664 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3665 let w:netrw_rexfile= bufname("#")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003666 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003667
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003668 " s:NetrwBrowse : initialize history {{{3
3669 if !exists("s:netrw_initbookhist")
3670 NetrwKeepj call s:NetrwBookHistRead()
3671 endif
3672
3673 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003674 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003675 let dirname= simplify(a:dirname)
3676 else
3677 let dirname= a:dirname
3678 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003679
Bram Moolenaar85850f32019-07-19 22:05:51 +02003680 " repoint t:netrw_lexbufnr if appropriate
3681 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02003682 let repointlexbufnr= 1
3683 endif
3684
3685 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003686 if exists("s:netrw_skipbrowse")
3687 unlet s:netrw_skipbrowse
Bram Moolenaar446cb832008-06-24 21:56:24 +00003688 return
3689 endif
3690 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003691 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003692 return
3693 endif
3694 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003695 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003696 return
3697 endif
3698
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003699 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003700 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003701
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003702 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003703 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3704 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaar85850f32019-07-19 22:05:51 +02003705 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3706 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003707 endif
3708
3709 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003710 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003711 if s:NetrwLcd(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003712 return
3713 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003714
Bram Moolenaar5c736222010-01-06 20:54:52 +01003715 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003716 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003717 if bufname(dirname) != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003718 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003719 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003720 " attempt transfer of remote regular file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003721
3722 " remove any filetype indicator from end of dirname, except for the
3723 " "this is a directory" indicator (/).
3724 " There shouldn't be one of those here, anyway.
3725 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003726 call s:RemotePathAnalysis(dirname)
3727
3728 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3729 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003730 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003731 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003732 let b:netrw_curdir = dirname
3733 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003734 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003735 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3736 sil call netrw#NetRead(2,url)
3737 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003738 if s:path =~ '.bz2'
3739 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3740 elseif s:path =~ '.gz'
3741 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3742 elseif s:path =~ '.gz'
3743 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3744 else
3745 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3746 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003747 endif
3748
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003749 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003750 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003751 call s:NetrwOptionsRestore("w:")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003752 setl ma nomod noro
Bram Moolenaar446cb832008-06-24 21:56:24 +00003753 return
3754 endif
3755
Bram Moolenaaradc21822011-04-01 18:03:16 +02003756 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003757 call s:UseBufWinVars()
3758
3759 " set up some variables {{{3
3760 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003761 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003762 let s:last_sort_by = g:netrw_sort_by
3763
3764 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003765 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003766
Bram Moolenaar97d62492012-11-15 21:28:22 +01003767 " get/set-up buffer {{{3
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003768 let svpos = winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01003769
3770 " NetrwGetBuffer might change buffers but s:rexposn_X was set for the
3771 " previous buffer
3772 let prevbufnr = bufnr('%')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003773 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Tom Benham64a536d2024-11-07 21:15:03 +01003774 if exists("s:rexposn_".prevbufnr)
3775 let s:rexposn_{bufnr('%')} = s:rexposn_{prevbufnr}
3776 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003777
Bram Moolenaar446cb832008-06-24 21:56:24 +00003778 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003779 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3780 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02003781 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3782 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003783 2match none
3784 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003785 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003786 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003787 call s:NetrwOptionsRestore("w:")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003788 setl noma nomod nowrap
Bram Moolenaar446cb832008-06-24 21:56:24 +00003789 return
3790 endif
3791
3792 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003793 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003794 if b:netrw_curdir =~ '[/\\]$'
3795 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3796 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003797 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003798 let b:netrw_curdir= b:netrw_curdir."/"
3799 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003800 if b:netrw_curdir == ''
3801 if has("amiga")
3802 " On the Amiga, the empty string connotes the current directory
3803 let b:netrw_curdir= getcwd()
3804 else
3805 " under unix, when the root directory is encountered, the result
3806 " from the preceding substitute is an empty string.
3807 let b:netrw_curdir= '/'
3808 endif
3809 endif
3810 if !a:islocal && b:netrw_curdir !~ '/$'
3811 let b:netrw_curdir= b:netrw_curdir.'/'
3812 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003813
3814 " ------------
3815 " (local only) {{{3
3816 " ------------
3817 if a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00003818 " Set up ShellCmdPost handling. Append current buffer to browselist
3819 call s:LocalFastBrowser()
3820
3821 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3822 if !g:netrw_keepdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003823 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003824 if s:NetrwLcd(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003825 return
3826 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003827 endif
3828 endif
3829
3830 " --------------------------------
3831 " remote handling: {{{3
3832 " --------------------------------
3833 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00003834
Bram Moolenaar97d62492012-11-15 21:28:22 +01003835 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003836 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003837 let dirname= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003838 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3839 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3840 if dirname !~ '/$'
3841 let dirname= dirname.'/'
3842 endif
3843 let b:netrw_curdir = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003844 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003845 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003846 endif
3847
3848 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
3849 if dirname !~ dirpat
3850 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003851 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003852 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003853 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003854 setl noma nomod nowrap
Bram Moolenaar446cb832008-06-24 21:56:24 +00003855 return
3856 endif
3857 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003858 endif " (additional remote handling)
3859
Bram Moolenaar85850f32019-07-19 22:05:51 +02003860 " -------------------------------
3861 " Perform Directory Listing: {{{3
3862 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003863 NetrwKeepj call s:NetrwMaps(a:islocal)
3864 NetrwKeepj call s:NetrwCommands(a:islocal)
3865 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003866
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003867 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003868 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003869
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003870 " If there is a rexposn: restore position with rexposn
3871 " Otherwise : set rexposn
3872 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003873 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
3874 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
3875 NetrwKeepj exe w:netrw_bannercnt
3876 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003877 else
3878 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
3879 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02003880 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01003881 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara6878372014-03-22 21:02:50 +01003882 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02003883 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003884
Bram Moolenaar85850f32019-07-19 22:05:51 +02003885 " repoint t:netrw_lexbufnr if appropriate
3886 if exists("repointlexbufnr")
3887 let t:netrw_lexbufnr= bufnr("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02003888 endif
3889
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003890 " restore position
3891 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003892 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003893 endif
3894
Bram Moolenaara6878372014-03-22 21:02:50 +01003895 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003896 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
3897 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaar446cb832008-06-24 21:56:24 +00003898 return
3899endfun
3900
3901" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003902" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
3903" may not apply correctly; ie. netrw's idea of the current directory may
3904" differ from vim's. This function insures that netrw's idea of the current
3905" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003906" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003907fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003908" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
3909" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
3910" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
3911" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
3912" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003913
3914 " clean up any leading treedepthstring
3915 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
3916 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02003917" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003918 else
3919 let fname= a:fname
3920 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003921
3922 if g:netrw_keepdir
3923 " vim's idea of the current directory possibly may differ from netrw's
3924 if !exists("b:netrw_curdir")
3925 let b:netrw_curdir= getcwd()
3926 endif
3927
Nir Lichtman1e34b952024-05-08 19:19:34 +02003928 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003929 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003930 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003931 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003932" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003933 else
3934 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003935 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003936" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003937 endif
3938
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003939 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003940 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003941 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003942" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003943 else
3944 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003945 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003946" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003947 endif
3948 else
3949 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003950 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003951" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
3952" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
3953" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003954 endif
3955
Bram Moolenaar85850f32019-07-19 22:05:51 +02003956" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003957 return ret
3958endfun
3959
3960" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003961" s:NetrwFileInfo: supports qf (query for file information) {{{2
3962fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01003963" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01003964 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00003965 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003966 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003967 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003968 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003969 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003970 let lsopt= "-lsadh --si"
3971 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02003972" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003973 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003974
3975 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003976 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003977" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003978
Bram Moolenaara6878372014-03-22 21:02:50 +01003979 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003980 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003981" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003982
3983 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003984 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003985" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003986
Bram Moolenaar446cb832008-06-24 21:56:24 +00003987 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003988" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003989 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003990" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003991 endif
3992 else
3993 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003994" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
3995 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003996 let fname= substitute(a:fname,".$","","")
3997 else
3998 let fname= a:fname
3999 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004000 let t = getftime(s:NetrwFile(fname))
4001 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004002 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004003 let sz= s:NetrwHumanReadable(sz)
4004 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004005 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4006" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004007 endif
4008 else
4009 echo "sorry, \"qf\" not supported yet for remote files"
4010 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004011 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004012" call Dret("s:NetrwFileInfo")
4013endfun
4014
4015" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004016" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4017fun! s:NetrwFullPath(filename)
4018" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4019 let filename= a:filename
4020 if filename !~ '^/'
4021 let filename= resolve(getcwd().'/'.filename)
4022 endif
4023 if filename != "/" && filename =~ '/$'
4024 let filename= substitute(filename,'/$','','')
4025 endif
4026" " call Dret("s:NetrwFullPath <".filename.">")
4027 return filename
4028endfun
4029
4030" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004031" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004032" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004033" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004034" 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 +00004035fun! s:NetrwGetBuffer(islocal,dirname)
4036" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004037" 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 +02004038" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4039" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004040 let dirname= a:dirname
4041
4042 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004043" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004044 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004045" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004046 let s:netrwbuf= {}
4047 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004048" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4049" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4050
4051 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4052 let bufnum = -1
4053
4054 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4055 if has_key(s:netrwbuf,"NetrwTreeListing")
4056 let bufnum= s:netrwbuf["NetrwTreeListing"]
4057 else
4058 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4059 endif
4060" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4061 if !bufexists(bufnum)
Peter Aronoffbe551da2024-09-22 11:29:40 +02004062 call remove(s:netrwbuf,"NetrwTreeListing")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004063 let bufnum= -1
4064 endif
4065 elseif bufnr("NetrwTreeListing") != -1
4066 let bufnum= bufnr("NetrwTreeListing")
4067" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4068 else
4069" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4070 let bufnum= -1
4071 endif
4072
4073 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004074 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004075" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004076 if !bufexists(bufnum)
4077 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4078 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004079 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004080
Bram Moolenaar446cb832008-06-24 21:56:24 +00004081 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004082" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004083 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004084 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004085" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4086
Bram Moolenaar71badf92023-04-22 22:40:14 +01004087 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004088 " IF the buffer already has the desired name
4089 " AND it is empty
4090 let curbuf = bufname("%")
4091 if curbuf == '.'
4092 let curbuf = getcwd()
4093 endif
4094" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004095" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004096" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4097" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4098" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4099" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4100 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004101" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4102 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004103 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004104" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004105 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004106 " 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 +00004107
4108 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004109 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004110" 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 +00004111 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004112" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004113 " name the buffer
4114 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4115 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004116" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004117 let w:netrw_treebufnr = bufnr("%")
4118 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004119 if g:netrw_use_noswf
4120 setl nobl bt=nofile noswf
4121 else
4122 setl nobl bt=nofile
4123 endif
4124 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4125 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4126 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4127 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004128" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004129 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004130 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004131 " enter the new buffer into the s:netrwbuf dictionary
4132 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4133" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4134" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004135 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004136" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004137
4138 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004139" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004140 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004141 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004142 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004143
4144 if &ft == "netrw"
4145" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4146 exe "sil! NetrwKeepj noswapfile b ".bufnum
4147" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004148 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004149" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4150 call s:NetrwEditBuf(bufnum)
4151" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004152 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004153" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004154 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004155 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004156 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004157
4158 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004159 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004160
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004161 if line("$") <= 1 && getline(1) == ""
4162 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004163 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004164" 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>"))
4165" 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 +01004166" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4167 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004168
Bram Moolenaar97d62492012-11-15 21:28:22 +01004169 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004170" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004171 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004172 sil NetrwKeepj %d _
4173" 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>"))
4174" 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 +01004175" 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 +00004176 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004177
Bram Moolenaar446cb832008-06-24 21:56:24 +00004178 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004179" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4180" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004181 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004182 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004183 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004184" 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>"))
4185" 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 +01004186" 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 +00004187 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004188
Bram Moolenaar446cb832008-06-24 21:56:24 +00004189 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004190" 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>"))
4191" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4192" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004193 return 1
4194 endif
4195 endif
4196
4197 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4198 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4199 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4200 " med 1 D H
4201 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004202" 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 +00004203 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004204 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004205 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004206
4207 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004208" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4209" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4210 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004211
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004212" 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>"))
4213" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4214" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004215 return 0
4216endfun
4217
4218" ---------------------------------------------------------------------
4219" s:NetrwGetcwd: get the current directory. {{{2
4220" Change backslashes to forward slashes, if any.
4221" If doesc is true, escape certain troublesome characters
4222fun! s:NetrwGetcwd(doesc)
4223" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4224 let curdir= substitute(getcwd(),'\\','/','ge')
4225 if curdir !~ '[\/]$'
4226 let curdir= curdir.'/'
4227 endif
4228 if a:doesc
4229 let curdir= fnameescape(curdir)
4230 endif
4231" call Dret("NetrwGetcwd <".curdir.">")
4232 return curdir
4233endfun
4234
4235" ---------------------------------------------------------------------
4236" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4237fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004238" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4239" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4240 let keepsol= &l:sol
4241 setl nosol
4242
Bram Moolenaar446cb832008-06-24 21:56:24 +00004243 call s:UseBufWinVars()
4244
4245 " insure that w:netrw_liststyle is set up
4246 if !exists("w:netrw_liststyle")
4247 if exists("g:netrw_liststyle")
4248 let w:netrw_liststyle= g:netrw_liststyle
4249 else
4250 let w:netrw_liststyle= s:THINLIST
4251 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004252" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004253 endif
4254
4255 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4256 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004257" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004258 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004259 let dirname= "./"
4260 let curline= getline('.')
4261
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004262 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004263 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004264 let s:netrw_skipbrowse= 1
4265 echo 'Pressing "s" also works'
4266
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004267 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004268 let s:netrw_skipbrowse= 1
4269 echo 'Press "S" to edit sorting sequence'
4270
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004271 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004272 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004273 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004274
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004275 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004276 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004277 let s:netrw_skipbrowse= 1
4278 echo 'Pressing "a" also works'
4279
4280 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004281 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004282 endif
4283
4284 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004285" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004286 NetrwKeepj norm! 0
4287 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004288
4289 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004290" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004291 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004292 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4293
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004294 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004295" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004296 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004297 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004298
4299 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004300" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004301 let dirname= getline('.')
4302
4303 if !exists("b:netrw_cpf")
4304 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004305 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 +01004306 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004307" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004308 endif
4309
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004310" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004311 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004312" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4313" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004314 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004315 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004316 else
4317 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004318 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004319 endif
Enno3146d632024-07-04 19:44:42 +02004320
4321 let dict={}
4322 " save the unnamed register and register 0-9 and a
4323 let dict.a=[getreg('a'), getregtype('a')]
4324 for i in range(0, 9)
4325 let dict[i] = [getreg(i), getregtype(i)]
4326 endfor
4327 let dict.unnamed = [getreg(''), getregtype('')]
4328
Bram Moolenaarc236c162008-07-13 17:41:49 +00004329 let eofname= filestart + b:netrw_cpf + 1
4330 if eofname <= col("$")
4331 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004332 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004333 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004334 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004335 endif
Enno3146d632024-07-04 19:44:42 +02004336
Bram Moolenaar446cb832008-06-24 21:56:24 +00004337 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004338 call s:RestoreRegister(dict)
4339
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004340" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004341 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004342" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004343 endif
4344
4345 " symlinks are indicated by a trailing "@". Remove it before further processing.
4346 let dirname= substitute(dirname,"@$","","")
4347
4348 " executables are indicated by a trailing "*". Remove it before further processing.
4349 let dirname= substitute(dirname,"\*$","","")
4350
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004351 let &l:sol= keepsol
4352
Bram Moolenaar446cb832008-06-24 21:56:24 +00004353" call Dret("s:NetrwGetWord <".dirname.">")
4354 return dirname
4355endfun
4356
4357" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004358" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4359" g:netrw_bufsettings will be used after the listing is produced.
4360" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004361fun! s:NetrwListSettings(islocal)
4362" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004363" 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 +00004364 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004365" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4366 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4367 setl bt=nofile nobl ma nonu nowrap noro nornu
4368 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004369 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004370 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004371 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004372" call Dredir("ls!","s:NetrwListSettings")
4373" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004374 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004375 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004376 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004377 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004378 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004379 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004380 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004381" 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 +00004382" call Dret("s:NetrwListSettings")
4383endfun
4384
4385" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004386" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004387" islocal=0: remote browsing
4388" =1: local browsing
4389fun! s:NetrwListStyle(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004390 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004391 let fname = s:NetrwGetWord()
4392 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004393 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004394 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00004395
Bram Moolenaar85850f32019-07-19 22:05:51 +02004396 " repoint t:netrw_lexbufnr if appropriate
4397 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02004398 let repointlexbufnr= 1
4399 endif
4400
Bram Moolenaar446cb832008-06-24 21:56:24 +00004401 if w:netrw_liststyle == s:THINLIST
4402 " use one column listing
Bram Moolenaar446cb832008-06-24 21:56:24 +00004403 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4404
4405 elseif w:netrw_liststyle == s:LONGLIST
4406 " use long list
Bram Moolenaar446cb832008-06-24 21:56:24 +00004407 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4408
4409 elseif w:netrw_liststyle == s:WIDELIST
4410 " give wide list
Bram Moolenaar446cb832008-06-24 21:56:24 +00004411 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4412
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004413 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00004414 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4415
4416 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004417 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004418 let g:netrw_liststyle = s:THINLIST
4419 let w:netrw_liststyle = g:netrw_liststyle
4420 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4421 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004422 setl ma noro
Bram Moolenaar446cb832008-06-24 21:56:24 +00004423
4424 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004425 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004426 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004427 setl nomod
Bram Moolenaar446cb832008-06-24 21:56:24 +00004428
4429 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01004430 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004431 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004432
Bram Moolenaar85850f32019-07-19 22:05:51 +02004433 " repoint t:netrw_lexbufnr if appropriate
4434 if exists("repointlexbufnr")
4435 let t:netrw_lexbufnr= bufnr("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004436 endif
4437
Bram Moolenaar13600302014-05-22 18:26:40 +02004438 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004439" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4440 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004441 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004442
Bram Moolenaar446cb832008-06-24 21:56:24 +00004443endfun
4444
4445" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004446" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4447fun! s:NetrwBannerCtrl(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004448 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004449 " toggle the banner (enable/suppress)
4450 let g:netrw_banner= !g:netrw_banner
4451
4452 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004453 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01004454 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004455
4456 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004457 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4458 let fname= s:NetrwGetWord()
4459 sil NetrwKeepj $
4460 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4461" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4462 if result <= 0 && exists("w:netrw_bannercnt")
4463 exe "NetrwKeepj ".w:netrw_bannercnt
4464 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004465 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004466 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004467" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4468endfun
4469
4470" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004471" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4472"
4473" No bang: enters files/directories into Netrw's bookmark system
4474" No argument and in netrw buffer:
4475" if there are marked files: bookmark marked files
4476" otherwise : bookmark file/directory under cursor
4477" No argument and not in netrw buffer: bookmarks current open file
4478" Has arguments: globs them individually and bookmarks them
4479"
4480" With bang: deletes files/directories from Netrw's bookmark system
4481fun! s:NetrwBookmark(del,...)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004482 if a:0 == 0
4483 if &ft == "netrw"
4484 let curbufnr = bufnr("%")
4485
4486 if exists("s:netrwmarkfilelist_{curbufnr}")
4487 " for every filename in the marked list
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004488 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004489 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004490 for fname in s:netrwmarkfilelist_{curbufnr}
4491 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4492 endfor
4493 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4494 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01004495 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004496 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004497 else
4498 let fname= s:NetrwGetWord()
4499 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4500 endif
4501
4502 else
4503 " bookmark currently open file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004504 let fname= expand("%")
4505 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4506 endif
4507
4508 else
4509 " bookmark specified files
4510 " attempts to infer if working remote or local
4511 " by deciding if the current file begins with an url
4512 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004513 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004514 let i = 1
4515 while i <= a:0
4516 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004517 if v:version > 704 || (v:version == 704 && has("patch656"))
4518 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004519 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004520 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004521 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004522 else
4523 let mbfiles= [a:{i}]
4524 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004525 for mbfile in mbfiles
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004526 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4527 endfor
4528 let i= i + 1
4529 endwhile
4530 endif
4531
4532 " update the menu
4533 call s:NetrwBookmarkMenu()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004534endfun
4535
4536" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004537" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4538" .2.[cnt] for bookmarks, and
4539" .3.[cnt] for history
4540" (see s:NetrwMenu())
4541fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004542 if !exists("s:netrw_menucnt")
4543 return
4544 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004545" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004546
4547 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004548 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004549 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004550" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004551 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4552 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004553 endif
4554 if !exists("s:netrw_initbookhist")
4555 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004556 endif
4557
4558 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004559 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004560 let cnt= 1
4561 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004562" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004563 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004564
4565 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004566 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004567
4568 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004569 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 +01004570 let cnt= cnt + 1
4571 endfor
4572
4573 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004574
4575 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004576 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004577 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004578 let first = 1
4579 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004580 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004581 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004582 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004583 if exists("g:netrw_dirhist_{cnt}")
4584 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004585" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004586 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4587 endif
4588 let first = 0
4589 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4590 if cnt < 0
4591 let cnt= cnt + g:netrw_dirhistmax
4592 endif
4593 endwhile
4594 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004595
Bram Moolenaar9964e462007-05-05 17:54:07 +00004596 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004597" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004598endfun
4599
4600" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004601" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4602" directory and a new directory name. Also, if the
4603" "new directory name" is actually a file,
4604" NetrwBrowseChgDir() edits the file.
Tom Benham64a536d2024-11-07 21:15:03 +01004605" cursor=0: newdir is relative to b:netrw_curdir
4606" =1: newdir is relative to the path to the word under the cursor in
4607" tree view
4608fun! s:NetrwBrowseChgDir(islocal,newdir,cursor,...)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004609 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004610 if !exists("b:netrw_curdir")
4611 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4612 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004613 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004614 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004615 endif
4616
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004617 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02004618 call s:SavePosn(s:netrw_posn)
4619 NetrwKeepj call s:NetrwOptionsSave("s:")
4620 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Tom Benham64a536d2024-11-07 21:15:03 +01004621
4622 let newdir = a:newdir
4623 if a:cursor && exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treetop")
4624 " dirname is the path to the word under the cursor
4625 let dirname = s:NetrwTreePath(w:netrw_treetop)
Christian Brabandt5b63b232024-11-10 20:22:34 +01004626 " newdir resolves to a directory and points to a directory in dirname
4627 " /tmp/test/folder_symlink/ -> /tmp/test/original_folder/
4628 if a:islocal && fnamemodify(dirname, ':t') == newdir && isdirectory(resolve(dirname)) && resolve(dirname) == resolve(newdir)
4629 let dirname = fnamemodify(resolve(dirname), ':p:h:h')
4630 let newdir = fnamemodify(resolve(newdir), ':t')
4631 endif
Tom Benham64a536d2024-11-07 21:15:03 +01004632 " Remove trailing "/"
4633 let dirname = substitute(dirname, "/$", "", "")
4634
4635 " If the word under the cursor is a directory (except for ../), NetrwTreePath
4636 " returns the full path, including the word under the cursor, remove it
4637 if newdir =~ "/$" && newdir != "../"
4638 let dirname = fnamemodify(dirname, ":h")
4639 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004640 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004641 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004642 endif
Tom Benham64a536d2024-11-07 21:15:03 +01004643 if has("win32")
4644 let dirname = substitute(dirname,'\\','/','ge')
4645 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004646 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004647 let dorestore = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01004648
4649 " ignore <cr>s when done in the banner
4650 if g:netrw_banner
Bram Moolenaara6878372014-03-22 21:02:50 +01004651 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004652 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +01004653 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaar13600302014-05-22 18:26:40 +02004654 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004655 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004656 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004657 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara6878372014-03-22 21:02:50 +01004658 endif
4659 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004660 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004661
Bram Moolenaar446cb832008-06-24 21:56:24 +00004662 " set up o/s-dependent directory recognition pattern
4663 if has("amiga")
4664 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004665 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004666 let dirpat= '[\/]$'
4667 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004668
4669 if dirname !~ dirpat
4670 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004671 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004672 let dirname= dirname.'/'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004673 endif
4674
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004675 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004676 " ------------------------------
4677 " NetrwBrowseChgDir: edit a file {{{3
4678 " ------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004679
Bram Moolenaar97d62492012-11-15 21:28:22 +01004680 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004681 let s:rexposn_{bufnr("%")}= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01004682
Bram Moolenaar446cb832008-06-24 21:56:24 +00004683 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004684 if dirname =~ '/$'
4685 let dirname= dirname.newdir
4686 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004687 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004688 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004689 elseif newdir =~ '^\(/\|\a:\)'
4690 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004691 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004692 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004693 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004694 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004695 if a:0 < 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004696 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004697 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004698 if !exists("s:didsplit")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004699 if type(g:netrw_browse_split) == 3
4700 " open file in server
4701 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004702 call s:NetrwServerEdit(a:islocal,dirname)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004703 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004704
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004705 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004706 " horizontally splitting the window first
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004707 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4708 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004709 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004710 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004711 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004712 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004713
Bram Moolenaar446cb832008-06-24 21:56:24 +00004714 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004715 " vertically splitting the window first
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004716 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4717 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004718 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004719 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004720 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004721 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004722
Bram Moolenaar446cb832008-06-24 21:56:24 +00004723 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004724 " open file in new tab
Bram Moolenaarff034192013-04-24 18:51:19 +02004725 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004726 if !exists("b:netrw_curdir")
4727 let b:netrw_curdir= getcwd()
4728 endif
4729 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004730
Bram Moolenaar446cb832008-06-24 21:56:24 +00004731 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004732 " act like "P" (ie. open previous window)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004733 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004734 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004735 return
4736 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004737 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004738
Bram Moolenaar9964e462007-05-05 17:54:07 +00004739 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004740 " handling a file, didn't split, so remove menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00004741 call s:NetrwMenu(0)
4742 " optional change to window
4743 if g:netrw_chgwin >= 1
Bram Moolenaar13600302014-05-22 18:26:40 +02004744 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004745 " if g:netrw_chgwin is set to one more than the last window, then
4746 " vertically split the last window to make that window available.
4747 let curwin= winnr()
4748 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4749 vs
4750 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004751 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004752 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004753 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004754 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004755 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004756
Bram Moolenaar9964e462007-05-05 17:54:07 +00004757 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004758
Bram Moolenaar446cb832008-06-24 21:56:24 +00004759 " the point where netrw actually edits the (local) file
4760 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004761 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004762 if !&mod
4763 " if e the new file would fail due to &mod, then don't change any of the flags
4764 let dolockout= 1
4765 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004766 if a:islocal
Bram Moolenaar8d043172014-01-23 14:24:41 +01004767 " some like c-^ to return to the last edited file
4768 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004769 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4770 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01004771 call s:NetrwEditFile("e","",dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004772 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02004773 if &hidden || &bufhidden == "hide"
4774 " file came from vim's hidden storage. Don't "restore" options with it.
4775 let dorestore= 0
4776 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004777 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00004778 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004779
4780 " handle g:Netrw_funcref -- call external-to-netrw functions
4781 " This code will handle g:Netrw_funcref as an individual function reference
4782 " or as a list of function references. It will ignore anything that's not
4783 " a function reference. See :help Funcref for information about function references.
4784 if exists("g:Netrw_funcref")
4785 if type(g:Netrw_funcref) == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004786 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004787 elseif type(g:Netrw_funcref) == 3
4788 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004789 if type(Fncref) == 2
4790 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004791 endif
4792 endfor
4793 endif
4794 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004795 endif
4796
4797 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004798 " ----------------------------------------------------
4799 " NetrwBrowseChgDir: just go to the new directory spec {{{3
4800 " ----------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004801 let dirname = newdir
4802 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004803 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004804 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004805
4806 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004807 " ---------------------------------------------
4808 " NetrwBrowseChgDir: refresh the directory list {{{3
4809 " ---------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004810 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004811 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004812
4813 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004814 " --------------------------------------
4815 " NetrwBrowseChgDir: go up one directory {{{3
4816 " --------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004817
4818 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
4819 " force a refresh
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004820 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004821 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004822 endif
4823
4824 if has("amiga")
4825 " amiga
Bram Moolenaar446cb832008-06-24 21:56:24 +00004826 if a:islocal
4827 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
4828 let dirname= substitute(dirname,'/$','','')
4829 else
4830 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
4831 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004832
Nir Lichtman1e34b952024-05-08 19:19:34 +02004833 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004834 " windows
4835 if a:islocal
4836 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4837 if dirname == ""
4838 let dirname= '/'
4839 endif
4840 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004841 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01004842 endif
4843 if dirname =~ '^\a:$'
4844 let dirname= dirname.'/'
4845 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01004846
Bram Moolenaar446cb832008-06-24 21:56:24 +00004847 else
4848 " unix or cygwin
Bram Moolenaar446cb832008-06-24 21:56:24 +00004849 if a:islocal
4850 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4851 if dirname == ""
4852 let dirname= '/'
4853 endif
4854 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004855 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004856 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004857 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004858 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004859 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004860
4861 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004862 " --------------------------------------
4863 " NetrwBrowseChgDir: Handle Tree Listing {{{3
4864 " --------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004865 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004866 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004867 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004868 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004869 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004870 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004871 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004872 let haskey = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004873
4874 " search treedict for tree dir as-is
4875 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004876 let haskey= 1
4877 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004878 endif
4879
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004880 " search treedict for treedir with a [/@] appended
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004881 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004882 if has_key(w:netrw_treedict,treedir."/")
4883 let treedir= treedir."/"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004884 let haskey = 1
4885 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004886 endif
4887 endif
4888
4889 " search treedict for treedir with any trailing / elided
4890 if !haskey && treedir =~ '/$'
4891 let treedir= substitute(treedir,'/$','','')
4892 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004893 let haskey = 1
4894 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004895 endif
4896 endif
4897
4898 if haskey
4899 " close tree listing for selected subdirectory
Bram Moolenaar446cb832008-06-24 21:56:24 +00004900 call remove(w:netrw_treedict,treedir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004901 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00004902 else
4903 " go down one directory
4904 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004905 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004906 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004907 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004908
4909 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01004910 " ----------------------------------------
4911 " NetrwBrowseChgDir: Go down one directory {{{3
4912 " ----------------------------------------
4913 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004914 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004915 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00004916 endif
4917
Bram Moolenaar97d62492012-11-15 21:28:22 +01004918 " --------------------------------------
4919 " NetrwBrowseChgDir: Restore and Cleanup {{{3
4920 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02004921 if dorestore
4922 " dorestore is zero'd when a local file was hidden or bufhidden;
4923 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004924 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02004925 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02004926 if dolockout && dorestore
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004927 if filewritable(dirname)
Bram Moolenaar13600302014-05-22 18:26:40 +02004928 setl ma noro nomod
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004929 else
Bram Moolenaar13600302014-05-22 18:26:40 +02004930 setl ma ro nomod
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004931 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004932 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004933 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004934 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004935
Bram Moolenaar446cb832008-06-24 21:56:24 +00004936 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00004937endfun
4938
4939" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004940" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
4941" for thin, long, and wide: cursor placed just after banner
4942" for tree, keeps cursor on current filename
4943fun! s:NetrwBrowseUpDir(islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004944 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
4945 " this test needed because occasionally this function seems to be incorrectly called
4946 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004947 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004948 " directories.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004949 return
4950 endif
4951
Bram Moolenaara6878372014-03-22 21:02:50 +01004952 norm! 0
4953 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara6878372014-03-22 21:02:50 +01004954 let curline= getline(".")
4955 let swwline= winline() - 1
4956 if exists("w:netrw_treetop")
4957 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02004958 elseif exists("b:netrw_curdir")
4959 let w:netrw_treetop= b:netrw_curdir
4960 else
4961 let w:netrw_treetop= getcwd()
4962 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01004963 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004964 let curfile = getline(".")
4965 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01004966 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01004967 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004968 else
Tom Benham64a536d2024-11-07 21:15:03 +01004969 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004970 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004971 if w:netrw_treetop == '/'
4972 keepj call search('^\M'.curfile,"w")
4973 elseif curfile == '../'
4974 keepj call search('^\M'.curfile,"wb")
4975 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004976 while 1
4977 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
4978 let treepath= s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004979 if treepath == curpath
4980 break
4981 endif
4982 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01004983 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004984
Bram Moolenaara6878372014-03-22 21:02:50 +01004985 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004986 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004987 if exists("b:netrw_curdir")
4988 let curdir= b:netrw_curdir
4989 else
4990 let curdir= expand(getcwd())
4991 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004992 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01004993 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004994 else
Tom Benham64a536d2024-11-07 21:15:03 +01004995 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004996 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004997 call s:RestorePosn(s:netrw_posn)
4998 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01004999 let curdir= '\<'. escape(curdir, '~'). '/'
5000 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005001 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005002endfun
5003
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005004func s:redir()
5005 " set up redirection (avoids browser messages)
5006 " by default if not set, g:netrw_suppress_gx_mesg is true
5007 if get(g:, 'netrw_suppress_gx_mesg', 1)
5008 if &srr =~# "%s"
5009 return printf(&srr, has("win32") ? "nul" : "/dev/null")
5010 else
5011 return &srr .. (has("win32") ? "nul" : "/dev/null")
5012 endif
5013 endif
5014 return ''
5015endfunc
5016
5017if has('unix')
5018 if has('win32unix')
5019 " Cygwin provides cygstart
5020 if executable('cygstart')
5021 fun! netrw#Launch(args)
5022 exe 'silent ! cygstart --hide' a:args s:redir() | redraw!
5023 endfun
5024 elseif !empty($MSYSTEM) && executable('start')
5025 " MSYS2/Git Bash comes by default without cygstart; see
5026 " https://www.msys2.org/wiki/How-does-MSYS2-differ-from-Cygwin
5027 " Instead it provides /usr/bin/start script running `cmd.exe //c start`
5028 " Adding "" //b` sets void title, hides cmd window and blocks path conversion
5029 " of /b to \b\ " by MSYS2; see https://www.msys2.org/docs/filesystem-paths/
5030 fun! netrw#Launch(args)
5031 exe 'silent !start "" //b' a:args s:redir() | redraw!
5032 endfun
5033 else
5034 " imitate /usr/bin/start script for other environments and hope for the best
5035 fun! netrw#Launch(args)
5036 exe 'silent !cmd //c start "" //b' a:args s:redir() | redraw!
5037 endfun
5038 endif
5039 elseif exists('$WSL_DISTRO_NAME') " use cmd.exe to start GUI apps in WSL
5040 fun! netrw#Launch(args)
5041 let args = a:args
5042 exe 'silent !' ..
5043 \ ((args =~? '\v<\f+\.(exe|com|bat|cmd)>') ?
Konfekt460799d2024-11-14 21:42:27 +01005044 \ 'cmd.exe /c start /b ' .. args :
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005045 \ 'nohup ' .. args .. ' ' .. s:redir() .. ' &')
5046 \ | redraw!
5047 endfun
5048 else
5049 fun! netrw#Launch(args)
Konfekteda923e2024-12-04 20:12:44 +01005050 exe ':silent ! nohup' a:args s:redir() (has('gui_running') ? '' : '&') | redraw!
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005051 endfun
5052 endif
5053elseif has('win32')
5054 fun! netrw#Launch(args)
5055 exe 'silent !' .. (&shell =~? '\<cmd\.exe\>' ? '' : 'cmd.exe /c')
5056 \ 'start "" /b' a:args s:redir() | redraw!
5057 endfun
5058else
5059 fun! netrw#Launch(dummy)
5060 echom 'No common launcher found'
5061 endfun
5062endif
5063
5064" Git Bash
5065if has('win32unix')
5066 " (cyg)start suffices
5067 let s:os_viewer = ''
5068" Windows / WSL
5069elseif executable('explorer.exe')
5070 let s:os_viewer = 'explorer.exe'
5071" Linux / BSD
5072elseif executable('xdg-open')
5073 let s:os_viewer = 'xdg-open'
5074" MacOS
5075elseif executable('open')
5076 let s:os_viewer = 'open'
5077endif
5078
5079fun! s:viewer()
Christian Brabandt92b36662024-12-08 09:52:37 +01005080 " g:netrw_browsex_viewer could be a string of program + its arguments,
5081 " test if first argument is executable
5082 if exists('g:netrw_browsex_viewer') && executable(split(g:netrw_browsex_viewer)[0])
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005083 " extract any viewing options. Assumes that they're set apart by spaces.
5084 " call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
5085 if g:netrw_browsex_viewer =~ '\s'
5086 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5087 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5088 let oviewer = ''
5089 let cnt = 1
5090 while !executable(viewer) && viewer != oviewer
5091 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5092 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5093 let cnt = cnt + 1
5094 let oviewer = viewer
5095 " call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
5096 endwhile
5097 else
5098 let viewer = g:netrw_browsex_viewer
5099 let viewopt = ""
5100 endif
5101 " call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
5102 return viewer .. ' ' .. viewopt
5103 else
5104 if !exists('s:os_viewer')
5105 call netrw#ErrorMsg(s:ERROR,"No program to open this path found. See :help Open for more information.",106)
5106 else
5107 return s:os_viewer
5108 endif
5109 endif
5110endfun
5111
5112fun! netrw#Open(file) abort
5113 call netrw#Launch(s:viewer() .. ' ' .. shellescape(a:file, 1))
5114endf
5115
5116if !exists('g:netrw_regex_url')
5117 let g:netrw_regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}'
5118endif
5119
Bram Moolenaara6878372014-03-22 21:02:50 +01005120" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005121" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005122" given filename; typically this means given their extension.
5123" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005124fun! netrw#BrowseX(fname,remote)
Konfekt460799d2024-11-14 21:42:27 +01005125 if a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
Bram Moolenaar91359012019-11-30 17:57:03 +01005126 " remote directory, not a webpage access, looks like an attempt to do a directory listing
Bram Moolenaar91359012019-11-30 17:57:03 +01005127 norm! gf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005128 endif
5129
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005130 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5131 let remote = a:remote
5132 else
5133 let remote = 0
5134 endif
5135
Bram Moolenaar97d62492012-11-15 21:28:22 +01005136 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005137 let screenposn = winsaveview()
Bram Moolenaar97d62492012-11-15 21:28:22 +01005138
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005139 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5140 let awkeep = &aw
5141 set noaw
5142
Bram Moolenaar5c736222010-01-06 20:54:52 +01005143 " special core dump handler
5144 if a:fname =~ '/core\(\.\d\+\)\=$'
5145 if exists("g:Netrw_corehandler")
5146 if type(g:Netrw_corehandler) == 2
5147 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005148 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005149 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005150 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005151 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005152 if type(Fncref) == 2
5153 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005154 endif
5155 endfor
5156 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005157 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005158 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005159 let &aw= awkeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005160 return
5161 endif
5162 endif
5163
Bram Moolenaar446cb832008-06-24 21:56:24 +00005164 " set up the filename
5165 " (lower case the extension, make a local copy of a remote file)
5166 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005167 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005168 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005169 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005170 if exten =~ "[\\/]"
5171 let exten= ""
5172 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005173
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005174 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005175 " create a local copy
Bram Moolenaarff034192013-04-24 18:51:19 +02005176 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005177 call netrw#NetRead(3,a:fname)
5178 " attempt to rename tempfile
5179 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005180 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02005181 if s:netrw_tmpfile != newname && newname != ""
5182 if rename(s:netrw_tmpfile,newname) == 0
5183 " renaming succeeded
Bram Moolenaar85850f32019-07-19 22:05:51 +02005184 let fname= newname
5185 else
5186 " renaming failed
Bram Moolenaar85850f32019-07-19 22:05:51 +02005187 let fname= s:netrw_tmpfile
5188 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005189 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005190 let fname= s:netrw_tmpfile
5191 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005192 else
5193 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005194 " special ~ handler for local
5195 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005196 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005197 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005198 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005199
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005200 " although shellescape(..., 1) is used in netrw#Open(), it's insufficient
5201 call netrw#Open(escape(fname, '#%'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005202
Bram Moolenaar446cb832008-06-24 21:56:24 +00005203 " cleanup: remove temporary file,
5204 " delete current buffer if success with handler,
5205 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005206 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005207 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005208" if remote == 1 && fname != a:fname
Bram Moolenaarc236c162008-07-13 17:41:49 +00005209" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005210" endif
5211
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005212 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005213 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005214 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005215 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005216 endif
Christian Brabandt9f320692024-10-30 18:36:20 +01005217 exe "sil! NetrwKeepj norm! \<c-o>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005218 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005219 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005220 let @@ = ykeep
5221 let &aw= awkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005222endfun
5223
5224" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005225" netrw#GX: gets word under cursor for gx support {{{2
5226" See also: netrw#BrowseXVis
5227" netrw#BrowseX
5228fun! netrw#GX()
5229" call Dfunc("netrw#GX()")
5230 if &ft == "netrw"
5231 let fname= s:NetrwGetWord()
5232 else
Konfekt3d7e5672024-10-27 22:16:49 +01005233 let fname= exists("g:netrw_gx")? expand(g:netrw_gx) : s:GetURL()
Bram Moolenaar85850f32019-07-19 22:05:51 +02005234 endif
5235" call Dret("netrw#GX <".fname.">")
5236 return fname
5237endfun
5238
Konfekt3d7e5672024-10-27 22:16:49 +01005239fun! s:GetURL() abort
5240 let URL = ''
5241 if exists('*Netrw_get_URL_' .. &filetype)
5242 let URL = call('Netrw_get_URL_' .. &filetype, [])
5243 endif
5244 if !empty(URL) | return URL | endif
5245 " URLs end in letter, digit or forward slash
5246 let URL = matchstr(expand("<cWORD>"), '\<' .. g:netrw_regex_url .. '\ze[^A-Za-z0-9/]*$')
5247 if !empty(URL) | return URL | endif
5248
5249 " Is it a file in the current work dir ...
5250 let file = expand("<cfile>")
5251 if filereadable(file) | return file | endif
5252 " ... or in that of the current buffer?
5253 let path = fnamemodify(expand('%'), ':p')
5254 if isdirectory(path)
5255 let dir = path
5256 elseif filereadable(path)
5257 let dir = fnamemodify(path, ':h')
5258 endif
5259 if exists('dir') && filereadable(dir..'/'..file) | return dir..'/'..file | endif
5260
5261 return ''
5262endf
5263
Bram Moolenaar85850f32019-07-19 22:05:51 +02005264" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005265" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5266fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005267 let dict={}
5268 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005269 norm! gv"ay
5270 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005271 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005272 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005273endfun
5274
5275" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005276" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5277" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5278" to become an unlisted buffer, so in that case don't bwipe it.
5279fun! s:NetrwBufRename(newname)
5280" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5281" call Dredir("ls!","s:NetrwBufRename (before rename)")
5282 let oldbufname= bufname(bufnr("%"))
5283" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5284
5285 if oldbufname != a:newname
5286" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5287 let b:junk= 1
5288" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5289 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005290" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005291 let oldbufnr= bufnr(oldbufname)
5292" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5293" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5294 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5295" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5296 exe "bwipe! ".oldbufnr
5297" else " Decho
5298" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005299" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5300" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5301" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005302 endif
5303" call Dredir("ls!","s:NetrwBufRename (after rename)")
5304" else " Decho
5305" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5306 endif
5307
5308" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5309endfun
5310
5311" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005312" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005313fun! netrw#CheckIfRemote(...)
5314" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5315 if a:0 > 0
5316 let curfile= a:1
5317 else
5318 let curfile= expand("%")
5319 endif
5320" call Decho("curfile<".curfile.">")
5321 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005322" call Dret("netrw#CheckIfRemote 1")
5323 return 1
5324 else
5325" call Dret("netrw#CheckIfRemote 0")
5326 return 0
5327 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005328endfun
5329
5330" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005331" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5332fun! s:NetrwChgPerm(islocal,curdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005333 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005334 call inputsave()
5335 let newperm= input("Enter new permission: ")
5336 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005337 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5338 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005339 call system(chgperm)
5340 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005341 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005342 endif
5343 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01005344 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005345 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005346 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005347endfun
5348
5349" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005350" s:CheckIfKde: checks if kdeinit is running {{{2
5351" Returns 0: kdeinit not running
5352" 1: kdeinit is running
5353fun! s:CheckIfKde()
5354" call Dfunc("s:CheckIfKde()")
5355 " seems kde systems often have gnome-open due to dependencies, even though
5356 " gnome-open's subsidiary display tools are largely absent. Kde systems
5357 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5358 if !exists("s:haskdeinit")
5359 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005360 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005361 if v:shell_error
5362 let s:haskdeinit = 0
5363 endif
5364 else
5365 let s:haskdeinit= 0
5366 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005367" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005368 endif
5369
5370" call Dret("s:CheckIfKde ".s:haskdeinit)
5371 return s:haskdeinit
5372endfun
5373
5374" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005375" s:NetrwClearExplore: clear explore variables (if any) {{{2
5376fun! s:NetrwClearExplore()
5377" call Dfunc("s:NetrwClearExplore()")
5378 2match none
5379 if exists("s:explore_match") |unlet s:explore_match |endif
5380 if exists("s:explore_indx") |unlet s:explore_indx |endif
5381 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5382 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5383 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5384 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5385 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5386 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5387 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5388" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005389" call Dret("s:NetrwClearExplore")
5390endfun
5391
5392" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005393" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5394fun! s:NetrwEditBuf(bufnum)
5395" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5396 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5397" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5398 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5399 else
5400" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005401 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005402 endif
5403" call Dret("s:NetrwEditBuf")
5404endfun
5405
5406" ---------------------------------------------------------------------
5407" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5408" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5409fun! s:NetrwEditFile(cmd,opt,fname)
5410" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5411 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5412" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5413 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5414 else
5415" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005416 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5417 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5418 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005419 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5420 endif
5421" call Dret("s:NetrwEditFile")
5422endfun
5423
5424" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005425" s:NetrwExploreListUniq: {{{2
5426fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005427 " this assumes that the list is already sorted
5428 let newexplist= []
5429 for member in a:explist
5430 if !exists("uniqmember") || member != uniqmember
5431 let uniqmember = member
5432 let newexplist = newexplist + [ member ]
5433 endif
5434 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01005435 return newexplist
5436endfun
5437
5438" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005439" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5440fun! s:NetrwForceChgDir(islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005441 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005442 if a:newdir !~ '/$'
5443 " ok, looks like force is needed to get directory-style treatment
5444 if a:newdir =~ '@$'
5445 let newdir= substitute(a:newdir,'@$','/','')
5446 elseif a:newdir =~ '[*=|\\]$'
5447 let newdir= substitute(a:newdir,'.$','/','')
5448 else
5449 let newdir= a:newdir.'/'
5450 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005451 else
5452 " should already be getting treatment as a directory
5453 let newdir= a:newdir
5454 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005455 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir,0)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005456 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005457 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005458endfun
5459
5460" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005461" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005462" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5463" expr : this is the expression to follow the directory. Will use s:ComposePath()
5464" pare =1: remove the current directory from the resulting glob() filelist
5465" =0: leave the current directory in the resulting glob() filelist
5466fun! s:NetrwGlob(direntry,expr,pare)
5467" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005468 if netrw#CheckIfRemote()
5469 keepalt 1sp
5470 keepalt enew
5471 let keep_liststyle = w:netrw_liststyle
5472 let w:netrw_liststyle = s:THINLIST
5473 if s:NetrwRemoteListing() == 0
5474 keepj keepalt %s@/@@
5475 let filelist= getline(1,$)
5476 q!
5477 else
5478 " remote listing error -- leave treedict unchanged
5479 let filelist= w:netrw_treedict[a:direntry]
5480 endif
5481 let w:netrw_liststyle= keep_liststyle
5482 else
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005483 let path= s:ComposePath(fnameescape(a:direntry), a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005484 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005485 " escape [ so it is not detected as wildcard character, see :h wildcard
5486 let path= substitute(path, '[', '[[]', 'g')
5487 endif
5488 if v:version > 704 || (v:version == 704 && has("patch656"))
5489 let filelist= glob(path,0,1,1)
5490 else
5491 let filelist= glob(path,0,1)
5492 endif
5493 if a:pare
5494 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5495 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005496 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005497 return filelist
5498endfun
5499
5500" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005501" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5502fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005503 if a:newfile =~ '[/@*=|\\]$'
5504 let newfile= substitute(a:newfile,'.$','','')
5505 else
5506 let newfile= a:newfile
5507 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005508 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01005509 call s:NetrwBrowseChgDir(a:islocal,newfile,0)
Bram Moolenaarff034192013-04-24 18:51:19 +02005510 else
Tom Benham64a536d2024-11-07 21:15:03 +01005511 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile,0))
Bram Moolenaarff034192013-04-24 18:51:19 +02005512 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005513endfun
5514
5515" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005516" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5517" and switches the hiding mode. The actual hiding is done by
5518" s:NetrwListHide().
5519" g:netrw_hide= 0: show all
5520" 1: show not-hidden files
5521" 2: show hidden files only
5522fun! s:NetrwHide(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005523 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005524 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005525
5526 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005527
5528 " hide the files in the markfile list
5529 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00005530 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5531 " remove fname from hiding list
5532 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5533 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5534 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005535 else
5536 " append fname to hiding list
5537 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5538 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5539 else
5540 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5541 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005542 endif
5543 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005544 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005545 let g:netrw_hide= 1
5546
5547 else
5548
5549 " switch between show-all/show-not-hidden/show-hidden
5550 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005551 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005552 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005553 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005554 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005555 return
5556 endif
5557 endif
5558
Tom Benham64a536d2024-11-07 21:15:03 +01005559 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005560 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005561 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005562endfun
5563
5564" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005565" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5566fun! s:NetrwHideEdit(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005567 let ykeep= @@
5568 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005569 let svpos= winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005570
5571 " get new hiding list from user
5572 call inputsave()
5573 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5574 call inputrestore()
5575 let g:netrw_list_hide= newhide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005576
5577 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01005578 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./",0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005579
5580 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005581 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005582 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005583endfun
5584
5585" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005586" s:NetrwHidden: invoked by "gh" {{{2
5587fun! s:NetrwHidden(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005588 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005589 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005590 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005591
5592 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005593 " remove .file pattern from hiding list
Bram Moolenaar446cb832008-06-24 21:56:24 +00005594 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005595 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005596 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5597 else
5598 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5599 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005600 if g:netrw_list_hide =~ '^,'
5601 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5602 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005603
5604 " refresh screen and return to saved position
Tom Benham64a536d2024-11-07 21:15:03 +01005605 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005606 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005607 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005608endfun
5609
5610" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005611" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5612fun! s:NetrwHome()
5613 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005614 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005615 else
5616 " go to vim plugin home
5617 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005618 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005619 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005620 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005621 let home= basehome."/.vim"
5622 break
5623 endif
5624 endfor
5625 if home == ""
5626 " just pick the first directory
5627 let home= substitute(&rtp,',.*$','','')
5628 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005629 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005630 let home= substitute(home,'/','\\','g')
5631 endif
5632 endif
5633 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005634 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005635" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005636 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005637" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005638 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005639 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005640" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005641 call mkdir(home)
5642 endif
5643 endif
5644 let g:netrw_home= home
5645 return home
5646endfun
5647
5648" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005649" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5650fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005651 if exists("s:netrwdrag")
5652 return
5653 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005654 if &ft != "netrw"
5655 return
5656 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005657
Bram Moolenaar97d62492012-11-15 21:28:22 +01005658 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005659 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005660 while getchar(0) != 0
5661 "clear the input stream
5662 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005663 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005664 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005665 let mouse_lnum = v:mouse_lnum
5666 let wlastline = line('w$')
5667 let lastline = line('$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005668 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5669 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005670 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005671 return
5672 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005673 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005674 " 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 +01005675 " without this test when its disabled.
5676 " 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 +01005677 if v:mouse_col > virtcol('.')
5678 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005679 return
5680 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005681
Bram Moolenaar446cb832008-06-24 21:56:24 +00005682 if a:islocal
5683 if exists("b:netrw_curdir")
Tom Benham64a536d2024-11-07 21:15:03 +01005684 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005685 endif
5686 else
5687 if exists("b:netrw_curdir")
Tom Benham64a536d2024-11-07 21:15:03 +01005688 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005689 endif
5690 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005691 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005692endfun
5693
5694" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005695" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
5696fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005697 if &ft != "netrw"
5698 return
5699 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005700 call s:NetrwMarkFileTgt(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005701endfun
5702
5703" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005704" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
5705" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02005706" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005707" a:islocal=2 : <c-r> used, remote
5708" a:islocal=3 : <c-r> used, local
5709fun! s:NetrwServerEdit(islocal,fname)
5710" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
5711 let islocal = a:islocal%2 " =0: remote =1: local
5712 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
5713
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005714 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005715 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005716 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005717 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005718 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005719 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5720 unlet s:netrw_browse_split_{winnr()}
5721 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005722 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname,0))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005723 return
5724 endif
5725
5726 if has("clientserver") && executable("gvim")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005727
5728 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005729 let srvrname = g:netrw_browse_split[0]
5730 let tabnum = g:netrw_browse_split[1]
5731 let winnum = g:netrw_browse_split[2]
5732
5733 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005734 if !ctrlr
5735 " user must have closed the server window and the user did not use <c-r>, but
5736 " used something like <cr>.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005737 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09005738 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005739 endif
5740 let g:netrw_browse_split= 0
5741 if exists("s:netrw_browse_split_".winnr())
5742 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5743 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005744 call s:NetrwBrowseChgDir(islocal,a:fname,0)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005745 return
5746
5747 elseif has("win32") && executable("start")
5748 " start up remote netrw server under windows
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005749 call system("start gvim --servername ".srvrname)
5750
5751 else
5752 " start up remote netrw server under linux
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005753 call system("gvim --servername ".srvrname)
5754 endif
5755 endif
5756
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005757 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
5758 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005759 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005760 else
5761
5762 if serverlist() !~ '\<'.g:netrw_servername.'\>'
5763
5764 if !ctrlr
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005765 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09005766 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005767 endif
5768 let g:netrw_browse_split= 0
Tom Benham64a536d2024-11-07 21:15:03 +01005769 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname,0))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005770 return
5771
5772 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005773 if has("win32") && executable("start")
5774 " start up remote netrw server under windows
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005775 call system("start gvim --servername ".g:netrw_servername)
5776 else
5777 " start up remote netrw server under linux
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005778 call system("gvim --servername ".g:netrw_servername)
5779 endif
5780 endif
5781 endif
5782
5783 while 1
5784 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005785 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005786 break
5787 catch /^Vim\%((\a\+)\)\=:E241/
5788 sleep 200m
5789 endtry
5790 endwhile
5791
5792 if exists("g:netrw_browse_split")
5793 if type(g:netrw_browse_split) != 3
5794 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
5795 endif
5796 unlet g:netrw_browse_split
5797 endif
5798 let g:netrw_browse_split= [g:netrw_servername,1,1]
5799 endif
5800
5801 else
5802 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
5803 endif
5804
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005805endfun
5806
5807" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005808" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
5809fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005810 if &ft != "netrw"
5811 return
5812 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005813" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005814
Bram Moolenaar8d043172014-01-23 14:24:41 +01005815 let s:ngw= s:NetrwGetWord()
5816 call s:NetrwMarkFile(a:islocal,s:ngw)
5817
5818" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02005819endfun
5820
5821" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005822" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
5823" Used to mark multiple files.
5824fun! s:NetrwSLeftdrag(islocal)
5825" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
5826 if !exists("s:netrwdrag")
5827 let s:netrwdrag = winnr()
5828 if a:islocal
5829 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005830 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01005831 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005832 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005833 endif
5834 let ngw = s:NetrwGetWord()
5835 if !exists("s:ngw") || s:ngw != ngw
5836 call s:NetrwMarkFile(a:islocal,ngw)
5837 endif
5838 let s:ngw= ngw
5839" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5840endfun
5841
5842" ---------------------------------------------------------------------
5843" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
5844fun! s:NetrwSLeftrelease(islocal)
5845" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5846 if exists("s:netrwdrag")
5847 nunmap <s-leftrelease>
5848 let ngw = s:NetrwGetWord()
5849 if !exists("s:ngw") || s:ngw != ngw
5850 call s:NetrwMarkFile(a:islocal,ngw)
5851 endif
5852 if exists("s:ngw")
5853 unlet s:ngw
5854 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005855 unlet s:netrwdrag
5856 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005857" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02005858endfun
5859
5860" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01005861" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
5862" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00005863fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005864" 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 +02005865" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005866 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005867
5868 " 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 +02005869 " How-it-works: take the hiding command, convert it into a range.
5870 " Duplicate characters don't matter.
5871 " Remove all such characters from the '/~@#...890' string.
5872 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005873" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005874 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01005875 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005876" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005877
5878 while listhide != ""
5879 if listhide =~ ','
5880 let hide = substitute(listhide,',.*$','','e')
5881 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
5882 else
5883 let hide = listhide
5884 let listhide = ""
5885 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005886" 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 +01005887 if g:netrw_sort_by =~ '^[ts]'
5888 if hide =~ '^\^'
5889" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
5890 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
5891 elseif hide =~ '^\\(\^'
5892 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
5893 endif
5894" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
5895 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005896
5897 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005898" 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 +00005899 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005900" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005901 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005902 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005903" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005904 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005905 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005906" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005907 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02005908
Bram Moolenaar446cb832008-06-24 21:56:24 +00005909 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005910 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005911" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005912 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005913" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005914 endif
5915
Bram Moolenaaradc21822011-04-01 18:03:16 +02005916 " remove any blank lines that have somehow remained.
5917 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005918 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02005919
Bram Moolenaar97d62492012-11-15 21:28:22 +01005920 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005921" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005922endfun
5923
5924" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005925" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005926" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005927fun! s:NetrwMakeDir(usrhost)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005928
Bram Moolenaar97d62492012-11-15 21:28:22 +01005929 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005930 " get name of new directory from user. A bare <CR> will skip.
5931 " if its currently a directory, also request will be skipped, but with
5932 " a message.
5933 call inputsave()
5934 let newdirname= input("Please give directory name: ")
5935 call inputrestore()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005936
5937 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01005938 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005939 return
5940 endif
5941
5942 if a:usrhost == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005943
5944 " Local mkdir:
5945 " sanity checks
5946 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005947 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005948 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005949 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005950 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005951 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005952 return
5953 endif
5954 if s:FileReadable(fullnewdir)
5955 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005956 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005957 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005958 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005959 return
5960 endif
5961
5962 " requested new local directory is neither a pre-existing file or
5963 " directory, so make it!
5964 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005965 if has("unix")
5966 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
5967 else
5968 call mkdir(fullnewdir,"p")
5969 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005970 else
5971 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005972 if s:NetrwLcd(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005973 return
5974 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005975 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005976 if v:shell_error != 0
5977 let @@= ykeep
5978 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 +01005979 return
5980 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005981 if !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02005982 if s:NetrwLcd(netrw_origdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005983 return
5984 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005985 endif
5986 endif
5987
5988 if v:shell_error == 0
5989 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005990 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01005991 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005992 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005993 elseif !exists("g:netrw_quiet")
5994 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
5995 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005996
5997 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01005998 " Remote mkdir: using ssh
Bram Moolenaar446cb832008-06-24 21:56:24 +00005999 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6000 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006001 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006002 if v:shell_error == 0
6003 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006004 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01006005 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006006 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006007 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006008 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006009 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006010
6011 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006012 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006013 let svpos= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01006014 if exists("b:netrw_fname")
Bram Moolenaara6878372014-03-22 21:02:50 +01006015 let remotepath= b:netrw_fname
6016 else
6017 let remotepath= ""
6018 endif
6019 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Tom Benham64a536d2024-11-07 21:15:03 +01006020 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006021 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006022
Bram Moolenaar446cb832008-06-24 21:56:24 +00006023 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006024 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006025 let svpos= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01006026 if exists("b:netrw_fname")
Bram Moolenaara6878372014-03-22 21:02:50 +01006027 let remotepath= b:netrw_fname
6028 else
6029 let remotepath= ""
6030 endif
6031 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Tom Benham64a536d2024-11-07 21:15:03 +01006032 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006033 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006034 endif
6035
Bram Moolenaar97d62492012-11-15 21:28:22 +01006036 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006037endfun
6038
6039" ---------------------------------------------------------------------
6040" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6041fun! s:TreeSqueezeDir(islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01006042 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6043 " its a tree-listing style
6044 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006045 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006046 let depth = strchars(substitute(curdepth,' ','','g'))
6047 let srch = -1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006048 if depth >= 2
6049 NetrwKeepj norm! 0
6050 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6051 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006052 elseif depth == 1
6053 NetrwKeepj norm! 0
6054 let treedepthchr= substitute(s:treedepthstring,' ','','')
6055 let srch = search('^[^'.treedepthchr.']','bW',stopline)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006056 endif
6057 if srch > 0
Tom Benham64a536d2024-11-07 21:15:03 +01006058 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord(),1))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006059 exe srch
6060 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006061 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006062endfun
6063
6064" ---------------------------------------------------------------------
6065" s:NetrwMaps: {{{2
6066fun! s:NetrwMaps(islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01006067
Bram Moolenaar85850f32019-07-19 22:05:51 +02006068 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006069 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006070" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006071 if !hasmapto("<Plug>NetrwReturn")
6072 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006073 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6074 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006075 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6076 endif
6077 endif
6078 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006079 endif
6080
Bram Moolenaar85850f32019-07-19 22:05:51 +02006081 " generate default <Plug> maps {{{3
6082 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006083 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006084 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6085 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6086 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6087 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6088 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6089 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6090 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6091 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6092 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6093 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006094
Bram Moolenaara6878372014-03-22 21:02:50 +01006095 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02006096 " local normal-mode maps {{{3
6097 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6098 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6099 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6100 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6101 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6102 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6103 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006104 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006105 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6106 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6107 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6108" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006109 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6110 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6111 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006112 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006113 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006114 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6115 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6116 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6117 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006118 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6119 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6120 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6121 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6122 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6123 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6124 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6125 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6126 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6127 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6128 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6129 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6130 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006131 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006132 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006133 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6134 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6135 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6136 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6137 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006138 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006139 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006140 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 +01006141 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006142 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6143 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6144 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006145 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006146 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006147 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6148 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006149 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006150 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006151 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6152 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6153 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006154 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 +01006155 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006156
Tom Benham64a536d2024-11-07 21:15:03 +01006157 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 +01006158 if !hasmapto('<Plug>NetrwHideEdit')
6159 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006160 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006161 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006162 if !hasmapto('<Plug>NetrwRefresh')
6163 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006164 endif
Tom Benham64a536d2024-11-07 21:15:03 +01006165 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 +01006166 if s:didstarstar || !mapcheck("<s-down>","n")
6167 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006168 endif
6169 if s:didstarstar || !mapcheck("<s-up>","n")
6170 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006171 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006172 if !hasmapto('<Plug>NetrwTreeSqueeze')
6173 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006174 endif
6175 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006176 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6177 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006178 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6179 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6180 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6181 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6182 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6183 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6184 imap <buffer> <leftmouse> <Plug>ILeftmouse
6185 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006186 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6187 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6188 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6189 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6190 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006191 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006192 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6193 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006194 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006195 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6196 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6197 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6198 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6199 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6200 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6201 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006202 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6203
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006204 " support user-specified maps
6205 call netrw#UserMaps(1)
6206
Bram Moolenaar85850f32019-07-19 22:05:51 +02006207 else
6208 " remote normal-mode maps {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006209 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006210 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6211 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6212 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6213 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6214 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6215 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6216 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006217 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./',0))<cr>
6218 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 +02006219 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6220 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6221" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006222 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6223 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6224 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6225 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6226 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6227 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6228 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6229 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006230 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006231 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006232 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6233 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6234 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6235 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6236 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6237 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6238 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6239 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6240 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6241 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6242 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006243 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006244 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006245 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6246 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6247 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6248 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6249 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006250 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6251 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006252 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 +01006253 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006254 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006255 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6256 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006257 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006258 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 +01006259 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6260 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6261 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6262 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6263 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6264 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6265 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6266 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006267 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord(),1),1)<cr>
Konfekt3d7e5672024-10-27 22:16:49 +01006268 nmap <buffer> <nowait> gx x
Bram Moolenaara6878372014-03-22 21:02:50 +01006269 if !hasmapto('<Plug>NetrwHideEdit')
6270 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006271 endif
6272 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6273 if !hasmapto('<Plug>NetrwRefresh')
6274 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006275 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006276 if !hasmapto('<Plug>NetrwTreeSqueeze')
6277 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006278 endif
6279 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006280
6281 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006282 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006283
Tom Benham64a536d2024-11-07 21:15:03 +01006284 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./',0))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006285 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006286 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006287 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006288 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006289 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006290 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006291 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006292 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006293 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006294 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006295 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006296 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6297 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6298 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006299 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006300 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006301 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6302 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006303 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006304 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6305 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6306 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6307 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6308 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6309 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6310 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006311 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006312
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006313 " support user-specified maps
6314 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006315 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006316endfun
6317
6318" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006319" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006320" If -buffer, the command is only available from within netrw buffers
6321" Otherwise, the command is available from any window, so long as netrw
6322" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006323fun! s:NetrwCommands(islocal)
6324" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6325
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006326 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6327 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006328 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 +01006329 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006330 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006331 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006332 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006333 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006334 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006335
6336" call Dret("s:NetrwCommands")
6337endfun
6338
6339" ---------------------------------------------------------------------
6340" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6341" glob()ing only works with local files
6342fun! s:NetrwMarkFiles(islocal,...)
6343" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006344 let curdir = s:NetrwGetCurdir(a:islocal)
6345 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006346 while i <= a:0
6347 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006348 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006349 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006350 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006351 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006352 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006353 else
6354 let mffiles= [a:{i}]
6355 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006356" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006357 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006358" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006359 call s:NetrwMarkFile(a:islocal,mffile)
6360 endfor
6361 let i= i + 1
6362 endwhile
6363" call Dret("s:NetrwMarkFiles")
6364endfun
6365
6366" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006367" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006368fun! s:NetrwMarkTarget(...)
Bram Moolenaara6878372014-03-22 21:02:50 +01006369 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006370 let curdir = s:NetrwGetCurdir(1)
6371 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006372 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006373 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6374 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006375 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006376 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006377 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6378 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006379 let svpos = winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01006380 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006381 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006382endfun
6383
6384" ---------------------------------------------------------------------
6385" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6386" mark and unmark files. If a markfile list exists,
6387" then the rename and delete functions will use it instead
6388" of whatever may happen to be under the cursor at that
6389" moment. When the mouse and gui are available,
6390" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006391"
6392" Creates two lists
6393" s:netrwmarkfilelist -- holds complete paths to all marked files
6394" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6395"
6396" Creates a marked file match string
6397" s:netrwmarfilemtch_# -- used with 2match to display marked files
6398"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006399" Creates a buffer version of islocal
6400" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006401fun! s:NetrwMarkFile(islocal,fname)
6402" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006403" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006404
6405 " sanity check
6406 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006407" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006408 return
6409 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006410 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006411
Bram Moolenaar97d62492012-11-15 21:28:22 +01006412 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006413 let curbufnr= bufnr("%")
yasudac18a9d52024-09-19 18:09:51 +02006414 let leader= '\%(^\|\s\)\zs'
Bram Moolenaara6878372014-03-22 21:02:50 +01006415 if a:fname =~ '\a$'
6416 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6417 else
6418 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6419 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006420
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006421 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006422 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006423" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6424" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6425" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006426 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006427
6428 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006429 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006430" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006431 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006432 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006433
6434 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006435 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006436" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006437 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6438 if s:netrwmarkfilelist_{curbufnr} == []
6439 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006440" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006441 call s:NetrwUnmarkList(curbufnr,curdir)
6442 else
6443 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006444" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006445 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006446 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006447 for fname in s:netrwmarkfilelist_{curbufnr}
6448 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006449 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006450 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006451 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006452 endif
6453 let first= 0
6454 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006455" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006456 endif
6457 endif
6458
6459 else
6460 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006461" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006462
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006463" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006464 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006465 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6466" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006467
6468 " build initial markfile matching pattern
6469 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006470 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006471 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006472 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006473 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006474" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006475 endif
6476
6477 " handle global markfilelist
6478 if exists("s:netrwmarkfilelist")
6479 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6480 if index(s:netrwmarkfilelist,dname) == -1
6481 " append new filename to global markfilelist
6482 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006483" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006484 else
6485 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006486" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6487" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006488 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006489" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006490 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006491" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006492 unlet s:netrwmarkfilelist
6493 endif
6494 endif
6495 else
6496 " initialize new global-directory markfilelist
6497 let s:netrwmarkfilelist= []
6498 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006499" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006500 endif
6501
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006502 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006503 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6504 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6505" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6506 if exists("g:did_drchip_netrwlist_syntax")
6507 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6508 endif
6509 else
6510" " call Decho("2match none",'~'.expand("<slnum>"))
6511 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006512 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006513 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006514 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006515" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6516" 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 +00006517endfun
6518
6519" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006520" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6521" mA: move the argument list to marked file list (tomflist=1)
6522" Uses the global marked file list
6523fun! s:NetrwMarkFileArgList(islocal,tomflist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006524 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006525 let curdir = s:NetrwGetCurdir(a:islocal)
6526 let curbufnr = bufnr("%")
6527
6528 if a:tomflist
6529 " mA: move argument list to marked file list
6530 while argc()
6531 let fname= argv(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006532 exe "argdel ".fnameescape(fname)
6533 call s:NetrwMarkFile(a:islocal,fname)
6534 endwhile
6535
6536 else
6537 " ma: move marked file list to argument list
6538 if exists("s:netrwmarkfilelist")
6539
6540 " for every filename in the marked list
6541 for fname in s:netrwmarkfilelist
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006542 exe "argadd ".fnameescape(fname)
6543 endfor " for every file in the marked list
6544
6545 " unmark list and refresh
6546 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01006547 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006548 NetrwKeepj call winrestview(svpos)
6549 endif
6550 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006551endfun
6552
6553" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006554" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
6555" compress/decompress files using the programs
6556" in g:netrw_compress and g:netrw_uncompress,
6557" using g:netrw_compress_suffix to know which to
6558" do. By default:
6559" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006560" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00006561fun! s:NetrwMarkFileCompress(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006562 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006563 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006564 let curbufnr = bufnr("%")
6565
Bram Moolenaarff034192013-04-24 18:51:19 +02006566 " sanity check
6567 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006568 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006569 return
6570 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006571
Bram Moolenaar446cb832008-06-24 21:56:24 +00006572 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02006573
6574 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00006575 for fname in s:netrwmarkfilelist_{curbufnr}
Christian Brabandtcacfccf2024-11-23 13:28:01 +01006576 let sfx= substitute(fname,'^.\{-}\(\.[[:alnum:]]\+\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02006577 if exists("g:netrw_decompress['".sfx."']")
6578 " fname has a suffix indicating that its compressed; apply associated decompression routine
6579 let exe= g:netrw_decompress[sfx]
Bram Moolenaarff034192013-04-24 18:51:19 +02006580 let exe= netrw#WinPath(exe)
6581 if a:islocal
6582 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006583 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006584 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006585 call system(exe." ".fname)
6586 if v:shell_error
6587 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01006588 endif
6589 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006590 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
6591 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01006592 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006593
Bram Moolenaarff034192013-04-24 18:51:19 +02006594 endif
6595 unlet sfx
6596
Bram Moolenaar446cb832008-06-24 21:56:24 +00006597 if exists("exe")
6598 unlet exe
6599 elseif a:islocal
6600 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006601 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006602 if v:shell_error
6603 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
6604 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006605 else
6606 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006607 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006608 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006609 endfor " for every file in the marked list
6610
Bram Moolenaar446cb832008-06-24 21:56:24 +00006611 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01006612 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006613 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006614 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006615endfun
6616
6617" ---------------------------------------------------------------------
6618" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
6619" If no marked files, then set up directory as the
6620" target. Currently does not support copying entire
6621" directories. Uses the local-buffer marked file list.
6622" Returns 1=success (used by NetrwMarkFileMove())
6623" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006624fun! s:NetrwMarkFileCopy(islocal,...)
6625" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
6626
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006627 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006628 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006629 if b:netrw_curdir !~ '/$'
6630 if !exists("b:netrw_curdir")
6631 let b:netrw_curdir= curdir
6632 endif
6633 let b:netrw_curdir= b:netrw_curdir."/"
6634 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006635
Bram Moolenaarff034192013-04-24 18:51:19 +02006636 " sanity check
6637 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006638 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006639" call Dret("s:NetrwMarkFileCopy")
6640 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006641 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006642" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006643
Bram Moolenaar446cb832008-06-24 21:56:24 +00006644 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006645 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006646" call Dret("s:NetrwMarkFileCopy 0")
6647 return 0
6648 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006649" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006650
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006651 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006652 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006653" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006654 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006655 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
6656" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
6657 return
6658 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006659
6660 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02006661 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006662 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
6663 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006664" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006665 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006666 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
6667 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006668" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006669 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006670 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006671 let oldname = a:1
6672 else
6673 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006674" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006675 let s:recursive= 1
6676 for oldname in s:netrwmarkfilelist_{bufnr("%")}
6677 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
6678 if ret == 0
6679 break
6680 endif
6681 endfor
6682 unlet s:recursive
6683 call s:NetrwUnmarkList(curbufnr,curdir)
6684" call Dret("s:NetrwMarkFileCopy ".ret)
6685 return ret
6686 endif
6687
6688 call inputsave()
6689 let newname= input("Copy ".oldname." to : ",oldname,"file")
6690 call inputrestore()
6691 if newname == ""
6692" call Dret("s:NetrwMarkFileCopy 0")
6693 return 0
6694 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006695 let args= s:ShellEscape(oldname)
6696 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006697 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006698 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
6699 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006700 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02006701 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02006702 let args= substitute(args,'/','\\','g')
6703 let tgt = substitute(tgt, '/','\\','g')
6704 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006705 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
6706 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
6707 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
6708 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
6709" call Decho("args <".args.">",'~'.expand("<slnum>"))
6710" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006711 if isdirectory(s:NetrwFile(args))
6712" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006713 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006714" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02006715 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006716 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
6717 " contents to a target. One must append the source directory name to the target to get xcopy to
6718 " do the right thing.
6719 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006720" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006721 endif
6722 else
6723 let copycmd= g:netrw_localcopycmd
6724 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006725 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006726 let copycmd = substitute(copycmd,'\s.*$','','')
6727 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02006728 let copycmd = netrw#WinPath(copycmd).copycmdargs
6729 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006730 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02006731 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006732" call Decho("args <".args.">",'~'.expand("<slnum>"))
6733" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
6734" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
6735" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006736 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01006737 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02006738 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02006739 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 +01006740 else
6741 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
6742 endif
6743" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006744 return 0
6745 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006746
6747 elseif a:islocal && !s:netrwmftgt_islocal
6748 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006749" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006750 NetrwKeepj call s:NetrwUpload(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 local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006754" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006755 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006756
6757 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006758 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006759" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006760 let curdir = getcwd()
6761 let tmpdir = s:GetTempfile("")
6762 if tmpdir !~ '/'
6763 let tmpdir= curdir."/".tmpdir
6764 endif
6765 if exists("*mkdir")
6766 call mkdir(tmpdir)
6767 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006768 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006769 if v:shell_error != 0
6770 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 +01006771" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01006772 return
6773 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006774 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006775 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006776 if s:NetrwLcd(tmpdir)
6777" call Dret("s:NetrwMarkFileCopy : lcd failure")
6778 return
6779 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006780 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006781 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006782 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006783 if getcwd() == tmpdir
6784 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006785 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006786 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02006787 if s:NetrwLcd(curdir)
6788" call Dret("s:NetrwMarkFileCopy : lcd failure")
6789 return
6790 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01006791 if delete(tmpdir,"d")
6792 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006793 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006794 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006795 if s:NetrwLcd(curdir)
6796" call Dret("s:NetrwMarkFileCopy : lcd failure")
6797 return
6798 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006799 endif
6800 endif
6801 endif
6802
6803 " -------
6804 " cleanup
6805 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006806" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006807 " remove markings from local buffer
6808 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006809" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
6810" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
6811" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
6812" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
6813" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
6814" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
6815 if exists("s:recursive")
6816" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
6817 else
6818" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006819 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006820 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01006821 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006822 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006823 else
6824 " refresh local and targets for fast browsing
6825 if !exists("s:recursive")
6826 " remove markings from local buffer
6827" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
6828 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
6829 endif
6830
6831 " refresh buffers
6832 if s:netrwmftgt_islocal
6833" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
6834 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
6835 endif
6836 if a:islocal && s:netrwmftgt != curdir
6837" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
6838 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
6839 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01006840 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006841
Bram Moolenaar446cb832008-06-24 21:56:24 +00006842" call Dret("s:NetrwMarkFileCopy 1")
6843 return 1
6844endfun
6845
6846" ---------------------------------------------------------------------
6847" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
6848" invoke vim's diff mode on the marked files.
6849" Either two or three files can be so handled.
6850" Uses the global marked file list.
6851fun! s:NetrwMarkFileDiff(islocal)
6852" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6853 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006854
Bram Moolenaarff034192013-04-24 18:51:19 +02006855 " sanity check
6856 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006857 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006858" call Dret("s:NetrwMarkFileDiff")
6859 return
6860 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006861 let curdir= s:NetrwGetCurdir(a:islocal)
6862" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006863
Bram Moolenaara6878372014-03-22 21:02:50 +01006864 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006865 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00006866 for fname in s:netrwmarkfilelist
6867 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006868 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006869" call Decho("diffthis: fname<".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 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09006873 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006874" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006875 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006876 diffthis
6877 else
6878 break
6879 endif
6880 endfor
6881 call s:NetrwUnmarkList(curbufnr,curdir)
6882 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006883
Bram Moolenaar446cb832008-06-24 21:56:24 +00006884" call Dret("s:NetrwMarkFileDiff")
6885endfun
6886
6887" ---------------------------------------------------------------------
6888" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
6889" Uses global markfilelist
6890fun! s:NetrwMarkFileEdit(islocal)
6891" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
6892
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006893 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006894 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02006895
6896 " sanity check
6897 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006898 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006899" call Dret("s:NetrwMarkFileEdit")
6900 return
6901 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006902" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006903
Bram Moolenaar446cb832008-06-24 21:56:24 +00006904 if exists("s:netrwmarkfilelist_{curbufnr}")
6905 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006906 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006907 " unmark markedfile list
6908" call s:NetrwUnmarkList(curbufnr,curdir)
6909 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006910" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02006911 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00006912 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006913 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006914
Bram Moolenaar446cb832008-06-24 21:56:24 +00006915" call Dret("s:NetrwMarkFileEdit")
6916endfun
6917
6918" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006919" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02006920fun! s:NetrwMarkFileQFEL(islocal,qfel)
6921" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
6922 call s:NetrwUnmarkAll()
6923 let curbufnr= bufnr("%")
6924
6925 if !empty(a:qfel)
6926 for entry in a:qfel
6927 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006928" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006929 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006930" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006931 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
6932 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
6933 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
6934 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006935" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006936 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
6937 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006938" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006939 endif
6940 endfor
6941 echo "(use me to edit marked files)"
6942 else
6943 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
6944 endif
6945
6946" call Dret("s:NetrwMarkFileQFEL")
6947endfun
6948
6949" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006950" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
6951" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
6952" mX enbloc=1: Uses the global marked-file list, applies command to entire list
6953fun! s:NetrwMarkFileExe(islocal,enbloc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006954 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006955 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006956 let curbufnr = bufnr("%")
6957
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006958 if a:enbloc == 0
6959 " individually apply command to files, one at a time
6960 " sanity check
6961 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6962 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006963 return
6964 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006965
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006966 if exists("s:netrwmarkfilelist_{curbufnr}")
6967 " get the command
6968 call inputsave()
6969 let cmd= input("Enter command: ","","file")
6970 call inputrestore()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006971 if cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006972 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006973 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006974
6975 " apply command to marked files, individually. Substitute: filename -> %
6976 " If no %, then append a space and the filename to the command
6977 for fname in s:netrwmarkfilelist_{curbufnr}
6978 if a:islocal
6979 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09006980 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006981 endif
6982 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006983 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006984 endif
6985 if cmd =~ '%'
6986 let xcmd= substitute(cmd,'%',fname,'g')
6987 else
6988 let xcmd= cmd.' '.fname
6989 endif
6990 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006991 let ret= system(xcmd)
6992 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006993 let ret= s:RemoteSystem(xcmd)
6994 endif
6995 if v:shell_error < 0
6996 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
6997 break
6998 else
yasudac75dad02024-08-22 21:06:32 +02006999 if ret !=# ''
7000 echo "\n"
7001 " skip trailing new line
7002 echo ret[0:-2]
7003 else
7004 echo ret
7005 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007006 endif
7007 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007008
7009 " unmark marked file list
7010 call s:NetrwUnmarkList(curbufnr,curdir)
7011
7012 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007013 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007014 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007015 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007016 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007017 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007018
7019 else " apply command to global list of files, en bloc
7020
7021 call inputsave()
7022 let cmd= input("Enter command: ","","file")
7023 call inputrestore()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007024 if cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007025 return
7026 endif
7027 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007028 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007029 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007030 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007031 endif
7032 if a:islocal
7033 call system(cmd)
7034 if v:shell_error < 0
7035 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7036 endif
7037 else
7038 let ret= s:RemoteSystem(cmd)
7039 endif
7040 call s:NetrwUnmarkAll()
7041
7042 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007043 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007044 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007045
7046 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007047endfun
7048
7049" ---------------------------------------------------------------------
7050" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7051" as the marked file(s) (toggles suffix presence)
7052" Uses the local marked file list.
7053fun! s:NetrwMarkHideSfx(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007054 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007055 let curbufnr = bufnr("%")
7056
7057 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7058 if exists("s:netrwmarkfilelist_{curbufnr}")
7059
7060 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007061 " construct suffix pattern
7062 if fname =~ '\.'
7063 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7064 else
7065 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7066 endif
7067 " determine if its in the hiding list or not
7068 let inhidelist= 0
7069 if g:netrw_list_hide != ""
7070 let itemnum = 0
7071 let hidelist= split(g:netrw_list_hide,',')
7072 for hidepat in hidelist
7073 if sfxpat == hidepat
7074 let inhidelist= 1
7075 break
7076 endif
7077 let itemnum= itemnum + 1
7078 endfor
7079 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007080 if inhidelist
7081 " remove sfxpat from list
7082 call remove(hidelist,itemnum)
7083 let g:netrw_list_hide= join(hidelist,",")
7084 elseif g:netrw_list_hide != ""
7085 " append sfxpat to non-empty list
7086 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7087 else
7088 " set hiding list to sfxpat
7089 let g:netrw_list_hide= sfxpat
7090 endif
7091 endfor
7092
7093 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007094 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007095 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007096 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007097 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007098 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007099endfun
7100
7101" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007102" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007103" Uses the local marked-file list.
7104fun! s:NetrwMarkFileVimCmd(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007105 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007106 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007107 let curbufnr = bufnr("%")
7108
Bram Moolenaarff034192013-04-24 18:51:19 +02007109 " sanity check
7110 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007111 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007112 return
7113 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007114
Bram Moolenaar15146672011-10-20 22:22:38 +02007115 if exists("s:netrwmarkfilelist_{curbufnr}")
7116 " get the command
7117 call inputsave()
7118 let cmd= input("Enter vim command: ","","file")
7119 call inputrestore()
Bram Moolenaar15146672011-10-20 22:22:38 +02007120 if cmd == ""
Bram Moolenaar15146672011-10-20 22:22:38 +02007121 return
7122 endif
7123
7124 " apply command to marked files. Substitute: filename -> %
7125 " If no %, then append a space and the filename to the command
7126 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar15146672011-10-20 22:22:38 +02007127 if a:islocal
7128 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007129 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaar15146672011-10-20 22:22:38 +02007130 exe cmd
7131 exe "sil! keepalt wq!"
7132 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007133 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007134 endif
7135 endfor
7136
7137 " unmark marked file list
7138 call s:NetrwUnmarkList(curbufnr,curdir)
7139
7140 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007141 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007142 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007143 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007144 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007145 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007146endfun
7147
7148" ---------------------------------------------------------------------
7149" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7150" as the marked file(s) (toggles suffix presence)
7151" Uses the local marked file list.
7152fun! s:NetrwMarkHideSfx(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007153 let svpos = winsaveview()
Bram Moolenaar15146672011-10-20 22:22:38 +02007154 let curbufnr = bufnr("%")
7155
7156 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7157 if exists("s:netrwmarkfilelist_{curbufnr}")
7158
7159 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar15146672011-10-20 22:22:38 +02007160 " construct suffix pattern
7161 if fname =~ '\.'
7162 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7163 else
7164 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7165 endif
7166 " determine if its in the hiding list or not
7167 let inhidelist= 0
7168 if g:netrw_list_hide != ""
7169 let itemnum = 0
7170 let hidelist= split(g:netrw_list_hide,',')
7171 for hidepat in hidelist
7172 if sfxpat == hidepat
7173 let inhidelist= 1
7174 break
7175 endif
7176 let itemnum= itemnum + 1
7177 endfor
7178 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007179 if inhidelist
7180 " remove sfxpat from list
7181 call remove(hidelist,itemnum)
7182 let g:netrw_list_hide= join(hidelist,",")
7183 elseif g:netrw_list_hide != ""
7184 " append sfxpat to non-empty list
7185 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7186 else
7187 " set hiding list to sfxpat
7188 let g:netrw_list_hide= sfxpat
7189 endif
7190 endfor
7191
7192 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007193 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007194 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007195 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007196 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007197 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007198endfun
7199
7200" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007201" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7202" Uses the global markfilelist
7203fun! s:NetrwMarkFileGrep(islocal)
7204" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007205 let svpos = winsaveview()
7206" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007207 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007208 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007209
7210 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007211" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007212 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007213" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007214 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007215 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007216" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007217 let netrwmarkfilelist= "*"
7218 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007219
Bram Moolenaarff034192013-04-24 18:51:19 +02007220 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007221" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007222 call inputsave()
7223 let pat= input("Enter pattern: ","")
7224 call inputrestore()
7225 let patbang = ""
7226 if pat =~ '^!'
7227 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007228 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007229 endif
7230 if pat =~ '^\i'
7231 let pat = escape(pat,'/')
7232 let pat = '/'.pat.'/'
7233 else
7234 let nonisi = pat[0]
7235 endif
7236
7237 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007238" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007239 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007240 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007241 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007242 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007243" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7244 return
7245 endtry
7246 echo "(use :cn, :cp to navigate, :Rex to return)"
7247
7248 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007249" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7250 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007251
7252 if exists("nonisi")
7253 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007254" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007255 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007256 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007257 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007258 endif
7259
7260" call Dret("s:NetrwMarkFileGrep")
7261endfun
7262
7263" ---------------------------------------------------------------------
7264" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7265" uses the global marked file list
7266" s:netrwmfloc= 0: target directory is remote
7267" = 1: target directory is local
7268fun! s:NetrwMarkFileMove(islocal)
7269" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007270 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007271 let curbufnr = bufnr("%")
7272
7273 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007274 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007275 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007276" call Dret("s:NetrwMarkFileMove")
7277 return
7278 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007279" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007280
Bram Moolenaar446cb832008-06-24 21:56:24 +00007281 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007282 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007283" call Dret("s:NetrwMarkFileCopy 0")
7284 return 0
7285 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007286" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007287
7288 if a:islocal && s:netrwmftgt_islocal
7289 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007290" call Decho("move from local to local",'~'.expand("<slnum>"))
7291" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007292 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007293 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7294" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7295 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007296 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007297 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007298" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007299 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007300 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007301" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007302 if g:netrw_localmovecmd =~ '\s'
7303 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7304 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7305 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007306" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007307 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007308 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007309" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007310 endif
7311 else
7312 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007313" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007314 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007315 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007316 if g:netrw_keepdir
7317 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7318 let fname= b:netrw_curdir."/".fname
7319 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007320 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007321 let fname= substitute(fname,'/','\\','g')
7322 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007323" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007324 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007325 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007326 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007327 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 +01007328 else
7329 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7330 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007331 break
7332 endif
7333 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007334
7335 elseif a:islocal && !s:netrwmftgt_islocal
7336 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007337" call Decho("move from local to remote",'~'.expand("<slnum>"))
7338" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007339 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007340 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007341" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007342 for fname in mflist
7343 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7344 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7345 endfor
7346 unlet mflist
7347
7348 elseif !a:islocal && s:netrwmftgt_islocal
7349 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007350" call Decho("move from remote to local",'~'.expand("<slnum>"))
7351" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007352 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007353 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007354" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007355 for fname in mflist
7356 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7357 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7358 endfor
7359 unlet mflist
7360
7361 elseif !a:islocal && !s:netrwmftgt_islocal
7362 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007363" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7364" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007365 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007366 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007367" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007368 for fname in mflist
7369 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7370 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7371 endfor
7372 unlet mflist
7373 endif
7374
7375 " -------
7376 " cleanup
7377 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007378" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007379
7380 " remove markings from local buffer
7381 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7382
7383 " refresh buffers
7384 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007385" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007386 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007387 endif
7388 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007389" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007390 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007391 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007392 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007393" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007394 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007395 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007396
Bram Moolenaar446cb832008-06-24 21:56:24 +00007397" call Dret("s:NetrwMarkFileMove")
7398endfun
7399
7400" ---------------------------------------------------------------------
7401" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7402" using the hardcopy command. Local marked-file list only.
7403fun! s:NetrwMarkFilePrint(islocal)
7404" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7405 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007406
7407 " sanity check
7408 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007409 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007410" call Dret("s:NetrwMarkFilePrint")
7411 return
7412 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007413" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7414 let curdir= s:NetrwGetCurdir(a:islocal)
7415
Bram Moolenaar446cb832008-06-24 21:56:24 +00007416 if exists("s:netrwmarkfilelist_{curbufnr}")
7417 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007418 call s:NetrwUnmarkList(curbufnr,curdir)
7419 for fname in netrwmarkfilelist
7420 if a:islocal
7421 if g:netrw_keepdir
7422 let fname= s:ComposePath(curdir,fname)
7423 endif
7424 else
7425 let fname= curdir.fname
7426 endif
7427 1split
7428 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007429" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007430 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007431" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007432 hardcopy
7433 q
7434 endfor
7435 2match none
7436 endif
7437" call Dret("s:NetrwMarkFilePrint")
7438endfun
7439
7440" ---------------------------------------------------------------------
7441" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7442" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007443" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007444fun! s:NetrwMarkFileRegexp(islocal)
7445" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7446
7447 " get the regular expression
7448 call inputsave()
7449 let regexp= input("Enter regexp: ","","file")
7450 call inputrestore()
7451
7452 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007453 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007454" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007455 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007456" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007457 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007458 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007459 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007460 else
7461 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007462 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007463 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007464" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007465
7466 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007467 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007468 if fname =~ '^'.fnameescape(curdir)
7469" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7470 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7471 else
7472" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7473 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7474 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007475 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007476
7477 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007478" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007479
7480 " convert displayed listing into a filelist
7481 let eikeep = &ei
7482 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007483 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007484 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007485" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007486 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007487 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02007488 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007489 sil NetrwKeepj norm! "ap
7490 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007491 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007492 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007493 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007494 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007495 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007496 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007497 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007498 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007499 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007500 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007501 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7502 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007503 call histdel("/",-1)
7504 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007505 endif
7506 " convert regexp into the more usual glob-style format
7507 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007508" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007509 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01007510 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007511 let filelist= getline(1,line("$"))
7512 q!
7513 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007514 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007515 endfor
7516 unlet filelist
7517 let @a = areg
7518 let &ei = eikeep
7519 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007520 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007521
7522" call Dret("s:NetrwMarkFileRegexp")
7523endfun
7524
7525" ---------------------------------------------------------------------
7526" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
7527" Uses the local marked file list.
7528fun! s:NetrwMarkFileSource(islocal)
7529" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
7530 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007531
7532 " sanity check
7533 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007534 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007535" call Dret("s:NetrwMarkFileSource")
7536 return
7537 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007538" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7539 let curdir= s:NetrwGetCurdir(a:islocal)
7540
Bram Moolenaar446cb832008-06-24 21:56:24 +00007541 if exists("s:netrwmarkfilelist_{curbufnr}")
7542 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007543 call s:NetrwUnmarkList(curbufnr,curdir)
7544 for fname in netrwmarkfilelist
7545 if a:islocal
7546 if g:netrw_keepdir
7547 let fname= s:ComposePath(curdir,fname)
7548 endif
7549 else
7550 let fname= curdir.fname
7551 endif
7552 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007553" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007554 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007555 endfor
7556 2match none
7557 endif
7558" call Dret("s:NetrwMarkFileSource")
7559endfun
7560
7561" ---------------------------------------------------------------------
7562" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
7563" Uses the global markfilelist
7564fun! s:NetrwMarkFileTag(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007565 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007566 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007567 let curbufnr = bufnr("%")
7568
Bram Moolenaarff034192013-04-24 18:51:19 +02007569 " sanity check
7570 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007571 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007572 return
7573 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007574
Bram Moolenaar446cb832008-06-24 21:56:24 +00007575 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007576 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007577 call s:NetrwUnmarkAll()
7578
7579 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02007580
Bram Moolenaar85850f32019-07-19 22:05:51 +02007581 call system(g:netrw_ctags." ".netrwmarkfilelist)
7582 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00007583 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
7584 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007585
Bram Moolenaar446cb832008-06-24 21:56:24 +00007586 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00007587 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01007588 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007589 let curdir= b:netrw_curdir
7590 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007591 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00007592 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007593 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01007594 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007595 wq!
7596 endif
7597 2match none
Tom Benham64a536d2024-11-07 21:15:03 +01007598 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007599 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007600 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007601endfun
7602
7603" ---------------------------------------------------------------------
7604" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007605" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02007606" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00007607" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02007608" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00007609fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007610 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007611 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007612 let hadtgt = exists("s:netrwmftgt")
7613 if !exists("w:netrw_bannercnt")
7614 let w:netrw_bannercnt= b:netrw_bannercnt
7615 endif
7616
7617 " set up target
7618 if line(".") < w:netrw_bannercnt
Bram Moolenaarff034192013-04-24 18:51:19 +02007619 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
7620 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaarff034192013-04-24 18:51:19 +02007621 unlet s:netrwmftgt s:netrwmftgt_islocal
7622 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007623 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02007624 endif
Tom Benham64a536d2024-11-07 21:15:03 +01007625 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007626 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007627 return
7628 else
7629 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaarff034192013-04-24 18:51:19 +02007630 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007631
7632 else
7633 " get word under cursor.
7634 " * If directory, use it for the target.
7635 " * If file, use b:netrw_curdir for the target
7636 let curword= s:NetrwGetWord()
7637 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007638 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007639 let s:netrwmftgt = tgtdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007640 elseif !a:islocal && tgtdir =~ '/$'
7641 let s:netrwmftgt = tgtdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007642 else
7643 let s:netrwmftgt = curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007644 endif
7645 endif
7646 if a:islocal
7647 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
7648 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007649 endif
7650 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007651 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007652 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
7653 endif
7654 let s:netrwmftgt_islocal= a:islocal
7655
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007656 " need to do refresh so that the banner will be updated
7657 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01007658 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007659 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007660 endif
Tom Benham64a536d2024-11-07 21:15:03 +01007661" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007662 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Tom Benham64a536d2024-11-07 21:15:03 +01007663 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop,0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007664 else
Tom Benham64a536d2024-11-07 21:15:03 +01007665 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007666 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007667 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007668 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007669 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00007670 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007671endfun
7672
7673" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007674" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
7675fun! s:NetrwGetCurdir(islocal)
7676" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
7677
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007678 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007679 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
7680" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
7681 elseif !exists("b:netrw_curdir")
7682 let b:netrw_curdir= getcwd()
7683" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
7684 endif
7685
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007686" 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 +01007687 if b:netrw_curdir !~ '\<\a\{3,}://'
7688 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007689" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007690 if g:netrw_keepdir == 0
7691 call s:NetrwLcd(curdir)
7692 endif
7693 endif
7694
7695" call Dret("s:NetrwGetCurdir <".curdir.">")
7696 return b:netrw_curdir
7697endfun
7698
7699" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00007700" s:NetrwOpenFile: query user for a filename and open it {{{2
7701fun! s:NetrwOpenFile(islocal)
7702" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007703 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00007704 call inputsave()
7705 let fname= input("Enter filename: ")
7706 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02007707" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
7708
7709 " determine if Lexplore is in use
7710 if exists("t:netrw_lexbufnr")
7711 " check if t:netrw_lexbufnr refers to a netrw window
7712" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
7713 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
7714 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
7715" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
7716 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
7717 exe "NetrwKeepj e ".fnameescape(fname)
7718 let @@= ykeep
7719" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
7720 endif
7721 endif
7722
7723 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00007724 if fname !~ '[/\\]'
7725 if exists("b:netrw_curdir")
7726 if exists("g:netrw_quiet")
7727 let netrw_quiet_keep = g:netrw_quiet
7728 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007729 let g:netrw_quiet = 1
7730 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007731 let s:rexposn_{bufnr("%")}= winsaveview()
7732" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007733 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007734 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007735 else
7736 exe "e ".fnameescape(b:netrw_curdir."/".fname)
7737 endif
7738 if exists("netrw_quiet_keep")
7739 let g:netrw_quiet= netrw_quiet_keep
7740 else
7741 unlet g:netrw_quiet
7742 endif
7743 endif
7744 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007745 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007746 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007747 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00007748" call Dret("s:NetrwOpenFile")
7749endfun
7750
7751" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007752" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
7753" For the mapping to this function be made via
7754" netrwPlugin, you'll need to have had
7755" g:netrw_usetab set to non-zero.
7756fun! netrw#Shrink()
7757" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
7758 let curwin = winnr()
7759 let wiwkeep = &wiw
7760 set wiw=1
7761
7762 if &ft == "netrw"
7763 if winwidth(0) > g:netrw_wiw
7764 let t:netrw_winwidth= winwidth(0)
7765 exe "vert resize ".g:netrw_wiw
7766 wincmd l
7767 if winnr() == curwin
7768 wincmd h
7769 endif
7770" call Decho("vert resize 0",'~'.expand("<slnum>"))
7771 else
7772 exe "vert resize ".t:netrw_winwidth
7773" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
7774 endif
7775
7776 elseif exists("t:netrw_lexbufnr")
7777 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
7778 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
7779 let t:netrw_winwidth= winwidth(0)
7780 exe "vert resize ".g:netrw_wiw
7781 wincmd l
7782 if winnr() == curwin
7783 wincmd h
7784 endif
7785" call Decho("vert resize 0",'~'.expand("<slnum>"))
7786 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
7787 exe "vert resize ".t:netrw_winwidth
7788" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01007789 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007790 call netrw#Lexplore(0,0)
7791 endif
7792
7793 else
7794 call netrw#Lexplore(0,0)
7795 endif
7796 let wiw= wiwkeep
7797
7798" call Dret("netrw#Shrink")
7799endfun
7800
7801" ---------------------------------------------------------------------
7802" s:NetSortSequence: allows user to edit the sorting sequence {{{2
7803fun! s:NetSortSequence(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007804 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007805 let svpos= winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007806 call inputsave()
7807 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
7808 call inputrestore()
7809
7810 " refresh the listing
7811 let g:netrw_sort_sequence= newsortseq
Tom Benham64a536d2024-11-07 21:15:03 +01007812 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007813 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007814 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007815endfun
7816
7817" ---------------------------------------------------------------------
7818" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
7819" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02007820" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00007821fun! s:NetrwUnmarkList(curbufnr,curdir)
7822" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
7823
7824 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007825 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007826 for mfile in s:netrwmarkfilelist_{a:curbufnr}
7827 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
7828 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
7829 call remove(s:netrwmarkfilelist,idx) " remove from global list
7830 endfor
7831 if s:netrwmarkfilelist == []
7832 unlet s:netrwmarkfilelist
7833 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007834
Bram Moolenaar446cb832008-06-24 21:56:24 +00007835 " getting rid of the local marked-file lists is easy
7836 unlet s:netrwmarkfilelist_{a:curbufnr}
7837 endif
7838 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
7839 unlet s:netrwmarkfilemtch_{a:curbufnr}
7840 endif
7841 2match none
7842" call Dret("s:NetrwUnmarkList")
7843endfun
7844
7845" ---------------------------------------------------------------------
7846" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
7847fun! s:NetrwUnmarkAll()
7848" call Dfunc("s:NetrwUnmarkAll()")
7849 if exists("s:netrwmarkfilelist")
7850 unlet s:netrwmarkfilelist
7851 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02007852 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007853 2match none
7854" call Dret("s:NetrwUnmarkAll")
7855endfun
7856
7857" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02007858" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007859fun! s:NetrwUnmarkAll2()
7860" call Dfunc("s:NetrwUnmarkAll2()")
7861 redir => netrwmarkfilelist_let
7862 let
7863 redir END
7864 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007865 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00007866 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
7867 for flist in netrwmarkfilelist_list
7868 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
7869 unlet s:netrwmarkfilelist_{curbufnr}
7870 unlet s:netrwmarkfilemtch_{curbufnr}
7871 endfor
7872" call Dret("s:NetrwUnmarkAll2")
7873endfun
7874
7875" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007876" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
7877"
7878" Marked files are in two types of lists:
7879" s:netrwmarkfilelist -- holds complete paths to all marked files
7880" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
7881"
7882" Marked files suitable for use with 2match are in:
7883" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00007884fun! s:NetrwUnMarkFile(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007885 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007886 let curbufnr = bufnr("%")
7887
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007888 " unmark marked file list
7889 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
7890 if exists("s:netrwmarkfilelist")
7891" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007892 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007893 endif
7894
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007895 let ibuf= 1
7896 while ibuf < bufnr("$")
7897 if exists("s:netrwmarkfilelist_".ibuf)
7898 unlet s:netrwmarkfilelist_{ibuf}
7899 unlet s:netrwmarkfilemtch_{ibuf}
7900 endif
7901 let ibuf = ibuf + 1
7902 endwhile
7903 2match none
7904
Tom Benham64a536d2024-11-07 21:15:03 +01007905" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007906call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007907endfun
7908
7909" ---------------------------------------------------------------------
7910" s:NetrwMenu: generates the menu for gvim and netrw {{{2
7911fun! s:NetrwMenu(domenu)
7912
7913 if !exists("g:NetrwMenuPriority")
7914 let g:NetrwMenuPriority= 80
7915 endif
7916
Bram Moolenaaradc21822011-04-01 18:03:16 +02007917 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00007918" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
7919
7920 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007921" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007922 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02007923 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
7924 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
7925 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
7926 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
7927 if g:netrw_dirhistmax > 0
7928 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
7929 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
7930 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
7931 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
7932 else
7933 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
7934 endif
7935 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
7936 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
7937 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
7938 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
7939 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
7940 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
7941 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
7942 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
7943 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
7944 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
7945 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
7946 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
7947 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
7948 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
7949 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 +01007950 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 +02007951 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
7952 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
7953 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
7954 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
7955 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
7956 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
7957 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
7958 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
7959 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
7960 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
7961 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
7962 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
7963 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
7964 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
7965 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
7966 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
7967 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
7968 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
7969 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
7970 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
7971 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
7972 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
7973 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
7974 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
7975 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
7976 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
7977 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
7978 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
7979 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
7980 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>'
7981 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>'
7982 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>'
7983 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
7984 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>'
7985 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>'
7986 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 +01007987 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 +02007988 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
7989 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00007990 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02007991 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
7992 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00007993
7994 elseif !a:domenu
7995 let s:netrwcnt = 0
7996 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007997 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007998 exe curwin."wincmd w"
7999
8000 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008001" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008002 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008003" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008004 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008005 endif
8006 endif
8007" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008008 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008009 endif
8010
8011endfun
8012
8013" ---------------------------------------------------------------------
8014" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8015" Used by the O maps (as <SID>NetrwObtain())
8016fun! s:NetrwObtain(islocal)
8017" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8018
Bram Moolenaar97d62492012-11-15 21:28:22 +01008019 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008020 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008021 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008022 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008023 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8024 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008025 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008026 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008027 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008028
8029" call Dret("NetrwObtain")
8030endfun
8031
8032" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008033" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8034" If there's only one window, then the window will first be split.
8035" Returns:
8036" choice = 0 : didn't have to choose
8037" choice = 1 : saved modified file in window first
8038" choice = 2 : didn't save modified file, opened window
8039" choice = 3 : cancel open
8040fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008041 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008042 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008043 let curdir = b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008044
8045 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008046 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008047 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008048 let curword = s:NetrwGetWord()
8049 let choice = 0
8050 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 +01008051 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01008052 let curdir = s:treedir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008053
Bram Moolenaar8d043172014-01-23 14:24:41 +01008054 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008055 if lastwinnr == 1
8056 " if only one window, open a new one first
Bram Moolenaar85850f32019-07-19 22:05:51 +02008057 " g:netrw_preview=0: preview window shown in a horizontally split window
8058 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008059 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008060 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008061 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar15146672011-10-20 22:22:38 +02008062 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008063 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008064 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008065 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar15146672011-10-20 22:22:38 +02008066 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008067 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008068 let didsplit = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00008069
8070 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008071 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008072 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01008073 setl ei=all
Bram Moolenaar446cb832008-06-24 21:56:24 +00008074 wincmd p
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01008075
Bram Moolenaar71badf92023-04-22 22:40:14 +01008076 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8077 " whoops -- user trying to open file in the Lexplore window.
8078 " Use Lexplore's opening-file window instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01008079" exe g:netrw_chgwin."wincmd w"
8080 wincmd p
Tom Benham64a536d2024-11-07 21:15:03 +01008081 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008082 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008083
8084 " prevwinnr: the window number of the "prev" window
8085 " prevbufnr: the buffer number of the buffer in the "prev" window
8086 " bnrcnt : the qty of windows open on the "prev" buffer
8087 let prevwinnr = winnr()
8088 let prevbufnr = bufnr("%")
8089 let prevbufname = bufname("%")
8090 let prevmod = &mod
8091 let bnrcnt = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008092 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008093
8094 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008095 " and it doesn't appear in any other extant window, then ask the
8096 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008097 if prevmod
Bram Moolenaar8d043172014-01-23 14:24:41 +01008098 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008099 exe prevwinnr."wincmd w"
8100
8101 if bnrcnt == 1 && &hidden == 0
8102 " only one copy of the modified buffer in a window, and
8103 " hidden not set, so overwriting will lose the modified file. Ask first...
8104 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008105 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008106
8107 if choice == 1
8108 " Yes -- write file & then browse
8109 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008110 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008111 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008112 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008113 exe origwin."wincmd w"
8114 let &ei = eikeep
8115 let @@ = ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008116 return choice
8117 endif
8118
8119 elseif choice == 2
8120 " No -- don't worry about changed file, just browse anyway
Bram Moolenaar8d043172014-01-23 14:24:41 +01008121 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008122
8123 else
8124 " Cancel -- don't do this
Bram Moolenaar8d043172014-01-23 14:24:41 +01008125 exe origwin."wincmd w"
8126 let &ei= eikeep
8127 let @@ = ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008128 return choice
8129 endif
8130 endif
8131 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008132 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008133 endif
8134
8135 " restore b:netrw_curdir (window split/enew may have lost it)
8136 let b:netrw_curdir= curdir
8137 if a:islocal < 2
8138 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01008139 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword,0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008140 else
Tom Benham64a536d2024-11-07 21:15:03 +01008141 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword,0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008142 endif
8143 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008144 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008145 return choice
8146endfun
8147
8148" ---------------------------------------------------------------------
8149" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8150" Always assumed to be local -> remote
8151" call s:NetrwUpload(filename, target)
8152" call s:NetrwUpload(filename, target, fromdirectory)
8153fun! s:NetrwUpload(fname,tgt,...)
8154" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8155
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008156 if a:tgt =~ '^\a\{3,}://'
8157 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008158 else
8159 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8160 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008161" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008162
8163 if a:0 > 0
8164 let fromdir= a:1
8165 else
8166 let fromdir= getcwd()
8167 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008168" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008169
8170 if type(a:fname) == 1
8171 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008172" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008173 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008174" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8175 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8176" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008177 if a:tgt =~ '/$'
8178 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008179" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008180 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008181 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008182" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008183 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008184" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008185 endif
8186 q!
8187
8188 elseif type(a:fname) == 3
8189 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008190" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008191 let curdir= getcwd()
8192 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008193 if s:NetrwLcd(fromdir)
8194" call Dret("s:NetrwUpload : lcd failure")
8195 return
8196 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008197 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008198 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008199 if exists("g:netrw_port") && g:netrw_port != ""
8200 let useport= " ".g:netrw_scpport." ".g:netrw_port
8201 else
8202 let useport= ""
8203 endif
8204 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8205 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008206 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 +02008207 if s:NetrwLcd(curdir)
8208" call Dret("s:NetrwUpload : lcd failure")
8209 return
8210 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008211
8212 elseif a:tgt =~ '^ftp:'
8213 call s:NetrwMethod(a:tgt)
8214
8215 if b:netrw_method == 2
8216 " handle uploading a list of files via ftp+.netrc
8217 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008218 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008219" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008220
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008221 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008222" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008223
8224 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008225 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008226" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008227 endif
8228
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008229 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008230" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008231
Bram Moolenaaradc21822011-04-01 18:03:16 +02008232 if tgtdir == ""
8233 let tgtdir= '/'
8234 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008235 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008236" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008237
8238 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008239 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8240" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008241 endfor
8242
8243 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008244 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 +00008245 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008246" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8247 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008248 endif
8249 " 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 +01008250 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008251 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008252 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8253 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8254 else
8255 bw!|q
8256 endif
8257
8258 elseif b:netrw_method == 3
8259 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8260 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008261 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008262 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008263 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008264
8265 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008266 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008267" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008268 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008269 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008270" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008271 endif
8272
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008273 if exists("g:netrw_uid") && g:netrw_uid != ""
8274 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008275 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008276" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008277 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008278 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008279 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008280" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008281 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008282 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008283" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008284 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008285 endif
8286
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008287 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008288" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008289
8290 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008291 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
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 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008296 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008297" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008298 endif
8299
8300 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008301 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008302" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008303 endfor
8304
8305 " perform ftp:
8306 " -i : turns off interactive prompting from ftp
8307 " -n unix : DON'T use <.netrc>, even though it exists
8308 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008309 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008310 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008311 " 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 +01008312 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008313 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008314 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8315 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008316 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008317 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8318 let &debug = debugkeep
8319 let mod = 1
8320 else
8321 bw!|q
8322 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008323 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008324" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008325 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008326 endif
8327 else
8328 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8329 endif
8330 endif
8331
8332" call Dret("s:NetrwUpload")
8333endfun
8334
8335" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008336" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008337fun! s:NetrwPreview(path) range
8338" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008339" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8340" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008341 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008342 NetrwKeepj call s:NetrwOptionsSave("s:")
8343 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8344 NetrwKeepj call s:NetrwOptionsSafe(1)
8345 else
8346 NetrwKeepj call s:NetrwOptionsSafe(0)
8347 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008348 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008349" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008350 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008351" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8352 if g:netrw_preview
8353 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008354 let pvhkeep = &pvh
8355 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8356 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008357" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8358 else
8359 " horizontal split
8360 let pvhkeep = &pvh
8361 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8362 let &pvh = winheight(0) - winsz
8363" 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 +02008364 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008365 " g:netrw_preview g:netrw_alto
8366 " 1 : vert 1: top -- preview window is vertically split off and on the left
8367 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8368 " 0 : 1: top -- preview window is horizontally split off and on the top
8369 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8370 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008371 " 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 +02008372 " the BufEnter event set up in netrwPlugin.vim
8373" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8374 let eikeep = &ei
8375 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008376 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008377 let &ei= eikeep
8378" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008379 if exists("pvhkeep")
8380 let &pvh= pvhkeep
8381 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008382 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008383 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008384 endif
8385 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008386 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 +00008387 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008388 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008389 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008390" call Dret("NetrwPreview")
8391endfun
8392
8393" ---------------------------------------------------------------------
8394" s:NetrwRefresh: {{{2
8395fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008396" 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 +00008397 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008398 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008399" call Decho("setl ma noro",'~'.expand("<slnum>"))
8400" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008401 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008402 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8403 if !exists("w:netrw_treetop")
8404 if exists("b:netrw_curdir")
8405 let w:netrw_treetop= b:netrw_curdir
8406 else
8407 let w:netrw_treetop= getcwd()
8408 endif
8409 endif
8410 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
8411 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008412
8413 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008414 let screenposn = winsaveview()
8415" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008416
8417" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
8418" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
8419 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008420 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008421 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008422 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008423 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008424 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008425
8426 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008427" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
8428 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008429
8430 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02008431 if has("syntax") && exists("g:syntax_on") && g:syntax_on
8432 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8433" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
8434 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8435 else
8436" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
8437 2match none
8438 endif
8439 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008440
Bram Moolenaar97d62492012-11-15 21:28:22 +01008441" restore
8442 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008443" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008444endfun
8445
8446" ---------------------------------------------------------------------
8447" s:NetrwRefreshDir: refreshes a directory by name {{{2
8448" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008449" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008450fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008451 if g:netrw_fastbrowse == 0
8452 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008453 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008454
8455 if tgtwin > 0
8456 " tgtwin is being displayed, so refresh it
8457 let curwin= winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008458 exe tgtwin."wincmd w"
Tom Benham64a536d2024-11-07 21:15:03 +01008459 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008460 exe curwin."wincmd w"
8461
8462 elseif bufnr(a:dirname) > 0
8463 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008464 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00008465 endif
8466
8467 elseif g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008468 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008469 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008470endfun
8471
8472" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02008473" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
8474" window number to do its editing in.
8475" Supports [count]C where the count, if present, is used to specify
8476" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008477fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02008478" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008479 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008480" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008481 if a:1 == "" " :NetrwC win#
8482 let g:netrw_chgwin= winnr()
8483 else " :NetrwC
8484 let g:netrw_chgwin= a:1
8485 endif
8486 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02008487 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008488 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02008489 let g:netrw_chgwin= winnr()
8490 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008491 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008492" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02008493endfun
8494
8495" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008496" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
8497" What this function does is to compute a priority for the patterns
8498" in the g:netrw_sort_sequence. It applies a substitute to any
8499" "files" that satisfy each pattern, putting the priority / in
8500" front. An "*" pattern handles the default priority.
8501fun! s:NetrwSetSort()
8502" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008503 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008504 if w:netrw_liststyle == s:LONGLIST
8505 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
8506 else
8507 let seqlist = g:netrw_sort_sequence
8508 endif
8509 " sanity check -- insure that * appears somewhere
8510 if seqlist == ""
8511 let seqlist= '*'
8512 elseif seqlist !~ '\*'
8513 let seqlist= seqlist.',*'
8514 endif
8515 let priority = 1
8516 while seqlist != ""
8517 if seqlist =~ ','
8518 let seq = substitute(seqlist,',.*$','','e')
8519 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
8520 else
8521 let seq = seqlist
8522 let seqlist = ""
8523 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008524 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01008525 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008526 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01008527 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008528 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01008529 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008530 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008531" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008532
8533 " sanity check
8534 if w:netrw_bannercnt > line("$")
8535 " apparently no files were left after a Hiding pattern was used
8536" call Dret("SetSort : no files left after hiding")
8537 return
8538 endif
8539 if seq == '*'
8540 let starpriority= spriority
8541 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008542 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008543 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008544 " sometimes multiple sorting patterns will match the same file or directory.
8545 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008546 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
8547 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008548 endif
8549 let priority = priority + 1
8550 endwhile
8551 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008552 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
8553 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008554 endif
8555
8556 " Following line associated with priority -- items that satisfy a priority
8557 " pattern get prefixed by ###/ which permits easy sorting by priority.
8558 " Sometimes files can satisfy multiple priority patterns -- only the latest
8559 " priority pattern needs to be retained. So, at this point, these excess
8560 " priority prefixes need to be removed, but not directories that happen to
8561 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008562 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
8563 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008564 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008565
8566" call Dret("SetSort")
8567endfun
8568
Bram Moolenaarff034192013-04-24 18:51:19 +02008569" ---------------------------------------------------------------------
8570" s:NetrwSetTgt: sets the target to the specified choice index {{{2
8571" Implements [count]Tb (bookhist<b>)
8572" [count]Th (bookhist<h>)
8573" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008574fun! s:NetrwSetTgt(islocal,bookhist,choice)
8575" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02008576
8577 if a:bookhist == 'b'
8578 " supports choosing a bookmark as a target using a qb-generated list
8579 let choice= a:choice - 1
8580 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01008581 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02008582 else
8583 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
8584 endif
8585
8586 elseif a:bookhist == 'h'
8587 " supports choosing a history stack entry as a target using a qb-generated list
8588 let choice= (a:choice % g:netrw_dirhistmax) + 1
8589 if exists("g:netrw_dirhist_".choice)
8590 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01008591 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02008592 else
8593 echomsg "Sorry, history#".a:choice." not available!"
8594 endif
8595 endif
8596
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008597 " refresh the display
8598 if !exists("b:netrw_curdir")
8599 let b:netrw_curdir= getcwd()
8600 endif
8601 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
8602
Bram Moolenaarff034192013-04-24 18:51:19 +02008603" call Dret("s:NetrwSetTgt")
8604endfun
8605
Bram Moolenaar446cb832008-06-24 21:56:24 +00008606" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02008607" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008608fun! s:NetrwSortStyle(islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008609 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008610 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008611
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008612 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 +01008613 NetrwKeepj norm! 0
Tom Benham64a536d2024-11-07 21:15:03 +01008614 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008615 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008616endfun
8617
8618" ---------------------------------------------------------------------
8619" s:NetrwSplit: mode {{{2
8620" =0 : net and o
8621" =1 : net and t
8622" =2 : net and v
8623" =3 : local and o
8624" =4 : local and t
8625" =5 : local and v
8626fun! s:NetrwSplit(mode)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008627
Bram Moolenaar97d62492012-11-15 21:28:22 +01008628 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008629 call s:SaveWinVars()
8630
8631 if a:mode == 0
8632 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02008633 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008634 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008635 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008636 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008637 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008638 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008639 unlet s:didsplit
8640
8641 elseif a:mode == 1
8642 " remote and t
Tom Benham64a536d2024-11-07 21:15:03 +01008643 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008644 tabnew
8645 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008646 NetrwKeepj call s:RestoreWinVars()
8647 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008648 unlet s:didsplit
8649
8650 elseif a:mode == 2
8651 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02008652 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008653 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008654 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008655 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008656 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008657 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008658 unlet s:didsplit
8659
8660 elseif a:mode == 3
8661 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02008662 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008663 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008664 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008665 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008666 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008667 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008668 unlet s:didsplit
8669
8670 elseif a:mode == 4
8671 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00008672 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008673 let eikeep = &ei
8674 let netrw_winnr = winnr()
8675 let netrw_line = line(".")
8676 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008677 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01008678 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01008679 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008680 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
8681 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008682 let &ei = eikeep
8683 let netrw_curdir = s:NetrwTreeDir(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008684 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01008685 let b:netrw_curdir = netrw_curdir
8686 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008687 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008688 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword,0))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008689 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01008690 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008691 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
8692 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01008693 let &ei= eikeep
8694 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008695 unlet s:didsplit
8696
8697 elseif a:mode == 5
8698 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02008699 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008700 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008701 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008702 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008703 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008704 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008705 unlet s:didsplit
8706
8707 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008708 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008709 endif
8710
Bram Moolenaar97d62492012-11-15 21:28:22 +01008711 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008712endfun
8713
8714" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008715" s:NetrwTgtMenu: {{{2
8716fun! s:NetrwTgtMenu()
8717 if !exists("s:netrw_menucnt")
8718 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008719 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008720" call Dfunc("s:NetrwTgtMenu()")
8721
8722 " the following test assures that gvim is running, has menus available, and has menus enabled.
8723 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
8724 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008725" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008726 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
8727 endif
8728 if !exists("s:netrw_initbookhist")
8729 call s:NetrwBookHistRead()
8730 endif
8731
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008732 " try to cull duplicate entries
8733 let tgtdict={}
8734
Bram Moolenaarff034192013-04-24 18:51:19 +02008735 " target bookmarked places
8736 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008737" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008738 let cnt= 1
8739 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008740 if has_key(tgtdict,bmd)
8741 let cnt= cnt + 1
8742 continue
8743 endif
8744 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02008745 let ebmd= escape(bmd,g:netrw_menu_escape)
8746 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008747" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008748 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 +02008749 let cnt= cnt + 1
8750 endfor
8751 endif
8752
8753 " target directory browsing history
8754 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008755" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008756 let histcnt = 1
8757 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02008758 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02008759 if exists("g:netrw_dirhist_{histcnt}")
8760 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008761 if has_key(tgtdict,histentry)
8762 let histcnt = histcnt + 1
8763 continue
8764 endif
8765 let tgtdict[histentry] = histcnt
8766 let ehistentry = escape(histentry,g:netrw_menu_escape)
8767" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008768 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 +02008769 endif
8770 let histcnt = histcnt + 1
8771 endwhile
8772 endif
8773 endif
8774" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008775endfun
8776
8777" ---------------------------------------------------------------------
8778" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
8779" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008780fun! s:NetrwTreeDir(islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008781
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008782 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008783 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
8784 let treedir= s:treedir
8785 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008786 unlet s:prevwinopen
Bram Moolenaar8d043172014-01-23 14:24:41 +01008787 return treedir
8788 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008789 if exists("s:prevwinopen")
8790 unlet s:prevwinopen
8791 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008792
Bram Moolenaar8d043172014-01-23 14:24:41 +01008793 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
8794 let b:netrw_curdir= getcwd()
8795 endif
8796 let treedir = b:netrw_curdir
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008797 let s:treecurpos= winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008798
8799 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar5c736222010-01-06 20:54:52 +01008800
8801 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008802 let curline= substitute(getline('.'),"\t -->.*$",'','')
8803 if curline =~ '/$'
Bram Moolenaar8d043172014-01-23 14:24:41 +01008804 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008805 elseif curline =~ '@$'
Tom Benham64a536d2024-11-07 21:15:03 +01008806 let potentialdir= resolve(s:NetrwTreePath(w:netrw_treetop))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008807 else
8808 let treedir= ""
8809 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008810
8811 " detect user attempting to close treeroot
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008812 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008813 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008814 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008815 return b:netrw_curdir
8816 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008817
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008818 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
8819" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
8820" let newdir = w:netrw_treetop.'/'.potentialdir
Christian Brabandt56b7da32024-02-29 17:48:14 +01008821 if a:islocal && curline =~ '@$'
8822 if isdirectory(s:NetrwFile(potentialdir))
Tom Benham64a536d2024-11-07 21:15:03 +01008823 let treedir = potentialdir
Christian Brabandt56b7da32024-02-29 17:48:14 +01008824 let w:netrw_treetop = treedir
8825 endif
8826 else
8827 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
8828 let treedir = s:NetrwTreePath(w:netrw_treetop)
8829 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008830 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008831
8832 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00008833 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008834 return treedir
8835endfun
8836
8837" ---------------------------------------------------------------------
8838" s:NetrwTreeDisplay: recursive tree display {{{2
8839fun! s:NetrwTreeDisplay(dir,depth)
Tom Benham64a536d2024-11-07 21:15:03 +01008840 " ensure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02008841 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00008842
8843 " install ../ and shortdir
8844 if a:depth == ""
8845 call setline(line("$")+1,'../')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008846 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008847 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008848 if a:dir == w:netrw_treetop
8849 let shortdir= a:dir
8850 else
8851 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
8852 endif
8853 call setline(line("$")+1,a:depth.shortdir)
8854 else
8855 let shortdir= substitute(a:dir,'^.*/','','e')
8856 call setline(line("$")+1,a:depth.shortdir.'/')
8857 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008858 " append a / to dir if its missing one
8859 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008860
8861 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008862 let depth= s:treedepthstring.a:depth
Bram Moolenaar446cb832008-06-24 21:56:24 +00008863
Bram Moolenaar85850f32019-07-19 22:05:51 +02008864 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
8865 if g:netrw_hide == 1
8866 " hide given patterns
8867 let listhide= split(g:netrw_list_hide,',')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008868 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02008869 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008870 endfor
8871
8872 elseif g:netrw_hide == 2
8873 " show given patterns (only)
8874 let listhide= split(g:netrw_list_hide,',')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008875 let entries=[]
8876 for entry in w:netrw_treedict[dir]
8877 for pat in listhide
8878 if entry =~ pat
8879 call add(entries,entry)
8880 break
8881 endif
8882 endfor
8883 endfor
8884 let w:netrw_treedict[dir]= entries
8885 endif
8886 if depth != ""
8887 " always remove "." and ".." entries when there's depth
8888 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
Tom Benham64a536d2024-11-07 21:15:03 +01008889 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\./$"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008890 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
Tom Benham64a536d2024-11-07 21:15:03 +01008891 call filter(w:netrw_treedict[dir],'v:val !~ "\\./$"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008892 endif
8893
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008894 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008895 if dir =~ '/$'
8896 let direntry= substitute(dir.entry,'[@/]$','','e')
8897 else
8898 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
8899 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008900 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008901 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008902 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008903 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
8904 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
Tom Benham64a536d2024-11-07 21:15:03 +01008905 NetrwKeepj call s:NetrwTreeDisplay(direntry.'@',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008906 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008907 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008908 endif
8909 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008910endfun
8911
8912" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008913" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
8914fun! s:NetrwRefreshTreeDict(dir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008915 if !exists("w:netrw_treedict")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008916 return
8917 endif
8918
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008919 for entry in w:netrw_treedict[a:dir]
8920 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008921
8922 if 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.'/')
Tom Benham64a536d2024-11-07 21:15:03 +01008929 let filelist = s:NetrwLocalListingList(direntry.'/',0)
8930 let w:netrw_treedict[direntry] = sort(filelist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008931
8932 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008933 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008934 let liststar = s:NetrwGlob(direntry.'/','*',1)
8935 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008936
8937 else
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008938 endif
8939 endfor
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008940endfun
8941
8942" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008943" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008944" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008945fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008946 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00008947
8948 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00008949 if !exists("w:netrw_treetop")
8950 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008951 let s:netrw_treetop= w:netrw_treetop
Tom Benham4d618002024-10-31 10:47:23 +01008952 " use \V in case the directory contains specials chars like '$' or '~'
8953 elseif (w:netrw_treetop =~ ('^'.'\V'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop))
8954 \ || a:dirname !~ ('^'.'\V'.w:netrw_treetop)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008955 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008956 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00008957 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008958 if exists("w:netrw_treetop")
8959 let s:netrw_treetop= w:netrw_treetop
8960 else
8961 let w:netrw_treetop= getcwd()
8962 let s:netrw_treetop= w:netrw_treetop
8963 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008964
Bram Moolenaar446cb832008-06-24 21:56:24 +00008965 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008966 " insure that we have a treedict, albeit empty
Bram Moolenaar446cb832008-06-24 21:56:24 +00008967 let w:netrw_treedict= {}
8968 endif
8969
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008970 " update the dictionary for the current directory
Christian Brabandta063b222024-11-07 14:30:30 +01008971 exe "sil! NetrwKeepj keepp ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008972 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008973 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008974
8975 " if past banner, record word
8976 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
8977 let fname= expand("<cword>")
8978 else
8979 let fname= ""
8980 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008981
8982 " display from treetop on down
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008983 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008984
8985 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
8986 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaar8d043172014-01-23 14:24:41 +01008987 1d
8988 endwhile
8989
Bram Moolenaar13600302014-05-22 18:26:40 +02008990 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00008991
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008992 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008993 endif
8994endfun
8995
8996" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008997" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01008998" Normally, treetop is w:netrw_treetop, but a
8999" user of the function ( netrw#SetTreetop() )
9000" wipes that out prior to calling this function
9001fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009002" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9003 if line(".") < w:netrw_bannercnt + 2
9004 let treedir= a:treetop
9005 if treedir !~ '/$'
9006 let treedir= treedir.'/'
9007 endif
9008" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9009 return treedir
9010 endif
9011
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009012 let svpos = winsaveview()
9013" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009014 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009015" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009016 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009017" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9018 let curline= getline('.')
9019" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9020 if curline =~ '/$'
9021" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9022 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9023" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9024 elseif curline =~ '@\s\+-->'
9025" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9026 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9027 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9028" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009029 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009030" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009031 let treedir= ""
9032 endif
9033 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009034" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9035" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009036 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9037 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9038 let treedir= dirname.treedir
9039 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009040" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009041 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009042" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009043 if a:treetop =~ '/$'
9044 let treedir= a:treetop.treedir
9045 else
9046 let treedir= a:treetop.'/'.treedir
9047 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009048" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009049 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009050" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009051" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9052 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009053" call Dret("s:NetrwTreePath <".treedir.">")
9054 return treedir
9055endfun
9056
9057" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009058" s:NetrwWideListing: {{{2
9059fun! s:NetrwWideListing()
9060
9061 if w:netrw_liststyle == s:WIDELIST
9062" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9063 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009064 " cpf: characters per filename
9065 " fpl: filenames per line
9066 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009067 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009068 let dict={}
9069 " save the unnamed register and register 0-9 and a
9070 let dict.a=[getreg('a'), getregtype('a')]
9071 for i in range(0, 9)
9072 let dict[i] = [getreg(i), getregtype(i)]
9073 endfor
9074 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009075" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009076 let b:netrw_cpf= 0
9077 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009078 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009079 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9080 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009081 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009082 " restore stored registers
9083 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009084" call Dret("NetrwWideListing")
9085 return
9086 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009087 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009088 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009089" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009090
9091 " determine qty files per line (fpl)
9092 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9093 if w:netrw_fpl <= 0
9094 let w:netrw_fpl= 1
9095 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009096" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009097
9098 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009099 " fpc: files per column of wide listing
9100 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009101 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009102 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9103 let newcolstart = w:netrw_bannercnt + fpc
9104 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009105" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009106 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009107" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009108 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009109 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009110 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009111 while line("$") >= newcolstart
9112 if newcolend > line("$") | let newcolend= line("$") | endif
9113 let newcolqty= newcolend - newcolstart
9114 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009115 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009116 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009117 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009118 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009119 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009120 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009121 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009122 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009123 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009124 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009125" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009126 if @* != keepregstar | sil! let @* = keepregstar | endif
9127 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009128 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009129 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9130 NetrwKeepj call histdel("/",-1)
9131 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9132 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009133" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009134 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009135 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009136" 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 +00009137" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009138 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009139 else
9140 if hasmapto("w","n")
9141 sil! nunmap <buffer> w
9142 endif
9143 if hasmapto("b","n")
9144 sil! nunmap <buffer> b
9145 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009146 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009147endfun
9148
9149" ---------------------------------------------------------------------
9150" s:PerformListing: {{{2
9151fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009152" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9153" 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 +02009154" 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>"))
9155 sil! NetrwKeepj %d _
9156" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009157
Bram Moolenaar15146672011-10-20 22:22:38 +02009158 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009159" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009160 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009161
Bram Moolenaar85850f32019-07-19 22:05:51 +02009162 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009163 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009164" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009165
9166" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009167" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009168" endif " Decho
9169
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009170" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009171 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9172 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009173" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9174 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009175 endif
9176
9177 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009178 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009179
9180 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009181 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009182" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009183 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009184 if exists("g:netrw_pchk")
9185 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9186 " failure detections.
9187 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009188 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009189 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9190 endif
9191 if exists("g:netrw_pchk")
9192 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9193 else
9194 let curdir= b:netrw_curdir
9195 endif
9196 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9197 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9198 else
9199 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009200 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009201 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009202 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009203 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009204" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009205 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009206 let w:netrw_bannercnt= 1
9207 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009208" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9209" 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 +00009210
Bram Moolenaar85850f32019-07-19 22:05:51 +02009211 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009212 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009213 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009214 let sortby= sortby." reversed"
9215 endif
9216
9217 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009218 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009219" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009220 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009221" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009222 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009223 NetrwKeepj put ='\" Sorted by '.sortby
9224 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009225 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9226 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009227" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009228 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009229 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009230 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9231 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009232 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009233" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009234" 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 +00009235 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009236
Bram Moolenaar85850f32019-07-19 22:05:51 +02009237 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009238 if g:netrw_banner
9239 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009240" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009241 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009242 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009243 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009244 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009245 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009246 endif
9247 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009248 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009249" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009250 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009251 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009252 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009253
9254 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009255 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009256" 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 +01009257 if g:netrw_list_hide != "" && g:netrw_hide
9258 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009259 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009260 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009261 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009262 endif
9263 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009264 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009265 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009266
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009267" 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 +01009268 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009269" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009270 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009271" 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 +01009272 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009273 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009274" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009275" 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 +00009276 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009277
9278 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009279 if g:netrw_banner
9280 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009281 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009282" 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 +01009283" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009284" 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 +01009285 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009286
Bram Moolenaar446cb832008-06-24 21:56:24 +00009287 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009288" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009289 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009290 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009291 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009292 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009293 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009294" 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 +01009295" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9296 return
9297 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009298 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009299
9300 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009301 if !exists("w:netrw_bannercnt")
9302 let w:netrw_bannercnt= 0
9303 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009304" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
9305" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
9306" 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 +01009307
Bram Moolenaar5c736222010-01-06 20:54:52 +01009308 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009309" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009310" 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 +00009311 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009312 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009313 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009314 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009315" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009316
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009317 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009318 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +02009319" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009320 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009321
Bram Moolenaar5c736222010-01-06 20:54:52 +01009322 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009323" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009324 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +02009325 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009326 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009327 else
9328 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009329 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009330 endif
9331 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009332
Bram Moolenaar446cb832008-06-24 21:56:24 +00009333 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009334" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009335 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
9336 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009337
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009338 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +02009339 " exten: sort by extension
9340 " The histdel(...,-1) calls remove the last search from the search history
9341" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009342 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
9343 NetrwKeepj call histdel("/",-1)
9344 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
9345 NetrwKeepj call histdel("/",-1)
9346 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
9347 NetrwKeepj call histdel("/",-1)
9348 if !g:netrw_banner || w:netrw_bannercnt < line("$")
9349" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009350 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009351 " normal direction sorting
9352 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
9353 else
9354 " reverse direction sorting
9355 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
9356 endif
9357 endif
9358 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
9359 NetrwKeepj call histdel("/",-1)
9360
Bram Moolenaar446cb832008-06-24 21:56:24 +00009361 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01009362 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009363" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009364 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009365" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009366 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009367 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009368" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009369 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009370 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009371" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009372 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
9373 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009374 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009375 endif
9376
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009377 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009378" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009379 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009380 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009381 call histdel("/",-1)
9382 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009383 endif
9384 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009385" 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 +00009386
9387 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009388" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
9389" 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 +01009390 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009391" 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 +01009392 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009393" 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 +00009394
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009395 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009396 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009397" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Christian Brabandta063b222024-11-07 14:30:30 +01009398 sil! keepp g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009399 endif
9400
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009401 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009402 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009403" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
9404 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009405 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009406" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
9407 else
9408" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
9409" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
9410" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
9411" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009412 endif
9413
9414 " record previous current directory
9415 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009416" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009417
9418 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009419" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
9420" 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 +01009421 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009422" 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 +02009423 NetrwKeepj call s:NetrwOptionsRestore("w:")
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#6)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009425
9426 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009427" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02009428 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009429" 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 +01009430 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009431" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009432 exe "setl ts=".(g:netrw_maxfilenamelen+1)
9433 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009434" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009435" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009436
Bram Moolenaar8d043172014-01-23 14:24:41 +01009437 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009438" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
9439" 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 +01009440" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
9441 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009442 unlet s:treecurpos
9443 endif
9444
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009445" 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>"))
9446" 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 +00009447" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
9448endfun
9449
9450" ---------------------------------------------------------------------
9451" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00009452fun! s:SetupNetrwStatusLine(statline)
9453" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
9454
9455 if !exists("s:netrw_setup_statline")
9456 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009457" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00009458
9459 if !exists("s:netrw_users_stl")
9460 let s:netrw_users_stl= &stl
9461 endif
9462 if !exists("s:netrw_users_ls")
9463 let s:netrw_users_ls= &laststatus
9464 endif
9465
9466 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +02009467 let dict={}
9468 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +00009469 redir @a
9470 try
9471 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009472 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +00009473 if &bg == "dark"
9474 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
9475 else
9476 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
9477 endif
9478 endtry
9479 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +02009480 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +00009481 endif
9482
9483 " set up status line (may use User9 highlighting)
9484 " insure that windows have a statusline
9485 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +09009486 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +02009487 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009488" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009489 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +00009490
9491" call Dret("SetupNetrwStatusLine : stl=".&stl)
9492endfun
9493
Bram Moolenaar85850f32019-07-19 22:05:51 +02009494" =========================================
9495" Remote Directory Browsing Support: {{{1
9496" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00009497
9498" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01009499" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
9500" This function assumes that a long listing will be received. Size, time,
9501" and reverse sorts will be requested of the server but not otherwise
9502" enforced here.
9503fun! s:NetrwRemoteFtpCmd(path,listcmd)
9504" 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 +01009505" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009506 " sanity check: {{{3
9507 if !exists("w:netrw_method")
9508 if exists("b:netrw_method")
9509 let w:netrw_method= b:netrw_method
9510 else
9511 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
9512" call Dret("NetrwRemoteFtpCmd")
9513 return
9514 endif
9515 endif
9516
9517 " WinXX ftp uses unix style input, so set ff to unix " {{{3
9518 let ffkeep= &ff
9519 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009520" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009521
9522 " clear off any older non-banner lines " {{{3
9523 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009524" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
9525 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +01009526
9527 ".........................................
9528 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
9529 " ftp + <.netrc>: Method #2
9530 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009531 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009532 endif
9533 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009534 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009535" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009536 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009537 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009538" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +01009539 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009540" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1),'~'.expand("<slnum>"))
9541 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 +01009542 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009543" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
9544 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 +01009545 endif
9546
9547 ".........................................
9548 elseif w:netrw_method == 3 " {{{3
9549 " ftp + machine,id,passwd,filename: Method #3
9550 setl ff=unix
9551 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009552 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +01009553 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009554 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +01009555 endif
9556
9557 " handle userid and password
9558 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009559" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009560 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
9561 call NetUserPass("ftp:".host)
9562 endif
9563 if exists("g:netrw_uid") && g:netrw_uid != ""
9564 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009565 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +01009566 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009567 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009568 endif
9569 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009570 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009571 endif
9572 endif
9573
9574 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009575 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009576 endif
9577 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009578 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009579" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009580 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009581 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +01009582
9583 " perform ftp:
9584 " -i : turns off interactive prompting from ftp
9585 " -n unix : DON'T use <.netrc>, even though it exists
9586 " -n win32: quit being obnoxious about password
9587 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009588" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009589 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +01009590" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009591" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
9592" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009593 endif
9594
9595 ".........................................
9596 elseif w:netrw_method == 9 " {{{3
9597 " sftp username@machine: Method #9
9598 " s:netrw_sftp_cmd
9599 setl ff=unix
9600
9601 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +09009602 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +01009603" call Dret("NetrwRemoteFtpCmd")
9604 return
9605
9606 ".........................................
9607 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009608 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +01009609 endif
9610
9611 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +02009612 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009613 sil! NetrwKeepj %s/\r$//e
9614 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009615 endif
9616 if a:listcmd == "dir"
9617 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009618 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
9619 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
9620 NetrwKeepj call histdel("/",-1)
9621 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009622 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 +01009623 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
9624 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009625 endif
9626 endif
9627
9628 " ftp's listing doesn't seem to include ./ or ../ " {{{3
9629 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009630 exe 'NetrwKeepj '.w:netrw_bannercnt
9631 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +01009632 endif
9633 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009634 exe 'NetrwKeepj '.w:netrw_bannercnt
9635 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +01009636 endif
9637
9638 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +09009639 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +01009640" call Dret("NetrwRemoteFtpCmd")
9641endfun
9642
9643" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009644" s:NetrwRemoteListing: {{{2
9645fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009646" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00009647
Bram Moolenaara6878372014-03-22 21:02:50 +01009648 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
9649 let w:netrw_bannercnt= s:bannercnt
9650 endif
9651 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +09009652 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009653 endif
9654
Bram Moolenaar446cb832008-06-24 21:56:24 +00009655 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009656
Bram Moolenaar446cb832008-06-24 21:56:24 +00009657 " sanity check:
9658 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009659" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009660 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009661" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009662 if !exists("g:netrw_quiet")
9663 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
9664 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009665 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009666" call Dret("s:NetrwRemoteListing -1")
9667 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00009668 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009669
Bram Moolenaar8d043172014-01-23 14:24:41 +01009670 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009671" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009672 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009673 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009674 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 +00009675 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009676 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 +00009677 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009678 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009679
Bram Moolenaar85850f32019-07-19 22:05:51 +02009680 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009681" call Dret("s:NetrwRemoteListing -1")
9682 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009683 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009684" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009685
Bram Moolenaar446cb832008-06-24 21:56:24 +00009686 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009687" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009688 let w:netrw_method= b:netrw_method
9689 endif
9690
Bram Moolenaar13600302014-05-22 18:26:40 +02009691 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +02009692 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009693" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009694 let s:method = "ftp"
9695 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009696 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009697 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009698 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009699 let listcmd= g:netrw_ftp_sizelist_cmd
9700 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009701" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009702 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009703" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009704
Bram Moolenaara6878372014-03-22 21:02:50 +01009705 " report on missing file or directory messages
9706 if search('[Nn]o such file or directory\|Failed to change directory')
9707 let mesg= getline(".")
9708 if exists("w:netrw_bannercnt")
9709 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009710 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +01009711 setl noma
9712 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009713 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009714 call netrw#ErrorMsg(s:WARNING,mesg,96)
9715" call Dret("s:NetrwRemoteListing : -1")
9716 return -1
9717 endif
9718
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009719 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 +00009720 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009721" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009722 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009723
9724 " cleanup
9725 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009726 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
9727 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009728 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009729 sil! NetrwKeepj %s/\r$//e
9730 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009731
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009732 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +00009733 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009734 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +01009735 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009736" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009737 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009738" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009739 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009740 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009741 exe "sil! NetrwKeepj ".line1
9742 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009743
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009744" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009745 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009746" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009747 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
9748 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009749 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009750" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009751 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
9752 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
9753 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
9754 NetrwKeepj call histdel("/",-1)
9755 NetrwKeepj call histdel("/",-1)
9756 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009757 endif
9758 endif
9759
Bram Moolenaar13600302014-05-22 18:26:40 +02009760 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00009761 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009762" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009763 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009764" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009765 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009766" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
9767 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009768 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009769 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
9770 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
9771 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
9772 NetrwKeepj call histdel("/",-1)
9773 NetrwKeepj call histdel("/",-1)
9774 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009775 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009776 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
9777 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009778 endif
9779 else
9780 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009781" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009782 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00009783 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009784" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
9785 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
9786" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009787 endif
9788 endif
9789
9790 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +01009791 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009792" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009793 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
9794 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009795 endif
9796 endif
9797
9798 if w:netrw_liststyle == s:LONGLIST
9799 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009800" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009801
9802 if s:method == "ftp"
9803 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009804 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009805 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009806 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +00009807 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009808 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +00009809 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009810 sil! NetrwKeepj 1
9811 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009812 let line2= line(".")
9813 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009814 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009815 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009816 endif
9817 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009818 exe "sil! NetrwKeepj ".line1
9819 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009820 endif
9821
9822 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009823" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009824 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 +00009825 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009826" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009827 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009828 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009829 exe 'sil NetrwKeepj '.w:netrw_bannercnt
9830 NetrwKeepj call histdel("/",-1)
9831 NetrwKeepj call histdel("/",-1)
9832 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009833 endif
9834 endif
9835
9836" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009837" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009838" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01009839
9840" call Dret("s:NetrwRemoteListing 0")
9841 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009842endfun
9843
Bram Moolenaar446cb832008-06-24 21:56:24 +00009844" ---------------------------------------------------------------------
9845" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
9846fun! s:NetrwRemoteRm(usrhost,path) range
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009847 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009848
9849 let all= 0
9850 if exists("s:netrwmarkfilelist_{bufnr('%')}")
9851 " remove all marked files
9852 for fname in s:netrwmarkfilelist_{bufnr("%")}
9853 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009854 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009855 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009856 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009857 let all= 1
9858 endif
9859 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01009860 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009861
9862 else
9863 " remove files specified by range
9864
9865 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009866 let keepsol = &l:sol
9867 setl nosol
9868 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +00009869
9870 " remove multiple files and directories
9871 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009872 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009873 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009874 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009875 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009876 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009877 let all= 1
9878 endif
9879 let ctr= ctr + 1
9880 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009881 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +00009882 endif
9883
9884 " refresh the (remote) directory listing
Tom Benham64a536d2024-11-07 21:15:03 +01009885 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009886 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009887endfun
9888
9889" ---------------------------------------------------------------------
9890" s:NetrwRemoteRmFile: {{{2
9891fun! s:NetrwRemoteRmFile(path,rmfile,all)
9892" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
9893
9894 let all= a:all
9895 let ok = ""
9896
9897 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
9898 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009899" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009900 if !all
9901 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009902" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009903 call inputsave()
9904 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
9905 call inputrestore()
9906 echohl NONE
9907 if ok == ""
9908 let ok="no"
9909 endif
9910 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009911 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009912 let all= 1
9913 endif
9914 endif
9915
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009916 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009917" 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 +00009918 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009919" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009920 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009921 if path =~ '^\a\{3,}://'
9922 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009923 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009924 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009925 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
9926 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009927" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009928 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009929" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009930 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009931 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009932 let ok="q"
9933 else
MiguelBarroc46c21b2024-01-31 20:07:17 +01009934 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009935" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
9936" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
9937" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009938 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009939 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009940 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009941 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009942 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009943" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009944 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009945 if v:shell_error != 0
9946 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09009947 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 +01009948 else
9949 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
9950 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009951 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009952 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009953 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009954" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009955 endif
9956 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009957 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009958" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009959 endif
9960
9961 else
9962 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009963" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009964 if !all
9965 call inputsave()
9966 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
9967 call inputrestore()
9968 if ok == ""
9969 let ok="no"
9970 endif
9971 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009972 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009973 let all= 1
9974 endif
9975 endif
9976
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009977 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00009978 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009979 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009980 else
9981 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009982 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
9983" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00009984 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009985" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009986
9987 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009988" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
9989 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
9990" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00009991 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009992" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009993
9994 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009995 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009996 endif
9997 endif
9998 endif
9999
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010000 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010001" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010002 endif
10003 endif
10004
10005" call Dret("s:NetrwRemoteRmFile ".ok)
10006 return ok
10007endfun
10008
10009" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010010" s:NetrwRemoteRename: rename a remote file or directory {{{2
10011fun! s:NetrwRemoteRename(usrhost,path) range
Bram Moolenaar446cb832008-06-24 21:56:24 +000010012
10013 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010014 let svpos = winsaveview()
10015" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010016 let ctr = a:firstline
10017 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10018
10019 " rename files given by the markfilelist
10020 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10021 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +000010022 if exists("subfrom")
10023 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010024 else
10025 call inputsave()
10026 let newname= input("Moving ".oldname." to : ",oldname)
10027 call inputrestore()
10028 if newname =~ '^s/'
10029 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10030 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10031 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010032 endif
10033 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010034
Bram Moolenaar446cb832008-06-24 21:56:24 +000010035 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010036 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010037 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010038 let oldname= s:ShellEscape(a:path.oldname)
10039 let newname= s:ShellEscape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010040 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010041 endif
10042
10043 endfor
10044 call s:NetrwUnMarkFile(1)
10045
10046 else
10047
10048 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010049 let keepsol= &l:sol
10050 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010051 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010052 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010053
10054 let oldname= s:NetrwGetWord()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010055
10056 call inputsave()
10057 let newname= input("Moving ".oldname." to : ",oldname)
10058 call inputrestore()
10059
10060 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10061 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10062 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010063 let oldname= s:ShellEscape(a:path.oldname)
10064 let newname= s:ShellEscape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010065 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010066 endif
10067
10068 let ctr= ctr + 1
10069 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010070 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010071 endif
10072
10073 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010074 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010075 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010076endfun
10077
Bram Moolenaar85850f32019-07-19 22:05:51 +020010078" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010079" Local Directory Browsing Support: {{{1
10080" ==========================================
10081
10082" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010083" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010084" Should accept: file://localhost/etc/fstab
10085" file:///etc/fstab
10086" file:///c:/WINDOWS/clock.avi
10087" file:///c|/WINDOWS/clock.avi
10088" file://localhost/c:/WINDOWS/clock.avi
10089" file://localhost/c|/WINDOWS/clock.avi
10090" file://c:/foo.txt
10091" file:///c:/foo.txt
10092" 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 +020010093fun! netrw#FileUrlEdit(fname)
10094" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010095 let fname = a:fname
10096 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010097" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010098 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010099" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010100 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010101 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010102 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010103" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010104 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010105" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010106 endif
10107 endif
10108 let fname2396 = netrw#RFC2396(fname)
10109 let fname2396e= fnameescape(fname2396)
10110 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010111 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010112" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010113 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010114" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010115 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10116 endif
10117 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010118
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010119" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10120" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010121 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010122 exe 'NetrwKeepj keepalt edit '.plainfname
10123 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10124
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010125" 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 +020010126" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010127 exe "sil doau BufReadPost ".fname2396e
10128endfun
10129
10130" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010131" netrw#LocalBrowseCheck: {{{2
10132fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010133 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010134 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10135 "
10136 " unfortunate interaction -- split window debugging can't be used here, must use
10137 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10138 " another call to LocalBrowseCheck() when attempts to write
10139 " to the DBG buffer are made.
10140 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010141 " The &ft == "netrw" test was installed because the BufEnter event
10142 " would hit when re-entering netrw windows, creating unexpected
10143 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010144" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010145" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010146" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +010010147 " getting E930: Cannot use :redir inside execute
10148"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010149" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10150" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010151
Bram Moolenaar97d62492012-11-15 21:28:22 +010010152 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010153 if isdirectory(s:NetrwFile(a:dirname))
10154" 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 +010010155
Bram Moolenaar97d62492012-11-15 21:28:22 +010010156 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010157" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10158" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010159 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010160
Bram Moolenaar446cb832008-06-24 21:56:24 +000010161 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010162" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010163 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010164
Bram Moolenaar5c736222010-01-06 20:54:52 +010010165 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010166" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010167 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010168 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010169 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010170" 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 +010010171" call Dret("netrw#LocalBrowseCheck")
10172 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010173 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010174
Bram Moolenaar85850f32019-07-19 22:05:51 +020010175 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010176 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10177 " AND IF the listing style is not a tree listing
10178 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010179" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010180 let ibuf = 1
10181 let buflast = bufnr("$")
10182 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010183 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10184 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010185 endif
10186 let ibuf= ibuf + 1
10187 endwhile
10188 endif
10189 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010190" 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>"))
10191" 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 +000010192 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010193" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010194endfun
10195
10196" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010197" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010198" performed any shell command. The idea is to cause all local-browsing
10199" buffers to be refreshed after a user has executed some shell command,
10200" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010201fun! s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010202 " determine which buffers currently reside in a tab
10203 if !exists("s:netrw_browselist")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010204 return
10205 endif
10206 if !exists("w:netrw_bannercnt")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010207 return
10208 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010209 if !empty(getcmdwintype())
10210 " cannot move away from cmdline window, see :h E11
10211 return
10212 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010213 if exists("s:netrw_events") && s:netrw_events == 1
10214 " s:LocalFastBrowser gets called (indirectly) from a
10215 let s:netrw_events= 2
Bram Moolenaara6878372014-03-22 21:02:50 +010010216 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010217 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010218 let itab = 1
10219 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010220 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010221 while itab <= tabpagenr("$")
10222 let buftablist = buftablist + tabpagebuflist()
10223 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010224 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010225 endwhile
Bram Moolenaar446cb832008-06-24 21:56:24 +000010226 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10227 " | refresh any netrw window
10228 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010229 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010230 let ibl = 0
10231 for ibuf in s:netrw_browselist
Bram Moolenaar446cb832008-06-24 21:56:24 +000010232 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10233 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010234 " (ibuf not shown in a current window AND
10235 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010236 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010237 call remove(s:netrw_browselist,ibl)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010238 continue
10239 elseif index(tabpagebuflist(),ibuf) != -1
10240 " refresh any netrw buffer
Bram Moolenaar446cb832008-06-24 21:56:24 +000010241 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010242 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010243 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10244 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10245 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10246 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010247 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10248 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10249 endif
Tom Benham64a536d2024-11-07 21:15:03 +010010250 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010251 endif
10252 let ibl= ibl + 1
10253 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010254 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010255 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010256endfun
10257
10258" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010259" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10260"
10261" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010262" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010263" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10264" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010265" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010266"
10267" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
10268" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010010269" (re-using a buffer may not be as accurate)
10270"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010271" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010010272" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
10273" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
10274" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
10275" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010276fun! s:LocalFastBrowser()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010277
10278 " initialize browselist, a list of buffer numbers that the local browser has used
10279 if !exists("s:netrw_browselist")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010280 let s:netrw_browselist= []
10281 endif
10282
10283 " append current buffer to fastbrowse list
10284 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaar97d62492012-11-15 21:28:22 +010010285 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010286 endif
10287
10288 " enable autocmd events to handle refreshing/removing local browser buffers
10289 " If local browse buffer is currently showing: refresh it
10290 " If local browse buffer is currently hidden : wipe it
10291 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
10292 " =1 : medium speed, re-use directory listing for remote only
10293 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010010294 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
10295 let s:netrw_events= 1
10296 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010297 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020010298 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010010299 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010300 else
Bram Moolenaara6878372014-03-22 21:02:50 +010010301 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010302 endif
10303 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010010304
10305 " user must have changed fastbrowse to its fast setting, so remove
10306 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010010307 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara6878372014-03-22 21:02:50 +010010308 unlet s:netrw_events
10309 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010310 au!
10311 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010010312 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010313 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010314endfun
10315
Tom Benham64a536d2024-11-07 21:15:03 +010010316fun! s:NetrwLocalListingList(dirname,setmaxfilenamelen)
Bram Moolenaara6878372014-03-22 21:02:50 +010010317 " get the list of files contained in the current directory
Tom Benham64a536d2024-11-07 21:15:03 +010010318 let dirname = a:dirname
10319 let dirnamelen = strlen(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010320 let filelist = s:NetrwGlob(dirname,"*",0)
10321 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara6878372014-03-22 21:02:50 +010010322
Nir Lichtman1e34b952024-05-08 19:19:34 +020010323 if g:netrw_cygwin == 0 && has("win32")
Tom Benham64a536d2024-11-07 21:15:03 +010010324 elseif index(filelist,'..') == -1 && dirname !~ '/'
Bram Moolenaara6878372014-03-22 21:02:50 +010010325 " include ../ in the glob() entry if its missing
Tom Benham64a536d2024-11-07 21:15:03 +010010326 let filelist= filelist+[s:ComposePath(dirname,"../")]
Bram Moolenaara6878372014-03-22 21:02:50 +010010327 endif
10328
Tom Benham64a536d2024-11-07 21:15:03 +010010329 if a:setmaxfilenamelen && get(g:, 'netrw_dynamic_maxfilenamelen', 0)
Bram Moolenaara6878372014-03-22 21:02:50 +010010330 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
10331 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara6878372014-03-22 21:02:50 +010010332 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010333
Tom Benham64a536d2024-11-07 21:15:03 +010010334 let resultfilelist = []
Bram Moolenaara6878372014-03-22 21:02:50 +010010335 for filename in filelist
Bram Moolenaara6878372014-03-22 21:02:50 +010010336
10337 if getftype(filename) == "link"
10338 " indicate a symbolic link
Bram Moolenaara6878372014-03-22 21:02:50 +010010339 let pfile= filename."@"
10340
10341 elseif getftype(filename) == "socket"
10342 " indicate a socket
Bram Moolenaara6878372014-03-22 21:02:50 +010010343 let pfile= filename."="
10344
10345 elseif getftype(filename) == "fifo"
10346 " indicate a fifo
Bram Moolenaara6878372014-03-22 21:02:50 +010010347 let pfile= filename."|"
10348
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010349 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010350 " indicate a directory
Bram Moolenaara6878372014-03-22 21:02:50 +010010351 let pfile= filename."/"
10352
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010353 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020010354 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010010355 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
10356 " indicate an executable
Bram Moolenaara6878372014-03-22 21:02:50 +010010357 let pfile= filename."*"
10358 else
10359 " normal file
10360 let pfile= filename
10361 endif
10362 elseif executable(filename)
10363 " indicate an executable
Bram Moolenaara6878372014-03-22 21:02:50 +010010364 let pfile= filename."*"
10365 else
10366 " normal file
10367 let pfile= filename
10368 endif
10369
10370 else
10371 " normal file
10372 let pfile= filename
10373 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010374
10375 if pfile =~ '//$'
10376 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara6878372014-03-22 21:02:50 +010010377 endif
10378 let pfile= strpart(pfile,dirnamelen)
10379 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara6878372014-03-22 21:02:50 +010010380
10381 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090010382 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
10383 let sz = getfsize(filename)
10384 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
10385 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010010386
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010387 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010388 let sz= s:NetrwHumanReadable(sz)
10389 endif
K.Takata8750e3c2023-11-22 18:20:01 +090010390 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090010391 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010392 endif
10393
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010394 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010010395 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010010396 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaara6878372014-03-22 21:02:50 +010010397 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090010398 let ft = printf("%018d",t)
Bram Moolenaara6878372014-03-22 21:02:50 +010010399 let ftpfile= ft.'/'.pfile
Tom Benham64a536d2024-11-07 21:15:03 +010010400 let resultfilelist += [ftpfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010401
10402 elseif g:netrw_sort_by =~ "^s"
10403 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaara6878372014-03-22 21:02:50 +010010404 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090010405 let fsz = printf("%018d",sz)
Bram Moolenaara6878372014-03-22 21:02:50 +010010406 let fszpfile= fsz.'/'.pfile
Tom Benham64a536d2024-11-07 21:15:03 +010010407 let resultfilelist += [fszpfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010408
10409 else
10410 " sort by name
Tom Benham64a536d2024-11-07 21:15:03 +010010411 let resultfilelist += [pfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010412 endif
Tom Benham64a536d2024-11-07 21:15:03 +010010413 endfor
10414
10415 return resultfilelist
10416endfun
10417
10418" ---------------------------------------------------------------------
10419" s:LocalListing: does the job of "ls" for local directories {{{2
10420fun! s:LocalListing()
10421
10422 let filelist = s:NetrwLocalListingList(b:netrw_curdir, 1)
10423 for filename in filelist
10424 sil! NetrwKeepj put =filename
Bram Moolenaara6878372014-03-22 21:02:50 +010010425 endfor
10426
10427 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010428 sil! NetrwKeepj g/^$/d
10429 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010010430 call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010431 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010432endfun
10433
10434" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010435" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
10436fun! s:NetrwLocalExecute(cmd)
10437" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
10438 let ykeep= @@
10439 " sanity check
10440 if !executable(a:cmd)
10441 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
10442 let @@= ykeep
10443" call Dret("s:NetrwLocalExecute")
10444 return
10445 endif
10446
10447 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010448" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010449 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010450" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010451
10452 " strip any ansi escape sequences off
10453 let result = substitute(result,"\e\\[[0-9;]*m","","g")
10454
10455 " show user the result(s)
10456 echomsg result
10457 let @@= ykeep
10458
10459" call Dret("s:NetrwLocalExecute")
10460endfun
10461
10462" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010463" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010464fun! s:NetrwLocalRename(path) range
Bram Moolenaar97d62492012-11-15 21:28:22 +010010465
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010466 if !exists("w:netrw_bannercnt")
10467 let w:netrw_bannercnt= b:netrw_bannercnt
10468 endif
10469
Bram Moolenaar97d62492012-11-15 21:28:22 +010010470 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010010471 let ykeep = @@
10472 let ctr = a:firstline
10473 let svpos = winsaveview()
10474 let all = 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010010475
10476 " rename files given by the markfilelist
10477 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10478 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar97d62492012-11-15 21:28:22 +010010479 if exists("subfrom")
10480 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaar97d62492012-11-15 21:28:22 +010010481 else
10482 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010483 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010484 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010485 if newname =~ ''
10486 " two ctrl-x's : ignore all of string preceding the ctrl-x's
10487 let newname = substitute(newname,'^.*','','')
10488 elseif newname =~ ''
10489 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
10490 let newname = substitute(newname,'[^/]*','','')
10491 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010492 if newname =~ '^s/'
10493 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10494 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaar97d62492012-11-15 21:28:22 +010010495 let newname = substitute(oldname,subfrom,subto,'')
10496 endif
10497 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010010498 if !all && filereadable(newname)
10499 call inputsave()
10500 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
10501 call inputrestore()
10502 if response == "all"
10503 let all= 1
10504 elseif response != "y" && response != "yes"
10505 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010506 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaar29634562020-01-09 21:46:04 +010010507 NetrwKeepj call winrestview(svpos)
10508 let @@= ykeep
Bram Moolenaar29634562020-01-09 21:46:04 +010010509 return
10510 endif
10511 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010512 call rename(oldname,newname)
10513 endfor
10514 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010515
Bram Moolenaar97d62492012-11-15 21:28:22 +010010516 else
10517
10518 " attempt to rename files/directories
10519 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010520 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010010521
10522 " sanity checks
10523 if line(".") < w:netrw_bannercnt
10524 let ctr= ctr + 1
10525 continue
10526 endif
10527 let curword= s:NetrwGetWord()
10528 if curword == "./" || curword == "../"
10529 let ctr= ctr + 1
10530 continue
10531 endif
10532
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010533 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010010534 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010535
10536 call inputsave()
10537 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
10538 call inputrestore()
10539
10540 call rename(oldname,newname)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010541 let ctr= ctr + 1
10542 endwhile
10543 endif
10544
10545 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010546 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010547 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010548 let @@= ykeep
Bram Moolenaar97d62492012-11-15 21:28:22 +010010549endfun
10550
10551" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010552" s:NetrwLocalRm: {{{2
10553fun! s:NetrwLocalRm(path) range
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010554 if !exists("w:netrw_bannercnt")
10555 let w:netrw_bannercnt= b:netrw_bannercnt
10556 endif
10557
Bram Moolenaar446cb832008-06-24 21:56:24 +000010558 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010010559 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010560 let ret = 0
10561 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010562 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010563
10564 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10565 " remove all marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +000010566 for fname in s:netrwmarkfilelist_{bufnr("%")}
10567 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010568 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010569 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010570 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010571 let all= 1
10572 endif
10573 endfor
10574 call s:NetrwUnMarkFile(1)
10575
10576 else
10577 " remove (multiple) files and directories
Bram Moolenaar446cb832008-06-24 21:56:24 +000010578
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010579 let keepsol= &l:sol
10580 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010581 let ctr = a:firstline
10582 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010583 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010584
10585 " sanity checks
10586 if line(".") < w:netrw_bannercnt
10587 let ctr= ctr + 1
10588 continue
10589 endif
10590 let curword= s:NetrwGetWord()
10591 if curword == "./" || curword == "../"
10592 let ctr= ctr + 1
10593 continue
10594 endif
10595 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010596 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010597 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010598 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010599 let all= 1
10600 endif
10601 let ctr= ctr + 1
10602 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010603 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010604 endif
10605
10606 " refresh the directory
Bram Moolenaar446cb832008-06-24 21:56:24 +000010607 if bufname("%") != "NetrwMessage"
Tom Benham64a536d2024-11-07 21:15:03 +010010608 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010609 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010610 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010611 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010612endfun
10613
10614" ---------------------------------------------------------------------
10615" s:NetrwLocalRmFile: remove file fname given the path {{{2
10616" Give confirmation prompt unless all==1
10617fun! s:NetrwLocalRmFile(path,fname,all)
10618" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010619
Bram Moolenaar446cb832008-06-24 21:56:24 +000010620 let all= a:all
10621 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010622 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020010623 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010624" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010625
10626 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
10627 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010628" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010629 if !all
10630 echohl Statement
10631 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020010632 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010633 call inputrestore()
10634 echohl NONE
10635 if ok == ""
10636 let ok="no"
10637 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010638" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010639 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010640" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010641 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010642 let all= 1
10643 endif
10644 endif
10645
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010646 if all || ok =~# '^y\%[es]$' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000010647 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010648" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010649 endif
10650
10651 else
10652 " attempt to remove directory
10653 if !all
10654 echohl Statement
10655 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020010656 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010657 call inputrestore()
10658 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
10659 if ok == ""
10660 let ok="no"
10661 endif
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010662 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010663 let all= 1
10664 endif
10665 endif
10666 let rmfile= substitute(rmfile,'[\/]$','','e')
10667
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010668 if all || ok =~# '^y\%[es]$' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020010669 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010010670 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010671 endif
10672 endif
10673 endif
10674
10675" call Dret("s:NetrwLocalRmFile ".ok)
10676 return ok
10677endfun
10678
Bram Moolenaar85850f32019-07-19 22:05:51 +020010679" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010680" Support Functions: {{{1
10681
Bram Moolenaar488c6512005-08-11 20:09:58 +000010682" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010683" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
10684" 0: marked file list of current buffer
10685" 1: marked file target
10686fun! netrw#Access(ilist)
10687 if a:ilist == 0
10688 if exists("s:netrwmarkfilelist_".bufnr('%'))
10689 return s:netrwmarkfilelist_{bufnr('%')}
10690 else
10691 return "no-list-buf#".bufnr('%')
10692 endif
10693 elseif a:ilist == 1
10694 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020010695 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010696endfun
10697
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010698" ---------------------------------------------------------------------
10699" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
10700fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010701 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010702endfun
10703
Bram Moolenaara6878372014-03-22 21:02:50 +010010704" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010705" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
10706" I expect this function to be used in
10707" :PChkAssert netrw#Expose("netrwmarkfilelist")
10708" for example.
10709fun! netrw#Expose(varname)
10710" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010711 if exists("s:".a:varname)
10712 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010713" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010714 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010715" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010716 if type(retval) == 3
10717 let retval = copy(retval)
10718 let i = 0
10719 while i < len(retval)
10720 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
10721 let i = i + 1
10722 endwhile
10723 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010724" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010725 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010726 else
10727" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010728 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010729 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010730" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010731 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010732 endif
10733
10734" call Dret("netrw#Expose ".string(retval))
10735 return retval
10736endfun
10737
10738" ---------------------------------------------------------------------
10739" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
10740fun! netrw#Modify(varname,newvalue)
10741" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
10742 exe "let s:".a:varname."= ".string(a:newvalue)
10743" call Dret("netrw#Modify")
10744endfun
10745
10746" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010747" netrw#RFC2396: converts %xx into characters {{{2
10748fun! netrw#RFC2396(fname)
10749" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090010750 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010010751" call Dret("netrw#RFC2396 ".fname)
10752 return fname
10753endfun
10754
10755" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010756" netrw#UserMaps: supports user-specified maps {{{2
10757" see :help function()
10758"
10759" g:Netrw_UserMaps is a List with members such as:
10760" [[keymap sequence, function reference],...]
10761"
10762" The referenced function may return a string,
10763" refresh : refresh the display
10764" -other- : this string will be executed
10765" or it may return a List of strings.
10766"
10767" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020010768" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010769" Related functions:
10770" netrw#Expose(varname) -- see s:varname variables
10771" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
10772" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
10773fun! netrw#UserMaps(islocal)
10774" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
10775" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
10776
10777 " set up usermaplist
10778 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
10779" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
10780 for umap in g:Netrw_UserMaps
10781" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
10782" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
10783 " if umap[0] is a string and umap[1] is a string holding a function name
10784 if type(umap[0]) == 1 && type(umap[1]) == 1
10785" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
10786 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
10787 else
10788 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
10789 endif
10790 endfor
10791 endif
10792" call Dret("netrw#UserMaps")
10793endfun
10794
10795" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010796" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
10797fun! netrw#WinPath(path)
10798" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010799 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010800 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010010801 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010802 " remove trailing slash (Win95)
10803 let path = substitute(path, '\(\\\|/\)$', '', 'g')
10804 " remove escaped spaces
10805 let path = substitute(path, '\ ', ' ', 'g')
10806 " convert slashes to backslashes
10807 let path = substitute(path, '/', '\', 'g')
10808 else
10809 let path= a:path
10810 endif
10811" call Dret("netrw#WinPath <".path.">")
10812 return path
10813endfun
10814
10815" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020010816" s:StripTrailingSlash: removes trailing slashes from a path {{{2
10817fun! s:StripTrailingSlash(path)
10818 " remove trailing slash
10819 return substitute(a:path, '[/\\]$', '', 'g')
10820endfun
10821
Travis Sheltone34d0e32024-07-30 21:08:56 +020010822" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010823" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
10824" cb : bl2mf=0 add marked files to buffer list
10825" cB : bl2mf=1 use bufferlist to mark files
10826" (mnemonic: cb = copy (marked files) to buffer list)
10827fun! s:NetrwBadd(islocal,bl2mf)
10828" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
10829 if a:bl2mf
10830 " cB: add buffer list to marked files
10831 redir => bufl
10832 ls
10833 redir END
10834 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
10835 for fname in bufl
10836 call s:NetrwMarkFile(a:islocal,fname)
10837 endfor
10838 else
10839 " cb: add marked files to buffer list
10840 for fname in s:netrwmarkfilelist_{bufnr("%")}
10841" " call Decho("badd ".fname,'~'.expand("<slnum>"))
10842 exe "badd ".fnameescape(fname)
10843 endfor
10844 let curbufnr = bufnr("%")
10845 let curdir = s:NetrwGetCurdir(a:islocal)
10846 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
10847 endif
10848" call Dret("s:NetrwBadd")
10849endfun
10850
10851" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000010852" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
10853fun! s:ComposePath(base,subdir)
10854" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
10855
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010856 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010857" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010858 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000010859 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010860 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000010861 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010862 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000010863 endif
10864
Bram Moolenaar85850f32019-07-19 22:05:51 +020010865 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020010866 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010867" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010868 let ret= a:subdir
10869
Nir Lichtman1e34b952024-05-08 19:19:34 +020010870 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010871" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010872 if a:base =~ '[/\\]$'
10873 let ret= a:base.a:subdir
10874 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010875 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010010876 endif
10877
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010878 elseif a:base =~ '^\a\{3,}://'
10879" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010880 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
10881 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
10882 if a:subdir == '../'
10883 if curpath =~ '[^/]/[^/]\+/$'
10884 let curpath= substitute(curpath,'[^/]\+/$','','')
10885 else
10886 let curpath=""
10887 endif
10888 let ret= urlbase.curpath
10889 else
10890 let ret= urlbase.curpath.a:subdir
10891 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010892" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
10893" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
10894" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010895
10896 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010897" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010898 let ret = substitute(a:base."/".a:subdir,"//","/","g")
10899 if a:base =~ '^//'
10900 " keeping initial '//' for the benefit of network share listing support
10901 let ret= '/'.ret
10902 endif
10903 let ret= simplify(ret)
10904 endif
10905
10906" call Dret("s:ComposePath ".ret)
10907 return ret
10908endfun
10909
10910" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010911" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
10912" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
10913fun! s:DeleteBookmark(fname)
10914" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
10915 call s:MergeBookmarks()
10916
10917 if exists("g:netrw_bookmarklist")
10918 let indx= index(g:netrw_bookmarklist,a:fname)
10919 if indx == -1
10920 let indx= 0
10921 while indx < len(g:netrw_bookmarklist)
10922 if g:netrw_bookmarklist[indx] =~ a:fname
10923 call remove(g:netrw_bookmarklist,indx)
10924 let indx= indx - 1
10925 endif
10926 let indx= indx + 1
10927 endwhile
10928 else
10929 " remove exact match
10930 call remove(g:netrw_bookmarklist,indx)
10931 endif
10932 endif
10933
10934" call Dret("s:DeleteBookmark")
10935endfun
10936
10937" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000010938" s:FileReadable: o/s independent filereadable {{{2
10939fun! s:FileReadable(fname)
10940" call Dfunc("s:FileReadable(fname<".a:fname.">)")
10941
10942 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010943 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010944 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010945 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010946 endif
10947
10948" call Dret("s:FileReadable ".ret)
10949 return ret
10950endfun
10951
10952" ---------------------------------------------------------------------
10953" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
10954" Places correct suffix on end of temporary filename,
10955" using the suffix provided with fname
10956fun! s:GetTempfile(fname)
10957" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
10958
10959 if !exists("b:netrw_tmpfile")
10960 " get a brand new temporary filename
10961 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010962" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010963
Bram Moolenaarc236c162008-07-13 17:41:49 +000010964 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010965" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010966
Bram Moolenaar9964e462007-05-05 17:54:07 +000010967 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010968 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
10969" 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 +010010970 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010971" call Dret("s:GetTempfile getcwd<".getcwd().">")
10972 return ""
10973 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010974
Bram Moolenaar9964e462007-05-05 17:54:07 +000010975 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010976 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010977" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010978
Bram Moolenaar9964e462007-05-05 17:54:07 +000010979 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000010980 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010010981 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020010982 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010983 if !exists("+shellslash") || !&ssl
10984 let tmpfile = substitute(tmpfile,'/','\','g')
10985 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010986 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010987 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000010988 endif
10989 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010990" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010991 else
10992 " re-use temporary filename
10993 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010994" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010995 endif
10996
10997 " use fname's suffix for the temporary file
10998 if a:fname != ""
10999 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011000" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011001 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011002 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011003 elseif a:fname =~ '.txz$'
11004 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011005 else
11006 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11007 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011008" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011009 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011010" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011011 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011012" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011013 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11014 endif
11015 endif
11016
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011017" 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 +000011018" call Dret("s:GetTempfile <".tmpfile.">")
11019 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011020endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011021
11022" ---------------------------------------------------------------------
11023" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011024" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011025fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011026" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011027 if s:user == ""
11028 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11029 else
11030 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11031 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011032 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011033 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011034 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011035 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011036 else
11037 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11038 endif
11039" call Dret("s:MakeSshCmd <".sshcmd.">")
11040 return sshcmd
11041endfun
11042
11043" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011044" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11045fun! s:MakeBookmark(fname)
11046" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11047
11048 if !exists("g:netrw_bookmarklist")
11049 let g:netrw_bookmarklist= []
11050 endif
11051
11052 if index(g:netrw_bookmarklist,a:fname) == -1
11053 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011054 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011055 call add(g:netrw_bookmarklist,a:fname.'/')
11056 elseif a:fname !~ '/'
11057 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11058 else
11059 call add(g:netrw_bookmarklist,a:fname)
11060 endif
11061 call sort(g:netrw_bookmarklist)
11062 endif
11063
11064" call Dret("s:MakeBookmark")
11065endfun
11066
11067" ---------------------------------------------------------------------
11068" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11069fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011070" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011071 " get bookmarks from .netrwbook file
11072 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011073 if filereadable(s:NetrwFile(savefile))
11074" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011075 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011076" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011077 NetrwKeepj call delete(savefile)
11078 endif
11079" call Dret("s:MergeBookmarks")
11080endfun
11081
11082" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011083" s:NetrwBMShow: {{{2
11084fun! s:NetrwBMShow()
11085" call Dfunc("s:NetrwBMShow()")
11086 redir => bmshowraw
11087 menu
11088 redir END
11089 let bmshowlist = split(bmshowraw,'\n')
11090 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011091 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011092 if bmshowfuncs != []
11093 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011094 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011095 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011096 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011097 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011098 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011099" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11100endfun
11101
11102" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011103" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011104fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011105 if !exists("w:netrw_liststyle")
11106 let w:netrw_liststyle= g:netrw_liststyle
11107 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011108" 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 +020011109
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011110" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11111
Bram Moolenaaradc21822011-04-01 18:03:16 +020011112 if &ft != "netrw"
11113 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11114 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011115" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011116
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011117 elseif g:netrw_cursor == 8
11118 if w:netrw_liststyle == s:WIDELIST
11119 setl cursorline
11120 setl cursorcolumn
11121 else
11122 setl cursorline
11123 endif
11124 elseif g:netrw_cursor == 7
11125 setl cursorline
11126 elseif g:netrw_cursor == 6
11127 if w:netrw_liststyle == s:WIDELIST
11128 setl cursorline
11129 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011130 elseif g:netrw_cursor == 4
11131 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011132" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011133 setl cursorline
11134 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011135
11136 elseif g:netrw_cursor == 3
11137 " thin-long-tree: cursorline, user's cursorcolumn
11138 " wide : cursorline, cursorcolumn
11139 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011140" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011141 setl cursorline
11142 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011143 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011144" 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 +020011145 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011146 endif
11147
11148 elseif g:netrw_cursor == 2
11149 " thin-long-tree: cursorline, user's cursorcolumn
11150 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011151" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011152 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011153
11154 elseif g:netrw_cursor == 1
11155 " thin-long-tree: user's cursorline, user's cursorcolumn
11156 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011157 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011158" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011159 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011160 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011161" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011162 endif
11163
11164 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011165 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011166" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011167 let &l:cursorline = s:netrw_usercul
11168 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011169 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011170
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011171" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011172" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011173endfun
11174
11175" ---------------------------------------------------------------------
11176" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11177fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011178" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011179 if exists("s:netrw_usercul")
11180 let &l:cursorline = s:netrw_usercul
11181 endif
11182 if exists("s:netrw_usercuc")
11183 let &l:cursorcolumn = s:netrw_usercuc
11184 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011185" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011186" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11187endfun
11188
Christian Brabandt62f7b552024-06-23 20:23:40 +020011189" s:RestoreRegister: restores all registers given in the dict {{{2
11190fun! s:RestoreRegister(dict)
11191 for [key, val] in items(a:dict)
11192 if key == 'unnamed'
11193 let key = ''
11194 endif
11195 call setreg(key, val[0], val[1])
11196 endfor
11197endfun
11198
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011199" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011200" s:NetrwDelete: Deletes a file. {{{2
11201" Uses Steve Hall's idea to insure that Windows paths stay
11202" acceptable. No effect on Unix paths.
11203" Examples of use: let result= s:NetrwDelete(path)
11204fun! s:NetrwDelete(path)
11205" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11206
Bram Moolenaar5c736222010-01-06 20:54:52 +010011207 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011208 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000011209 if exists("+shellslash")
11210 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011211 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011212 let result = delete(path)
11213 let &shellslash = sskeep
11214 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011215" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011216 let result= delete(path)
11217 endif
11218 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011219" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011220 let result= delete(path)
11221 endif
11222 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011223 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011224 endif
11225
11226" call Dret("s:NetrwDelete ".result)
11227 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000011228endfun
11229
11230" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011231" s:NetrwBufRemover: removes a buffer that: {{{2s
11232" has buffer-id > 1
11233" is unlisted
11234" is unnamed
11235" does not appear in any window
11236fun! s:NetrwBufRemover(bufid)
11237" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
11238" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
11239" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
11240" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
11241" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
11242
yasuda4dbb2662023-10-04 20:50:35 +020011243 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011244" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020011245 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011246 endif
11247
11248" call Dret("s:NetrwBufRemover")
11249endfun
11250
11251" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011252" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010011253fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011254" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011255" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011256
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011257 " Clean out the last buffer:
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011258 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
11259 " If so, delete it.
11260 call s:NetrwBufRemover(bufnr("$"))
11261
Bram Moolenaar446cb832008-06-24 21:56:24 +000011262 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011263" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011264 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
11265 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
11266 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
11267 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
11268 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11269 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
11270 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
11271 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
11272 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
11273 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11274 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
11275 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
11276 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
11277 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
11278 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
11279 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
11280
Bram Moolenaar85850f32019-07-19 22:05:51 +020011281 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011282" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011283 " when tree listing uses file TreeListing... a new buffer is made.
11284 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011285 " COMBAK: this causes a problem, see P43
11286" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011287 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010011288 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011289 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011290" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020011291 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011292
Bram Moolenaar446cb832008-06-24 21:56:24 +000011293 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011294" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011295 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
11296 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
11297 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
11298 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
11299 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
11300 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
11301 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
11302 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
11303 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
11304 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
11305 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
11306 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
11307 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
11308 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
11309 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
11310 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
11311
Bram Moolenaar5c736222010-01-06 20:54:52 +010011312 if a:0 > 0
11313 let b:netrw_curdir= a:1
11314 if b:netrw_curdir =~ '/$'
11315 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011316 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010011317 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011318 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020011319 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
11320 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010011321 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011322 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010011323 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011324 endif
11325 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011326 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
11327 let &l:bexpr = "netrw#BalloonHelp()"
11328 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011329
Bram Moolenaar8d043172014-01-23 14:24:41 +010011330" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011331endfun
11332
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011333" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011334" s:NetrwExe: executes a string using "!" {{{2
11335fun! s:NetrwExe(cmd)
GuyBrushd7745ac2024-11-23 14:13:10 +010011336 if has("win32") && exepath(&shell) !~? '\v[\/]?(cmd|pwsh|powershell)(\.exe)?$' && !g:netrw_cygwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011337 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
11338 set shell& shellcmdflag& shellxquote& shellxescape&
11339 set shellquote& shellpipe& shellredir& shellslash&
Konfekt3d7e5672024-10-27 22:16:49 +010011340 try
11341 exe a:cmd
11342 finally
11343 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
11344 endtry
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011345 else
11346 exe a:cmd
11347 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011348 if v:shell_error
11349 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
11350 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011351endfun
11352
11353" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011354" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
11355fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011356 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011357" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011358 let curbuf = bufnr("%")
11359 let curwin = winnr()
11360 let iwin = 1
11361 while iwin <= winnr("$")
11362 exe iwin."wincmd w"
11363 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
11364 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
11365 let winvars= w:
11366 break
11367 endif
11368 let iwin= iwin + 1
11369 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020011370 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011371 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011372" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011373 for k in keys(winvars)
11374 let w:{k}= winvars[k]
11375 endfor
11376 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011377" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011378 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011379endfun
11380
Bram Moolenaara6878372014-03-22 21:02:50 +010011381" ---------------------------------------------------------------------
11382" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020011383" Returns: 0=success
11384" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010011385fun! s:NetrwLcd(newdir)
11386" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011387" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011388
Bram Moolenaar85850f32019-07-19 22:05:51 +020011389 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011390 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011391 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010011392 catch /^Vim\%((\a\+)\)\=:E344/
11393 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
11394 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011395 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010011396 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
11397 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020011398 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010011399 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
11400 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090011401 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010011402 endif
11403 endif
11404 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020011405 let err472= 1
11406 endtry
11407
11408 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010011409 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
11410 if exists("w:netrw_prvdir")
11411 let a:newdir= w:netrw_prvdir
11412 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011413 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011414" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020011415 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011416" 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 +010011417 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010011418 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011419" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
11420 return -1
11421 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011422
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011423" call Decho("getcwd <".getcwd().">")
11424" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020011425" call Dret("s:NetrwLcd 0")
11426 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011427endfun
11428
Bram Moolenaar9964e462007-05-05 17:54:07 +000011429" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011430" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
11431" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
11432fun! s:NetrwSaveWordPosn()
11433" call Dfunc("NetrwSaveWordPosn()")
11434 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
11435" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
11436endfun
11437
11438" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011439" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
11440" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
11441fun! s:NetrwHumanReadable(sz)
11442" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
11443
11444 if g:netrw_sizestyle == 'h'
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011445 if a:sz >= 1000000000
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011446 let sz = printf("%.1f",a:sz/1000000000.0)."g"
11447 elseif a:sz >= 10000000
11448 let sz = printf("%d",a:sz/1000000)."m"
11449 elseif a:sz >= 1000000
11450 let sz = printf("%.1f",a:sz/1000000.0)."m"
11451 elseif a:sz >= 10000
11452 let sz = printf("%d",a:sz/1000)."k"
11453 elseif a:sz >= 1000
11454 let sz = printf("%.1f",a:sz/1000.0)."k"
11455 else
11456 let sz= a:sz
11457 endif
11458
11459 elseif g:netrw_sizestyle == 'H'
11460 if a:sz >= 1073741824
11461 let sz = printf("%.1f",a:sz/1073741824.0)."G"
11462 elseif a:sz >= 10485760
11463 let sz = printf("%d",a:sz/1048576)."M"
11464 elseif a:sz >= 1048576
11465 let sz = printf("%.1f",a:sz/1048576.0)."M"
11466 elseif a:sz >= 10240
11467 let sz = printf("%d",a:sz/1024)."K"
11468 elseif a:sz >= 1024
11469 let sz = printf("%.1f",a:sz/1024.0)."K"
11470 else
11471 let sz= a:sz
11472 endif
11473
11474 else
11475 let sz= a:sz
11476 endif
11477
11478" call Dret("s:NetrwHumanReadable ".sz)
11479 return sz
11480endfun
11481
11482" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011483" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
11484" changed sorting, etc. Also see s:NetrwSaveWordPosn().
11485fun! s:NetrwRestoreWordPosn()
11486" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020011487 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000011488" call Dret("NetrwRestoreWordPosn")
11489endfun
11490
11491" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011492" s:RestoreBufVars: {{{2
11493fun! s:RestoreBufVars()
11494" call Dfunc("s:RestoreBufVars()")
11495
11496 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
11497 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
11498 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
11499 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
11500 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
11501 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
11502
11503" call Dret("s:RestoreBufVars")
11504endfun
11505
11506" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011507" s:RemotePathAnalysis: {{{2
11508fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020011509" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011510
Bram Moolenaara6878372014-03-22 21:02:50 +010011511 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010011512 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011513 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010011514 let s:user = substitute(a:dirname,dirpat,'\3','')
11515 let s:machine = substitute(a:dirname,dirpat,'\4','')
11516 let s:port = substitute(a:dirname,dirpat,'\5','')
11517 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020011518 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010011519 if s:machine =~ '@'
11520 let dirpat = '^\(.*\)@\(.\{-}\)$'
11521 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
11522 let s:machine = substitute(s:machine,dirpat,'\2','')
11523 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011524
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011525" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
11526" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
11527" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
11528" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
11529" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
11530" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011531
11532" call Dret("s:RemotePathAnalysis")
11533endfun
11534
11535" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011536" s:RemoteSystem: runs a command on a remote host using ssh {{{2
11537" Returns status
11538" Runs system() on
11539" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011540" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000011541fun! s:RemoteSystem(cmd)
11542" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
11543 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011544 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 +000011545 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011546 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011547 else
11548 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
11549 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
11550 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011551 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000011552 else
11553 let cmd= cmd.' '
11554 endif
11555 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011556" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011557 let ret= system(cmd)
11558 endif
11559" call Dret("s:RemoteSystem ".ret)
11560 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000011561endfun
11562
11563" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011564" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000011565fun! s:RestoreWinVars()
11566" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000011567 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011568 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
11569 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
11570 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
11571 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
11572 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
11573 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
11574 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
11575 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
11576 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
11577 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
11578 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
11579 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000011580 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
11581 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011582 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
11583 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
11584 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
11585" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000011586endfun
11587
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011588" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011589" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
11590"
11591" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
11592" is true) and a command, :Rexplore, which call this function.
11593"
Bram Moolenaar85850f32019-07-19 22:05:51 +020011594" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011595"
11596" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000011597fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020011598 if exists("s:netrwdrag")
11599 return
11600 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011601" 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 +010011602" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
11603" 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 +010011604
11605 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011606 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011607" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011608 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011609 unlet w:netrw_rexfile
11610" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020011611 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011612" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011613" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
11614" 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 +020011615 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011616
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011617 " ---------------------------
11618 " :Rex issued while in a file
11619 " ---------------------------
11620
Bram Moolenaara6878372014-03-22 21:02:50 +010011621 " record current file so :Rex can return to it from netrw
11622 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011623" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011624
11625 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011626" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010011627 return
11628 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011629" 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 +020011630 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011631 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011632 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011633 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011634 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011635 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010011636 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020011637 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011638 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011639" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
11640 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011641" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
11642 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011643 if exists("s:rexposn_".bufnr('%'))
11644 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011645 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011646 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011647" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011648 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011649
Bram Moolenaar85850f32019-07-19 22:05:51 +020011650 if has("syntax") && exists("g:syntax_on") && g:syntax_on
11651 if exists("s:explore_match")
11652 exe "2match netrwMarkFile /".s:explore_match."/"
11653 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010011654 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011655
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011656" 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 +010011657" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011658endfun
11659
11660" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010011661" s:SaveBufVars: save selected b: variables to s: variables {{{2
11662" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000011663fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011664" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011665
11666 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
11667 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
11668 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
11669 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
11670 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
11671 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
11672
11673" call Dret("s:SaveBufVars")
11674endfun
11675
11676" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011677" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
11678fun! s:SavePosn(posndict)
11679" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
11680
Bram Moolenaar85850f32019-07-19 22:05:51 +020011681 if !exists("a:posndict[bufnr('%')]")
11682 let a:posndict[bufnr("%")]= []
11683 endif
11684" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11685 call add(a:posndict[bufnr("%")],winsaveview())
11686" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011687
11688" call Dret("s:SavePosn posndict")
11689 return a:posndict
11690endfun
11691
11692" ---------------------------------------------------------------------
11693" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
11694fun! s:RestorePosn(posndict)
11695" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020011696 if exists("a:posndict")
11697 if has_key(a:posndict,bufnr("%"))
11698" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11699 let posnlen= len(a:posndict[bufnr("%")])
11700 if posnlen > 0
11701 let posnlen= posnlen - 1
11702" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
11703 call winrestview(a:posndict[bufnr("%")][posnlen])
11704 call remove(a:posndict[bufnr("%")],posnlen)
11705" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11706 endif
11707 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011708 endif
11709" call Dret("s:RestorePosn")
11710endfun
11711
11712" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011713" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000011714fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011715" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000011716 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
11717 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
11718 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
11719 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
11720 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
11721 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
11722 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
11723 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
11724 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
11725 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
11726 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
11727 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
11728 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
11729 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
11730 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
11731 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
11732 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
11733 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
11734" call Dret("s:SaveWinVars")
11735endfun
11736
11737" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011738" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011739" To allow separate windows to have their own activities, such as
11740" Explore **/pattern, several variables have been made window-oriented.
11741" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011742" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011743" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011744fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011745" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000011746 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
11747 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
11748 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
11749 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
11750 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
11751 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
11752 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
11753 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
11754 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
11755 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
11756" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011757endfun
11758
11759" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011760" s:SetRexDir: set directory for :Rexplore {{{2
11761fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011762" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011763 let w:netrw_rexdir = a:dirname
11764 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011765 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011766" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
11767" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011768" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011769" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011770" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011771endfun
11772
11773" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011774" s:ShowLink: used to modify thin and tree listings to show links {{{2
11775fun! s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011776 if exists("b:netrw_curdir")
11777 norm! $?\a
Tom Benham64a536d2024-11-07 21:15:03 +010011778 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treetop")
11779 let basedir = s:NetrwTreePath(w:netrw_treetop)
11780 else
11781 let basedir = b:netrw_curdir.'/'
11782 endif
11783 let fname = basedir.s:NetrwGetWord()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011784 let resname = resolve(fname)
Tom Benham64a536d2024-11-07 21:15:03 +010011785 if resname =~ '^\M'.basedir
11786 let dirlen = strlen(basedir)
11787 let resname = strpart(resname,dirlen)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011788 endif
11789 let modline = getline(".")."\t --> ".resname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011790 setl noro ma
11791 call setline(".",modline)
11792 setl ro noma nomod
11793 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011794endfun
11795
11796" ---------------------------------------------------------------------
11797" s:ShowStyle: {{{2
11798fun! s:ShowStyle()
11799 if !exists("w:netrw_liststyle")
11800 let liststyle= g:netrw_liststyle
11801 else
11802 let liststyle= w:netrw_liststyle
11803 endif
11804 if liststyle == s:THINLIST
11805 return s:THINLIST.":thin"
11806 elseif liststyle == s:LONGLIST
11807 return s:LONGLIST.":long"
11808 elseif liststyle == s:WIDELIST
11809 return s:WIDELIST.":wide"
11810 elseif liststyle == s:TREELIST
11811 return s:TREELIST.":tree"
11812 else
11813 return 'n/a'
11814 endif
11815endfun
11816
11817" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010011818" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
11819" Solution from Nicolai Weibull, vim docs (:help strlen()),
11820" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000011821fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011822" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
11823
11824 if v:version >= 703 && exists("*strdisplaywidth")
11825 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011826
Bram Moolenaar8d043172014-01-23 14:24:41 +010011827 elseif type(g:Align_xstrlen) == 1
11828 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
11829 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011830
Bram Moolenaar8d043172014-01-23 14:24:41 +010011831 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000011832 " number of codepoints (Latin a + combining circumflex is two codepoints)
11833 " (comment from TM, solution from NW)
11834 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011835
Bram Moolenaar8d043172014-01-23 14:24:41 +010011836 elseif g:Align_xstrlen == 2
11837 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000011838 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
11839 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011840 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011841
Bram Moolenaar8d043172014-01-23 14:24:41 +010011842 elseif g:Align_xstrlen == 3
11843 " virtual length (counting, for instance, tabs as anything between 1 and
11844 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000011845 " preceded by lam, one otherwise, etc.)
11846 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011847 let modkeep= &l:mod
11848 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011849 call setline(line("."),a:x)
11850 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010011851 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011852 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010011853 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011854
Bram Moolenaar446cb832008-06-24 21:56:24 +000011855 else
11856 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010011857 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011858 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010011859" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011860 return ret
11861endfun
11862
11863" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011864" s:ShellEscape: shellescape(), or special windows handling {{{2
11865fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011866 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011867 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011868 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011869 let f = a:0 > 0 ? a:1 : 0
11870 return shellescape(a:s, f)
11871endfun
11872
11873" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011874" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000011875fun! s:TreeListMove(dir)
11876" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011877 let curline = getline('.')
11878 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
11879 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
11880 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
11881 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
11882 let treedepthchr = substitute(s:treedepthstring,' ','','g')
11883 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
11884" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
11885" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
11886" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
11887" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
11888" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
11889 " COMBAK : need to handle when on a directory
11890 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000011891 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011892 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011893 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011894 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011895" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011896 elseif a:dir == '[]' && nxtline != ''
11897 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011898" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011899 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
11900 if nl != 0
11901 NetrwKeepj norm! k
11902 else
11903 NetrwKeepj norm! G
11904 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011905" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011906 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011907 endif
11908
11909" call Dret("s:TreeListMove")
11910endfun
11911
11912" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011913" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
11914" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
11915" can't be called except via emenu. But due to locale, that menu line may not be called
11916" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
11917fun! s:UpdateBuffersMenu()
11918" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020011919 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000011920 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020011921 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000011922 catch /^Vim\%((\a\+)\)\=:E/
11923 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011924 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000011925 endtry
11926 endif
11927" call Dret("s:UpdateBuffersMenu")
11928endfun
11929
11930" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011931" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020011932" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011933fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000011934" call Dfunc("s:UseBufWinVars()")
11935 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011936 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
11937 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
11938 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
11939 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
11940 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
11941 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11942 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11943 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
11944 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 +000011945" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011946endfun
11947
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011948" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011949" s:UserMaps: supports user-defined UserMaps {{{2
11950" * calls a user-supplied funcref(islocal,curdir)
11951" * interprets result
11952" See netrw#UserMaps()
11953fun! s:UserMaps(islocal,funcname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011954 if !exists("b:netrw_curdir")
11955 let b:netrw_curdir= getcwd()
11956 endif
11957 let Funcref = function(a:funcname)
11958 let result = Funcref(a:islocal)
11959
11960 if type(result) == 1
11961 " if result from user's funcref is a string...
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011962 if result == "refresh"
Tom Benham64a536d2024-11-07 21:15:03 +010011963 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011964 elseif result != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011965 exe result
11966 endif
11967
11968 elseif type(result) == 3
11969 " if result from user's funcref is a List...
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011970 for action in result
11971 if action == "refresh"
Tom Benham64a536d2024-11-07 21:15:03 +010011972 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011973 elseif action != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011974 exe action
11975 endif
11976 endfor
11977 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011978endfun
11979
Bram Moolenaar85850f32019-07-19 22:05:51 +020011980" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011981" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020011982" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000011983let &cpo= s:keepcpo
11984unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000011985
Bram Moolenaar85850f32019-07-19 22:05:51 +020011986" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000011987" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020011988" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000011989" vim:ts=8 fdm=marker