blob: f8554c9dee133afe1ded0e347e4e4c1bd0f4ac7b [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)
Travis Sheltone34d0e32024-07-30 21:08:56 +020035" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010036" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000037" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010038" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000039" Permission is hereby granted to use and distribute this code,
40" with or without modifications, provided that this copyright
41" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000042" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000043" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000044" expressed or implied. By using this plugin, you agree that
45" in no event will the copyright holder be liable for any damages
46" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010047"
48" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
49" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
50"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020051"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000052"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000053" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000054" (James 1:22 RSV)
55" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000056" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000057if &cp || exists("g:loaded_netrw")
58 finish
59endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020060
61" Check that vim has patches that netrw requires.
62" Patches needed for v7.4: 1557, and 213.
63" (netrw will benefit from vim's having patch#656, too)
64let s:needspatches=[1557,213]
65if exists("s:needspatches")
66 for ptch in s:needspatches
67 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
68 if !exists("s:needpatch{ptch}")
69 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
70 endif
71 let s:needpatch{ptch}= 1
72 finish
73 endif
74 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020075endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020076
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010077let g:loaded_netrw = "v173"
Bram Moolenaar446cb832008-06-24 21:56:24 +000078
Bram Moolenaar1afcace2005-11-25 19:54:28 +000079let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010080setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020081"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010082"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010083"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000084
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000085" ======================
86" Netrw Variables: {{{1
87" ======================
88
Bram Moolenaar071d4272004-06-13 20:20:40 +000089" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020090" netrw#ErrorMsg: {{{2
91" 0=note = s:NOTE
92" 1=warning = s:WARNING
93" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010094" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
95" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
96" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010097" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020098fun! netrw#ErrorMsg(level,msg,errnum)
99" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
100
101 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200102" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200103 return
104 endif
105
106 if a:level == 1
107 let level= "**warning** (netrw) "
108 elseif a:level == 2
109 let level= "**error** (netrw) "
110 else
111 let level= "**note** (netrw) "
112 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100113" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200114
Damienb4d11642024-08-15 22:00:45 +0200115 if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200116 " use popup window
117 if type(a:msg) == 3
118 let msg = [level]+a:msg
119 else
120 let msg= level.a:msg
121 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200122 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200123 let s:popuperr_text= ""
124 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200125 " (default) netrw creates a one-line window to show error/warning
126 " messages (reliably displayed)
127
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100128 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200129 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100130" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200131
132 " getting messages out reliably is just plain difficult!
133 " This attempt splits the current window, creating a one line window.
134 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100135" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200136 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100137" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200138 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100139 if type(a:msg) == 3
140 for msg in a:msg
141 NetrwKeepj call setline(line("$")+1,level.msg)
142 endfor
143 else
144 NetrwKeepj call setline(line("$")+1,level.a:msg)
145 endif
146 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200147 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100148" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200149 bo 1split
150 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200151 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200152 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100153 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100154" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200155 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100156 if type(a:msg) == 3
157 for msg in a:msg
158 NetrwKeepj call setline(line("$")+1,level.msg)
159 endfor
160 else
161 NetrwKeepj call setline(line("$"),level.a:msg)
162 endif
163 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200164 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100165" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200166 if &fo !~ '[ta]'
167 syn clear
168 syn match netrwMesgNote "^\*\*note\*\*"
169 syn match netrwMesgWarning "^\*\*warning\*\*"
170 syn match netrwMesgError "^\*\*error\*\*"
171 hi link netrwMesgWarning WarningMsg
172 hi link netrwMesgError Error
173 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100174" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200175 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200176
177 else
178 " (optional) netrw will show messages using echomsg. Even if the
179 " message doesn't appear, at least it'll be recallable via :messages
180" redraw!
181 if a:level == s:WARNING
182 echohl WarningMsg
183 elseif a:level == s:ERROR
184 echohl Error
185 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100186
187 if type(a:msg) == 3
188 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100189 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100190 endfor
191 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100192 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100193 endif
194
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100195" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200196 echohl None
197 endif
198
199" call Dret("netrw#ErrorMsg")
200endfun
201
202" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100203" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100204" Loosely, varname = value.
205fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100206" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100207 if !exists(a:varname)
208 if type(a:value) == 0
209 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200210 elseif type(a:value) == 1 && a:value =~ '^[{[]'
211 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100212 elseif type(a:value) == 1
213 exe "let ".a:varname."="."'".a:value."'"
214 else
215 exe "let ".a:varname."=".a:value
216 endif
217 endif
218endfun
219
220" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000221" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200222call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000223if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100224 call s:NetrwInit("s:THINLIST",0)
225 call s:NetrwInit("s:LONGLIST",1)
226 call s:NetrwInit("s:WIDELIST",2)
227 call s:NetrwInit("s:TREELIST",3)
228 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000229endif
230
Damien7c754112024-08-15 21:58:57 +0200231let s:NOTE = 0
232let s:WARNING = 1
233let s:ERROR = 2
234call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
235
Bram Moolenaar9964e462007-05-05 17:54:07 +0000236" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200237" Default option values: {{{2
238let g:netrw_localcopycmdopt = ""
239let g:netrw_localcopydircmdopt = ""
240let g:netrw_localmkdiropt = ""
241let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200242
243" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000244" Default values for netrw's global protocol variables {{{2
Damienb4d11642024-08-15 22:00:45 +0200245if exists("*popup_atcursor")
246\ && has("syntax")
247\ && exists("g:syntax_on")
248\ && has("mouse")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200249 call s:NetrwInit("g:netrw_use_errorwindow",2)
250else
251 call s:NetrwInit("g:netrw_use_errorwindow",1)
252endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200253
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000254if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100255 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000256 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100257 elseif executable("curl")
258 let g:netrw_dav_cmd = "curl"
259 else
260 let g:netrw_dav_cmd = ""
261 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000262endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000263if !exists("g:netrw_fetch_cmd")
264 if executable("fetch")
265 let g:netrw_fetch_cmd = "fetch -o"
266 else
267 let g:netrw_fetch_cmd = ""
268 endif
269endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100270if !exists("g:netrw_file_cmd")
271 if executable("elinks")
272 call s:NetrwInit("g:netrw_file_cmd","elinks")
273 elseif executable("links")
274 call s:NetrwInit("g:netrw_file_cmd","links")
275 endif
276endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000277if !exists("g:netrw_ftp_cmd")
278 let g:netrw_ftp_cmd = "ftp"
279endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200280let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200281if !exists("g:netrw_ftp_options")
282 let g:netrw_ftp_options= "-i -n"
283endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000284if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100285 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100286 let g:netrw_http_cmd = "wget"
287 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100288 elseif executable("curl")
289 let g:netrw_http_cmd = "curl"
290 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200291 elseif executable("elinks")
292 let g:netrw_http_cmd = "elinks"
293 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000294 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100295 let g:netrw_http_cmd = "fetch"
296 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200297 elseif executable("links")
298 let g:netrw_http_cmd = "links"
299 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000300 else
301 let g:netrw_http_cmd = ""
302 endif
303endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100304call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100305call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100306call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
307call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200308call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200309if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200310 if executable("scp")
311 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
312 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200313 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200314 else
315 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
316 endif
317endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100318call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
319call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000320
Nir Lichtman1e34b952024-05-08 19:19:34 +0200321if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000322 \ && exists("g:netrw_use_nt_rcp")
323 \ && g:netrw_use_nt_rcp
324 \ && executable( $SystemRoot .'/system32/rcp.exe')
325 let s:netrw_has_nt_rcp = 1
326 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000327else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000328 let s:netrw_has_nt_rcp = 0
329 let s:netrw_rcpmode = ''
330endif
331
332" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000333" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000334" Cygwin Detection ------- {{{3
335if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200336 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
337 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000338 else
339 let g:netrw_cygwin= 0
340 endif
341endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000342" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100343call s:NetrwInit("g:netrw_alto" , &sb)
344call s:NetrwInit("g:netrw_altv" , &spr)
345call s:NetrwInit("g:netrw_banner" , 1)
346call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200347call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100348call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200349call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100350call s:NetrwInit("g:netrw_compress" , "gzip")
351call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200352if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
353 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
354 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000355endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200356call s:NetrwInit("g:netrw_cursor" , 2)
357let s:netrw_usercul = &cursorline
358let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200359"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100360call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000361" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200362call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200363call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200364call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100365call s:NetrwInit("g:netrw_dirhistmax" , 10)
366call s:NetrwInit("g:netrw_fastbrowse" , 1)
367call 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 +0000368if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000369 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
370 let g:netrw_ftp_list_cmd = "ls -lF"
371 let g:netrw_ftp_timelist_cmd = "ls -tlF"
372 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000373 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000374 let g:netrw_ftp_list_cmd = "dir"
375 let g:netrw_ftp_timelist_cmd = "dir"
376 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000377 endif
378endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100379call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000380" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100381call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000382if !exists("g:netrw_ignorenetrc")
383 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
384 let g:netrw_ignorenetrc= 1
385 else
386 let g:netrw_ignorenetrc= 0
387 endif
388endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100389call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000390if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000391 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100392 if exists("g:netrw_list_cmd_options")
393 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
394 else
395 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
396 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000397 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200398 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100399 if exists("g:netrw_list_cmd_options")
400 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
401 else
402 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
403 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000404 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100405" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000406 let g:netrw_list_cmd= ""
407 endif
408endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100409call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000410" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200411if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200412 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200413 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
414endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100415if !exists("g:netrw_localcmdshell")
416 let g:netrw_localcmdshell= ""
417endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000418if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200419 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000420 if g:netrw_cygwin
421 let g:netrw_localcopycmd= "cp"
422 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000423 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200424 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000425 endif
426 elseif has("unix") || has("macunix")
427 let g:netrw_localcopycmd= "cp"
428 else
429 let g:netrw_localcopycmd= ""
430 endif
431endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100432if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200433 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100434 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200435 let g:netrw_localcopydircmd = "cp"
436 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100437 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000438 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200439 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100440 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200441 elseif has("unix")
442 let g:netrw_localcopydircmd = "cp"
443 let g:netrw_localcopydircmdopt= " -R"
444 elseif has("macunix")
445 let g:netrw_localcopydircmd = "cp"
446 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100447 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200448 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100449 endif
450endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200451if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100452 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200453 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
454endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200455if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200456 if g:netrw_cygwin
457 call s:NetrwInit("g:netrw_localmkdir","mkdir")
458 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000459 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200460 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200461 endif
462else
463 call s:NetrwInit("g:netrw_localmkdir","mkdir")
464endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200465call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200466if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200467 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200468 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
469endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000470if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200471 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000472 if g:netrw_cygwin
473 let g:netrw_localmovecmd= "mv"
474 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000475 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200476 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000477 endif
478 elseif has("unix") || has("macunix")
479 let g:netrw_localmovecmd= "mv"
480 else
481 let g:netrw_localmovecmd= ""
482 endif
483endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100484" following serves as an example for how to insert a version&patch specific test
485"if v:version < 704 || (v:version == 704 && !has("patch1107"))
486"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100487call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
488" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000489if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000490 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000491endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000492if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000493 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
494endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000495" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100496call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
497call s:NetrwInit("g:netrw_maxfilenamelen", 32)
498call s:NetrwInit("g:netrw_menu" , 1)
499call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200500call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100501call s:NetrwInit("g:netrw_retmap" , 0)
502if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
503 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200504elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100505 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
506else
507 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000508endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100509call s:NetrwInit("g:netrw_preview" , 0)
510call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100511call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100512call s:NetrwInit("g:netrw_sshport" , "-p")
513call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
514call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
515call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100516call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
517" Default values - q-s ---------- {{{3
518call s:NetrwInit("g:netrw_quickhelp",0)
519let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100520 \ "(create new) %:file d:directory",
521 \ "(windows split&open) o:horz v:vert p:preview",
522 \ "i:style qf:file info O:obtain r:reverse",
523 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
524 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
525 \ "(history) qb:list u:go up U:go down",
526 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100527" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
528call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100529if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
530 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
531else
532 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
533endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100534call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
535call s:NetrwInit("g:netrw_sort_options" , "")
536call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000537if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100538 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200539 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100540 else
541 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000542 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000543endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100544call s:NetrwInit("g:netrw_special_syntax" , 0)
545call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaara6878372014-03-22 21:02:50 +0100546call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100547call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000548" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100549call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200550if !exists("g:netrw_xstrlen")
551 if exists("g:Align_xstrlen")
552 let g:netrw_xstrlen= g:Align_xstrlen
553 elseif exists("g:drawit_xstrlen")
554 let g:netrw_xstrlen= g:drawit_xstrlen
555 elseif &enc == "latin1" || !has("multi_byte")
556 let g:netrw_xstrlen= 0
557 else
558 let g:netrw_xstrlen= 1
559 endif
560endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100561call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200562call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100563call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200564if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000565" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000566" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100567call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200568if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200569 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200570else
Bram Moolenaarff034192013-04-24 18:51:19 +0200571 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200572endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200573call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100574call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
575call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100576if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100577 let s:treedepthstring= "│ "
578else
579 let s:treedepthstring= "| "
580endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200581call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000582
583" BufEnter event ignored by decho when following variable is true
584" Has a side effect that doau BufReadPost doesn't work, so
585" files read by network transfer aren't appropriately highlighted.
586"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000587
Bram Moolenaaradc21822011-04-01 18:03:16 +0200588" ======================
589" Netrw Initialization: {{{1
590" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200591if 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 +0100592" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100593 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200594" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100595 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100596 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
597 au VimEnter * let s:initbeval= &beval
598"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100599" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
600" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
601" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
602" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
603" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
604" 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 +0200605endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200606au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200607
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200608if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100609 com! -nargs=* NetrwKeepj keepj <args>
610else
611 let g:netrw_keepj= ""
612 com! -nargs=* NetrwKeepj <args>
613endif
614
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000615" ==============================
616" Netrw Utility Functions: {{{1
617" ==============================
618
Bram Moolenaaradc21822011-04-01 18:03:16 +0200619" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100620" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100621if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100622" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100623 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100624 if &ft != "netrw"
625 return ""
626 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200627 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
628 " popup error window is still showing
629 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
630 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
631 " text under mouse hasn't changed; only close window when it changes
632 call popup_close(s:popuperr_id)
633 unlet s:popuperr_text
634 else
635 let s:popuperr_text= v:beval_text
636 endif
637 let mesg= ""
638 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 +0100639 let mesg= ""
640 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
641 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
642 elseif getline(v:beval_lnum) =~ '^"\s*/'
643 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
644 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100645 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100646 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
647 let mesg = "S: edit sorting sequence"
648 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
649 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
650 elseif v:beval_text == "Quick" || v:beval_text == "Help"
651 let mesg = "Help: press <F1>"
652 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
653 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
654 else
655 let mesg= ""
656 endif
657 return mesg
658 endfun
659"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100660" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
661" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
662" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
663" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
664" 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 +0200665endif
666
Bram Moolenaar071d4272004-06-13 20:20:40 +0000667" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200668" netrw#Explore: launch the local browser in the directory of the current file {{{2
669" indx: == -1: Nexplore
670" == -2: Pexplore
671" == +: this is overloaded:
672" * If Nexplore/Pexplore is in use, then this refers to the
673" indx'th item in the w:netrw_explore_list[] of items which
674" matched the */pattern **/pattern *//pattern **//pattern
675" * If Hexplore or Vexplore, then this will override
676" g:netrw_winsize to specify the qty of rows or columns the
677" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100678" 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 +0200679" dosplit==1: the window will be split before running the local browser
680" style == 0: Explore style == 1: Explore!
681" == 2: Hexplore style == 3: Hexplore!
682" == 4: Vexplore style == 5: Vexplore!
683" == 6: Texplore
684fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100685" call Dfunc("netrw#Explore(indx=".a:indx." dosplit=".a:dosplit." style=".a:style.",a:1<".a:1.">) &modified=".&modified." modifiable=".&modifiable." a:0=".a:0." win#".winnr()." buf#".bufnr("%")." ft=".&ft)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100686" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200687 if !exists("b:netrw_curdir")
688 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100689" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200690 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100691
692 " record current file for Rexplore's benefit
693 if &ft != "netrw"
694 let w:netrw_rexfile= expand("%:p")
695 endif
696
697 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200698 let curdir = simplify(b:netrw_curdir)
699 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200700 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200701 let curdir= substitute(curdir,'\','/','g')
702 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100703" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100704
705 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
706 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
707 " try Explore again.
708 if a:0 > 0
709" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100710 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
711 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
712 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
713 \ '~'.expand("<slnum>"))
714 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200715 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
716 if a1 != a:1
717 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
718 return
719 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100720 endif
721 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200722
723 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200724 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100725" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100726 sil! let keepregstar = @*
727 sil! let keepregplus = @+
728 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200729 sil! let keepregslash= @/
730
Bram Moolenaar8d043172014-01-23 14:24:41 +0100731 " if dosplit
732 " -or- file has been modified AND file not hidden when abandoned
733 " -or- Texplore used
734 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaarff034192013-04-24 18:51:19 +0200735 call s:SaveWinVars()
736 let winsz= g:netrw_winsize
737 if a:indx > 0
738 let winsz= a:indx
739 endif
740
741 if a:style == 0 " Explore, Sexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200742 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200743 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200744 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200745
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200746 elseif a:style == 1 " Explore!, Sexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200747 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200748 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200749 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200750
751 elseif a:style == 2 " Hexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200752 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200753 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200754 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200755
756 elseif a:style == 3 " Hexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200757 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200758 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200759 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200760
761 elseif a:style == 4 " Vexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200762 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200763 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200764 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200765
766 elseif a:style == 5 " Vexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200767 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200768 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200769 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200770
771 elseif a:style == 6 " Texplore
772 call s:SaveBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200773 exe "keepalt tabnew ".fnameescape(curdir)
774 call s:RestoreBufVars()
775 endif
776 call s:RestoreWinVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200777 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100778 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200779
780 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100781" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200782 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100783" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200784 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100785" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200786 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100787" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200788 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
789 if dirname !~ '/$'
790 let dirname= dirname."/"
791 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100792" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200793 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100794" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200795 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100796" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200797 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100798" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200799 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100800" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200801 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100802" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200803 let dirname= a:1
804 endif
805 else
806 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100807" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200808 call s:NetrwClearExplore()
809" call Dret("netrw#Explore : cleared list")
810 return
811 endif
812
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100813" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200814 if dirname =~ '\.\./\=$'
815 let dirname= simplify(fnamemodify(dirname,':p:h'))
816 elseif dirname =~ '\.\.' || dirname == '.'
817 let dirname= simplify(fnamemodify(dirname,':p'))
818 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100819" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200820
821 if dirname =~ '^\*//'
822 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100823" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200824 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
825 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100826" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200827 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
828
829 elseif dirname =~ '^\*\*//'
830 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100831" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200832 let pattern= substitute(dirname,'^\*\*//','','')
833 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100834" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200835
836 elseif dirname =~ '/\*\*/'
837 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100838" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200839 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200840 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200841 let b:netrw_curdir = prefixdir
842 else
843 let b:netrw_curdir= getcwd().'/'.prefixdir
844 endif
845 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
846 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100847" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
848" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200849
850 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200851 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200852 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100853" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200854
855 elseif dirname=~ '^\*\*/'
856 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
857 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100858" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200859
860 else
861 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100862" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200863 endif
864
865 if starpat == 0 && a:indx >= 0
866 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100867" call Decho("case starpat==0 && a:indx=".a:indx.": dirname<".dirname.">, handles Explore Hexplore Vexplore Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200868 if dirname == ""
869 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100870" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200871 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200872 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200873 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200874 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200875 if dirname == ""
876 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200877 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100878 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100879 " depending on whether backslashes have been converted to forward slashes by earlier code).
880 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200881 let dirname= b:netrw_curdir."/".dirname
882 endif
883 elseif dirname !~ '^/'
884 let dirname= b:netrw_curdir."/".dirname
885 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100886" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200887 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100888" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
889" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200890 endif
891 if exists("w:netrw_bannercnt")
892 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
893 " If one wants to return the same place in the netrw window, use :Rex instead.
894 exe w:netrw_bannercnt
895 endif
896
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100897" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200898 " ---------------------------------------------------------------------
899 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
900" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100901" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200902" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100903" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200904" endif
905 " ---------------------------------------------------------------------
906
907 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
908 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
909 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
910 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
911 elseif a:indx <= 0
912 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100913" call Decho("case a:indx<=0: Nexplore, Pexplore, <s-down>, <s-up> starpat=".starpat." a:indx=".a:indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200914 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100915" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200916 let s:didstarstar= 1
917 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
918 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
919 endif
920
921 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100922" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200923 if !exists("w:netrw_explore_indx")
924 let w:netrw_explore_indx= 0
925 endif
926
927 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100928" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200929
930 if indx == -1
931 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100932" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200933 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100934 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"using Nexplore or <s-down> improperly; see help for netrw-starstar",40)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200935 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100936" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100937 if @* != keepregstar | sil! let @* = keepregstar | endif
938 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100939 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200940 sil! let @/ = keepregslash
941" call Dret("netrw#Explore")
942 return
943 endif
944 let indx= w:netrw_explore_indx
945 if indx < 0 | let indx= 0 | endif
946 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
947 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100948" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200949 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
950 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100951" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200952 endwhile
953 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100954" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200955
956 elseif indx == -2
957 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100958" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200959 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100960 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"using Pexplore or <s-up> improperly; see help for netrw-starstar",41)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200961 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100962" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100963 if @* != keepregstar | sil! let @* = keepregstar | endif
964 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100965 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200966 sil! let @/ = keepregslash
967" call Dret("netrw#Explore")
968 return
969 endif
970 let indx= w:netrw_explore_indx
971 if indx < 0 | let indx= 0 | endif
972 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
973 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100974" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200975 while indx >= 0 && curfile == w:netrw_explore_list[indx]
976 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100977" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200978 endwhile
979 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100980" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200981
982 else
983 " Explore -- initialize
984 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100985" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100986 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200987 let w:netrw_explore_indx= 0
988 if !exists("b:netrw_curdir")
989 let b:netrw_curdir= getcwd()
990 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100991" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200992
993 " switch on starpat to build the w:netrw_explore_list of files
994 if starpat == 1
995 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100996" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
997" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200998 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100999 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001000 catch /^Vim\%((\a\+)\)\=:E480/
1001 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
1002" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
1003 return
1004 endtry
1005 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1006 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1007
1008 elseif starpat == 2
1009 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001010" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1011" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001012 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001013 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001014 catch /^Vim\%((\a\+)\)\=:E480/
1015 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1016 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001017 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001018" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001019 if @* != keepregstar | sil! let @* = keepregstar | endif
1020 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001021 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001022 sil! let @/ = keepregslash
1023" call Dret("netrw#Explore : no files matched pattern")
1024 return
1025 endtry
1026 let s:netrw_curdir = b:netrw_curdir
1027 let w:netrw_explore_list = getqflist()
1028 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1029 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1030
1031 elseif starpat == 3
1032 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001033" call Decho("..case starpat=".starpat.": build */filepat list (curdir-only srch filenames matching filepat) &hls=".&hls,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001034 let filepat= substitute(dirname,'^\*/','','')
1035 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001036" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1037" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001038 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1039 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1040
1041 elseif starpat == 4
1042 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001043" call Decho("..case starpat=".starpat.": build **/filepat list (recursive descent srch filenames matching filepat) &hls=".&hls,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001044 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1045 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1046 endif " switch on starpat to build w:netrw_explore_list
1047
1048 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001049" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1050" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001051
1052 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001053 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001054 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001055" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001056 if @* != keepregstar | sil! let @* = keepregstar | endif
1057 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001058 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001059 sil! let @/ = keepregslash
1060" call Dret("netrw#Explore : no files matched")
1061 return
1062 endif
1063 endif " if indx ... endif
1064
1065 " NetrwStatusLine support - for exploring support
1066 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001067" call Decho("....w:netrw_explore_list<".join(w:netrw_explore_list,',')."> len=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001068
1069 " wrap the indx around, but issue a note
1070 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001071" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001072 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1073 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001074 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001075 endif
1076
1077 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001078" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001079 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001080" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001081
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001082" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001083 call netrw#LocalBrowseCheck(newdir)
1084 if !exists("w:netrw_liststyle")
1085 let w:netrw_liststyle= g:netrw_liststyle
1086 endif
1087 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001088 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001089 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001090 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001091 endif
1092 let w:netrw_explore_mtchcnt = indx + 1
1093 let w:netrw_explore_bufnr = bufnr("%")
1094 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001095 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001096" call Decho("....explore: mtchcnt=".w:netrw_explore_mtchcnt." bufnr=".w:netrw_explore_bufnr." line#".w:netrw_explore_line,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001097
1098 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001099" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001100 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001101 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your vim needs the +path_extra feature for Exploring with **!",44)
Bram Moolenaarff034192013-04-24 18:51:19 +02001102 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001103 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001104" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001105 if @* != keepregstar | sil! let @* = keepregstar | endif
1106 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001107 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001108 sil! let @/ = keepregslash
1109" call Dret("netrw#Explore : missing +path_extra")
1110 return
1111 endif
1112
1113 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001114" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001115 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1116 sil! unlet w:netrw_treedict
1117 sil! unlet w:netrw_treetop
1118 endif
1119 let newdir= dirname
1120 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001121 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001122 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001123 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001124 endif
1125 endif
1126
1127 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001128" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1129" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001130 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001131" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001132 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001133 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001134" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001135 let s:explore_prvdir = b:netrw_curdir
1136 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001137 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001138 if b:netrw_curdir !~ '/$'
1139 let dirlen= dirlen + 1
1140 endif
1141 let prvfname= ""
1142 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001143" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001144 if fname =~ '^'.b:netrw_curdir
1145 if s:explore_match == ""
1146 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1147 else
1148 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1149 endif
1150 elseif fname !~ '^/' && fname != prvfname
1151 if s:explore_match == ""
1152 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1153 else
1154 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1155 endif
1156 endif
1157 let prvfname= fname
1158 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001159" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001160 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1161 exe "2match netrwMarkFile /".s:explore_match."/"
1162 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001163 endif
1164 echo "<s-up>==Pexplore <s-down>==Nexplore"
1165 else
1166 2match none
1167 if exists("s:explore_match") | unlet s:explore_match | endif
1168 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001169" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001170 endif
1171
Bram Moolenaara6878372014-03-22 21:02:50 +01001172 " since Explore may be used to initialize netrw's browser,
1173 " there's no danger of a late FocusGained event on initialization.
1174 " Consequently, set s:netrw_events to 2.
1175 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001176 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001177" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001178 if @* != keepregstar | sil! let @* = keepregstar | endif
1179 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001180 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001181 sil! let @/ = keepregslash
1182" call Dret("netrw#Explore : @/<".@/.">")
1183endfun
1184
1185" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001186" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001187" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1188" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1189" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1190" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1191" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001192fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001193" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001194 let curwin= winnr()
1195
Bram Moolenaara6878372014-03-22 21:02:50 +01001196 if a:0 > 0 && a:1 != ""
1197 " if a netrw window is already on the left-side of the tab
1198 " and a directory has been specified, explore with that
1199 " directory.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001200 let a1 = expand(a:1)
Bram Moolenaara6878372014-03-22 21:02:50 +01001201 exe "1wincmd w"
1202 if &ft == "netrw"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001203 exe "Explore ".fnameescape(a1)
1204 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001205 let s:lexplore_win= curwin
1206 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001207 if exists("t:netrw_lexposn")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001208 unlet t:netrw_lexposn
1209 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001210 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001211 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001212 exe curwin."wincmd w"
1213 else
1214 let a1= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01001215 endif
1216
Bram Moolenaar8d043172014-01-23 14:24:41 +01001217 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001218 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001219 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001220 else
1221 let lexwinnr= 0
1222 endif
1223
1224 if lexwinnr > 0
1225 " close down netrw explorer window
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001226 exe lexwinnr."wincmd w"
1227 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001228 let t:netrw_lexposn = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001229 close
1230 if lexwinnr < curwin
1231 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001232 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001233 if lexwinnr != curwin
1234 exe curwin."wincmd w"
1235 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001236 unlet t:netrw_lexbufnr
1237
1238 else
1239 " open netrw explorer window
1240 exe "1wincmd w"
1241 let keep_altv = g:netrw_altv
1242 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001243 if a:count != 0
1244 let netrw_winsize = g:netrw_winsize
1245 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001246 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001247 let curfile= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001248 exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
1249 if a:0 > 0 && a1 != ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001250 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001251 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001252 elseif curfile =~ '^\a\{3,}://'
Bram Moolenaar85850f32019-07-19 22:05:51 +02001253 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001254 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02001255 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001256 endif
1257 if a:count != 0
1258 let g:netrw_winsize = netrw_winsize
1259 endif
1260 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001261 let g:netrw_altv = keep_altv
1262 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001263 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1264 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001265 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001266 set bh=wipe
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001267 if exists("t:netrw_lexposn")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001268 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001269 unlet t:netrw_lexposn
1270 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001271 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001272
1273 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001274 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001275 if a:rightside
1276 let g:netrw_chgwin= 1
1277 else
1278 let g:netrw_chgwin= 2
1279 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001280 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001281
Bram Moolenaar8d043172014-01-23 14:24:41 +01001282endfun
1283
1284" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001285" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001286" supports :NetrwClean -- remove netrw from first directory on runtimepath
1287" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001288fun! netrw#Clean(sys)
1289" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001290
1291 if a:sys
1292 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1293 else
1294 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1295 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001296" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001297 let diddel= 0
1298 let diddir= ""
1299
1300 if choice == 1
1301 for dir in split(&rtp,',')
1302 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001303" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001304 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1305 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1306 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1307 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1308 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1309 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 +00001310 let diddir= dir
1311 let diddel= diddel + 1
1312 if !a:sys|break|endif
1313 endif
1314 endfor
1315 endif
1316
1317 echohl WarningMsg
1318 if diddel == 0
1319 echomsg "netrw is either not installed or not removable"
1320 elseif diddel == 1
1321 echomsg "removed one copy of netrw from <".diddir.">"
1322 else
1323 echomsg "removed ".diddel." copies of netrw"
1324 endif
1325 echohl None
1326
Bram Moolenaara6878372014-03-22 21:02:50 +01001327" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001328endfun
1329
Bram Moolenaar5c736222010-01-06 20:54:52 +01001330" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001331" netrw#MakeTgt: make a target out of the directory name provided {{{2
1332fun! netrw#MakeTgt(dname)
1333" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1334 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001335 let svpos = winsaveview()
1336" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001337 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1338" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001339 if s:netrwmftgt_islocal
1340 let netrwmftgt= simplify(a:dname)
1341 else
1342 let netrwmftgt= a:dname
1343 endif
1344 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1345 " re-selected target, so just clear it
1346 unlet s:netrwmftgt s:netrwmftgt_islocal
1347 else
1348 let s:netrwmftgt= netrwmftgt
1349 endif
1350 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001351 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001352 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001353" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1354 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001355" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001356endfun
1357
Bram Moolenaara6878372014-03-22 21:02:50 +01001358" ---------------------------------------------------------------------
1359" netrw#Obtain: {{{2
1360" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001361" islocal=0 obtain from remote source
1362" =1 obtain from local source
1363" fname : a filename or a list of filenames
1364" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001365fun! netrw#Obtain(islocal,fname,...)
1366" 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 +02001367 " NetrwStatusLine support - for obtaining support
1368
1369 if type(a:fname) == 1
1370 let fnamelist= [ a:fname ]
1371 elseif type(a:fname) == 3
1372 let fnamelist= a:fname
1373 else
1374 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 +01001375" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001376 return
1377 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001378" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001379 if a:0 > 0
1380 let tgtdir= a:1
1381 else
1382 let tgtdir= getcwd()
1383 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001384" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001385
1386 if exists("b:netrw_islocal") && b:netrw_islocal
1387 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001388" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001389 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1390 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001391 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001392 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001393" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001394 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001395" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001396 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001397 if v:shell_error != 0
1398 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 +01001399" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001400 return
1401 endif
1402 endfor
1403 else
1404 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001405" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1406 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1407" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001408 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001409 if v:shell_error != 0
1410 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 +01001411" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001412 return
1413 endif
1414 endif
1415 elseif !exists("b:netrw_curdir")
1416 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1417 else
1418 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1419 endif
1420
1421 else
1422 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001423" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001424 if type(a:fname) == 1
1425 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1426 endif
1427 call s:NetrwMethod(b:netrw_curdir)
1428
1429 if b:netrw_method == 4
1430 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001431" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001432 if exists("g:netrw_port") && g:netrw_port != ""
1433 let useport= " ".g:netrw_scpport." ".g:netrw_port
1434 else
1435 let useport= ""
1436 endif
1437 if b:netrw_fname =~ '/'
1438 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1439 else
1440 let path= ""
1441 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001442 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001443 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 +02001444
1445 elseif b:netrw_method == 2
1446 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001447" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001448 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001449 let tmpbufnr= bufnr("%")
1450 setl ff=unix
1451 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001452 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001453" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001454 endif
1455
1456 if exists("b:netrw_fname") && b:netrw_fname != ""
1457 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001458" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001459 endif
1460
1461 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001462 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001463" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001464 endif
1465 for fname in fnamelist
1466 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001467" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001468 endfor
1469 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001470 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 +02001471 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001472 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001473 endif
1474 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1475 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1476 let debugkeep= &debug
1477 setl debug=msg
1478 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1479 let &debug= debugkeep
1480 endif
1481
1482 elseif b:netrw_method == 3
1483 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001484" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001485 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001486 let tmpbufnr= bufnr("%")
1487 setl ff=unix
1488
1489 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001490 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001491" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001492 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001493 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001494" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001495 endif
1496
1497 if exists("g:netrw_uid") && g:netrw_uid != ""
1498 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001499 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001500" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001501 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001502 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001503 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001504" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001505 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001506 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001507" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001508 endif
1509 endif
1510
1511 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001512 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001513" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001514 endif
1515
1516 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001517 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001518" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001519 endif
1520
1521 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001522 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001523" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001524 endif
1525
1526 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001527 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001528" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001529 endif
1530 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001531 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001532 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001533" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001534
1535 " perform ftp:
1536 " -i : turns off interactive prompting from ftp
1537 " -n unix : DON'T use <.netrc>, even though it exists
1538 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001539 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1540 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001541 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001542 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1543 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001544" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001545 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001546 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001547 endif
1548 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001549
1550 elseif b:netrw_method == 9
1551 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001552" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001553 if a:fname =~ '/'
1554 let localfile= substitute(a:fname,'^.*/','','')
1555 else
1556 let localfile= a:fname
1557 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001558 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 +02001559
Bram Moolenaarff034192013-04-24 18:51:19 +02001560 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001561 " probably a badly formed url; protocol not recognized
1562" call Dret("netrw#Obtain : unsupported method")
1563 return
1564
1565 else
1566 " protocol recognized but not supported for Obtain (yet?)
1567 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001568 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001569 endif
1570" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001571 return
1572 endif
1573
1574 " restore status line
1575 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001576 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001577 endif
1578
1579 endif
1580
1581 " cleanup
1582 if exists("tmpbufnr")
1583 if bufnr("%") != tmpbufnr
1584 exe tmpbufnr."bw!"
1585 else
1586 q!
1587 endif
1588 endif
1589
Bram Moolenaara6878372014-03-22 21:02:50 +01001590" call Dret("netrw#Obtain")
1591endfun
1592
1593" ---------------------------------------------------------------------
1594" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1595fun! netrw#Nread(mode,fname)
1596" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001597 let svpos= winsaveview()
1598" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001599 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001600" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1601 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001602
1603 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1604 if exists("w:netrw_bannercnt")
1605 " start with cursor just after the banner
1606 exe w:netrw_bannercnt
1607 endif
1608 endif
1609" call Dret("netrw#Nread")
1610endfun
1611
1612" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001613" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1614" Options get restored by s:NetrwOptionsRestore()
1615"
1616" Option handling:
1617" * save user's options (s:NetrwOptionsSave)
1618" * set netrw-safe options (s:NetrwOptionsSafe)
1619" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1620" * restore user's options (s:netrwOPtionsRestore)
1621" - restore a user option when != safe option (s:NetrwRestoreSetting)
1622" vt: (variable type) normally its either "w:" or "s:"
1623fun! s:NetrwOptionsSave(vt)
1624" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1625" 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 +02001626" 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>"))
1627" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001628
1629 if !exists("{a:vt}netrw_optionsave")
1630 let {a:vt}netrw_optionsave= 1
1631 else
1632" call Dret("s:NetrwOptionsSave : options already saved")
1633 return
1634 endif
1635" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1636
1637 " Save current settings and current directory
1638" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1639 let s:yykeep = @@
1640 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1641 let {a:vt}netrw_aikeep = &l:ai
1642 let {a:vt}netrw_awkeep = &l:aw
1643 let {a:vt}netrw_bhkeep = &l:bh
1644 let {a:vt}netrw_blkeep = &l:bl
1645 let {a:vt}netrw_btkeep = &l:bt
1646 let {a:vt}netrw_bombkeep = &l:bomb
1647 let {a:vt}netrw_cedit = &cedit
1648 let {a:vt}netrw_cikeep = &l:ci
1649 let {a:vt}netrw_cinkeep = &l:cin
1650 let {a:vt}netrw_cinokeep = &l:cino
1651 let {a:vt}netrw_comkeep = &l:com
1652 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001653 let {a:vt}netrw_cuckeep = &l:cuc
1654 let {a:vt}netrw_culkeep = &l:cul
1655" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001656 let {a:vt}netrw_diffkeep = &l:diff
1657 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001658 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1659 let {a:vt}netrw_ffkeep = &l:ff
1660 endif
1661 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1662 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001663 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001664 let {a:vt}netrw_hidkeep = &l:hidden
1665 let {a:vt}netrw_imkeep = &l:im
1666 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001667 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001668 let {a:vt}netrw_lskeep = &l:ls
1669 let {a:vt}netrw_makeep = &l:ma
1670 let {a:vt}netrw_magickeep = &l:magic
1671 let {a:vt}netrw_modkeep = &l:mod
1672 let {a:vt}netrw_nukeep = &l:nu
1673 let {a:vt}netrw_rnukeep = &l:rnu
1674 let {a:vt}netrw_repkeep = &l:report
1675 let {a:vt}netrw_rokeep = &l:ro
1676 let {a:vt}netrw_selkeep = &l:sel
1677 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001678 if !g:netrw_use_noswf
1679 let {a:vt}netrw_swfkeep = &l:swf
1680 endif
1681 let {a:vt}netrw_tskeep = &l:ts
1682 let {a:vt}netrw_twkeep = &l:tw " textwidth
1683 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1684 let {a:vt}netrw_wrapkeep = &l:wrap
1685 let {a:vt}netrw_writekeep = &l:write
1686
1687 " save a few selected netrw-related variables
1688" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1689 if g:netrw_keepdir
1690 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001691" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001692 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001693 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001694 sil! let {a:vt}netrw_starkeep = @*
1695 sil! let {a:vt}netrw_pluskeep = @+
1696 endif
1697 sil! let {a:vt}netrw_slashkeep= @/
1698
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001699" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001700" 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>"))
1701" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1702endfun
1703
1704" ---------------------------------------------------------------------
1705" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1706" Use s:NetrwSaveOptions() to save user settings
1707" Use s:NetrwOptionsRestore() to restore user settings
1708fun! s:NetrwOptionsSafe(islocal)
1709" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1710" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1711" 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>"))
1712 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1713 call s:NetrwSetSafeSetting("&l:ai",0)
1714 call s:NetrwSetSafeSetting("&l:aw",0)
1715 call s:NetrwSetSafeSetting("&l:bl",0)
1716 call s:NetrwSetSafeSetting("&l:bomb",0)
1717 if a:islocal
1718 call s:NetrwSetSafeSetting("&l:bt","nofile")
1719 else
1720 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1721 endif
1722 call s:NetrwSetSafeSetting("&l:ci",0)
1723 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001724 if g:netrw_fastbrowse > a:islocal
1725 call s:NetrwSetSafeSetting("&l:bh","hide")
1726 else
1727 call s:NetrwSetSafeSetting("&l:bh","delete")
1728 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001729 call s:NetrwSetSafeSetting("&l:cino","")
1730 call s:NetrwSetSafeSetting("&l:com","")
1731 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1732 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1733 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001734 if &go =~ 'a' | set go-=a | endif
1735 if &go =~ 'A' | set go-=A | endif
1736 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001737 call s:NetrwSetSafeSetting("&l:hid",0)
1738 call s:NetrwSetSafeSetting("&l:im",0)
1739 setl isk+=@ isk+=* isk+=/
1740 call s:NetrwSetSafeSetting("&l:magic",1)
1741 if g:netrw_use_noswf
1742 call s:NetrwSetSafeSetting("swf",0)
1743 endif
1744 call s:NetrwSetSafeSetting("&l:report",10000)
1745 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1746 call s:NetrwSetSafeSetting("&l:spell",0)
1747 call s:NetrwSetSafeSetting("&l:tw",0)
1748 call s:NetrwSetSafeSetting("&l:wig","")
1749 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001750
1751 " set up cuc and cul based on g:netrw_cursor and listing style
1752 " COMBAK -- cuc cul related
1753 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001754
1755 " allow the user to override safe options
1756" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1757 if &ft == "netrw"
1758" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1759 keepalt NetrwKeepj doau FileType netrw
1760 endif
1761
1762" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1763" 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>"))
1764" call Dret("s:NetrwOptionsSafe")
1765endfun
1766
1767" ---------------------------------------------------------------------
1768" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1769fun! s:NetrwOptionsRestore(vt)
Bram Moolenaara6878372014-03-22 21:02:50 +01001770 if !exists("{a:vt}netrw_optionsave")
Christian Brabandtaa2ce6f2024-10-30 18:27:03 +01001771 " filereadable() returns zero for remote files (e.g. scp://user@localhost//etc/fstab)
1772 " Note: @ may not be in 'isfname', so '^\w\+://\f\+/' may not match
1773 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+'
Bram Moolenaar71badf92023-04-22 22:40:14 +01001774 filetype detect
Bram Moolenaar71badf92023-04-22 22:40:14 +01001775 else
1776 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001777 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001778 return
1779 endif
1780 unlet {a:vt}netrw_optionsave
1781
1782 if exists("+acd")
1783 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara6878372014-03-22 21:02:50 +01001784 let curdir = getcwd()
1785 let &l:acd = {a:vt}netrw_acdkeep
1786 unlet {a:vt}netrw_acdkeep
1787 if &l:acd
1788 call s:NetrwLcd(curdir)
1789 endif
1790 endif
1791 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001792 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1793 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1794 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1795 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1796 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
1797 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1798 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1799 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1800 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1801 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
1802 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1803 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1804 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1805 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1806 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001807 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001808 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1809 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001810 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001811 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001812 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1813 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001814 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001815 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1816 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001817 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001818 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1819 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001820 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1821 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1822 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1823 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001824 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001825 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1826 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1827 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001828 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
1829 call s:NetrwRestoreSetting("s:yykeep","@@")
1830 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1831 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1832 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1833 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1834
Bram Moolenaara6878372014-03-22 21:02:50 +01001835 if exists("{a:vt}netrw_swfkeep")
1836 if &directory == ""
1837 " user hasn't specified a swapfile directory;
1838 " netrw will temporarily set the swapfile directory
1839 " to the current directory as returned by getcwd().
1840 let &l:directory= getcwd()
1841 sil! let &l:swf = {a:vt}netrw_swfkeep
1842 setl directory=
1843 unlet {a:vt}netrw_swfkeep
1844 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001845 if !g:netrw_use_noswf
1846 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1847 sil! let &l:swf= {a:vt}netrw_swfkeep
1848 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001849 unlet {a:vt}netrw_swfkeep
1850 endif
1851 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001852 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001853 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1854 if exists("{a:vt}netrw_dirkeep")
1855 call s:NetrwLcd(dirkeep)
1856 unlet {a:vt}netrw_dirkeep
1857 endif
1858 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001859 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001860 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1861 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001862 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001863 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001864
Bram Moolenaara6878372014-03-22 21:02:50 +01001865 " Moved the filetype detect here from NetrwGetFile() because remote files
1866 " were having their filetype detect-generated settings overwritten by
1867 " NetrwOptionRestore.
1868 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001869 filetype detect
Bram Moolenaara6878372014-03-22 21:02:50 +01001870 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001871endfun
1872
1873" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001874" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1875" but only when the options' value and the safe setting differ
1876" Doing this means that netrw will not come up as having changed a
1877" setting last when it really didn't actually change it.
1878"
1879" Called from s:NetrwOptionsSafe
1880" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1881fun! s:NetrwSetSafeSetting(setting,safesetting)
1882" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001883
Bram Moolenaar85850f32019-07-19 22:05:51 +02001884 if a:setting =~ '^&'
1885" call Decho("fyi: a:setting starts with &")
1886 exe "let settingval= ".a:setting
1887" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001888
Bram Moolenaar85850f32019-07-19 22:05:51 +02001889 if settingval != a:safesetting
1890" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1891 if type(a:safesetting) == 0
1892 exe "let ".a:setting."=".a:safesetting
1893 elseif type(a:safesetting) == 1
1894 exe "let ".a:setting."= '".a:safesetting."'"
1895 else
1896 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1897 endif
1898 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001899 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001900
Bram Moolenaar85850f32019-07-19 22:05:51 +02001901" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001902endfun
1903
1904" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001905" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1906" but only if the setting value differs from the associated keepvar.
1907" Doing this means that netrw will not come up as having changed a
1908" setting last when it really didn't actually change it.
1909"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001910" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001911" keepvars are set up by s:NetrwOptionsSave
1912fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001913""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001914
Bram Moolenaar85850f32019-07-19 22:05:51 +02001915 " typically called from s:NetrwOptionsRestore
1916 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1917 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001918 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001919 if exists(a:keepvar)
1920 exe "let keepvarval= ".a:keepvar
1921 exe "let setting= ".a:setting
1922
1923"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1924"" call Decho("fyi: keepvarval=".keepvarval)
1925"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1926
1927 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001928"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001929 if type(a:setting) == 0
1930 exe "let ".a:setting."= ".keepvarval
1931 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001932 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001933 else
1934 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1935 endif
1936 endif
1937
1938 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001939 endif
1940
Bram Moolenaar85850f32019-07-19 22:05:51 +02001941"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001942endfun
1943
1944" ---------------------------------------------------------------------
1945" NetrwStatusLine: {{{2
1946fun! NetrwStatusLine()
1947
1948" vvv NetrwStatusLine() debugging vvv
1949" let g:stlmsg=""
1950" if !exists("w:netrw_explore_bufnr")
1951" let g:stlmsg="!X<explore_bufnr>"
1952" elseif w:netrw_explore_bufnr != bufnr("%")
1953" let g:stlmsg="explore_bufnr!=".bufnr("%")
1954" endif
1955" if !exists("w:netrw_explore_line")
1956" let g:stlmsg=" !X<explore_line>"
1957" elseif w:netrw_explore_line != line(".")
1958" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
1959" endif
1960" if !exists("w:netrw_explore_list")
1961" let g:stlmsg=" !X<explore_list>"
1962" endif
1963" ^^^ NetrwStatusLine() debugging ^^^
1964
1965 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")
1966 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09001967 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02001968 let &laststatus = s:netrw_users_ls
1969 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
1970 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
1971 return ""
1972 else
1973 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
1974 endif
1975endfun
1976
Bram Moolenaar85850f32019-07-19 22:05:51 +02001977" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001978" Netrw Transfer Functions: {{{1
1979" ===============================
1980
Bram Moolenaar071d4272004-06-13 20:20:40 +00001981" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001982" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001983" mode: =0 read remote file and insert before current line
1984" =1 read remote file and insert after current line
1985" =2 replace with remote file
1986" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001987fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02001988" 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 +00001989
Bram Moolenaar5c736222010-01-06 20:54:52 +01001990 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02001991 call s:NetrwOptionsSave("w:")
1992 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001993 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001994 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
1995 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
1996 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02001997" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001998
Bram Moolenaar5c736222010-01-06 20:54:52 +01001999 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002000 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002001 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002002 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002003 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002004 elseif a:mode == 2 " replace with remote file
2005 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002006 elseif a:mode == 3 " skip read of file (leave as temporary)
2007 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002008 else
2009 exe a:mode
2010 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002011 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002012 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002013" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002014
Bram Moolenaar5c736222010-01-06 20:54:52 +01002015 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002016 let tmpfile= s:GetTempfile("")
2017 if tmpfile == ""
2018" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002019 return
2020 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002021
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002022 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002023
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002024 " attempt to repeat with previous host-file-etc
2025 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002026" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002027 let choice = b:netrw_lastfile
2028 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002029
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002030 else
2031 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002032" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002033
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002034 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002035 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002036 echomsg 'NetRead Usage:'
2037 echomsg ':Nread machine:path uses rcp'
2038 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2039 echomsg ':Nread "machine id password path" uses ftp'
2040 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2041 echomsg ':Nread fetch://machine/path uses fetch'
2042 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2043 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002044 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002045 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002046 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2047 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2048 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2049 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002050 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002051 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002052
Bram Moolenaar9964e462007-05-05 17:54:07 +00002053 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002054 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002055" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002056 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002057 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002058 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002059 else
2060 " case "... ... ..."
2061 let choice = strpart(choice,1,strlen(choice)-1)
2062 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002063
Bram Moolenaar9964e462007-05-05 17:54:07 +00002064 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002065 let wholechoice = wholechoice . " " . choice
2066 let ichoice = ichoice + 1
2067 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002068 if !exists("g:netrw_quiet")
2069 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2070 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002071" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002072 return
2073 endif
2074 let choice= a:{ichoice}
2075 endwhile
2076 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2077 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002078 endif
2079 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002080
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002081" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002082 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002083
Bram Moolenaar5c736222010-01-06 20:54:52 +01002084 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002085 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002086 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002087" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002088 return
2089 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002090 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002091
Bram Moolenaar8d043172014-01-23 14:24:41 +01002092 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002093" 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 +02002094 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002095" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002096 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002097" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002098 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002099 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002100
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002101 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002102 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002103 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002104 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2105 echo "(netrw) Processing your read request..."
2106 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002107
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002108 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002109 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002110 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002111" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002112 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002113 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002114 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002115 " ER: the tmpfile is full path: rcp sees C:\... as host C
2116 if s:netrw_has_nt_rcp == 1
2117 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2118 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2119 else
2120 " Any way needed it machine contains a '.'
2121 let uid_machine = g:netrw_machine .'.'. $USERNAME
2122 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002123 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002124 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2125 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2126 else
2127 let uid_machine = g:netrw_machine
2128 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002129 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002130 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 +00002131 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002132 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002133
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002134 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002135 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002136 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002137" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002138 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002139 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002140 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002141 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002142 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002143" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002144 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002145 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002146" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002147 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002148 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002149" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002150 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002151 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 +00002152 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002153 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002154 endif
2155 " 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 +00002156 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002157 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002158 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002159 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002160 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002161 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002162 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002163 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002164 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2165 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002166 q!
2167 endif
2168 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: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002174 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2175 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002176" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002177 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002178 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002179 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002180 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002181 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002182 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002183" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002184 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002185 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002186" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002187 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002188
Bram Moolenaar97d62492012-11-15 21:28:22 +01002189 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002190 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002191 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002192" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002193 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002194 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002195 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002196" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002197 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002198 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002199" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002200 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002201 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002202
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002203 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002204 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002205" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002206 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002207 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002208 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002209" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002210 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002211 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002212" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002213
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002214 " perform ftp:
2215 " -i : turns off interactive prompting from ftp
2216 " -n unix : DON'T use <.netrc>, even though it exists
2217 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002218 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002219 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002220 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2221 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002222" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002223 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002224 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002225 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002226 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002227 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002228 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002229 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002230
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002231 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002232 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002233 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002234" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002235 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002236 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002237 else
2238 let useport= ""
2239 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002240 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2241 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002242 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002243 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2244 else
2245 let tmpfile_get = tmpfile
2246 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002247 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 +00002248 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002249 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002250
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002251 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002252 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002253 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002254" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002255 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002256 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002257 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002258 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002259" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002260 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002261 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002262
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002263 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2264 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002265" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002266 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002267 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 +00002268 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002269 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 +00002270 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002271 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002272
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002273 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002274 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002275" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002276 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2277 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002278" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2279" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2280 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 +00002281 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002282" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002283 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002284 endif
2285 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002286" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002287 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002288
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002289 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002290 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002291 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002292" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002293
Bram Moolenaar5c736222010-01-06 20:54:52 +01002294 if !executable(g:netrw_dav_cmd)
2295 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2296" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2297 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002298 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002299 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002300 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 +01002301 else
2302 " Construct execution string (four lines) which will be passed through filter
2303 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2304 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002305 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002306 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002307 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002308 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002309 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002310 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002311 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002312 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002313 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002314 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2315 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002316
Bram Moolenaar5c736222010-01-06 20:54:52 +01002317 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002318 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002319 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002320 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002321 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002322 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002323 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002324
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002325 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002326 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002327 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002328" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002329 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 +00002330 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002331 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002332
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002333 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002334 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002335 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002336 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002337" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002338 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002339 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002340 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002341 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002342" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002343 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002344 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002345 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002346 let netrw_option= "http"
2347 else
2348 let netrw_option= "ftp"
2349 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002350" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002351
Bram Moolenaar446cb832008-06-24 21:56:24 +00002352 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002353 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 +00002354 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002355 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 +00002356 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002357
Bram Moolenaar446cb832008-06-24 21:56:24 +00002358 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002359 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002360" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002361 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002362
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002363 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002364 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002365 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002366" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2367 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 +00002368 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002369 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002370
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002371 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002372 " NetRead: (file) NetRead Method #10 {{{3
2373 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002374" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2375 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002376 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2377 let b:netrw_lastfile = choice
2378
2379 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002380 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002381 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002382 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002383 endif
2384 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002385
Bram Moolenaar5c736222010-01-06 20:54:52 +01002386 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002387 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002388" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002389 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002390 unlet b:netrw_fname
2391 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002392 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 +01002393" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002394 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002395 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002396 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002397
Bram Moolenaar9964e462007-05-05 17:54:07 +00002398" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002399endfun
2400
2401" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002402" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002403fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002404" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002405
Bram Moolenaar5c736222010-01-06 20:54:52 +01002406 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002407 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002408 call s:NetrwOptionsSave("w:")
2409 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002410
Bram Moolenaar5c736222010-01-06 20:54:52 +01002411 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002412 let tmpfile= s:GetTempfile("")
2413 if tmpfile == ""
2414" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002415 return
2416 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002417
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002418 if a:0 == 0
2419 let ichoice = 0
2420 else
2421 let ichoice = 1
2422 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002423
Bram Moolenaar9964e462007-05-05 17:54:07 +00002424 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002425" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002426 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002427 " For binary writes, always write entire file.
2428 " (line numbers don't really make sense for that).
2429 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002430" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002431 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002432 elseif g:netrw_cygwin
2433 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002434 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002435" 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 +01002436 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002437 else
2438 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002439" 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 +01002440 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002441 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002442
Bram Moolenaar9964e462007-05-05 17:54:07 +00002443 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002444 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002445 " on the temporary file's name. Deletion of the temporary file during
2446 " cleanup then causes an error message.
2447 0file!
2448 endif
2449
Bram Moolenaar5c736222010-01-06 20:54:52 +01002450 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002451 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002452
Bram Moolenaar9964e462007-05-05 17:54:07 +00002453 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002454 " attempt to repeat with previous host-file-etc
2455 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002456" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002457 let choice = b:netrw_lastfile
2458 let ichoice= ichoice + 1
2459 else
2460 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002461
Bram Moolenaar8d043172014-01-23 14:24:41 +01002462 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002463 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002464 echomsg 'NetWrite Usage:"'
2465 echomsg ':Nwrite machine:path uses rcp'
2466 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2467 echomsg ':Nwrite "machine id password path" uses ftp'
2468 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2469 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2470 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2471 echomsg ':Nwrite rcp://machine/path uses rcp'
2472 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2473 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2474 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002475 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002476 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002477
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002478 elseif match(choice,"^\"") != -1
2479 if match(choice,"\"$") != -1
2480 " case "..."
2481 let choice=strpart(choice,1,strlen(choice)-2)
2482 else
2483 " case "... ... ..."
2484 let choice = strpart(choice,1,strlen(choice)-1)
2485 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002486
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002487 while match(choice,"\"$") == -1
2488 let wholechoice= wholechoice . " " . choice
2489 let ichoice = ichoice + 1
2490 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002491 if !exists("g:netrw_quiet")
2492 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2493 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002494" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002495 return
2496 endif
2497 let choice= a:{ichoice}
2498 endwhile
2499 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2500 endif
2501 endif
2502 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002503 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002504" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002505
Bram Moolenaar9964e462007-05-05 17:54:07 +00002506 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002507 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002508 if !exists("b:netrw_method") || b:netrw_method < 0
2509" call Dfunc("netrw#NetWrite : unsupported method")
2510 return
2511 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002512
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002513 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002514 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002515 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002516 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2517 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002518" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002519 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002520
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002521 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002522 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002523 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002524" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002525 if s:netrw_has_nt_rcp == 1
2526 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2527 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2528 else
2529 let uid_machine = g:netrw_machine .'.'. $USERNAME
2530 endif
2531 else
2532 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2533 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2534 else
2535 let uid_machine = g:netrw_machine
2536 endif
2537 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002538 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 +00002539 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002540
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002541 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002542 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002543 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002544" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002545 let netrw_fname = b:netrw_fname
2546
2547 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2548 let bhkeep = &l:bh
2549 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002550 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002551 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002552
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002553" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002554 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002555 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002556" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002557 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002558 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002559" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002560 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002561 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002562" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002563 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002564 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 +00002565 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002566" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2567 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002568 endif
2569 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2570 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002571 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002572 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002573 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002574 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002575 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002576
2577 " remove enew buffer (quietly)
2578 let filtbuf= bufnr("%")
2579 exe curbuf."b!"
2580 let &l:bh = bhkeep
2581 exe filtbuf."bw!"
2582
Bram Moolenaar071d4272004-06-13 20:20:40 +00002583 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002584
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002585 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002586 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002587 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002588 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002589" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002590 let netrw_fname = b:netrw_fname
2591 let bhkeep = &l:bh
2592
2593 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2594 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002595 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002596 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002597 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002598
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002599 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002600 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002601" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002602 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002603 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002604" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002605 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002606 if exists("g:netrw_uid") && g:netrw_uid != ""
2607 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002608 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002609" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002610 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002611 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002612 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002613" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002614 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002615 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002616" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002617 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002618 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002619 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002620" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002621 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002622 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002623" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002624 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002625 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002626" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002627 " save choice/id/password for future use
2628 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002629
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002630 " perform ftp:
2631 " -i : turns off interactive prompting from ftp
2632 " -n unix : DON'T use <.netrc>, even though it exists
2633 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002634 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002635 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002636 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2637 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002638 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002639 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002640 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002641 let mod=1
2642 endif
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!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002649
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002650 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002651 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002652 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002653" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002654 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002655 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002656 else
2657 let useport= ""
2658 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002659 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 +00002660 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002661
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002662 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002663 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002664 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002665" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002666 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2667 if executable(curl)
2668 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002669 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 +01002670 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002671 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002672 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002673
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002674 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002675 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002676 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002677" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002678
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002679 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002680 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2681 let bhkeep = &l:bh
2682
2683 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2684 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002685 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002686 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002687
Bram Moolenaarff034192013-04-24 18:51:19 +02002688 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002689 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002690 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002691 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002692 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002693 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002694 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002695 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002696 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002697 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002698
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002699 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002700 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002701 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002702
2703 " remove enew buffer (quietly)
2704 let filtbuf= bufnr("%")
2705 exe curbuf."b!"
2706 let &l:bh = bhkeep
2707 exe filtbuf."bw!"
2708
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002709 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002710
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002711 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002712 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002713 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002714" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002715 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 +00002716 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002717
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002718 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002719 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002720 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002721" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002722 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002723 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2724 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2725 else
2726 let uid_machine = g:netrw_machine
2727 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002728
2729 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2730 let bhkeep = &l:bh
2731 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002732 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002733 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002734
Bram Moolenaarff034192013-04-24 18:51:19 +02002735 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002736 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002737" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002738 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002739 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002740 let filtbuf= bufnr("%")
2741 exe curbuf."b!"
2742 let &l:bh = bhkeep
2743 exe filtbuf."bw!"
2744 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002745
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002746 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002747 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002748 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002749 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002750 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002751 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002752 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002753
Bram Moolenaar5c736222010-01-06 20:54:52 +01002754 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002755" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002756 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002757" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002758 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002759 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002760 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002761
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002762 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002763 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002764 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002765" 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 +02002766 elseif !exists("leavemod")
2767 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002768" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002769 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002770" 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 +00002771 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002772
Bram Moolenaar9964e462007-05-05 17:54:07 +00002773" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002774endfun
2775
2776" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002777" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002778" uses NetRead to get a copy of the file into a temporarily file,
2779" then sources that file,
2780" then removes that file.
2781fun! netrw#NetSource(...)
2782" call Dfunc("netrw#NetSource() a:0=".a:0)
2783 if a:0 > 0 && a:1 == '?'
2784 " give help
2785 echomsg 'NetSource Usage:'
2786 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2787 echomsg ':Nsource fetch://machine/path uses fetch'
2788 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002789 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002790 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2791 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2792 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2793 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2794 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002795 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002796 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002797 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002798 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002799" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002800 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002801" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002802 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002803" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002804 if delete(s:netrw_tmpfile)
2805 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2806 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002807 unlet s:netrw_tmpfile
2808 else
2809 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2810 endif
2811 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002812 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002813 endif
2814" call Dret("netrw#NetSource")
2815endfun
2816
Bram Moolenaar8d043172014-01-23 14:24:41 +01002817" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002818" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2819" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002820fun! netrw#SetTreetop(iscmd,...)
2821" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2822" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002823
Bram Moolenaar85850f32019-07-19 22:05:51 +02002824 " iscmd==0: netrw#SetTreetop called using gn mapping
2825 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2826" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002827 " clear out the current tree
2828 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002829" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002830 let inittreetop= w:netrw_treetop
2831 unlet w:netrw_treetop
2832 endif
2833 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002834" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002835 unlet w:netrw_treedict
2836 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002837" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002838
Bram Moolenaar85850f32019-07-19 22:05:51 +02002839 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002840 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002841" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002842 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002843 if isdirectory(s:NetrwFile(a:1))
2844" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002845 let treedir = a:1
2846 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002847 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002848 let treedir = b:netrw_curdir."/".a:1
2849 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002850" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002851 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002852 " normally the cursor is left in the message window.
2853 " However, here this results in the directory being listed in the message window, which is not wanted.
2854 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002855 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002856 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002857 let treedir = "."
2858 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002859 endif
2860 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002861" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002862
2863 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002864 let islocal= expand("%") !~ '^\a\{3,}://'
2865" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002866
2867 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002868 if islocal
2869 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2870 else
2871 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2872 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002873
Bram Moolenaara6878372014-03-22 21:02:50 +01002874" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002875endfun
2876
Bram Moolenaar9964e462007-05-05 17:54:07 +00002877" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002878" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002879" readcmd == %r : replace buffer with newly read file
2880" == 0r : read file at top of buffer
2881" == r : read file after current line
2882" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002883fun! s:NetrwGetFile(readcmd, tfile, method)
2884" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002885
2886 " readcmd=='t': simply do nothing
2887 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002888" 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 +01002889" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002890 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002891 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002892
Bram Moolenaar9964e462007-05-05 17:54:07 +00002893 " get name of remote filename (ie. url and all)
2894 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002895" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002896
Bram Moolenaar9964e462007-05-05 17:54:07 +00002897 if exists("*NetReadFixup")
2898 " for the use of NetReadFixup (not otherwise used internally)
2899 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002900 endif
2901
Bram Moolenaar9964e462007-05-05 17:54:07 +00002902 if a:readcmd[0] == '%'
2903 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002904" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002905
2906 " rename the current buffer to the temp file (ie. tfile)
2907 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002908 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002909 else
2910 let tfile= a:tfile
2911 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002912 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002913
2914 " edit temporary file (ie. read the temporary file in)
2915 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002916" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002917 call zip#Browse(tfile)
2918 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002919" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002920 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002921 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002922" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002923 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002924 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002925" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002926 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002927 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002928" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002929 call tar#Browse(tfile)
2930 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002931" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002932 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002933 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002934" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002935 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002936 endif
2937
2938 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002939 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002940
Bram Moolenaar71badf92023-04-22 22:40:14 +01002941 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002942 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002943 " Note that isk must not include a "/" for scripts.vim
2944 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002945" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2946" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002947" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002948" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
2949 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01002950 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01002951 filetype detect
2952" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09002953 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02002954" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002955 let line1 = 1
2956 let line2 = line("$")
2957
Bram Moolenaar8d043172014-01-23 14:24:41 +01002958 elseif !&ma
2959 " 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 +01002960 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002961" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002962 return
2963
Bram Moolenaar9964e462007-05-05 17:54:07 +00002964 elseif s:FileReadable(a:tfile)
2965 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002966" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002967 let curline = line(".")
2968 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002969" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002970 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002971 let line1= curline + 1
2972 let line2= line("$") - lastline + 1
2973
2974 else
2975 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002976" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
2977" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002978 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002979" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002980 return
2981 endif
2982
2983 " User-provided (ie. optional) fix-it-up command
2984 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002985" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002986 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002987" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002988" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002989 endif
2990
Bram Moolenaaradc21822011-04-01 18:03:16 +02002991 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00002992 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002993 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00002994 endif
2995
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002996" 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 +00002997
2998 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00002999" redraw!
3000
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003001" 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 +00003002" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003003endfun
3004
Bram Moolenaar9964e462007-05-05 17:54:07 +00003005" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003006" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003007" Input:
3008" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3009" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003010" b:netrw_method= 1: rcp
3011" 2: ftp + <.netrc>
3012" 3: ftp + machine, id, password, and [path]filename
3013" 4: scp
3014" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003015" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003016" 7: rsync
3017" 8: fetch
3018" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003019" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003020" g:netrw_machine= hostname
3021" b:netrw_fname = filename
3022" g:netrw_port = optional port number (for ftp)
3023" g:netrw_choice = copy of input url (choice)
3024fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003025" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003026
Bram Moolenaar251e1912011-06-19 05:09:16 +02003027 " sanity check: choice should have at least three slashes in it
3028 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3029 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3030 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003031" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003032 return
3033 endif
3034
Bram Moolenaar5c736222010-01-06 20:54:52 +01003035 " record current g:netrw_machine, if any
3036 " curmachine used if protocol == ftp and no .netrc
3037 if exists("g:netrw_machine")
3038 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003039" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003040 else
3041 let curmachine= "N O T A HOST"
3042 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003043 if exists("g:netrw_port")
3044 let netrw_port= g:netrw_port
3045 endif
3046
3047 " insure that netrw_ftp_cmd starts off every method determination
3048 " with the current g:netrw_ftp_cmd
3049 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003050
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003051 " initialization
3052 let b:netrw_method = 0
3053 let g:netrw_machine = ""
3054 let b:netrw_fname = ""
3055 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003056 let g:netrw_choice = a:choice
3057
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003058 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003059 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003060 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3061 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003062 " rcpurm : rcp://[user@]host/filename Use rcp
3063 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003064 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003065 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003066 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003067 " rsyncurm : rsync://host[:port]/path Use rsync
3068 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3069 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003070 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003071 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3072 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003073 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3074 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003075 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003076 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003077 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003078 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003079 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003080 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003081 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003082 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003083
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003084" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003085 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003086 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003087 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003088" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003089 let b:netrw_method = 1
3090 let userid = substitute(a:choice,rcpurm,'\1',"")
3091 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3092 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003093 if userid != ""
3094 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003096
Bram Moolenaaradc21822011-04-01 18:03:16 +02003097 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003098 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003099" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003100 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003101 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3102 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3103 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003104
Bram Moolenaar15146672011-10-20 22:22:38 +02003105 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003106 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003107" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003108 let b:netrw_method = 5
3109 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3110 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003111 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003112
Bram Moolenaaradc21822011-04-01 18:03:16 +02003113 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003114 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003115" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003116 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003117 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003118 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3119 else
3120 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3121 endif
3122 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003123
Bram Moolenaaradc21822011-04-01 18:03:16 +02003124 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003125 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003126" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003127 let b:netrw_method = 7
3128 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3129 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003130
Bram Moolenaaradc21822011-04-01 18:03:16 +02003131 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003132 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003133" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003134 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003135 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3136 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3137 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003138" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003139 if userid != ""
3140 let g:netrw_uid= userid
3141 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003142
Bram Moolenaaradc21822011-04-01 18:03:16 +02003143 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003144 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003145 call NetUserPass("ftp:".g:netrw_machine)
3146 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003147 " if there's a change in hostname, require password re-entry
3148 unlet s:netrw_passwd
3149 endif
3150 if exists("netrw_port")
3151 unlet netrw_port
3152 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003153 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003154
Bram Moolenaar446cb832008-06-24 21:56:24 +00003155 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003156 let b:netrw_method = 3
3157 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003158 let host= substitute(g:netrw_machine,'\..*$','','')
3159 if exists("s:netrw_hup[host]")
3160 call NetUserPass("ftp:".host)
3161
Nir Lichtman1e34b952024-05-08 19:19:34 +02003162 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003163" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3164" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003165 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003166 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003167" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003168 endif
3169 let b:netrw_method= 2
3170 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003171" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003172 let b:netrw_method= 2
3173 else
3174 if !exists("g:netrw_uid") || g:netrw_uid == ""
3175 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003176 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003177 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003178 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003179 endif
3180 let b:netrw_method= 3
3181 endif
3182 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003183
Bram Moolenaaradc21822011-04-01 18:03:16 +02003184 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003185 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003186" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003187 let b:netrw_method = 8
3188 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3189 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3190 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3191 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003192
Bram Moolenaaradc21822011-04-01 18:03:16 +02003193 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003194 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003195" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003196 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003197 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3198 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003199 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003200 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003201 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003202
Bram Moolenaaradc21822011-04-01 18:03:16 +02003203 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003204 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003205" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003206 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003207 let b:netrw_method = 3
3208 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3209 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003210
Bram Moolenaar9964e462007-05-05 17:54:07 +00003211 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003212 let b:netrw_method = 2
3213 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3214 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3215 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003216
Bram Moolenaaradc21822011-04-01 18:03:16 +02003217 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003218 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003219" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003220 let b:netrw_method = 9
3221 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3222 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003223
Bram Moolenaaradc21822011-04-01 18:03:16 +02003224 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003225 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003226" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003227 let b:netrw_method = 1
3228 let userid = substitute(a:choice,rcphf,'\2',"")
3229 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3230 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003231" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3232" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3233" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3234" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003235 if userid != ""
3236 let g:netrw_uid= userid
3237 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003238
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003239 " Method#10: file://user@hostname/...path-to-file {{{3
3240 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003241" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003242 let b:netrw_method = 10
3243 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003244" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003245
Bram Moolenaaradc21822011-04-01 18:03:16 +02003246 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003247 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003248 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003249 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003250 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003251 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003252 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003253 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003254
Bram Moolenaar81695252004-12-29 20:58:21 +00003255 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003256 " remove any leading [:#] from port number
3257 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3258 elseif exists("netrw_port")
3259 " retain port number as implicit for subsequent ftp operations
3260 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003261 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003262
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003263" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3264" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3265" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3266" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003267" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003268" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003269" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003270" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003271" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003272" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003273" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003274" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003275endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003276
Bram Moolenaar9964e462007-05-05 17:54:07 +00003277" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003278" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003279" Usage: :call NetUserPass() -- will prompt for userid and password
3280" :call NetUserPass("uid") -- will prompt for password
3281" :call NetUserPass("uid","password") -- sets global userid and password
3282" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3283" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003284fun! NetUserPass(...)
3285
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003286" call Dfunc("NetUserPass() a:0=".a:0)
3287
3288 if !exists('s:netrw_hup')
3289 let s:netrw_hup= {}
3290 endif
3291
Bram Moolenaar071d4272004-06-13 20:20:40 +00003292 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003293 " case: no input arguments
3294
3295 " change host and username if not previously entered; get new password
3296 if !exists("g:netrw_machine")
3297 let g:netrw_machine= input('Enter hostname: ')
3298 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003299 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003300 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003301 let g:netrw_uid= input('Enter username: ')
3302 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003303 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003304 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003305
3306 " set up hup database
3307 let host = substitute(g:netrw_machine,'\..*$','','')
3308 if !exists('s:netrw_hup[host]')
3309 let s:netrw_hup[host]= {}
3310 endif
3311 let s:netrw_hup[host].uid = g:netrw_uid
3312 let s:netrw_hup[host].passwd = s:netrw_passwd
3313
3314 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003315 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003316
3317 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003318 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003319 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003320" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003321 let host = substitute(a:1,'^ftp:','','')
3322 let host = substitute(host,'\..*','','')
3323 if exists("s:netrw_hup[host]")
3324 let g:netrw_uid = s:netrw_hup[host].uid
3325 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003326" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3327" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003328 else
3329 let g:netrw_uid = input("Enter UserId: ")
3330 let s:netrw_passwd = inputsecret("Enter Password: ")
3331 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003332
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003333 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003334 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003335" 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 +02003336 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003337 if g:netrw_machine =~ '[0-9.]\+'
3338 let host= g:netrw_machine
3339 else
3340 let host= substitute(g:netrw_machine,'\..*$','','')
3341 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003342 else
3343 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003344 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003345 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003346" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003347 if exists("g:netrw_passwd")
3348 " ask for password if one not previously entered
3349 let s:netrw_passwd= g:netrw_passwd
3350 else
3351 let s:netrw_passwd = inputsecret("Enter Password: ")
3352 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003353 endif
3354
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003355" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003356 if exists("host")
3357 if !exists('s:netrw_hup[host]')
3358 let s:netrw_hup[host]= {}
3359 endif
3360 let s:netrw_hup[host].uid = g:netrw_uid
3361 let s:netrw_hup[host].passwd = s:netrw_passwd
3362 endif
3363
3364 elseif a:0 == 2
3365 let g:netrw_uid = a:1
3366 let s:netrw_passwd = a:2
3367
3368 elseif a:0 == 3
3369 " enter hostname, user-id, and password into the hup dictionary
3370 let host = substitute(a:1,'^\a\+:','','')
3371 let host = substitute(host,'\..*$','','')
3372 if !exists('s:netrw_hup[host]')
3373 let s:netrw_hup[host]= {}
3374 endif
3375 let s:netrw_hup[host].uid = a:2
3376 let s:netrw_hup[host].passwd = a:3
3377 let g:netrw_uid = s:netrw_hup[host].uid
3378 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003379" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3380" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003381 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003382
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003383" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003384endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003385
Bram Moolenaar85850f32019-07-19 22:05:51 +02003386" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003387" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003388" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003389
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003390" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003391" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3392fun! s:ExplorePatHls(pattern)
3393" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3394 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003395" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003396 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003397" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003398 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3399" call Dret("s:ExplorePatHls repat<".repat.">")
3400 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003401endfun
3402
3403" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003404" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003405" 0: (user: <mb>) bookmark current directory
3406" 1: (user: <gb>) change to the bookmarked directory
3407" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003408" 3: (browsing) records current directory history
3409" 4: (user: <u>) go up (previous) directory, using history
3410" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003411" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003412fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003413" 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 +02003414 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3415" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3416 return
3417 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003418
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003419 let ykeep = @@
3420 let curbufnr = bufnr("%")
3421
Bram Moolenaar9964e462007-05-05 17:54:07 +00003422 if a:chg == 0
3423 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003424" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003425 if exists("s:netrwmarkfilelist_{curbufnr}")
3426 call s:NetrwBookmark(0)
3427 echo "bookmarked marked files"
3428 else
3429 call s:MakeBookmark(a:curdir)
3430 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003431 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003432
KSR-Yasudaf4498252023-10-06 03:34:17 +09003433 try
3434 call s:NetrwBookHistSave()
3435 catch
3436 endtry
3437
Bram Moolenaar9964e462007-05-05 17:54:07 +00003438 elseif a:chg == 1
3439 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003440" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003441 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003442" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003443 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003444 else
3445 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3446 endif
3447
3448 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003449" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003450 let didwork= 0
3451 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003452" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003453 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003454" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003455 let cnt= 1
3456 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003457" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003458 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003459 let didwork = 1
3460 let cnt = cnt + 1
3461 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003462 endif
3463
3464 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003465 " Note: history is saved only when PerformListing is done;
3466 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3467 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003468 let first = 1
3469 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003470 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003471 while ( first || cnt != g:netrw_dirhistcnt )
3472" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003473 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003474" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003475 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003476 let didwork= 1
3477 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003478 let histcnt = histcnt + 1
3479 let first = 0
3480 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003481 if cnt < 0
3482 let cnt= cnt + g:netrw_dirhistmax
3483 endif
3484 endwhile
3485 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003486 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003487 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003488 if didwork
3489 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3490 endif
3491
3492 elseif a:chg == 3
3493 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003494" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003495 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 +02003496 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003497 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3498 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003499 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003500" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003501 endif
3502
3503 elseif a:chg == 4
3504 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003505" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003506 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003507 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3508 if g:netrw_dirhistcnt < 0
3509 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003510 endif
3511 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003512 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003513 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003514 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3515" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003516 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003517 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003518" call Decho("setl ma noro",'~'.expand("<slnum>"))
3519 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003520 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003521" call Decho("setl nomod",'~'.expand("<slnum>"))
3522" 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 +00003523 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003524" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3525 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003526 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003527 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003528 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003529 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003530 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003531 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003532 echo "Sorry, no predecessor directory exists yet"
3533 endif
3534
3535 elseif a:chg == 5
3536 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003537" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003538 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003539 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3540 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3541" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003542 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003543" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003544 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003545 sil! NetrwKeepj %d _
3546" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3547" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003548 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003549" 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 +02003550 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003551" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3552 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003553 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003554 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3555 if g:netrw_dirhistcnt < 0
3556 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003557 endif
3558 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003559 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003560 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003561 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003562 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003563 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003564
3565 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003566" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003567 if exists("s:netrwmarkfilelist_{curbufnr}")
3568 call s:NetrwBookmark(1)
3569 echo "removed marked files from bookmarks"
3570 else
3571 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003572 let iremove = v:count
3573 let dremove = g:netrw_bookmarklist[iremove - 1]
3574" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003575 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003576" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3577 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3578 echo "removed ".dremove." from g:netrw_bookmarklist"
3579" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003580 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003581" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003582
3583 try
3584 call s:NetrwBookHistSave()
3585 catch
3586 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003587 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003588 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003589 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003590 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003591" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003592endfun
3593
3594" ---------------------------------------------------------------------
3595" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003596" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003597" Sister function: s:NetrwBookHistSave()
3598fun! s:NetrwBookHistRead()
3599" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003600 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003601" 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 +02003602 return
3603 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003604 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003605
3606 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003607 if !exists("s:netrw_initbookhist")
3608 let home = s:NetrwHome()
3609 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003610 if filereadable(s:NetrwFile(savefile))
3611" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003612 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003613 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003614
3615 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003616 if g:netrw_dirhistmax > 0
3617 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003618 if filereadable(s:NetrwFile(savefile))
3619" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003620 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003621 endif
3622 let s:netrw_initbookhist= 1
3623 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003624 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003625 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003626
Bram Moolenaar97d62492012-11-15 21:28:22 +01003627 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003628" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3629" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003630" call Dret("s:NetrwBookHistRead")
3631endfun
3632
3633" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003634" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003635" Sister function: s:NetrwBookHistRead()
3636" I used to do this via viminfo but that appears to
3637" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003638" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3639" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003640" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003641fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003642" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003643 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003644" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003645 return
3646 endif
3647
Bram Moolenaar5c736222010-01-06 20:54:52 +01003648 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003649" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003650 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003651
3652 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003653 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003654" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003655 if g:netrw_use_noswf
3656 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3657 else
3658 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3659 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003660 setl nocin noai noci magic nospell nohid wig= noaw
3661 setl ma noro write
3662 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003663 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003664
Bram Moolenaar85850f32019-07-19 22:05:51 +02003665 " rename enew'd file: .netrwhist -- no attempt to merge
3666 " record dirhistmax and current dirhistcnt
3667 " save history
3668" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003669 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003670 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003671 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3672 if g:netrw_dirhistmax > 0
3673 let lastline = line("$")
3674 let cnt = g:netrw_dirhistcnt
3675 let first = 1
3676 while ( first || cnt != g:netrw_dirhistcnt )
3677 let lastline= lastline + 1
3678 if exists("g:netrw_dirhist_{cnt}")
3679 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3680" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3681 endif
3682 let first = 0
3683 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3684 if cnt < 0
3685 let cnt= cnt + g:netrw_dirhistmax
3686 endif
3687 endwhile
3688 exe "sil! w! ".savefile
3689" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3690 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003691
Bram Moolenaar85850f32019-07-19 22:05:51 +02003692 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003693 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003694 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003695" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003696 " merge and write .netrwbook
3697 let savefile= s:NetrwHome()."/.netrwbook"
3698
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003699 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003700 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003701 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003702 for bdm in booklist
3703 if index(g:netrw_bookmarklist,bdm) == -1
3704 call add(g:netrw_bookmarklist,bdm)
3705 endif
3706 endfor
3707 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003708 endif
3709
3710 " construct and save .netrwbook
3711 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003712 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003713" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003714 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003715
3716 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003717 let bgone= bufnr("%")
3718 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003719 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003720
3721" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003722endfun
3723
3724" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003725" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3726" list of the contents of a local or remote directory. It is assumed that the
3727" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3728" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003729" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003730fun! s:NetrwBrowse(islocal,dirname)
3731 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003732" call Dfunc("s:NetrwBrowse(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".w:netrw_liststyle." ".g:loaded_netrw." buf#".bufnr("%")."<".bufname("%")."> win#".winnr())
Bram Moolenaar85850f32019-07-19 22:05:51 +02003733" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3734" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3735" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003736
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003737 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3738 " This is useful when one edits a local file, then :e ., then :Rex
3739 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3740 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003741" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003742 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003743
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003744 " s:NetrwBrowse : initialize history {{{3
3745 if !exists("s:netrw_initbookhist")
3746 NetrwKeepj call s:NetrwBookHistRead()
3747 endif
3748
3749 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003750 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003751 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003752" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003753 else
3754 let dirname= a:dirname
3755 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003756
Bram Moolenaar85850f32019-07-19 22:05:51 +02003757 " repoint t:netrw_lexbufnr if appropriate
3758 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3759" call Decho("set repointlexbufnr to true!")
3760 let repointlexbufnr= 1
3761 endif
3762
3763 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003764 if exists("s:netrw_skipbrowse")
3765 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003766" 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 +01003767" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003768 return
3769 endif
3770 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003771 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003772" call Dret("s:NetrwBrowse : missing shellescape()")
3773 return
3774 endif
3775 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003776 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003777" call Dret("s:NetrwBrowse : missing fnameescape()")
3778 return
3779 endif
3780
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003781 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003782 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003783
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003784 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003785 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3786 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3787" call Decho("clearing marked files",'~'.expand("<slnum>"))
3788 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3789 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003790 endif
3791
3792 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003793 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003794" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3795" call Decho("NetrwKeepj lcd ".fnameescape(dirname)." (due to w:netrw_acdkeep=".w:netrw_acdkeep." - acd=".&acd.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003796 if s:NetrwLcd(dirname)
3797" call Dret("s:NetrwBrowse : lcd failure")
3798 return
3799 endif
3800 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003801" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003802
Bram Moolenaar5c736222010-01-06 20:54:52 +01003803 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003804 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003805" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003806 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003807" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003808 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003809 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003810 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003811" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003812
3813 " remove any filetype indicator from end of dirname, except for the
3814 " "this is a directory" indicator (/).
3815 " There shouldn't be one of those here, anyway.
3816 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003817" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003818 call s:RemotePathAnalysis(dirname)
3819
3820 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3821 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003822 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003823 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003824" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003825 let b:netrw_curdir = dirname
3826 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003827 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003828 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3829 sil call netrw#NetRead(2,url)
3830 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003831" call Decho("url<".url.">",'~'.expand("<slnum>"))
3832" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3833" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003834 if s:path =~ '.bz2'
3835 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3836 elseif s:path =~ '.gz'
3837 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3838 elseif s:path =~ '.gz'
3839 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3840 else
3841 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3842 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003843 endif
3844
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003845 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003846 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003847 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003848" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003849 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003850" 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 +00003851
Bram Moolenaar446cb832008-06-24 21:56:24 +00003852" call Dret("s:NetrwBrowse : file<".s:fname.">")
3853 return
3854 endif
3855
Bram Moolenaaradc21822011-04-01 18:03:16 +02003856 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003857 call s:UseBufWinVars()
3858
3859 " set up some variables {{{3
3860 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003861 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003862 let s:last_sort_by = g:netrw_sort_by
3863
3864 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003865 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003866
Bram Moolenaar97d62492012-11-15 21:28:22 +01003867 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003868" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003869 let svpos = winsaveview()
3870" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003871 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003872
Bram Moolenaar446cb832008-06-24 21:56:24 +00003873 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003874 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3875 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3876" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3877" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3878 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3879 else
3880" " call Decho("2match none",'~'.expand("<slnum>"))
3881 2match none
3882 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003883 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003884 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003885 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003886" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003887 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003888" call Decho("(set noma nomod nowrap) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003889" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003890 return
3891 endif
3892
3893 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003894" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003895 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003896 if b:netrw_curdir =~ '[/\\]$'
3897 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3898 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003899 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003900 let b:netrw_curdir= b:netrw_curdir."/"
3901 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003902 if b:netrw_curdir == ''
3903 if has("amiga")
3904 " On the Amiga, the empty string connotes the current directory
3905 let b:netrw_curdir= getcwd()
3906 else
3907 " under unix, when the root directory is encountered, the result
3908 " from the preceding substitute is an empty string.
3909 let b:netrw_curdir= '/'
3910 endif
3911 endif
3912 if !a:islocal && b:netrw_curdir !~ '/$'
3913 let b:netrw_curdir= b:netrw_curdir.'/'
3914 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003915" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003916
3917 " ------------
3918 " (local only) {{{3
3919 " ------------
3920 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003921" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003922
3923 " Set up ShellCmdPost handling. Append current buffer to browselist
3924 call s:LocalFastBrowser()
3925
3926 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3927 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003928" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3929" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003930 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003931 if s:NetrwLcd(b:netrw_curdir)
3932" call Dret("s:NetrwBrowse : lcd failure")
3933 return
3934 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003935 endif
3936 endif
3937
3938 " --------------------------------
3939 " remote handling: {{{3
3940 " --------------------------------
3941 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003942" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003943
Bram Moolenaar97d62492012-11-15 21:28:22 +01003944 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003945" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist")."> dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003946 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003947 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003948" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003949 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3950 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3951 if dirname !~ '/$'
3952 let dirname= dirname.'/'
3953 endif
3954 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003955" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003956 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003957 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003958" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003959 endif
3960
3961 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
3962 if dirname !~ dirpat
3963 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003964 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003965 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003966 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003967" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003968 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003969" 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 +00003970" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
3971 return
3972 endif
3973 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003974" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003975 endif " (additional remote handling)
3976
Bram Moolenaar85850f32019-07-19 22:05:51 +02003977 " -------------------------------
3978 " Perform Directory Listing: {{{3
3979 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003980 NetrwKeepj call s:NetrwMaps(a:islocal)
3981 NetrwKeepj call s:NetrwCommands(a:islocal)
3982 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003983
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003984 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003985 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003986" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3987
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003988 " If there is a rexposn: restore position with rexposn
3989 " Otherwise : set rexposn
3990 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003991" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
3992 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
3993 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
3994 NetrwKeepj exe w:netrw_bannercnt
3995 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003996 else
3997 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
3998 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02003999 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004000 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004001" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004002 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004003 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004004
Bram Moolenaar85850f32019-07-19 22:05:51 +02004005 " repoint t:netrw_lexbufnr if appropriate
4006 if exists("repointlexbufnr")
4007 let t:netrw_lexbufnr= bufnr("%")
4008" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4009 endif
4010
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004011 " restore position
4012 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004013" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4014 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004015 endif
4016
Bram Moolenaara6878372014-03-22 21:02:50 +01004017 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004018 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4019 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004020" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4021" 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 +02004022" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004023 return
4024endfun
4025
4026" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004027" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4028" may not apply correctly; ie. netrw's idea of the current directory may
4029" differ from vim's. This function insures that netrw's idea of the current
4030" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004031" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004032fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004033" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4034" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4035" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4036" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4037" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004038
4039 " clean up any leading treedepthstring
4040 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4041 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004042" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004043 else
4044 let fname= a:fname
4045 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004046
4047 if g:netrw_keepdir
4048 " vim's idea of the current directory possibly may differ from netrw's
4049 if !exists("b:netrw_curdir")
4050 let b:netrw_curdir= getcwd()
4051 endif
4052
Nir Lichtman1e34b952024-05-08 19:19:34 +02004053 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004054 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004055 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004056 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004057" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004058 else
4059 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004060 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004061" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004062 endif
4063
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004064 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004065 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004066 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004067" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004068 else
4069 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004070 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004071" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004072 endif
4073 else
4074 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004075 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004076" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4077" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4078" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004079 endif
4080
Bram Moolenaar85850f32019-07-19 22:05:51 +02004081" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004082 return ret
4083endfun
4084
4085" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004086" s:NetrwFileInfo: supports qf (query for file information) {{{2
4087fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004088" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004089 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004090 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004091 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004092 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004093 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004094 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004095 let lsopt= "-lsadh --si"
4096 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004097" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004098 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004099
4100 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004101 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004102" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004103
Bram Moolenaara6878372014-03-22 21:02:50 +01004104 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004105 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004106" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004107
4108 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004109 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004110" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004111
Bram Moolenaar446cb832008-06-24 21:56:24 +00004112 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004113" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004114 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004115" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004116 endif
4117 else
4118 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004119" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4120 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004121 let fname= substitute(a:fname,".$","","")
4122 else
4123 let fname= a:fname
4124 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004125 let t = getftime(s:NetrwFile(fname))
4126 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004127 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004128 let sz= s:NetrwHumanReadable(sz)
4129 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004130 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4131" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004132 endif
4133 else
4134 echo "sorry, \"qf\" not supported yet for remote files"
4135 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004136 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004137" call Dret("s:NetrwFileInfo")
4138endfun
4139
4140" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004141" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4142fun! s:NetrwFullPath(filename)
4143" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4144 let filename= a:filename
4145 if filename !~ '^/'
4146 let filename= resolve(getcwd().'/'.filename)
4147 endif
4148 if filename != "/" && filename =~ '/$'
4149 let filename= substitute(filename,'/$','','')
4150 endif
4151" " call Dret("s:NetrwFullPath <".filename.">")
4152 return filename
4153endfun
4154
4155" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004156" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004157" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004158" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004159" 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 +00004160fun! s:NetrwGetBuffer(islocal,dirname)
4161" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004162" 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 +02004163" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4164" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004165 let dirname= a:dirname
4166
4167 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004168" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004169 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004170" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004171 let s:netrwbuf= {}
4172 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004173" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4174" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4175
4176 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4177 let bufnum = -1
4178
4179 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4180 if has_key(s:netrwbuf,"NetrwTreeListing")
4181 let bufnum= s:netrwbuf["NetrwTreeListing"]
4182 else
4183 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4184 endif
4185" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4186 if !bufexists(bufnum)
Peter Aronoffbe551da2024-09-22 11:29:40 +02004187 call remove(s:netrwbuf,"NetrwTreeListing")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004188 let bufnum= -1
4189 endif
4190 elseif bufnr("NetrwTreeListing") != -1
4191 let bufnum= bufnr("NetrwTreeListing")
4192" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4193 else
4194" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4195 let bufnum= -1
4196 endif
4197
4198 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004199 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004200" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004201 if !bufexists(bufnum)
4202 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4203 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004204 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004205
Bram Moolenaar446cb832008-06-24 21:56:24 +00004206 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004207" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004208 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004209 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004210" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4211
Bram Moolenaar71badf92023-04-22 22:40:14 +01004212 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004213 " IF the buffer already has the desired name
4214 " AND it is empty
4215 let curbuf = bufname("%")
4216 if curbuf == '.'
4217 let curbuf = getcwd()
4218 endif
4219" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004220" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004221" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4222" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4223" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4224" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4225 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004226" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4227 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004228 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004229" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004230 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004231 " 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 +00004232
4233 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004234 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004235" 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 +00004236 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004237" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004238 " name the buffer
4239 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4240 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004241" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004242 let w:netrw_treebufnr = bufnr("%")
4243 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004244 if g:netrw_use_noswf
4245 setl nobl bt=nofile noswf
4246 else
4247 setl nobl bt=nofile
4248 endif
4249 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4250 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4251 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4252 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004253" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004254 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004255 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004256 " enter the new buffer into the s:netrwbuf dictionary
4257 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4258" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4259" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004260 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004261" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004262
4263 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004264" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004265 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004266 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004267 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004268
4269 if &ft == "netrw"
4270" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4271 exe "sil! NetrwKeepj noswapfile b ".bufnum
4272" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004273 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004274" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4275 call s:NetrwEditBuf(bufnum)
4276" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004277 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004278" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004279 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004280 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004281 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004282
4283 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004284 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004285
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004286 if line("$") <= 1 && getline(1) == ""
4287 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004288 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004289" 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>"))
4290" 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 +01004291" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4292 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004293
Bram Moolenaar97d62492012-11-15 21:28:22 +01004294 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004295" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004296 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004297 sil NetrwKeepj %d _
4298" 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>"))
4299" 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 +01004300" 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 +00004301 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004302
Bram Moolenaar446cb832008-06-24 21:56:24 +00004303 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004304" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4305" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004306 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004307 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004308 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004309" 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>"))
4310" 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 +01004311" 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 +00004312 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004313
Bram Moolenaar446cb832008-06-24 21:56:24 +00004314 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004315" 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>"))
4316" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4317" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004318 return 1
4319 endif
4320 endif
4321
4322 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4323 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4324 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4325 " med 1 D H
4326 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004327" 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 +00004328 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004329 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004330 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004331
4332 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004333" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4334" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4335 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004336
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004337" 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>"))
4338" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4339" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004340 return 0
4341endfun
4342
4343" ---------------------------------------------------------------------
4344" s:NetrwGetcwd: get the current directory. {{{2
4345" Change backslashes to forward slashes, if any.
4346" If doesc is true, escape certain troublesome characters
4347fun! s:NetrwGetcwd(doesc)
4348" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4349 let curdir= substitute(getcwd(),'\\','/','ge')
4350 if curdir !~ '[\/]$'
4351 let curdir= curdir.'/'
4352 endif
4353 if a:doesc
4354 let curdir= fnameescape(curdir)
4355 endif
4356" call Dret("NetrwGetcwd <".curdir.">")
4357 return curdir
4358endfun
4359
4360" ---------------------------------------------------------------------
4361" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4362fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004363" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4364" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4365 let keepsol= &l:sol
4366 setl nosol
4367
Bram Moolenaar446cb832008-06-24 21:56:24 +00004368 call s:UseBufWinVars()
4369
4370 " insure that w:netrw_liststyle is set up
4371 if !exists("w:netrw_liststyle")
4372 if exists("g:netrw_liststyle")
4373 let w:netrw_liststyle= g:netrw_liststyle
4374 else
4375 let w:netrw_liststyle= s:THINLIST
4376 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004377" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004378 endif
4379
4380 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4381 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004382" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004383 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004384 let dirname= "./"
4385 let curline= getline('.')
4386
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004387 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004388 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004389 let s:netrw_skipbrowse= 1
4390 echo 'Pressing "s" also works'
4391
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004392 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004393 let s:netrw_skipbrowse= 1
4394 echo 'Press "S" to edit sorting sequence'
4395
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004396 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004397 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004398 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004399
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004400 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004401 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004402 let s:netrw_skipbrowse= 1
4403 echo 'Pressing "a" also works'
4404
4405 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004406 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004407 endif
4408
4409 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004410" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004411 NetrwKeepj norm! 0
4412 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004413
4414 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004415" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004416 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004417 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4418
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004419 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004420" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004421 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004422 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004423
4424 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004425" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004426 let dirname= getline('.')
4427
4428 if !exists("b:netrw_cpf")
4429 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004430 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 +01004431 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004432" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004433 endif
4434
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004435" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004436 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004437" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4438" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004439 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004440 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004441 else
4442 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004443 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004444 endif
Enno3146d632024-07-04 19:44:42 +02004445
4446 let dict={}
4447 " save the unnamed register and register 0-9 and a
4448 let dict.a=[getreg('a'), getregtype('a')]
4449 for i in range(0, 9)
4450 let dict[i] = [getreg(i), getregtype(i)]
4451 endfor
4452 let dict.unnamed = [getreg(''), getregtype('')]
4453
Bram Moolenaarc236c162008-07-13 17:41:49 +00004454 let eofname= filestart + b:netrw_cpf + 1
4455 if eofname <= col("$")
4456 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004457 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004458 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004459 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004460 endif
Enno3146d632024-07-04 19:44:42 +02004461
Bram Moolenaar446cb832008-06-24 21:56:24 +00004462 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004463 call s:RestoreRegister(dict)
4464
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004465" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004466 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004467" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004468 endif
4469
4470 " symlinks are indicated by a trailing "@". Remove it before further processing.
4471 let dirname= substitute(dirname,"@$","","")
4472
4473 " executables are indicated by a trailing "*". Remove it before further processing.
4474 let dirname= substitute(dirname,"\*$","","")
4475
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004476 let &l:sol= keepsol
4477
Bram Moolenaar446cb832008-06-24 21:56:24 +00004478" call Dret("s:NetrwGetWord <".dirname.">")
4479 return dirname
4480endfun
4481
4482" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004483" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4484" g:netrw_bufsettings will be used after the listing is produced.
4485" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004486fun! s:NetrwListSettings(islocal)
4487" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004488" 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 +00004489 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004490" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4491 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4492 setl bt=nofile nobl ma nonu nowrap noro nornu
4493 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004494 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004495 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004496 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004497" call Dredir("ls!","s:NetrwListSettings")
4498" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004499 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004500 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004501 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004502 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004503 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004504 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004505 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004506" 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 +00004507" call Dret("s:NetrwListSettings")
4508endfun
4509
4510" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004511" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004512" islocal=0: remote browsing
4513" =1: local browsing
4514fun! s:NetrwListStyle(islocal)
4515" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004516
Bram Moolenaar97d62492012-11-15 21:28:22 +01004517 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004518 let fname = s:NetrwGetWord()
4519 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004520 let svpos = winsaveview()
4521" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004522 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004523" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4524" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4525" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004526
Bram Moolenaar85850f32019-07-19 22:05:51 +02004527 " repoint t:netrw_lexbufnr if appropriate
4528 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4529" call Decho("set repointlexbufnr to true!")
4530 let repointlexbufnr= 1
4531 endif
4532
Bram Moolenaar446cb832008-06-24 21:56:24 +00004533 if w:netrw_liststyle == s:THINLIST
4534 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004535" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004536 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4537
4538 elseif w:netrw_liststyle == s:LONGLIST
4539 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004540" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004541 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4542
4543 elseif w:netrw_liststyle == s:WIDELIST
4544 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004545" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004546 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4547
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004548 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004549" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004550 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4551
4552 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004553 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004554 let g:netrw_liststyle = s:THINLIST
4555 let w:netrw_liststyle = g:netrw_liststyle
4556 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4557 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004558 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004559" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004560
4561 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004562" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4563 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004564 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004565" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004566 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004567" 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 +00004568
4569 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004570" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004571 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004572 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004573
Bram Moolenaar85850f32019-07-19 22:05:51 +02004574 " repoint t:netrw_lexbufnr if appropriate
4575 if exists("repointlexbufnr")
4576 let t:netrw_lexbufnr= bufnr("%")
4577" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4578 endif
4579
Bram Moolenaar13600302014-05-22 18:26:40 +02004580 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004581" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4582 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004583 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004584
4585" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4586endfun
4587
4588" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004589" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4590fun! s:NetrwBannerCtrl(islocal)
4591" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4592
Bram Moolenaar97d62492012-11-15 21:28:22 +01004593 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004594 " toggle the banner (enable/suppress)
4595 let g:netrw_banner= !g:netrw_banner
4596
4597 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004598 let svpos= winsaveview()
4599" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004600 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4601
4602 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004603 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4604 let fname= s:NetrwGetWord()
4605 sil NetrwKeepj $
4606 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4607" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4608 if result <= 0 && exists("w:netrw_bannercnt")
4609 exe "NetrwKeepj ".w:netrw_bannercnt
4610 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004611 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004612 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004613" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4614endfun
4615
4616" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004617" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4618"
4619" No bang: enters files/directories into Netrw's bookmark system
4620" No argument and in netrw buffer:
4621" if there are marked files: bookmark marked files
4622" otherwise : bookmark file/directory under cursor
4623" No argument and not in netrw buffer: bookmarks current open file
4624" Has arguments: globs them individually and bookmarks them
4625"
4626" With bang: deletes files/directories from Netrw's bookmark system
4627fun! s:NetrwBookmark(del,...)
4628" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4629 if a:0 == 0
4630 if &ft == "netrw"
4631 let curbufnr = bufnr("%")
4632
4633 if exists("s:netrwmarkfilelist_{curbufnr}")
4634 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004635" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004636 let svpos = winsaveview()
4637" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004638 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004639 for fname in s:netrwmarkfilelist_{curbufnr}
4640 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4641 endfor
4642 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4643 call s:NetrwUnmarkList(curbufnr,curdir)
4644 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004645" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4646 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004647 else
4648 let fname= s:NetrwGetWord()
4649 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4650 endif
4651
4652 else
4653 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004654" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004655 let fname= expand("%")
4656 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4657 endif
4658
4659 else
4660 " bookmark specified files
4661 " attempts to infer if working remote or local
4662 " by deciding if the current file begins with an url
4663 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004664 let islocal= expand("%") !~ '^\a\{3,}://'
4665" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004666 let i = 1
4667 while i <= a:0
4668 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004669 if v:version > 704 || (v:version == 704 && has("patch656"))
4670 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004671 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004672 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004673 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004674 else
4675 let mbfiles= [a:{i}]
4676 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004677" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004678 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004679" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004680 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4681 endfor
4682 let i= i + 1
4683 endwhile
4684 endif
4685
4686 " update the menu
4687 call s:NetrwBookmarkMenu()
4688
4689" call Dret("s:NetrwBookmark")
4690endfun
4691
4692" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004693" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4694" .2.[cnt] for bookmarks, and
4695" .3.[cnt] for history
4696" (see s:NetrwMenu())
4697fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004698 if !exists("s:netrw_menucnt")
4699 return
4700 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004701" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004702
4703 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004704 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004705 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004706" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004707 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4708 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004709 endif
4710 if !exists("s:netrw_initbookhist")
4711 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004712 endif
4713
4714 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004715 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004716 let cnt= 1
4717 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004718" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004719 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004720
4721 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004722 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004723
4724 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004725 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 +01004726 let cnt= cnt + 1
4727 endfor
4728
4729 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004730
4731 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004732 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004733 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004734 let first = 1
4735 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004736 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004737 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004738 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004739 if exists("g:netrw_dirhist_{cnt}")
4740 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004741" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004742 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4743 endif
4744 let first = 0
4745 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4746 if cnt < 0
4747 let cnt= cnt + g:netrw_dirhistmax
4748 endif
4749 endwhile
4750 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004751
Bram Moolenaar9964e462007-05-05 17:54:07 +00004752 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004753" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004754endfun
4755
4756" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004757" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4758" directory and a new directory name. Also, if the
4759" "new directory name" is actually a file,
4760" NetrwBrowseChgDir() edits the file.
4761fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004762" call Dfunc("s:NetrwBrowseChgDir(islocal=".a:islocal."> newdir<".a:newdir.">) a:0=".a:0." win#".winnr()." curpos<".string(getpos("."))."> b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004763" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00004764
Bram Moolenaar97d62492012-11-15 21:28:22 +01004765 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004766 if !exists("b:netrw_curdir")
4767 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4768 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004769 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004770" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4771" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004772" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004773" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004774 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004775 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004776" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004777
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004778 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004779" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004780 call s:SavePosn(s:netrw_posn)
4781 NetrwKeepj call s:NetrwOptionsSave("s:")
4782 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004783 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004784 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004785 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004786 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004787 endif
4788 let newdir = a:newdir
4789 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004790 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004791" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004792" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004793" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004794
4795 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004796" call Decho('(s:NetrwBrowseChgDir) ignore [return]s when done in banner (g:netrw_banner='.g:netrw_banner.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004797 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004798" call Decho("win#".winnr()." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a')." line(.)#".line('.')." line($)#".line("#"),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004799 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004800 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004801" call Decho("#1: quickhelp=".g:netrw_quickhelp." ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004802 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004803" call Decho("#2: quickhelp=".g:netrw_quickhelp." ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02004804 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004805 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004806 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004807 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004808" 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 +01004809 endif
4810 endif
4811" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004812" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004813 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004814
Bram Moolenaar446cb832008-06-24 21:56:24 +00004815 " set up o/s-dependent directory recognition pattern
4816 if has("amiga")
4817 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004818 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004819 let dirpat= '[\/]$'
4820 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004821" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004822
4823 if dirname !~ dirpat
4824 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004825 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004826 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004827" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004828 endif
4829
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004830" call Decho("[newdir<".newdir."> ".((newdir =~ dirpat)? "=~" : "!~")." dirpat<".dirpat.">] && [islocal=".a:islocal."] && [newdir is ".(isdirectory(s:NetrwFile(newdir))? "" : "not ")."a directory]",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004831 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004832 " ------------------------------
4833 " NetrwBrowseChgDir: edit a file {{{3
4834 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004835" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004836
Bram Moolenaar97d62492012-11-15 21:28:22 +01004837 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004838 let s:rexposn_{bufnr("%")}= winsaveview()
4839" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004840" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4841" call Decho("edit-a-file: w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a')." w:netrw_treedict:".(exists("w:netrw_treedict")? "exists" : 'n/a')." newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004842
Bram Moolenaar446cb832008-06-24 21:56:24 +00004843 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004844" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4845" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004846" let newdir = s:NetrwTreePath(s:netrw_treetop)
4847" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004848 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004849 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4850" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4851 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004852 if dirname =~ '/$'
4853 let dirname= dirname.newdir
4854 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004855 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004856 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004857" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4858" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004859 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004860" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004861 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004862 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004863 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004864 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004865" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004866 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004867 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004868" call Decho("edit-a-file: (a:0=".a:0."<1) set up windows for editing<".fnameescape(dirname)."> didsplit=".(exists("s:didsplit")? s:didsplit : "doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004869 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004870 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004871 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004872" " call Decho("edit-a-file: s:didsplit does not exist; g:netrw_browse_split=".string(g:netrw_browse_split)." win#".winnr()." g:netrw_chgwin=".g:netrw_chgwin",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004873 if type(g:netrw_browse_split) == 3
4874 " open file in server
4875 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004876" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004877 call s:NetrwServerEdit(a:islocal,dirname)
4878" call Dret("s:NetrwBrowseChgDir")
4879 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004880
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004881 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004882 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004883" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004884 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4885 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004886 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004887 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004888 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004889 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004890
Bram Moolenaar446cb832008-06-24 21:56:24 +00004891 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004892 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004893" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004894 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4895 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004896 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004897 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004898 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004899 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004900
Bram Moolenaar446cb832008-06-24 21:56:24 +00004901 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004902 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004903" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004904 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004905 if !exists("b:netrw_curdir")
4906 let b:netrw_curdir= getcwd()
4907 endif
4908 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004909
Bram Moolenaar446cb832008-06-24 21:56:24 +00004910 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004911 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004912" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004913 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004914 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004915" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004916 return
4917 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004918 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004919
Bram Moolenaar9964e462007-05-05 17:54:07 +00004920 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004921 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004922" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004923 call s:NetrwMenu(0)
4924 " optional change to window
4925 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004926" call Decho("edit-a-file: changing window to #".g:netrw_chgwin.": (due to g:netrw_chgwin)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02004927 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004928 " if g:netrw_chgwin is set to one more than the last window, then
4929 " vertically split the last window to make that window available.
4930 let curwin= winnr()
4931 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4932 vs
4933 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004934 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004935 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004936 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004937 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004938 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004939
Bram Moolenaar9964e462007-05-05 17:54:07 +00004940 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004941
Bram Moolenaar446cb832008-06-24 21:56:24 +00004942 " the point where netrw actually edits the (local) file
4943 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004944 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004945 if !&mod
4946 " if e the new file would fail due to &mod, then don't change any of the flags
4947 let dolockout= 1
4948 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004949 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004950" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004951 " some like c-^ to return to the last edited file
4952 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004953 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4954 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01004955 call s:NetrwEditFile("e","",dirname)
4956" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004957 " COMBAK -- cuc cul related
4958 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02004959 if &hidden || &bufhidden == "hide"
4960 " file came from vim's hidden storage. Don't "restore" options with it.
4961 let dorestore= 0
4962 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004963 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004964" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00004965 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004966
4967 " handle g:Netrw_funcref -- call external-to-netrw functions
4968 " This code will handle g:Netrw_funcref as an individual function reference
4969 " or as a list of function references. It will ignore anything that's not
4970 " a function reference. See :help Funcref for information about function references.
4971 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004972" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004973 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004974" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004975 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004976 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004977" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004978 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004979 if type(Fncref) == 2
4980 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004981 endif
4982 endfor
4983 endif
4984 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004985 endif
4986
4987 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004988 " ----------------------------------------------------
4989 " NetrwBrowseChgDir: just go to the new directory spec {{{3
4990 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004991" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004992 let dirname = newdir
4993 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004994 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004995 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004996
4997 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004998 " ---------------------------------------------
4999 " NetrwBrowseChgDir: refresh the directory list {{{3
5000 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005001" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005002 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005003 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005004
5005 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005006 " --------------------------------------
5007 " NetrwBrowseChgDir: go up one directory {{{3
5008 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005009" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005010
5011 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5012 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005013" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5014" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005015 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005016 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005017 endif
5018
5019 if has("amiga")
5020 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005021" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005022 if a:islocal
5023 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5024 let dirname= substitute(dirname,'/$','','')
5025 else
5026 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5027 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005028" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005029
Nir Lichtman1e34b952024-05-08 19:19:34 +02005030 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005031 " windows
5032 if a:islocal
5033 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5034 if dirname == ""
5035 let dirname= '/'
5036 endif
5037 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005038 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005039 endif
5040 if dirname =~ '^\a:$'
5041 let dirname= dirname.'/'
5042 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005043" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005044
Bram Moolenaar446cb832008-06-24 21:56:24 +00005045 else
5046 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005047" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../" and unix or cygwin','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005048 if a:islocal
5049 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5050 if dirname == ""
5051 let dirname= '/'
5052 endif
5053 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005054 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005055 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005056" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005057 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005058 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005059 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005060
5061 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005062 " --------------------------------------
5063 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5064 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005065" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005066 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5067" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005068 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005069 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005070" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5071 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005072 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005073 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005074" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005075 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005076 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005077" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005078
5079 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005080" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005081 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005082" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005083 let haskey= 1
5084 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005085" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005086 endif
5087
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005088 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005089" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005090 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005091 if has_key(w:netrw_treedict,treedir."/")
5092 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005093" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005094 let haskey = 1
5095 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005096" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005097 endif
5098 endif
5099
5100 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005101" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005102 if !haskey && treedir =~ '/$'
5103 let treedir= substitute(treedir,'/$','','')
5104 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005105" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005106 let haskey = 1
5107 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005108" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005109 endif
5110 endif
5111
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005112" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005113 if haskey
5114 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005115" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005116 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005117" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5118" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005119 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005120 else
5121 " go down one directory
5122 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005123" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5124" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005125 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005126 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005127" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005128 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005129
5130 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005131 " ----------------------------------------
5132 " NetrwBrowseChgDir: Go down one directory {{{3
5133 " ----------------------------------------
5134 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005135" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005136 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005137 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005138 endif
5139
Bram Moolenaar97d62492012-11-15 21:28:22 +01005140 " --------------------------------------
5141 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5142 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005143 if dorestore
5144 " dorestore is zero'd when a local file was hidden or bufhidden;
5145 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005146" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005147 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005148" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005149" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005150 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005151 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005152" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005153 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005154" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5155" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005156 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005157" call Decho("restore: ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005158 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005159" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5160" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005161 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005162" call Decho("restore: ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005163 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005164 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005165 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005166 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005167
Bram Moolenaar446cb832008-06-24 21:56:24 +00005168" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5169 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005170endfun
5171
5172" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005173" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5174" for thin, long, and wide: cursor placed just after banner
5175" for tree, keeps cursor on current filename
5176fun! s:NetrwBrowseUpDir(islocal)
5177" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005178 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5179 " this test needed because occasionally this function seems to be incorrectly called
5180 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005181 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005182 " directories.
5183" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5184 return
5185 endif
5186
Bram Moolenaara6878372014-03-22 21:02:50 +01005187 norm! 0
5188 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005189" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005190 let curline= getline(".")
5191 let swwline= winline() - 1
5192 if exists("w:netrw_treetop")
5193 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005194 elseif exists("b:netrw_curdir")
5195 let w:netrw_treetop= b:netrw_curdir
5196 else
5197 let w:netrw_treetop= getcwd()
5198 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005199 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005200 let curfile = getline(".")
5201 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005202 if a:islocal
5203 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5204 else
5205 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5206 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005207" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5208" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5209 if w:netrw_treetop == '/'
5210 keepj call search('^\M'.curfile,"w")
5211 elseif curfile == '../'
5212 keepj call search('^\M'.curfile,"wb")
5213 else
5214" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5215 while 1
5216 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5217 let treepath= s:NetrwTreePath(w:netrw_treetop)
5218" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5219 if treepath == curpath
5220 break
5221 endif
5222 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005223 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005224
Bram Moolenaara6878372014-03-22 21:02:50 +01005225 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005226" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005227 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005228 if exists("b:netrw_curdir")
5229 let curdir= b:netrw_curdir
5230 else
5231 let curdir= expand(getcwd())
5232 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005233 if a:islocal
5234 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5235 else
5236 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5237 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005238 call s:RestorePosn(s:netrw_posn)
5239 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005240 let curdir= '\<'. escape(curdir, '~'). '/'
5241 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005242 endif
5243" call Dret("s:NetrwBrowseUpDir")
5244endfun
5245
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005246func s:redir()
5247 " set up redirection (avoids browser messages)
5248 " by default if not set, g:netrw_suppress_gx_mesg is true
5249 if get(g:, 'netrw_suppress_gx_mesg', 1)
5250 if &srr =~# "%s"
5251 return printf(&srr, has("win32") ? "nul" : "/dev/null")
5252 else
5253 return &srr .. (has("win32") ? "nul" : "/dev/null")
5254 endif
5255 endif
5256 return ''
5257endfunc
5258
5259if has('unix')
5260 if has('win32unix')
5261 " Cygwin provides cygstart
5262 if executable('cygstart')
5263 fun! netrw#Launch(args)
5264 exe 'silent ! cygstart --hide' a:args s:redir() | redraw!
5265 endfun
5266 elseif !empty($MSYSTEM) && executable('start')
5267 " MSYS2/Git Bash comes by default without cygstart; see
5268 " https://www.msys2.org/wiki/How-does-MSYS2-differ-from-Cygwin
5269 " Instead it provides /usr/bin/start script running `cmd.exe //c start`
5270 " Adding "" //b` sets void title, hides cmd window and blocks path conversion
5271 " of /b to \b\ " by MSYS2; see https://www.msys2.org/docs/filesystem-paths/
5272 fun! netrw#Launch(args)
5273 exe 'silent !start "" //b' a:args s:redir() | redraw!
5274 endfun
5275 else
5276 " imitate /usr/bin/start script for other environments and hope for the best
5277 fun! netrw#Launch(args)
5278 exe 'silent !cmd //c start "" //b' a:args s:redir() | redraw!
5279 endfun
5280 endif
5281 elseif exists('$WSL_DISTRO_NAME') " use cmd.exe to start GUI apps in WSL
5282 fun! netrw#Launch(args)
5283 let args = a:args
5284 exe 'silent !' ..
5285 \ ((args =~? '\v<\f+\.(exe|com|bat|cmd)>') ?
5286 \ 'cmd.exe /c start "" /b ' .. args :
5287 \ 'nohup ' .. args .. ' ' .. s:redir() .. ' &')
5288 \ | redraw!
5289 endfun
5290 else
5291 fun! netrw#Launch(args)
5292 exe ':silent ! nohup' a:args s:redir() '&' | redraw!
5293 endfun
5294 endif
5295elseif has('win32')
5296 fun! netrw#Launch(args)
5297 exe 'silent !' .. (&shell =~? '\<cmd\.exe\>' ? '' : 'cmd.exe /c')
5298 \ 'start "" /b' a:args s:redir() | redraw!
5299 endfun
5300else
5301 fun! netrw#Launch(dummy)
5302 echom 'No common launcher found'
5303 endfun
5304endif
5305
5306" Git Bash
5307if has('win32unix')
5308 " (cyg)start suffices
5309 let s:os_viewer = ''
5310" Windows / WSL
5311elseif executable('explorer.exe')
5312 let s:os_viewer = 'explorer.exe'
5313" Linux / BSD
5314elseif executable('xdg-open')
5315 let s:os_viewer = 'xdg-open'
5316" MacOS
5317elseif executable('open')
5318 let s:os_viewer = 'open'
5319endif
5320
5321fun! s:viewer()
5322 if exists('g:netrw_browsex_viewer') && executable(g:netrw_browsex_viewer)
5323 " extract any viewing options. Assumes that they're set apart by spaces.
5324 " call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
5325 if g:netrw_browsex_viewer =~ '\s'
5326 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5327 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5328 let oviewer = ''
5329 let cnt = 1
5330 while !executable(viewer) && viewer != oviewer
5331 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5332 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5333 let cnt = cnt + 1
5334 let oviewer = viewer
5335 " call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
5336 endwhile
5337 else
5338 let viewer = g:netrw_browsex_viewer
5339 let viewopt = ""
5340 endif
5341 " call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
5342 return viewer .. ' ' .. viewopt
5343 else
5344 if !exists('s:os_viewer')
5345 call netrw#ErrorMsg(s:ERROR,"No program to open this path found. See :help Open for more information.",106)
5346 else
5347 return s:os_viewer
5348 endif
5349 endif
5350endfun
5351
5352fun! netrw#Open(file) abort
5353 call netrw#Launch(s:viewer() .. ' ' .. shellescape(a:file, 1))
5354endf
5355
5356if !exists('g:netrw_regex_url')
5357 let g:netrw_regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}'
5358endif
5359
Bram Moolenaara6878372014-03-22 21:02:50 +01005360" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005361" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005362" given filename; typically this means given their extension.
5363" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005364fun! netrw#BrowseX(fname,remote)
Bram Moolenaar91359012019-11-30 17:57:03 +01005365 if a:remote == 0 && isdirectory(a:fname)
5366 " if its really just a local directory, then do a "gf" instead
Bram Moolenaar29634562020-01-09 21:46:04 +01005367 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005368 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5369 " remote directory, not a webpage access, looks like an attempt to do a directory listing
Bram Moolenaar91359012019-11-30 17:57:03 +01005370 norm! gf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005371 endif
5372
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005373 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5374 let remote = a:remote
5375 else
5376 let remote = 0
5377 endif
5378
Bram Moolenaar97d62492012-11-15 21:28:22 +01005379 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005380 let screenposn = winsaveview()
Bram Moolenaar97d62492012-11-15 21:28:22 +01005381
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005382 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5383 let awkeep = &aw
5384 set noaw
5385
Bram Moolenaar5c736222010-01-06 20:54:52 +01005386 " special core dump handler
5387 if a:fname =~ '/core\(\.\d\+\)\=$'
5388 if exists("g:Netrw_corehandler")
5389 if type(g:Netrw_corehandler) == 2
5390 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005391 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005392 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005393 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005394 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005395 if type(Fncref) == 2
5396 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005397 endif
5398 endfor
5399 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005400 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005401 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005402 let &aw= awkeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005403 return
5404 endif
5405 endif
5406
Bram Moolenaar446cb832008-06-24 21:56:24 +00005407 " set up the filename
5408 " (lower case the extension, make a local copy of a remote file)
5409 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005410 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005411 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005412 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005413 if exten =~ "[\\/]"
5414 let exten= ""
5415 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005416
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005417 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005418 " create a local copy
Bram Moolenaarff034192013-04-24 18:51:19 +02005419 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005420 call netrw#NetRead(3,a:fname)
5421 " attempt to rename tempfile
5422 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005423 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02005424 if s:netrw_tmpfile != newname && newname != ""
5425 if rename(s:netrw_tmpfile,newname) == 0
5426 " renaming succeeded
Bram Moolenaar85850f32019-07-19 22:05:51 +02005427 let fname= newname
5428 else
5429 " renaming failed
Bram Moolenaar85850f32019-07-19 22:05:51 +02005430 let fname= s:netrw_tmpfile
5431 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005432 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005433 let fname= s:netrw_tmpfile
5434 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005435 else
5436 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005437 " special ~ handler for local
5438 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005439 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005440 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005441 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005442
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005443 " although shellescape(..., 1) is used in netrw#Open(), it's insufficient
5444 call netrw#Open(escape(fname, '#%'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005445
Bram Moolenaar446cb832008-06-24 21:56:24 +00005446 " cleanup: remove temporary file,
5447 " delete current buffer if success with handler,
5448 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005449 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005450 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005451" if remote == 1 && fname != a:fname
Bram Moolenaarc236c162008-07-13 17:41:49 +00005452" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005453" endif
5454
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005455 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005456 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005457 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005458 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005459 endif
Christian Brabandt9f320692024-10-30 18:36:20 +01005460 exe "sil! NetrwKeepj norm! \<c-o>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005461 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005462 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005463 let @@ = ykeep
5464 let &aw= awkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005465endfun
5466
5467" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005468" netrw#GX: gets word under cursor for gx support {{{2
5469" See also: netrw#BrowseXVis
5470" netrw#BrowseX
5471fun! netrw#GX()
5472" call Dfunc("netrw#GX()")
5473 if &ft == "netrw"
5474 let fname= s:NetrwGetWord()
5475 else
Konfekt3d7e5672024-10-27 22:16:49 +01005476 let fname= exists("g:netrw_gx")? expand(g:netrw_gx) : s:GetURL()
Bram Moolenaar85850f32019-07-19 22:05:51 +02005477 endif
5478" call Dret("netrw#GX <".fname.">")
5479 return fname
5480endfun
5481
Konfekt3d7e5672024-10-27 22:16:49 +01005482fun! s:GetURL() abort
5483 let URL = ''
5484 if exists('*Netrw_get_URL_' .. &filetype)
5485 let URL = call('Netrw_get_URL_' .. &filetype, [])
5486 endif
5487 if !empty(URL) | return URL | endif
5488 " URLs end in letter, digit or forward slash
5489 let URL = matchstr(expand("<cWORD>"), '\<' .. g:netrw_regex_url .. '\ze[^A-Za-z0-9/]*$')
5490 if !empty(URL) | return URL | endif
5491
5492 " Is it a file in the current work dir ...
5493 let file = expand("<cfile>")
5494 if filereadable(file) | return file | endif
5495 " ... or in that of the current buffer?
5496 let path = fnamemodify(expand('%'), ':p')
5497 if isdirectory(path)
5498 let dir = path
5499 elseif filereadable(path)
5500 let dir = fnamemodify(path, ':h')
5501 endif
5502 if exists('dir') && filereadable(dir..'/'..file) | return dir..'/'..file | endif
5503
5504 return ''
5505endf
5506
Bram Moolenaar85850f32019-07-19 22:05:51 +02005507" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005508" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5509fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005510 let dict={}
5511 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005512 norm! gv"ay
5513 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005514 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005515 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005516endfun
5517
5518" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005519" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5520" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5521" to become an unlisted buffer, so in that case don't bwipe it.
5522fun! s:NetrwBufRename(newname)
5523" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5524" call Dredir("ls!","s:NetrwBufRename (before rename)")
5525 let oldbufname= bufname(bufnr("%"))
5526" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5527
5528 if oldbufname != a:newname
5529" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5530 let b:junk= 1
5531" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5532 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005533" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005534 let oldbufnr= bufnr(oldbufname)
5535" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5536" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5537 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5538" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5539 exe "bwipe! ".oldbufnr
5540" else " Decho
5541" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005542" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5543" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5544" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005545 endif
5546" call Dredir("ls!","s:NetrwBufRename (after rename)")
5547" else " Decho
5548" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5549 endif
5550
5551" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5552endfun
5553
5554" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005555" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005556fun! netrw#CheckIfRemote(...)
5557" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5558 if a:0 > 0
5559 let curfile= a:1
5560 else
5561 let curfile= expand("%")
5562 endif
5563" call Decho("curfile<".curfile.">")
5564 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005565" call Dret("netrw#CheckIfRemote 1")
5566 return 1
5567 else
5568" call Dret("netrw#CheckIfRemote 0")
5569 return 0
5570 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005571endfun
5572
5573" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005574" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5575fun! s:NetrwChgPerm(islocal,curdir)
5576" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005577 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005578 call inputsave()
5579 let newperm= input("Enter new permission: ")
5580 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005581 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5582 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5583" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005584 call system(chgperm)
5585 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005586 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005587 endif
5588 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005589 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005590 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005591 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005592" call Dret("s:NetrwChgPerm")
5593endfun
5594
5595" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005596" s:CheckIfKde: checks if kdeinit is running {{{2
5597" Returns 0: kdeinit not running
5598" 1: kdeinit is running
5599fun! s:CheckIfKde()
5600" call Dfunc("s:CheckIfKde()")
5601 " seems kde systems often have gnome-open due to dependencies, even though
5602 " gnome-open's subsidiary display tools are largely absent. Kde systems
5603 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5604 if !exists("s:haskdeinit")
5605 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005606 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005607 if v:shell_error
5608 let s:haskdeinit = 0
5609 endif
5610 else
5611 let s:haskdeinit= 0
5612 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005613" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005614 endif
5615
5616" call Dret("s:CheckIfKde ".s:haskdeinit)
5617 return s:haskdeinit
5618endfun
5619
5620" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005621" s:NetrwClearExplore: clear explore variables (if any) {{{2
5622fun! s:NetrwClearExplore()
5623" call Dfunc("s:NetrwClearExplore()")
5624 2match none
5625 if exists("s:explore_match") |unlet s:explore_match |endif
5626 if exists("s:explore_indx") |unlet s:explore_indx |endif
5627 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5628 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5629 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5630 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5631 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5632 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5633 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5634" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005635" call Dret("s:NetrwClearExplore")
5636endfun
5637
5638" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005639" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5640fun! s:NetrwEditBuf(bufnum)
5641" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5642 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5643" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5644 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5645 else
5646" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005647 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005648 endif
5649" call Dret("s:NetrwEditBuf")
5650endfun
5651
5652" ---------------------------------------------------------------------
5653" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5654" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5655fun! s:NetrwEditFile(cmd,opt,fname)
5656" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5657 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5658" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5659 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5660 else
5661" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005662 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5663 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5664 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005665 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5666 endif
5667" call Dret("s:NetrwEditFile")
5668endfun
5669
5670" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005671" s:NetrwExploreListUniq: {{{2
5672fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005673" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005674
5675 " this assumes that the list is already sorted
5676 let newexplist= []
5677 for member in a:explist
5678 if !exists("uniqmember") || member != uniqmember
5679 let uniqmember = member
5680 let newexplist = newexplist + [ member ]
5681 endif
5682 endfor
5683
Bram Moolenaar15146672011-10-20 22:22:38 +02005684" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005685 return newexplist
5686endfun
5687
5688" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005689" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5690fun! s:NetrwForceChgDir(islocal,newdir)
5691" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005692 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005693 if a:newdir !~ '/$'
5694 " ok, looks like force is needed to get directory-style treatment
5695 if a:newdir =~ '@$'
5696 let newdir= substitute(a:newdir,'@$','/','')
5697 elseif a:newdir =~ '[*=|\\]$'
5698 let newdir= substitute(a:newdir,'.$','/','')
5699 else
5700 let newdir= a:newdir.'/'
5701 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005702" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005703 else
5704 " should already be getting treatment as a directory
5705 let newdir= a:newdir
5706 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005707 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005708 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005709 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005710" call Dret("s:NetrwForceChgDir")
5711endfun
5712
5713" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005714" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005715" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5716" expr : this is the expression to follow the directory. Will use s:ComposePath()
5717" pare =1: remove the current directory from the resulting glob() filelist
5718" =0: leave the current directory in the resulting glob() filelist
5719fun! s:NetrwGlob(direntry,expr,pare)
5720" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005721 if netrw#CheckIfRemote()
5722 keepalt 1sp
5723 keepalt enew
5724 let keep_liststyle = w:netrw_liststyle
5725 let w:netrw_liststyle = s:THINLIST
5726 if s:NetrwRemoteListing() == 0
5727 keepj keepalt %s@/@@
5728 let filelist= getline(1,$)
5729 q!
5730 else
5731 " remote listing error -- leave treedict unchanged
5732 let filelist= w:netrw_treedict[a:direntry]
5733 endif
5734 let w:netrw_liststyle= keep_liststyle
5735 else
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005736 let path= s:ComposePath(fnameescape(a:direntry), a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005737 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005738 " escape [ so it is not detected as wildcard character, see :h wildcard
5739 let path= substitute(path, '[', '[[]', 'g')
5740 endif
5741 if v:version > 704 || (v:version == 704 && has("patch656"))
5742 let filelist= glob(path,0,1,1)
5743 else
5744 let filelist= glob(path,0,1)
5745 endif
5746 if a:pare
5747 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5748 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005749 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005750 return filelist
5751endfun
5752
5753" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005754" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5755fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005756" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005757 if a:newfile =~ '[/@*=|\\]$'
5758 let newfile= substitute(a:newfile,'.$','','')
5759 else
5760 let newfile= a:newfile
5761 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005762 if a:islocal
5763 call s:NetrwBrowseChgDir(a:islocal,newfile)
5764 else
5765 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5766 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005767" call Dret("s:NetrwForceFile")
5768endfun
5769
5770" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005771" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5772" and switches the hiding mode. The actual hiding is done by
5773" s:NetrwListHide().
5774" g:netrw_hide= 0: show all
5775" 1: show not-hidden files
5776" 2: show hidden files only
5777fun! s:NetrwHide(islocal)
5778" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005779 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005780 let svpos= winsaveview()
5781" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005782
5783 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005784" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5785" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005786
5787 " hide the files in the markfile list
5788 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005789" call Decho("match(g:netrw_list_hide<".g:netrw_list_hide.'> fname<\<'.fname.'\>>)='.match(g:netrw_list_hide,'\<'.fname.'\>')." l:isk=".&l:isk,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005790 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5791 " remove fname from hiding list
5792 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5793 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5794 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005795" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005796 else
5797 " append fname to hiding list
5798 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5799 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5800 else
5801 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5802 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005803" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005804 endif
5805 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005806 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005807 let g:netrw_hide= 1
5808
5809 else
5810
5811 " switch between show-all/show-not-hidden/show-hidden
5812 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005813 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005814 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005815 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005816 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005817" call Dret("NetrwHide")
5818 return
5819 endif
5820 endif
5821
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005822 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005823" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5824 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005825 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005826" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005827endfun
5828
5829" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005830" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5831fun! s:NetrwHideEdit(islocal)
5832" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5833
5834 let ykeep= @@
5835 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005836 let svpos= winsaveview()
5837" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005838
5839 " get new hiding list from user
5840 call inputsave()
5841 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5842 call inputrestore()
5843 let g:netrw_list_hide= newhide
5844" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5845
5846 " refresh the listing
5847 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5848
5849 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005850" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5851 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005852 let @@= ykeep
5853
5854" call Dret("NetrwHideEdit")
5855endfun
5856
5857" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005858" s:NetrwHidden: invoked by "gh" {{{2
5859fun! s:NetrwHidden(islocal)
5860" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005861 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005862 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005863 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005864" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005865
5866 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005867 " remove .file pattern from hiding list
5868" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005869 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005870 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005871" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005872 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5873 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005874" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005875 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5876 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005877 if g:netrw_list_hide =~ '^,'
5878 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5879 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005880
5881 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005882 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005883" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5884 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005885 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005886" call Dret("s:NetrwHidden")
5887endfun
5888
5889" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005890" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5891fun! s:NetrwHome()
5892 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005893 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005894 else
5895 " go to vim plugin home
5896 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005897 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005898 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005899 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005900 let home= basehome."/.vim"
5901 break
5902 endif
5903 endfor
5904 if home == ""
5905 " just pick the first directory
5906 let home= substitute(&rtp,',.*$','','')
5907 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005908 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005909 let home= substitute(home,'/','\\','g')
5910 endif
5911 endif
5912 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005913 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005914" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005915 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005916" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005917 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005918 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005919" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005920 call mkdir(home)
5921 endif
5922 endif
5923 let g:netrw_home= home
5924 return home
5925endfun
5926
5927" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005928" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5929fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005930 if exists("s:netrwdrag")
5931 return
5932 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005933 if &ft != "netrw"
5934 return
5935 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005936" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005937
Bram Moolenaar97d62492012-11-15 21:28:22 +01005938 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005939 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005940 while getchar(0) != 0
5941 "clear the input stream
5942 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005943 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005944 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005945 let mouse_lnum = v:mouse_lnum
5946 let wlastline = line('w$')
5947 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005948" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
5949" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005950 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5951 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005952 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005953" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
5954 return
5955 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005956 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005957 " 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 +01005958 " without this test when its disabled.
5959 " May 26, 2014: edit file, :Lex, resize window -- causes refresh. Reinstated a modified test. See if problems develop.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005960" call Decho("v:mouse_col=".v:mouse_col." col#".col('.')." virtcol#".virtcol('.')." col($)#".col("$")." virtcol($)#".virtcol("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005961 if v:mouse_col > virtcol('.')
5962 let @@= ykeep
5963" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
5964 return
5965 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005966
Bram Moolenaar446cb832008-06-24 21:56:24 +00005967 if a:islocal
5968 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005969 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005970 endif
5971 else
5972 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005973 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005974 endif
5975 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005976 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005977" call Dret("s:NetrwLeftmouse")
5978endfun
5979
5980" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005981" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
5982fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005983 if &ft != "netrw"
5984 return
5985 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005986" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
5987 call s:NetrwMarkFileTgt(a:islocal)
5988" call Dret("s:NetrwCLeftmouse")
5989endfun
5990
5991" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005992" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
5993" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02005994" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005995" a:islocal=2 : <c-r> used, remote
5996" a:islocal=3 : <c-r> used, local
5997fun! s:NetrwServerEdit(islocal,fname)
5998" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
5999 let islocal = a:islocal%2 " =0: remote =1: local
6000 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006001" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006002
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006003 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006004 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006005 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006006" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006007 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006008 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006009 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6010 unlet s:netrw_browse_split_{winnr()}
6011 endif
6012 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6013" call Dret("s:NetrwServerEdit")
6014 return
6015 endif
6016
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006017" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006018 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006019" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006020
6021 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006022" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006023 let srvrname = g:netrw_browse_split[0]
6024 let tabnum = g:netrw_browse_split[1]
6025 let winnum = g:netrw_browse_split[2]
6026
6027 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006028" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006029
6030 if !ctrlr
6031 " user must have closed the server window and the user did not use <c-r>, but
6032 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006033" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006034 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006035 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006036 endif
6037 let g:netrw_browse_split= 0
6038 if exists("s:netrw_browse_split_".winnr())
6039 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6040 endif
6041 call s:NetrwBrowseChgDir(islocal,a:fname)
6042" call Dret("s:NetrwServerEdit")
6043 return
6044
6045 elseif has("win32") && executable("start")
6046 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006047" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006048 call system("start gvim --servername ".srvrname)
6049
6050 else
6051 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006052" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006053 call system("gvim --servername ".srvrname)
6054 endif
6055 endif
6056
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006057" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006058 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6059 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006060 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006061
6062 else
6063
6064 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6065
6066 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006067" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006068 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006069 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006070 endif
6071 let g:netrw_browse_split= 0
6072 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6073" call Dret("s:NetrwServerEdit")
6074 return
6075
6076 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006077" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006078 if has("win32") && executable("start")
6079 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006080" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006081 call system("start gvim --servername ".g:netrw_servername)
6082 else
6083 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006084" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006085 call system("gvim --servername ".g:netrw_servername)
6086 endif
6087 endif
6088 endif
6089
6090 while 1
6091 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006092" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6093 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006094 break
6095 catch /^Vim\%((\a\+)\)\=:E241/
6096 sleep 200m
6097 endtry
6098 endwhile
6099
6100 if exists("g:netrw_browse_split")
6101 if type(g:netrw_browse_split) != 3
6102 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6103 endif
6104 unlet g:netrw_browse_split
6105 endif
6106 let g:netrw_browse_split= [g:netrw_servername,1,1]
6107 endif
6108
6109 else
6110 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6111 endif
6112
6113" call Dret("s:NetrwServerEdit")
6114endfun
6115
6116" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006117" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6118fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006119 if &ft != "netrw"
6120 return
6121 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006122" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006123
Bram Moolenaar8d043172014-01-23 14:24:41 +01006124 let s:ngw= s:NetrwGetWord()
6125 call s:NetrwMarkFile(a:islocal,s:ngw)
6126
6127" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006128endfun
6129
6130" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006131" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6132" Used to mark multiple files.
6133fun! s:NetrwSLeftdrag(islocal)
6134" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6135 if !exists("s:netrwdrag")
6136 let s:netrwdrag = winnr()
6137 if a:islocal
6138 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006139 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006140 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006141 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006142 endif
6143 let ngw = s:NetrwGetWord()
6144 if !exists("s:ngw") || s:ngw != ngw
6145 call s:NetrwMarkFile(a:islocal,ngw)
6146 endif
6147 let s:ngw= ngw
6148" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6149endfun
6150
6151" ---------------------------------------------------------------------
6152" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6153fun! s:NetrwSLeftrelease(islocal)
6154" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6155 if exists("s:netrwdrag")
6156 nunmap <s-leftrelease>
6157 let ngw = s:NetrwGetWord()
6158 if !exists("s:ngw") || s:ngw != ngw
6159 call s:NetrwMarkFile(a:islocal,ngw)
6160 endif
6161 if exists("s:ngw")
6162 unlet s:ngw
6163 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006164 unlet s:netrwdrag
6165 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006166" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006167endfun
6168
6169" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006170" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6171" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006172fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006173" 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 +02006174" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006175 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006176
6177 " 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 +02006178 " How-it-works: take the hiding command, convert it into a range.
6179 " Duplicate characters don't matter.
6180 " Remove all such characters from the '/~@#...890' string.
6181 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006182" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006183 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006184 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006185" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006186
6187 while listhide != ""
6188 if listhide =~ ','
6189 let hide = substitute(listhide,',.*$','','e')
6190 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6191 else
6192 let hide = listhide
6193 let listhide = ""
6194 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006195" 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 +01006196 if g:netrw_sort_by =~ '^[ts]'
6197 if hide =~ '^\^'
6198" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6199 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6200 elseif hide =~ '^\\(\^'
6201 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6202 endif
6203" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6204 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006205
6206 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006207" 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 +00006208 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006209" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006210 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006211 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006212" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006213 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006214 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006215" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006216 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006217
Bram Moolenaar446cb832008-06-24 21:56:24 +00006218 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006219 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006220" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006221 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006222" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006223 endif
6224
Bram Moolenaaradc21822011-04-01 18:03:16 +02006225 " remove any blank lines that have somehow remained.
6226 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006227 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006228
Bram Moolenaar97d62492012-11-15 21:28:22 +01006229 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006230" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006231endfun
6232
6233" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006234" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006235" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006236fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006237" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006238
Bram Moolenaar97d62492012-11-15 21:28:22 +01006239 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006240 " get name of new directory from user. A bare <CR> will skip.
6241 " if its currently a directory, also request will be skipped, but with
6242 " a message.
6243 call inputsave()
6244 let newdirname= input("Please give directory name: ")
6245 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006246" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006247
6248 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006249 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006250" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006251 return
6252 endif
6253
6254 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006255" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006256
6257 " Local mkdir:
6258 " sanity checks
6259 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006260" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6261 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006262 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006263 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006264 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006265 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006266" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006267 return
6268 endif
6269 if s:FileReadable(fullnewdir)
6270 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006271 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006272 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006273 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006274" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006275 return
6276 endif
6277
6278 " requested new local directory is neither a pre-existing file or
6279 " directory, so make it!
6280 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006281 if has("unix")
6282 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6283 else
6284 call mkdir(fullnewdir,"p")
6285 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006286 else
6287 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006288 if s:NetrwLcd(b:netrw_curdir)
6289" call Dret("s:NetrwMakeDir : lcd failure")
6290 return
6291 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006292" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006293 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006294 if v:shell_error != 0
6295 let @@= ykeep
6296 call netrw#ErrorMsg(s:ERROR,"consider setting g:netrw_localmkdir<".g:netrw_localmkdir."> to something that works",80)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006297" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006298 return
6299 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006300 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006301" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006302 if s:NetrwLcd(netrw_origdir)
6303" call Dret("s:NetrwBrowse : lcd failure")
6304 return
6305 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006306 endif
6307 endif
6308
6309 if v:shell_error == 0
6310 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006311" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006312 let svpos= winsaveview()
6313" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006314 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006315" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6316 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006317 elseif !exists("g:netrw_quiet")
6318 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6319 endif
6320" redraw!
6321
6322 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006323 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006324" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006325 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6326 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006327 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006328 if v:shell_error == 0
6329 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006330 let svpos= winsaveview()
6331" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006332 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006333" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6334 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006335 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006336 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006337 endif
6338" redraw!
6339
6340 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006341 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006342 let svpos= winsaveview()
6343" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006344" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006345 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006346" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006347 let remotepath= b:netrw_fname
6348 else
6349 let remotepath= ""
6350 endif
6351 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006352 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006353" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6354 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006355
Bram Moolenaar446cb832008-06-24 21:56:24 +00006356 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006357 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006358 let svpos= winsaveview()
6359" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006360" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006361 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006362" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006363 let remotepath= b:netrw_fname
6364 else
6365 let remotepath= ""
6366 endif
6367 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006368 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006369" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6370 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006371 endif
6372
Bram Moolenaar97d62492012-11-15 21:28:22 +01006373 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006374" call Dret("s:NetrwMakeDir")
6375endfun
6376
6377" ---------------------------------------------------------------------
6378" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6379fun! s:TreeSqueezeDir(islocal)
6380" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6381 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6382 " its a tree-listing style
6383 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006384 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006385 let depth = strchars(substitute(curdepth,' ','','g'))
6386 let srch = -1
6387" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6388" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006389" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006390" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6391 if depth >= 2
6392 NetrwKeepj norm! 0
6393 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6394 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6395" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6396" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6397 elseif depth == 1
6398 NetrwKeepj norm! 0
6399 let treedepthchr= substitute(s:treedepthstring,' ','','')
6400 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6401" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6402 endif
6403 if srch > 0
6404" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6405 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6406 exe srch
6407 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006408 endif
6409" call Dret("s:TreeSqueezeDir")
6410endfun
6411
6412" ---------------------------------------------------------------------
6413" s:NetrwMaps: {{{2
6414fun! s:NetrwMaps(islocal)
6415" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6416
Bram Moolenaar85850f32019-07-19 22:05:51 +02006417 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006418 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006419" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006420 if !hasmapto("<Plug>NetrwReturn")
6421 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006422" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006423 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6424 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006425" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006426 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6427 endif
6428 endif
6429 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006430" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006431 endif
6432
Bram Moolenaar85850f32019-07-19 22:05:51 +02006433 " generate default <Plug> maps {{{3
6434 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006435 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006436 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6437 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6438 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6439 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6440 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6441 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6442 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6443 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6444 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6445 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6446" ---------------------------------------------------------------------
6447" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6448" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6449" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6450" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6451" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6452" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6453" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6454" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6455" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6456" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6457" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6458" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6459" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6460" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6461" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6462" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6463" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6464" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6465" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6466" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6467" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6468" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6469" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6470" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6471" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6472" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6473" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6474" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6475" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6476" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6477" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6478" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6479" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6480" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6481" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6482" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6483" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6484" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6485" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6486" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6487" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6488" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6489" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6490" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6491" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6492" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6493" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6494
Bram Moolenaara6878372014-03-22 21:02:50 +01006495 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006496" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006497 " local normal-mode maps {{{3
6498 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6499 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6500 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6501 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6502 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6503 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6504 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6505 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6506 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6507 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6508 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6509" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006510 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6511 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6512 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006513 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006514 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006515 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6516 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6517 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6518 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006519 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6520 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6521 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6522 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6523 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6524 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6525 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6526 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6527 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6528 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6529 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6530 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6531 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006532 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006533 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006534 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6535 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6536 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6537 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6538 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006539 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006540 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006541 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6542 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006543 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6544 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6545 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006546 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006547 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006548 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6549 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006550 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006551 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006552 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6553 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6554 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006555 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6556 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006557
6558 nnoremap <buffer> <silent> <nowait> r :<c-u>let g:netrw_sort_direction= (g:netrw_sort_direction =~# 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,'./'))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006559 if !hasmapto('<Plug>NetrwHideEdit')
6560 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006561 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006562 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006563 if !hasmapto('<Plug>NetrwRefresh')
6564 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006565 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006566 nnoremap <buffer> <silent> <Plug>NetrwRefresh <c-l>:call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,(exists("w:netrw_liststyle") && exists("w:netrw_treetop") && w:netrw_liststyle == 3)? w:netrw_treetop : './'))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006567 if s:didstarstar || !mapcheck("<s-down>","n")
6568 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006569 endif
6570 if s:didstarstar || !mapcheck("<s-up>","n")
6571 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006572 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006573 if !hasmapto('<Plug>NetrwTreeSqueeze')
6574 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006575 endif
6576 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006577 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6578 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006579 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6580 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6581 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6582 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6583 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6584 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6585 imap <buffer> <leftmouse> <Plug>ILeftmouse
6586 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006587 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6588 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6589 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6590 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6591 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006592 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006593 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6594 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006595 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006596 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6597 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6598 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6599 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6600 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6601 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6602 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006603 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6604
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006605 " support user-specified maps
6606 call netrw#UserMaps(1)
6607
Bram Moolenaar85850f32019-07-19 22:05:51 +02006608 else
6609 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006610" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006611 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006612 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6613 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6614 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6615 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6616 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6617 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6618 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6619 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6620 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6621 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6622 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6623" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006624 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6625 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6626 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6627 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6628 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6629 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6630 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6631 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006632 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006633 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006634 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6635 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6636 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6637 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6638 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6639 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6640 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6641 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6642 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6643 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6644 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006645 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006646 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006647 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6648 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6649 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6650 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6651 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006652 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6653 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6654 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6655 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006656 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006657 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6658 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006659 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006660 nnoremap <buffer> <silent> <nowait> r :<c-u>let g:netrw_sort_direction= (g:netrw_sort_direction =~# 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006661 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6662 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6663 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6664 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6665 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6666 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6667 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6668 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6669 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Konfekt3d7e5672024-10-27 22:16:49 +01006670 nmap <buffer> <nowait> gx x
Bram Moolenaara6878372014-03-22 21:02:50 +01006671 if !hasmapto('<Plug>NetrwHideEdit')
6672 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006673 endif
6674 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6675 if !hasmapto('<Plug>NetrwRefresh')
6676 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006677 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006678 if !hasmapto('<Plug>NetrwTreeSqueeze')
6679 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006680 endif
6681 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006682
6683 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006684 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006685
6686 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6687 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006688 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006689 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006690 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006691 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006692 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006693 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006694 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006695 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006696 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006697 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006698 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6699 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6700 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006701 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006702 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006703 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6704 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006705 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006706 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6707 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6708 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6709 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6710 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6711 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6712 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006713 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006714
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006715 " support user-specified maps
6716 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006717 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006718
6719" call Dret("s:NetrwMaps")
6720endfun
6721
6722" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006723" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006724" If -buffer, the command is only available from within netrw buffers
6725" Otherwise, the command is available from any window, so long as netrw
6726" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006727fun! s:NetrwCommands(islocal)
6728" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6729
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006730 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6731 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006732 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 +01006733 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006734 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006735 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006736 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006737 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006738 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006739
6740" call Dret("s:NetrwCommands")
6741endfun
6742
6743" ---------------------------------------------------------------------
6744" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6745" glob()ing only works with local files
6746fun! s:NetrwMarkFiles(islocal,...)
6747" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006748 let curdir = s:NetrwGetCurdir(a:islocal)
6749 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006750 while i <= a:0
6751 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006752 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006753 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006754 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006755 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006756 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006757 else
6758 let mffiles= [a:{i}]
6759 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006760" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006761 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006762" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006763 call s:NetrwMarkFile(a:islocal,mffile)
6764 endfor
6765 let i= i + 1
6766 endwhile
6767" call Dret("s:NetrwMarkFiles")
6768endfun
6769
6770" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006771" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006772fun! s:NetrwMarkTarget(...)
6773" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6774 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006775 let curdir = s:NetrwGetCurdir(1)
6776 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006777 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006778 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6779 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006780 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006781" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006782 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006783 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6784 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006785 let svpos = winsaveview()
6786" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006787 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006788" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6789 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006790" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006791endfun
6792
6793" ---------------------------------------------------------------------
6794" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6795" mark and unmark files. If a markfile list exists,
6796" then the rename and delete functions will use it instead
6797" of whatever may happen to be under the cursor at that
6798" moment. When the mouse and gui are available,
6799" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006800"
6801" Creates two lists
6802" s:netrwmarkfilelist -- holds complete paths to all marked files
6803" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6804"
6805" Creates a marked file match string
6806" s:netrwmarfilemtch_# -- used with 2match to display marked files
6807"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006808" Creates a buffer version of islocal
6809" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006810fun! s:NetrwMarkFile(islocal,fname)
6811" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006812" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006813
6814 " sanity check
6815 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006816" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006817 return
6818 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006819 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006820
Bram Moolenaar97d62492012-11-15 21:28:22 +01006821 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006822 let curbufnr= bufnr("%")
yasudac18a9d52024-09-19 18:09:51 +02006823 let leader= '\%(^\|\s\)\zs'
Bram Moolenaara6878372014-03-22 21:02:50 +01006824 if a:fname =~ '\a$'
6825 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6826 else
6827 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6828 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006829
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006830 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006831 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006832" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6833" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6834" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006835 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006836
6837 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006838 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006839" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006840 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006841 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006842
6843 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006844 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006845" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006846 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6847 if s:netrwmarkfilelist_{curbufnr} == []
6848 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006849" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006850 call s:NetrwUnmarkList(curbufnr,curdir)
6851 else
6852 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006853" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006854 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006855 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006856 for fname in s:netrwmarkfilelist_{curbufnr}
6857 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006858 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006859 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006860 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006861 endif
6862 let first= 0
6863 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006864" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006865 endif
6866 endif
6867
6868 else
6869 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006870" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006871
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006872" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006873 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006874 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6875" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006876
6877 " build initial markfile matching pattern
6878 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006879 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006880 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006881 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006882 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006883" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006884 endif
6885
6886 " handle global markfilelist
6887 if exists("s:netrwmarkfilelist")
6888 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6889 if index(s:netrwmarkfilelist,dname) == -1
6890 " append new filename to global markfilelist
6891 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006892" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006893 else
6894 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006895" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6896" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006897 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006898" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006899 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006900" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006901 unlet s:netrwmarkfilelist
6902 endif
6903 endif
6904 else
6905 " initialize new global-directory markfilelist
6906 let s:netrwmarkfilelist= []
6907 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006908" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006909 endif
6910
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006911 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006912 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6913 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6914" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6915 if exists("g:did_drchip_netrwlist_syntax")
6916 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6917 endif
6918 else
6919" " call Decho("2match none",'~'.expand("<slnum>"))
6920 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006921 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006922 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006923 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006924" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6925" 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 +00006926endfun
6927
6928" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006929" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6930" mA: move the argument list to marked file list (tomflist=1)
6931" Uses the global marked file list
6932fun! s:NetrwMarkFileArgList(islocal,tomflist)
6933" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
6934
6935 let svpos = winsaveview()
6936" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6937 let curdir = s:NetrwGetCurdir(a:islocal)
6938 let curbufnr = bufnr("%")
6939
6940 if a:tomflist
6941 " mA: move argument list to marked file list
6942 while argc()
6943 let fname= argv(0)
6944" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
6945 exe "argdel ".fnameescape(fname)
6946 call s:NetrwMarkFile(a:islocal,fname)
6947 endwhile
6948
6949 else
6950 " ma: move marked file list to argument list
6951 if exists("s:netrwmarkfilelist")
6952
6953 " for every filename in the marked list
6954 for fname in s:netrwmarkfilelist
6955" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
6956 exe "argadd ".fnameescape(fname)
6957 endfor " for every file in the marked list
6958
6959 " unmark list and refresh
6960 call s:NetrwUnmarkList(curbufnr,curdir)
6961 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
6962" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6963 NetrwKeepj call winrestview(svpos)
6964 endif
6965 endif
6966
6967" call Dret("s:NetrwMarkFileArgList")
6968endfun
6969
6970" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006971" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
6972" compress/decompress files using the programs
6973" in g:netrw_compress and g:netrw_uncompress,
6974" using g:netrw_compress_suffix to know which to
6975" do. By default:
6976" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006977" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00006978fun! s:NetrwMarkFileCompress(islocal)
6979" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006980 let svpos = winsaveview()
6981" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006982 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006983 let curbufnr = bufnr("%")
6984
Bram Moolenaarff034192013-04-24 18:51:19 +02006985 " sanity check
6986 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006987 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006988" call Dret("s:NetrwMarkFileCompress")
6989 return
6990 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006991" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006992
Bram Moolenaar446cb832008-06-24 21:56:24 +00006993 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02006994
6995 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00006996 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02006997 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006998" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006999 if exists("g:netrw_decompress['".sfx."']")
7000 " fname has a suffix indicating that its compressed; apply associated decompression routine
7001 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007002" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007003 let exe= netrw#WinPath(exe)
7004 if a:islocal
7005 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007006 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007007 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007008 call system(exe." ".fname)
7009 if v:shell_error
7010 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007011 endif
7012 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007013 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7014 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007015 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007016
Bram Moolenaarff034192013-04-24 18:51:19 +02007017 endif
7018 unlet sfx
7019
Bram Moolenaar446cb832008-06-24 21:56:24 +00007020 if exists("exe")
7021 unlet exe
7022 elseif a:islocal
7023 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007024 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007025 if v:shell_error
7026 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7027 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007028 else
7029 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007030 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007031 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007032 endfor " for every file in the marked list
7033
Bram Moolenaar446cb832008-06-24 21:56:24 +00007034 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007035 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007036" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7037 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007038 endif
7039" call Dret("s:NetrwMarkFileCompress")
7040endfun
7041
7042" ---------------------------------------------------------------------
7043" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7044" If no marked files, then set up directory as the
7045" target. Currently does not support copying entire
7046" directories. Uses the local-buffer marked file list.
7047" Returns 1=success (used by NetrwMarkFileMove())
7048" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007049fun! s:NetrwMarkFileCopy(islocal,...)
7050" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7051
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007052 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007053 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007054 if b:netrw_curdir !~ '/$'
7055 if !exists("b:netrw_curdir")
7056 let b:netrw_curdir= curdir
7057 endif
7058 let b:netrw_curdir= b:netrw_curdir."/"
7059 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007060
Bram Moolenaarff034192013-04-24 18:51:19 +02007061 " sanity check
7062 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007063 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007064" call Dret("s:NetrwMarkFileCopy")
7065 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007066 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007067" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007068
Bram Moolenaar446cb832008-06-24 21:56:24 +00007069 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007070 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007071" call Dret("s:NetrwMarkFileCopy 0")
7072 return 0
7073 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007074" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007075
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007076 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007077 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007078" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007079 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007080 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7081" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7082 return
7083 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007084
7085 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02007086 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007087 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7088 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007089" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007090 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007091 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7092 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007093" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007094 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007095 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007096 let oldname = a:1
7097 else
7098 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007099" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007100 let s:recursive= 1
7101 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7102 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7103 if ret == 0
7104 break
7105 endif
7106 endfor
7107 unlet s:recursive
7108 call s:NetrwUnmarkList(curbufnr,curdir)
7109" call Dret("s:NetrwMarkFileCopy ".ret)
7110 return ret
7111 endif
7112
7113 call inputsave()
7114 let newname= input("Copy ".oldname." to : ",oldname,"file")
7115 call inputrestore()
7116 if newname == ""
7117" call Dret("s:NetrwMarkFileCopy 0")
7118 return 0
7119 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007120 let args= s:ShellEscape(oldname)
7121 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007122 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007123 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7124 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007125 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007126 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007127 let args= substitute(args,'/','\\','g')
7128 let tgt = substitute(tgt, '/','\\','g')
7129 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007130 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7131 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7132 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7133 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7134" call Decho("args <".args.">",'~'.expand("<slnum>"))
7135" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007136 if isdirectory(s:NetrwFile(args))
7137" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007138 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007139" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007140 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007141 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7142 " contents to a target. One must append the source directory name to the target to get xcopy to
7143 " do the right thing.
7144 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007145" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007146 endif
7147 else
7148 let copycmd= g:netrw_localcopycmd
7149 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007150 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007151 let copycmd = substitute(copycmd,'\s.*$','','')
7152 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007153 let copycmd = netrw#WinPath(copycmd).copycmdargs
7154 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007155 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007156 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007157" call Decho("args <".args.">",'~'.expand("<slnum>"))
7158" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7159" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7160" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007161 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007162 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02007163 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007164 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 +01007165 else
7166 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7167 endif
7168" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007169 return 0
7170 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007171
7172 elseif a:islocal && !s:netrwmftgt_islocal
7173 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007174" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007175 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007176
7177 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007178 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007179" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007180 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007181
7182 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007183 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007184" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007185 let curdir = getcwd()
7186 let tmpdir = s:GetTempfile("")
7187 if tmpdir !~ '/'
7188 let tmpdir= curdir."/".tmpdir
7189 endif
7190 if exists("*mkdir")
7191 call mkdir(tmpdir)
7192 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007193 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007194 if v:shell_error != 0
7195 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 +01007196" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007197 return
7198 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007199 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007200 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007201 if s:NetrwLcd(tmpdir)
7202" call Dret("s:NetrwMarkFileCopy : lcd failure")
7203 return
7204 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007205 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007206 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007207 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007208 if getcwd() == tmpdir
7209 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007210 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007211 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007212 if s:NetrwLcd(curdir)
7213" call Dret("s:NetrwMarkFileCopy : lcd failure")
7214 return
7215 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007216 if delete(tmpdir,"d")
7217 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007218 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007219 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007220 if s:NetrwLcd(curdir)
7221" call Dret("s:NetrwMarkFileCopy : lcd failure")
7222 return
7223 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007224 endif
7225 endif
7226 endif
7227
7228 " -------
7229 " cleanup
7230 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007231" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007232 " remove markings from local buffer
7233 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007234" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7235" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7236" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7237" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7238" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7239" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7240 if exists("s:recursive")
7241" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7242 else
7243" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007244 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007245 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007246 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007247 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007248 else
7249 " refresh local and targets for fast browsing
7250 if !exists("s:recursive")
7251 " remove markings from local buffer
7252" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7253 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7254 endif
7255
7256 " refresh buffers
7257 if s:netrwmftgt_islocal
7258" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7259 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7260 endif
7261 if a:islocal && s:netrwmftgt != curdir
7262" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7263 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7264 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007265 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007266
Bram Moolenaar446cb832008-06-24 21:56:24 +00007267" call Dret("s:NetrwMarkFileCopy 1")
7268 return 1
7269endfun
7270
7271" ---------------------------------------------------------------------
7272" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7273" invoke vim's diff mode on the marked files.
7274" Either two or three files can be so handled.
7275" Uses the global marked file list.
7276fun! s:NetrwMarkFileDiff(islocal)
7277" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7278 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007279
Bram Moolenaarff034192013-04-24 18:51:19 +02007280 " sanity check
7281 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007282 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007283" call Dret("s:NetrwMarkFileDiff")
7284 return
7285 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007286 let curdir= s:NetrwGetCurdir(a:islocal)
7287" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007288
Bram Moolenaara6878372014-03-22 21:02:50 +01007289 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007290 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007291 for fname in s:netrwmarkfilelist
7292 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007293 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007294" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007295 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007296 diffthis
7297 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007298 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007299" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007300 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007301 diffthis
7302 else
7303 break
7304 endif
7305 endfor
7306 call s:NetrwUnmarkList(curbufnr,curdir)
7307 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007308
Bram Moolenaar446cb832008-06-24 21:56:24 +00007309" call Dret("s:NetrwMarkFileDiff")
7310endfun
7311
7312" ---------------------------------------------------------------------
7313" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7314" Uses global markfilelist
7315fun! s:NetrwMarkFileEdit(islocal)
7316" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7317
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007318 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007319 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007320
7321 " sanity check
7322 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007323 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007324" call Dret("s:NetrwMarkFileEdit")
7325 return
7326 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007327" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007328
Bram Moolenaar446cb832008-06-24 21:56:24 +00007329 if exists("s:netrwmarkfilelist_{curbufnr}")
7330 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007331 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007332 " unmark markedfile list
7333" call s:NetrwUnmarkList(curbufnr,curdir)
7334 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007335" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007336 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007337 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007338 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007339
Bram Moolenaar446cb832008-06-24 21:56:24 +00007340" call Dret("s:NetrwMarkFileEdit")
7341endfun
7342
7343" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007344" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007345fun! s:NetrwMarkFileQFEL(islocal,qfel)
7346" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7347 call s:NetrwUnmarkAll()
7348 let curbufnr= bufnr("%")
7349
7350 if !empty(a:qfel)
7351 for entry in a:qfel
7352 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007353" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007354 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007355" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007356 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7357 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7358 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7359 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007360" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007361 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7362 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007363" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007364 endif
7365 endfor
7366 echo "(use me to edit marked files)"
7367 else
7368 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7369 endif
7370
7371" call Dret("s:NetrwMarkFileQFEL")
7372endfun
7373
7374" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007375" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7376" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7377" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7378fun! s:NetrwMarkFileExe(islocal,enbloc)
7379" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007380 let svpos = winsaveview()
7381" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007382 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007383 let curbufnr = bufnr("%")
7384
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007385 if a:enbloc == 0
7386 " individually apply command to files, one at a time
7387 " sanity check
7388 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7389 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7390" call Dret("s:NetrwMarkFileExe")
7391 return
7392 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007393" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007394
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007395 if exists("s:netrwmarkfilelist_{curbufnr}")
7396 " get the command
7397 call inputsave()
7398 let cmd= input("Enter command: ","","file")
7399 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007400" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007401 if cmd == ""
7402" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7403 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007404 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007405
7406 " apply command to marked files, individually. Substitute: filename -> %
7407 " If no %, then append a space and the filename to the command
7408 for fname in s:netrwmarkfilelist_{curbufnr}
7409 if a:islocal
7410 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007411 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007412 endif
7413 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007414 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007415 endif
7416 if cmd =~ '%'
7417 let xcmd= substitute(cmd,'%',fname,'g')
7418 else
7419 let xcmd= cmd.' '.fname
7420 endif
7421 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007422" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007423 let ret= system(xcmd)
7424 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007425" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007426 let ret= s:RemoteSystem(xcmd)
7427 endif
7428 if v:shell_error < 0
7429 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7430 break
7431 else
yasudac75dad02024-08-22 21:06:32 +02007432 if ret !=# ''
7433 echo "\n"
7434 " skip trailing new line
7435 echo ret[0:-2]
7436 else
7437 echo ret
7438 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007439 endif
7440 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007441
7442 " unmark marked file list
7443 call s:NetrwUnmarkList(curbufnr,curdir)
7444
7445 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007446 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007447" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7448 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007449 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007450 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007451 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007452
7453 else " apply command to global list of files, en bloc
7454
7455 call inputsave()
7456 let cmd= input("Enter command: ","","file")
7457 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007458" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007459 if cmd == ""
7460" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7461 return
7462 endif
7463 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007464 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007465 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007466 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007467 endif
7468 if a:islocal
7469 call system(cmd)
7470 if v:shell_error < 0
7471 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7472 endif
7473 else
7474 let ret= s:RemoteSystem(cmd)
7475 endif
7476 call s:NetrwUnmarkAll()
7477
7478 " refresh the listing
7479 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007480" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7481 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007482
7483 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007484
Bram Moolenaar446cb832008-06-24 21:56:24 +00007485" call Dret("s:NetrwMarkFileExe")
7486endfun
7487
7488" ---------------------------------------------------------------------
7489" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7490" as the marked file(s) (toggles suffix presence)
7491" Uses the local marked file list.
7492fun! s:NetrwMarkHideSfx(islocal)
7493" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007494 let svpos = winsaveview()
7495" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007496 let curbufnr = bufnr("%")
7497
7498 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7499 if exists("s:netrwmarkfilelist_{curbufnr}")
7500
7501 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007502" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007503 " construct suffix pattern
7504 if fname =~ '\.'
7505 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7506 else
7507 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7508 endif
7509 " determine if its in the hiding list or not
7510 let inhidelist= 0
7511 if g:netrw_list_hide != ""
7512 let itemnum = 0
7513 let hidelist= split(g:netrw_list_hide,',')
7514 for hidepat in hidelist
7515 if sfxpat == hidepat
7516 let inhidelist= 1
7517 break
7518 endif
7519 let itemnum= itemnum + 1
7520 endfor
7521 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007522" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007523 if inhidelist
7524 " remove sfxpat from list
7525 call remove(hidelist,itemnum)
7526 let g:netrw_list_hide= join(hidelist,",")
7527 elseif g:netrw_list_hide != ""
7528 " append sfxpat to non-empty list
7529 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7530 else
7531 " set hiding list to sfxpat
7532 let g:netrw_list_hide= sfxpat
7533 endif
7534 endfor
7535
7536 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007537 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007538" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7539 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007540 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007541 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007542 endif
7543
7544" call Dret("s:NetrwMarkHideSfx")
7545endfun
7546
7547" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007548" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007549" Uses the local marked-file list.
7550fun! s:NetrwMarkFileVimCmd(islocal)
7551" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007552 let svpos = winsaveview()
7553" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007554 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007555 let curbufnr = bufnr("%")
7556
Bram Moolenaarff034192013-04-24 18:51:19 +02007557 " sanity check
7558 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007559 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007560" call Dret("s:NetrwMarkFileVimCmd")
7561 return
7562 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007563" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007564
Bram Moolenaar15146672011-10-20 22:22:38 +02007565 if exists("s:netrwmarkfilelist_{curbufnr}")
7566 " get the command
7567 call inputsave()
7568 let cmd= input("Enter vim command: ","","file")
7569 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007570" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007571 if cmd == ""
7572" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7573 return
7574 endif
7575
7576 " apply command to marked files. Substitute: filename -> %
7577 " If no %, then append a space and the filename to the command
7578 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007579" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007580 if a:islocal
7581 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007582 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007583" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007584 exe cmd
7585 exe "sil! keepalt wq!"
7586 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007587" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007588 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007589 endif
7590 endfor
7591
7592 " unmark marked file list
7593 call s:NetrwUnmarkList(curbufnr,curdir)
7594
7595 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007596 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007597" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7598 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007599 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007600 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007601 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007602
Bram Moolenaar15146672011-10-20 22:22:38 +02007603" call Dret("s:NetrwMarkFileVimCmd")
7604endfun
7605
7606" ---------------------------------------------------------------------
7607" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7608" as the marked file(s) (toggles suffix presence)
7609" Uses the local marked file list.
7610fun! s:NetrwMarkHideSfx(islocal)
7611" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007612 let svpos = winsaveview()
7613" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007614 let curbufnr = bufnr("%")
7615
7616 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7617 if exists("s:netrwmarkfilelist_{curbufnr}")
7618
7619 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007620" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007621 " construct suffix pattern
7622 if fname =~ '\.'
7623 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7624 else
7625 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7626 endif
7627 " determine if its in the hiding list or not
7628 let inhidelist= 0
7629 if g:netrw_list_hide != ""
7630 let itemnum = 0
7631 let hidelist= split(g:netrw_list_hide,',')
7632 for hidepat in hidelist
7633 if sfxpat == hidepat
7634 let inhidelist= 1
7635 break
7636 endif
7637 let itemnum= itemnum + 1
7638 endfor
7639 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007640" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007641 if inhidelist
7642 " remove sfxpat from list
7643 call remove(hidelist,itemnum)
7644 let g:netrw_list_hide= join(hidelist,",")
7645 elseif g:netrw_list_hide != ""
7646 " append sfxpat to non-empty list
7647 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7648 else
7649 " set hiding list to sfxpat
7650 let g:netrw_list_hide= sfxpat
7651 endif
7652 endfor
7653
7654 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007655 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007656" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7657 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007658 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007659 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007660 endif
7661
7662" call Dret("s:NetrwMarkHideSfx")
7663endfun
7664
7665" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007666" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7667" Uses the global markfilelist
7668fun! s:NetrwMarkFileGrep(islocal)
7669" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007670 let svpos = winsaveview()
7671" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007672 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007673 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007674
7675 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007676" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007677 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007678" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007679 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007680 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007681" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007682 let netrwmarkfilelist= "*"
7683 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007684
Bram Moolenaarff034192013-04-24 18:51:19 +02007685 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007686" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007687 call inputsave()
7688 let pat= input("Enter pattern: ","")
7689 call inputrestore()
7690 let patbang = ""
7691 if pat =~ '^!'
7692 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007693 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007694 endif
7695 if pat =~ '^\i'
7696 let pat = escape(pat,'/')
7697 let pat = '/'.pat.'/'
7698 else
7699 let nonisi = pat[0]
7700 endif
7701
7702 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007703" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007704 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007705 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007706 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007707 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007708" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7709 return
7710 endtry
7711 echo "(use :cn, :cp to navigate, :Rex to return)"
7712
7713 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007714" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7715 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007716
7717 if exists("nonisi")
7718 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007719" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007720 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007721 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007722 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007723 endif
7724
7725" call Dret("s:NetrwMarkFileGrep")
7726endfun
7727
7728" ---------------------------------------------------------------------
7729" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7730" uses the global marked file list
7731" s:netrwmfloc= 0: target directory is remote
7732" = 1: target directory is local
7733fun! s:NetrwMarkFileMove(islocal)
7734" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007735 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007736 let curbufnr = bufnr("%")
7737
7738 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007739 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007740 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007741" call Dret("s:NetrwMarkFileMove")
7742 return
7743 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007744" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007745
Bram Moolenaar446cb832008-06-24 21:56:24 +00007746 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007747 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007748" call Dret("s:NetrwMarkFileCopy 0")
7749 return 0
7750 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007751" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007752
7753 if a:islocal && s:netrwmftgt_islocal
7754 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007755" call Decho("move from local to local",'~'.expand("<slnum>"))
7756" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007757 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007758 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7759" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7760 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007761 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007762 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007763" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007764 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007765 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007766" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007767 if g:netrw_localmovecmd =~ '\s'
7768 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7769 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7770 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007771" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007772 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007773 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007774" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007775 endif
7776 else
7777 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007778" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007779 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007780 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007781 if g:netrw_keepdir
7782 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7783 let fname= b:netrw_curdir."/".fname
7784 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007785 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007786 let fname= substitute(fname,'/','\\','g')
7787 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007788" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007789 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007790 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007791 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007792 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 +01007793 else
7794 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7795 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007796 break
7797 endif
7798 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007799
7800 elseif a:islocal && !s:netrwmftgt_islocal
7801 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007802" call Decho("move from local to remote",'~'.expand("<slnum>"))
7803" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007804 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007805 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007806" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007807 for fname in mflist
7808 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7809 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7810 endfor
7811 unlet mflist
7812
7813 elseif !a:islocal && s:netrwmftgt_islocal
7814 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007815" call Decho("move from remote to local",'~'.expand("<slnum>"))
7816" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007817 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007818 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007819" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007820 for fname in mflist
7821 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7822 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7823 endfor
7824 unlet mflist
7825
7826 elseif !a:islocal && !s:netrwmftgt_islocal
7827 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007828" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7829" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007830 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007831 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007832" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007833 for fname in mflist
7834 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7835 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7836 endfor
7837 unlet mflist
7838 endif
7839
7840 " -------
7841 " cleanup
7842 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007843" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007844
7845 " remove markings from local buffer
7846 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7847
7848 " refresh buffers
7849 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007850" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007851 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007852 endif
7853 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007854" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007855 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007856 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007857 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007858" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007859 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007860 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007861
Bram Moolenaar446cb832008-06-24 21:56:24 +00007862" call Dret("s:NetrwMarkFileMove")
7863endfun
7864
7865" ---------------------------------------------------------------------
7866" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7867" using the hardcopy command. Local marked-file list only.
7868fun! s:NetrwMarkFilePrint(islocal)
7869" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7870 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007871
7872 " sanity check
7873 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007874 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007875" call Dret("s:NetrwMarkFilePrint")
7876 return
7877 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007878" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7879 let curdir= s:NetrwGetCurdir(a:islocal)
7880
Bram Moolenaar446cb832008-06-24 21:56:24 +00007881 if exists("s:netrwmarkfilelist_{curbufnr}")
7882 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007883 call s:NetrwUnmarkList(curbufnr,curdir)
7884 for fname in netrwmarkfilelist
7885 if a:islocal
7886 if g:netrw_keepdir
7887 let fname= s:ComposePath(curdir,fname)
7888 endif
7889 else
7890 let fname= curdir.fname
7891 endif
7892 1split
7893 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007894" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007895 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007896" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007897 hardcopy
7898 q
7899 endfor
7900 2match none
7901 endif
7902" call Dret("s:NetrwMarkFilePrint")
7903endfun
7904
7905" ---------------------------------------------------------------------
7906" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7907" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007908" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007909fun! s:NetrwMarkFileRegexp(islocal)
7910" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7911
7912 " get the regular expression
7913 call inputsave()
7914 let regexp= input("Enter regexp: ","","file")
7915 call inputrestore()
7916
7917 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007918 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007919" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007920 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007921" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007922 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007923 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007924 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007925 else
7926 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007927 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007928 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007929" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007930
7931 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007932 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007933 if fname =~ '^'.fnameescape(curdir)
7934" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7935 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7936 else
7937" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7938 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7939 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007940 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007941
7942 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007943" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007944
7945 " convert displayed listing into a filelist
7946 let eikeep = &ei
7947 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007948 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007949 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007950" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007951 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007952 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02007953 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007954 sil NetrwKeepj norm! "ap
7955 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007956 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007957 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007958 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007959 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007960 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007961 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007962 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007963 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007964 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007965 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007966 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7967 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007968 call histdel("/",-1)
7969 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007970 endif
7971 " convert regexp into the more usual glob-style format
7972 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007973" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007974 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01007975 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007976 let filelist= getline(1,line("$"))
7977 q!
7978 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007979 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007980 endfor
7981 unlet filelist
7982 let @a = areg
7983 let &ei = eikeep
7984 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007985 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007986
7987" call Dret("s:NetrwMarkFileRegexp")
7988endfun
7989
7990" ---------------------------------------------------------------------
7991" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
7992" Uses the local marked file list.
7993fun! s:NetrwMarkFileSource(islocal)
7994" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
7995 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007996
7997 " sanity check
7998 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007999 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008000" call Dret("s:NetrwMarkFileSource")
8001 return
8002 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008003" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8004 let curdir= s:NetrwGetCurdir(a:islocal)
8005
Bram Moolenaar446cb832008-06-24 21:56:24 +00008006 if exists("s:netrwmarkfilelist_{curbufnr}")
8007 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008008 call s:NetrwUnmarkList(curbufnr,curdir)
8009 for fname in netrwmarkfilelist
8010 if a:islocal
8011 if g:netrw_keepdir
8012 let fname= s:ComposePath(curdir,fname)
8013 endif
8014 else
8015 let fname= curdir.fname
8016 endif
8017 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008018" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008019 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008020 endfor
8021 2match none
8022 endif
8023" call Dret("s:NetrwMarkFileSource")
8024endfun
8025
8026" ---------------------------------------------------------------------
8027" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8028" Uses the global markfilelist
8029fun! s:NetrwMarkFileTag(islocal)
8030" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008031 let svpos = winsaveview()
8032" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008033 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008034 let curbufnr = bufnr("%")
8035
Bram Moolenaarff034192013-04-24 18:51:19 +02008036 " sanity check
8037 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008038 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008039" call Dret("s:NetrwMarkFileTag")
8040 return
8041 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008042" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008043
Bram Moolenaar446cb832008-06-24 21:56:24 +00008044 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008045" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8046 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008047 call s:NetrwUnmarkAll()
8048
8049 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008050
8051" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8052 call system(g:netrw_ctags." ".netrwmarkfilelist)
8053 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008054 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8055 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008056
Bram Moolenaar446cb832008-06-24 21:56:24 +00008057 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008058 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008059 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008060 let curdir= b:netrw_curdir
8061 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008062 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008063 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008064" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008065 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008066 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008067 wq!
8068 endif
8069 2match none
8070 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008071" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8072 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008073 endif
8074
8075" call Dret("s:NetrwMarkFileTag")
8076endfun
8077
8078" ---------------------------------------------------------------------
8079" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008080" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008081" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008082" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008083" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008084fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008085" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8086 let svpos = winsaveview()
8087" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008088 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008089 let hadtgt = exists("s:netrwmftgt")
8090 if !exists("w:netrw_bannercnt")
8091 let w:netrw_bannercnt= b:netrw_bannercnt
8092 endif
8093
8094 " set up target
8095 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008096" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008097 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8098 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008099" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008100 unlet s:netrwmftgt s:netrwmftgt_islocal
8101 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008102 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008103 endif
8104 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008105" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8106 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008107" call Dret("s:NetrwMarkFileTgt : removed target")
8108 return
8109 else
8110 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008111" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008112 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008113
8114 else
8115 " get word under cursor.
8116 " * If directory, use it for the target.
8117 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008118" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008119 let curword= s:NetrwGetWord()
8120 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008121 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008122 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008123" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008124 elseif !a:islocal && tgtdir =~ '/$'
8125 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008126" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008127 else
8128 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008129" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008130 endif
8131 endif
8132 if a:islocal
8133 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8134 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008135" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008136 endif
8137 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008138 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008139 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8140 endif
8141 let s:netrwmftgt_islocal= a:islocal
8142
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008143 " need to do refresh so that the banner will be updated
8144 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008145 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008146" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008147 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008148 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008149" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008150 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008151 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8152 else
8153 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8154 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008155" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8156 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008157 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008158 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008159 endif
8160
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008161" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8162" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008163" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8164endfun
8165
8166" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008167" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8168fun! s:NetrwGetCurdir(islocal)
8169" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8170
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008171 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008172 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8173" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8174 elseif !exists("b:netrw_curdir")
8175 let b:netrw_curdir= getcwd()
8176" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8177 endif
8178
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008179" 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 +01008180 if b:netrw_curdir !~ '\<\a\{3,}://'
8181 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008182" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008183 if g:netrw_keepdir == 0
8184 call s:NetrwLcd(curdir)
8185 endif
8186 endif
8187
8188" call Dret("s:NetrwGetCurdir <".curdir.">")
8189 return b:netrw_curdir
8190endfun
8191
8192" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008193" s:NetrwOpenFile: query user for a filename and open it {{{2
8194fun! s:NetrwOpenFile(islocal)
8195" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008196 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008197 call inputsave()
8198 let fname= input("Enter filename: ")
8199 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008200" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8201
8202 " determine if Lexplore is in use
8203 if exists("t:netrw_lexbufnr")
8204 " check if t:netrw_lexbufnr refers to a netrw window
8205" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8206 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8207 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8208" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8209 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8210 exe "NetrwKeepj e ".fnameescape(fname)
8211 let @@= ykeep
8212" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8213 endif
8214 endif
8215
8216 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008217 if fname !~ '[/\\]'
8218 if exists("b:netrw_curdir")
8219 if exists("g:netrw_quiet")
8220 let netrw_quiet_keep = g:netrw_quiet
8221 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008222 let g:netrw_quiet = 1
8223 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008224 let s:rexposn_{bufnr("%")}= winsaveview()
8225" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008226 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008227 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008228 else
8229 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8230 endif
8231 if exists("netrw_quiet_keep")
8232 let g:netrw_quiet= netrw_quiet_keep
8233 else
8234 unlet g:netrw_quiet
8235 endif
8236 endif
8237 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008238 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008239 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008240 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008241" call Dret("s:NetrwOpenFile")
8242endfun
8243
8244" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008245" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8246" For the mapping to this function be made via
8247" netrwPlugin, you'll need to have had
8248" g:netrw_usetab set to non-zero.
8249fun! netrw#Shrink()
8250" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8251 let curwin = winnr()
8252 let wiwkeep = &wiw
8253 set wiw=1
8254
8255 if &ft == "netrw"
8256 if winwidth(0) > g:netrw_wiw
8257 let t:netrw_winwidth= winwidth(0)
8258 exe "vert resize ".g:netrw_wiw
8259 wincmd l
8260 if winnr() == curwin
8261 wincmd h
8262 endif
8263" call Decho("vert resize 0",'~'.expand("<slnum>"))
8264 else
8265 exe "vert resize ".t:netrw_winwidth
8266" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8267 endif
8268
8269 elseif exists("t:netrw_lexbufnr")
8270 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8271 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8272 let t:netrw_winwidth= winwidth(0)
8273 exe "vert resize ".g:netrw_wiw
8274 wincmd l
8275 if winnr() == curwin
8276 wincmd h
8277 endif
8278" call Decho("vert resize 0",'~'.expand("<slnum>"))
8279 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8280 exe "vert resize ".t:netrw_winwidth
8281" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01008282 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008283 call netrw#Lexplore(0,0)
8284 endif
8285
8286 else
8287 call netrw#Lexplore(0,0)
8288 endif
8289 let wiw= wiwkeep
8290
8291" call Dret("netrw#Shrink")
8292endfun
8293
8294" ---------------------------------------------------------------------
8295" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8296fun! s:NetSortSequence(islocal)
8297" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8298
8299 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008300 let svpos= winsaveview()
8301" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008302 call inputsave()
8303 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8304 call inputrestore()
8305
8306 " refresh the listing
8307 let g:netrw_sort_sequence= newsortseq
8308 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008309" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8310 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008311 let @@= ykeep
8312
8313" call Dret("NetSortSequence")
8314endfun
8315
8316" ---------------------------------------------------------------------
8317" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8318" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008319" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008320fun! s:NetrwUnmarkList(curbufnr,curdir)
8321" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8322
8323 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008324 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008325 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8326 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8327 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8328 call remove(s:netrwmarkfilelist,idx) " remove from global list
8329 endfor
8330 if s:netrwmarkfilelist == []
8331 unlet s:netrwmarkfilelist
8332 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008333
Bram Moolenaar446cb832008-06-24 21:56:24 +00008334 " getting rid of the local marked-file lists is easy
8335 unlet s:netrwmarkfilelist_{a:curbufnr}
8336 endif
8337 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8338 unlet s:netrwmarkfilemtch_{a:curbufnr}
8339 endif
8340 2match none
8341" call Dret("s:NetrwUnmarkList")
8342endfun
8343
8344" ---------------------------------------------------------------------
8345" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8346fun! s:NetrwUnmarkAll()
8347" call Dfunc("s:NetrwUnmarkAll()")
8348 if exists("s:netrwmarkfilelist")
8349 unlet s:netrwmarkfilelist
8350 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008351 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008352 2match none
8353" call Dret("s:NetrwUnmarkAll")
8354endfun
8355
8356" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008357" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008358fun! s:NetrwUnmarkAll2()
8359" call Dfunc("s:NetrwUnmarkAll2()")
8360 redir => netrwmarkfilelist_let
8361 let
8362 redir END
8363 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008364 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008365 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8366 for flist in netrwmarkfilelist_list
8367 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8368 unlet s:netrwmarkfilelist_{curbufnr}
8369 unlet s:netrwmarkfilemtch_{curbufnr}
8370 endfor
8371" call Dret("s:NetrwUnmarkAll2")
8372endfun
8373
8374" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008375" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8376"
8377" Marked files are in two types of lists:
8378" s:netrwmarkfilelist -- holds complete paths to all marked files
8379" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8380"
8381" Marked files suitable for use with 2match are in:
8382" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008383fun! s:NetrwUnMarkFile(islocal)
8384" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008385 let svpos = winsaveview()
8386" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008387 let curbufnr = bufnr("%")
8388
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008389 " unmark marked file list
8390 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8391 if exists("s:netrwmarkfilelist")
8392" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008393 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008394 endif
8395
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008396 let ibuf= 1
8397 while ibuf < bufnr("$")
8398 if exists("s:netrwmarkfilelist_".ibuf)
8399 unlet s:netrwmarkfilelist_{ibuf}
8400 unlet s:netrwmarkfilemtch_{ibuf}
8401 endif
8402 let ibuf = ibuf + 1
8403 endwhile
8404 2match none
8405
Bram Moolenaar446cb832008-06-24 21:56:24 +00008406" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008407"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8408call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008409" call Dret("s:NetrwUnMarkFile")
8410endfun
8411
8412" ---------------------------------------------------------------------
8413" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8414fun! s:NetrwMenu(domenu)
8415
8416 if !exists("g:NetrwMenuPriority")
8417 let g:NetrwMenuPriority= 80
8418 endif
8419
Bram Moolenaaradc21822011-04-01 18:03:16 +02008420 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008421" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8422
8423 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008424" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008425 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008426 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8427 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8428 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8429 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8430 if g:netrw_dirhistmax > 0
8431 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8432 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8433 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8434 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8435 else
8436 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8437 endif
8438 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8439 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8440 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8441 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8442 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8443 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8444 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8445 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8446 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8447 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8448 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8449 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8450 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8451 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8452 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 +01008453 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 +02008454 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8455 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8456 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8457 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8458 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8459 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8460 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8461 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8462 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8463 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8464 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8465 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8466 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8467 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8468 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8469 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8470 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8471 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8472 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8473 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8474 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8475 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8476 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8477 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8478 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8479 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8480 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8481 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8482 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8483 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>'
8484 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>'
8485 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>'
8486 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8487 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>'
8488 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>'
8489 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 +01008490 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 +02008491 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8492 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008493 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008494 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8495 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008496
8497 elseif !a:domenu
8498 let s:netrwcnt = 0
8499 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008500 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008501 exe curwin."wincmd w"
8502
8503 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008504" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008505 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008506" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008507 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008508 endif
8509 endif
8510" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008511 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008512 endif
8513
8514endfun
8515
8516" ---------------------------------------------------------------------
8517" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8518" Used by the O maps (as <SID>NetrwObtain())
8519fun! s:NetrwObtain(islocal)
8520" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8521
Bram Moolenaar97d62492012-11-15 21:28:22 +01008522 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008523 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008524 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008525 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008526 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8527 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008528 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008529 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008530 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008531
8532" call Dret("NetrwObtain")
8533endfun
8534
8535" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008536" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8537" If there's only one window, then the window will first be split.
8538" Returns:
8539" choice = 0 : didn't have to choose
8540" choice = 1 : saved modified file in window first
8541" choice = 2 : didn't save modified file, opened window
8542" choice = 3 : cancel open
8543fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008544" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008545
Bram Moolenaar97d62492012-11-15 21:28:22 +01008546 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008547 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008548 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008549" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008550
8551 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008552 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008553 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008554" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8555" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8556 let curword = s:NetrwGetWord()
8557 let choice = 0
8558 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8559" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008560 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008561" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008562 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008563" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008564" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008565" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008566
Bram Moolenaar8d043172014-01-23 14:24:41 +01008567 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008568 if lastwinnr == 1
8569 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008570" call Decho("only one window, so open a new one (g:netrw_alto=".g:netrw_alto.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008571 " g:netrw_preview=0: preview window shown in a horizontally split window
8572 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008573 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008574 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008575 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008576" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008577 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008578 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008579 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008580 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008581" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008582 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008583 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008584 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008585" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008586
8587 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008588" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008589 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008590" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008591 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008592" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008593 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008594" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008595 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008596" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008597" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008598" call Decho("COMBAK#12: mod=".&mod)
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01008599
Bram Moolenaar71badf92023-04-22 22:40:14 +01008600 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8601 " whoops -- user trying to open file in the Lexplore window.
8602 " Use Lexplore's opening-file window instead.
8603" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8604" exe g:netrw_chgwin."wincmd w"
8605 wincmd p
8606 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8607 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008608
8609 " prevwinnr: the window number of the "prev" window
8610 " prevbufnr: the buffer number of the buffer in the "prev" window
8611 " bnrcnt : the qty of windows open on the "prev" buffer
8612 let prevwinnr = winnr()
8613 let prevbufnr = bufnr("%")
8614 let prevbufname = bufname("%")
8615 let prevmod = &mod
8616 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008617" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008618 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008619" call Decho("after wincmd p: win#".winnr()." win($)#".winnr("$")." origwin#".origwin." &mod=".&mod." bufname(%)<".bufname("%")."> prevbufnr=".prevbufnr,'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008620" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008621
8622 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008623 " and it doesn't appear in any other extant window, then ask the
8624 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008625 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008626" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008627 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008628" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008629 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008630" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008631
8632 if bnrcnt == 1 && &hidden == 0
8633 " only one copy of the modified buffer in a window, and
8634 " hidden not set, so overwriting will lose the modified file. Ask first...
8635 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008636" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008637 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008638" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008639
8640 if choice == 1
8641 " Yes -- write file & then browse
8642 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008643 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008644 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008645 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008646 exe origwin."wincmd w"
8647 let &ei = eikeep
8648 let @@ = ykeep
8649" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008650 return choice
8651 endif
8652
8653 elseif choice == 2
8654 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008655" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008656 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008657
8658 else
8659 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008660" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008661 exe origwin."wincmd w"
8662 let &ei= eikeep
8663 let @@ = ykeep
8664" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008665 return choice
8666 endif
8667 endif
8668 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008669 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008670 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008671" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008672
8673 " restore b:netrw_curdir (window split/enew may have lost it)
8674 let b:netrw_curdir= curdir
8675 if a:islocal < 2
8676 if a:islocal
8677 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8678 else
8679 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8680 endif
8681 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008682 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008683" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008684 return choice
8685endfun
8686
8687" ---------------------------------------------------------------------
8688" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8689" Always assumed to be local -> remote
8690" call s:NetrwUpload(filename, target)
8691" call s:NetrwUpload(filename, target, fromdirectory)
8692fun! s:NetrwUpload(fname,tgt,...)
8693" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8694
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008695 if a:tgt =~ '^\a\{3,}://'
8696 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008697 else
8698 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8699 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008700" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008701
8702 if a:0 > 0
8703 let fromdir= a:1
8704 else
8705 let fromdir= getcwd()
8706 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008707" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008708
8709 if type(a:fname) == 1
8710 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008711" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008712 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008713" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8714 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8715" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008716 if a:tgt =~ '/$'
8717 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008718" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008719 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008720 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008721" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008722 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008723" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008724 endif
8725 q!
8726
8727 elseif type(a:fname) == 3
8728 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008729" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008730 let curdir= getcwd()
8731 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008732 if s:NetrwLcd(fromdir)
8733" call Dret("s:NetrwUpload : lcd failure")
8734 return
8735 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008736 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008737 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008738 if exists("g:netrw_port") && g:netrw_port != ""
8739 let useport= " ".g:netrw_scpport." ".g:netrw_port
8740 else
8741 let useport= ""
8742 endif
8743 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8744 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008745 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 +02008746 if s:NetrwLcd(curdir)
8747" call Dret("s:NetrwUpload : lcd failure")
8748 return
8749 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008750
8751 elseif a:tgt =~ '^ftp:'
8752 call s:NetrwMethod(a:tgt)
8753
8754 if b:netrw_method == 2
8755 " handle uploading a list of files via ftp+.netrc
8756 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008757 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008758" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008759
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008760 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008761" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008762
8763 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008764 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008765" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008766 endif
8767
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008768 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008769" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008770
Bram Moolenaaradc21822011-04-01 18:03:16 +02008771 if tgtdir == ""
8772 let tgtdir= '/'
8773 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008774 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008775" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008776
8777 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008778 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8779" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008780 endfor
8781
8782 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008783 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 +00008784 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008785" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8786 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008787 endif
8788 " 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 +01008789 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008790 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008791 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8792 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8793 else
8794 bw!|q
8795 endif
8796
8797 elseif b:netrw_method == 3
8798 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8799 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008800 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008801 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008802 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008803
8804 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008805 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008806" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008807 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008808 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008809" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008810 endif
8811
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008812 if exists("g:netrw_uid") && g:netrw_uid != ""
8813 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008814 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008815" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008816 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008817 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008818 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008819" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008820 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008821 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008822" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008823 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008824 endif
8825
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008826 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008827" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008828
8829 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008830 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008831" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008832 endif
8833
8834 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008835 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008836" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008837 endif
8838
8839 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008840 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008841" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008842 endfor
8843
8844 " perform ftp:
8845 " -i : turns off interactive prompting from ftp
8846 " -n unix : DON'T use <.netrc>, even though it exists
8847 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008848 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008849 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008850 " 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 +01008851 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008852 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008853 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8854 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008855 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008856 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8857 let &debug = debugkeep
8858 let mod = 1
8859 else
8860 bw!|q
8861 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008862 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008863" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008864 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008865 endif
8866 else
8867 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8868 endif
8869 endif
8870
8871" call Dret("s:NetrwUpload")
8872endfun
8873
8874" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008875" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008876fun! s:NetrwPreview(path) range
8877" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008878" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8879" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008880 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008881 NetrwKeepj call s:NetrwOptionsSave("s:")
8882 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8883 NetrwKeepj call s:NetrwOptionsSafe(1)
8884 else
8885 NetrwKeepj call s:NetrwOptionsSafe(0)
8886 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008887 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008888" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008889 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008890" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8891 if g:netrw_preview
8892 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008893 let pvhkeep = &pvh
8894 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8895 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008896" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8897 else
8898 " horizontal split
8899 let pvhkeep = &pvh
8900 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8901 let &pvh = winheight(0) - winsz
8902" 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 +02008903 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008904 " g:netrw_preview g:netrw_alto
8905 " 1 : vert 1: top -- preview window is vertically split off and on the left
8906 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8907 " 0 : 1: top -- preview window is horizontally split off and on the top
8908 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8909 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008910 " 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 +02008911 " the BufEnter event set up in netrwPlugin.vim
8912" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8913 let eikeep = &ei
8914 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008915 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008916 let &ei= eikeep
8917" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008918 if exists("pvhkeep")
8919 let &pvh= pvhkeep
8920 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008921 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008922 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008923 endif
8924 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008925 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 +00008926 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008927 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008928 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008929" call Dret("NetrwPreview")
8930endfun
8931
8932" ---------------------------------------------------------------------
8933" s:NetrwRefresh: {{{2
8934fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008935" 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 +00008936 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008937 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008938" call Decho("setl ma noro",'~'.expand("<slnum>"))
8939" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008940 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008941 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8942 if !exists("w:netrw_treetop")
8943 if exists("b:netrw_curdir")
8944 let w:netrw_treetop= b:netrw_curdir
8945 else
8946 let w:netrw_treetop= getcwd()
8947 endif
8948 endif
8949 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
8950 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008951
8952 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008953 let screenposn = winsaveview()
8954" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008955
8956" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
8957" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
8958 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008959 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008960 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008961 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008962 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008963 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008964
8965 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008966" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
8967 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008968
8969 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02008970 if has("syntax") && exists("g:syntax_on") && g:syntax_on
8971 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8972" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
8973 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8974 else
8975" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
8976 2match none
8977 endif
8978 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008979
Bram Moolenaar97d62492012-11-15 21:28:22 +01008980" restore
8981 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008982" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008983endfun
8984
8985" ---------------------------------------------------------------------
8986" s:NetrwRefreshDir: refreshes a directory by name {{{2
8987" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008988" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008989fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008990" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008991 if g:netrw_fastbrowse == 0
8992 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008993" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008994 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008995" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008996
8997 if tgtwin > 0
8998 " tgtwin is being displayed, so refresh it
8999 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009000" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009001 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009002 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009003 exe curwin."wincmd w"
9004
9005 elseif bufnr(a:dirname) > 0
9006 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009007" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9008 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009009 endif
9010
9011 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009012" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009013 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009014 endif
9015" call Dret("s:NetrwRefreshDir")
9016endfun
9017
9018" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009019" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9020" window number to do its editing in.
9021" Supports [count]C where the count, if present, is used to specify
9022" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009023fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009024" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009025 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009026" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009027 if a:1 == "" " :NetrwC win#
9028 let g:netrw_chgwin= winnr()
9029 else " :NetrwC
9030 let g:netrw_chgwin= a:1
9031 endif
9032 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009033 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009034 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009035 let g:netrw_chgwin= winnr()
9036 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009037 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009038" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009039endfun
9040
9041" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009042" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9043" What this function does is to compute a priority for the patterns
9044" in the g:netrw_sort_sequence. It applies a substitute to any
9045" "files" that satisfy each pattern, putting the priority / in
9046" front. An "*" pattern handles the default priority.
9047fun! s:NetrwSetSort()
9048" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009049 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009050 if w:netrw_liststyle == s:LONGLIST
9051 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9052 else
9053 let seqlist = g:netrw_sort_sequence
9054 endif
9055 " sanity check -- insure that * appears somewhere
9056 if seqlist == ""
9057 let seqlist= '*'
9058 elseif seqlist !~ '\*'
9059 let seqlist= seqlist.',*'
9060 endif
9061 let priority = 1
9062 while seqlist != ""
9063 if seqlist =~ ','
9064 let seq = substitute(seqlist,',.*$','','e')
9065 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9066 else
9067 let seq = seqlist
9068 let seqlist = ""
9069 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009070 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009071 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009072 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009073 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009074 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009075 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009076 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009077" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009078
9079 " sanity check
9080 if w:netrw_bannercnt > line("$")
9081 " apparently no files were left after a Hiding pattern was used
9082" call Dret("SetSort : no files left after hiding")
9083 return
9084 endif
9085 if seq == '*'
9086 let starpriority= spriority
9087 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009088 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009089 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009090 " sometimes multiple sorting patterns will match the same file or directory.
9091 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009092 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9093 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009094 endif
9095 let priority = priority + 1
9096 endwhile
9097 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009098 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9099 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009100 endif
9101
9102 " Following line associated with priority -- items that satisfy a priority
9103 " pattern get prefixed by ###/ which permits easy sorting by priority.
9104 " Sometimes files can satisfy multiple priority patterns -- only the latest
9105 " priority pattern needs to be retained. So, at this point, these excess
9106 " priority prefixes need to be removed, but not directories that happen to
9107 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009108 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9109 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009110 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009111
9112" call Dret("SetSort")
9113endfun
9114
Bram Moolenaarff034192013-04-24 18:51:19 +02009115" ---------------------------------------------------------------------
9116" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9117" Implements [count]Tb (bookhist<b>)
9118" [count]Th (bookhist<h>)
9119" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009120fun! s:NetrwSetTgt(islocal,bookhist,choice)
9121" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009122
9123 if a:bookhist == 'b'
9124 " supports choosing a bookmark as a target using a qb-generated list
9125 let choice= a:choice - 1
9126 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009127 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009128 else
9129 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9130 endif
9131
9132 elseif a:bookhist == 'h'
9133 " supports choosing a history stack entry as a target using a qb-generated list
9134 let choice= (a:choice % g:netrw_dirhistmax) + 1
9135 if exists("g:netrw_dirhist_".choice)
9136 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009137 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009138 else
9139 echomsg "Sorry, history#".a:choice." not available!"
9140 endif
9141 endif
9142
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009143 " refresh the display
9144 if !exists("b:netrw_curdir")
9145 let b:netrw_curdir= getcwd()
9146 endif
9147 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9148
Bram Moolenaarff034192013-04-24 18:51:19 +02009149" call Dret("s:NetrwSetTgt")
9150endfun
9151
Bram Moolenaar446cb832008-06-24 21:56:24 +00009152" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009153" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009154fun! s:NetrwSortStyle(islocal)
9155" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009156 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009157 let svpos= winsaveview()
9158" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009159
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009160 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 +01009161 NetrwKeepj norm! 0
9162 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009163" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9164 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009165
9166" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9167endfun
9168
9169" ---------------------------------------------------------------------
9170" s:NetrwSplit: mode {{{2
9171" =0 : net and o
9172" =1 : net and t
9173" =2 : net and v
9174" =3 : local and o
9175" =4 : local and t
9176" =5 : local and v
9177fun! s:NetrwSplit(mode)
9178" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9179
Bram Moolenaar97d62492012-11-15 21:28:22 +01009180 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009181 call s:SaveWinVars()
9182
9183 if a:mode == 0
9184 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009185 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009186 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009187" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009188 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009189 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009190 NetrwKeepj call s:RestoreWinVars()
9191 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009192 unlet s:didsplit
9193
9194 elseif a:mode == 1
9195 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009196 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009197" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009198 tabnew
9199 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009200 NetrwKeepj call s:RestoreWinVars()
9201 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009202 unlet s:didsplit
9203
9204 elseif a:mode == 2
9205 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009206 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009207 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009208" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009209 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009210 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009211 NetrwKeepj call s:RestoreWinVars()
9212 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009213 unlet s:didsplit
9214
9215 elseif a:mode == 3
9216 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009217 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009218 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009219" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009220 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009221 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009222 NetrwKeepj call s:RestoreWinVars()
9223 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009224 unlet s:didsplit
9225
9226 elseif a:mode == 4
9227 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009228 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009229 let eikeep = &ei
9230 let netrw_winnr = winnr()
9231 let netrw_line = line(".")
9232 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009233 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009234 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009235 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009236 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9237 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009238 let &ei = eikeep
9239 let netrw_curdir = s:NetrwTreeDir(0)
9240" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009241 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009242 let b:netrw_curdir = netrw_curdir
9243 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009244 NetrwKeepj call s:RestoreWinVars()
9245 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009246 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009247 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009248 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9249 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009250 let &ei= eikeep
9251 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009252 unlet s:didsplit
9253
9254 elseif a:mode == 5
9255 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009256 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009257 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009258" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009259 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009260 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009261 NetrwKeepj call s:RestoreWinVars()
9262 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009263 unlet s:didsplit
9264
9265 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009266 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009267 endif
9268
Bram Moolenaar97d62492012-11-15 21:28:22 +01009269 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009270" call Dret("s:NetrwSplit")
9271endfun
9272
9273" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009274" s:NetrwTgtMenu: {{{2
9275fun! s:NetrwTgtMenu()
9276 if !exists("s:netrw_menucnt")
9277 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009278 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009279" call Dfunc("s:NetrwTgtMenu()")
9280
9281 " the following test assures that gvim is running, has menus available, and has menus enabled.
9282 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9283 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009284" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009285 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9286 endif
9287 if !exists("s:netrw_initbookhist")
9288 call s:NetrwBookHistRead()
9289 endif
9290
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009291 " try to cull duplicate entries
9292 let tgtdict={}
9293
Bram Moolenaarff034192013-04-24 18:51:19 +02009294 " target bookmarked places
9295 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009296" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009297 let cnt= 1
9298 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009299 if has_key(tgtdict,bmd)
9300 let cnt= cnt + 1
9301 continue
9302 endif
9303 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009304 let ebmd= escape(bmd,g:netrw_menu_escape)
9305 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009306" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009307 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 +02009308 let cnt= cnt + 1
9309 endfor
9310 endif
9311
9312 " target directory browsing history
9313 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009314" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009315 let histcnt = 1
9316 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009317 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009318 if exists("g:netrw_dirhist_{histcnt}")
9319 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009320 if has_key(tgtdict,histentry)
9321 let histcnt = histcnt + 1
9322 continue
9323 endif
9324 let tgtdict[histentry] = histcnt
9325 let ehistentry = escape(histentry,g:netrw_menu_escape)
9326" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009327 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 +02009328 endif
9329 let histcnt = histcnt + 1
9330 endwhile
9331 endif
9332 endif
9333" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009334endfun
9335
9336" ---------------------------------------------------------------------
9337" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9338" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009339fun! s:NetrwTreeDir(islocal)
9340" call Dfunc("s:NetrwTreeDir(islocal=".a:islocal.") getline(".line(".").")"."<".getline('.')."> b:netrw_curdir<".b:netrw_curdir."> tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009341" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009342" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9343" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9344" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009345" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009346
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009347 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009348 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009349" call Decho('s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early')
Bram Moolenaar8d043172014-01-23 14:24:41 +01009350 let treedir= s:treedir
9351 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009352 unlet s:prevwinopen
9353" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009354 return treedir
9355 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009356 if exists("s:prevwinopen")
9357 unlet s:prevwinopen
9358 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009359" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009360
Bram Moolenaar8d043172014-01-23 14:24:41 +01009361 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9362 let b:netrw_curdir= getcwd()
9363 endif
9364 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009365" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009366" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009367
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009368 let s:treecurpos= winsaveview()
9369" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009370" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009371
9372 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009373" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9374" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009375" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009376
9377 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009378 let curline= substitute(getline('.'),"\t -->.*$",'','')
9379 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009380" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009381 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009382" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9383 elseif curline =~ '@$'
9384" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009385 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009386" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009387 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009388" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009389 let treedir= ""
9390 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009391" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009392
9393 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009394" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9395" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009396" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009397 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009398" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009399 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009400" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9401 sil! NetrwKeepj %d _
9402" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009403 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009404" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009405" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009406 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009407" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009408
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009409" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009410" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009411" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009412
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009413 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9414" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9415" let newdir = w:netrw_treetop.'/'.potentialdir
9416" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9417" let treedir = s:NetrwTreePath(newdir)
9418" let w:netrw_treetop = newdir
9419" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9420" else
9421" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009422 if a:islocal && curline =~ '@$'
9423 if isdirectory(s:NetrwFile(potentialdir))
9424 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9425 let w:netrw_treetop = treedir
9426 endif
9427 else
9428 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9429 let treedir = s:NetrwTreePath(w:netrw_treetop)
9430 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009431 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009432" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009433
9434 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009435 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009436" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009437" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009438
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009439" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009440 return treedir
9441endfun
9442
9443" ---------------------------------------------------------------------
9444" s:NetrwTreeDisplay: recursive tree display {{{2
9445fun! s:NetrwTreeDisplay(dir,depth)
9446" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9447
9448 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009449 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009450
9451 " install ../ and shortdir
9452 if a:depth == ""
9453 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009454" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009455 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009456 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009457 if a:dir == w:netrw_treetop
9458 let shortdir= a:dir
9459 else
9460 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9461 endif
9462 call setline(line("$")+1,a:depth.shortdir)
9463 else
9464 let shortdir= substitute(a:dir,'^.*/','','e')
9465 call setline(line("$")+1,a:depth.shortdir.'/')
9466 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009467" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009468 " append a / to dir if its missing one
9469 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009470
9471 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009472 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009473" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009474
Bram Moolenaar85850f32019-07-19 22:05:51 +02009475 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9476 if g:netrw_hide == 1
9477 " hide given patterns
9478 let listhide= split(g:netrw_list_hide,',')
9479" call Decho("listhide=".string(listhide))
9480 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009481 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009482 endfor
9483
9484 elseif g:netrw_hide == 2
9485 " show given patterns (only)
9486 let listhide= split(g:netrw_list_hide,',')
9487" call Decho("listhide=".string(listhide))
9488 let entries=[]
9489 for entry in w:netrw_treedict[dir]
9490 for pat in listhide
9491 if entry =~ pat
9492 call add(entries,entry)
9493 break
9494 endif
9495 endfor
9496 endfor
9497 let w:netrw_treedict[dir]= entries
9498 endif
9499 if depth != ""
9500 " always remove "." and ".." entries when there's depth
9501 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9502 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9503 endif
9504
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009505" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009506 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009507 if dir =~ '/$'
9508 let direntry= substitute(dir.entry,'[@/]$','','e')
9509 else
9510 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9511 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009512" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009513 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009514" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009515 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009516 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009517" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9518 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9519 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9520" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009521 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009522 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009523" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009524 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009525 endif
9526 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009527" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009528
Bram Moolenaar446cb832008-06-24 21:56:24 +00009529" call Dret("NetrwTreeDisplay")
9530endfun
9531
9532" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009533" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9534fun! s:NetrwRefreshTreeDict(dir)
9535" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009536 if !exists("w:netrw_treedict")
9537" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9538 return
9539 endif
9540
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009541 for entry in w:netrw_treedict[a:dir]
9542 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9543" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9544
9545 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9546" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9547 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009548 let liststar = s:NetrwGlob(direntry,'*',1)
9549 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009550 let w:netrw_treedict[direntry] = liststar + listdotstar
9551" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9552
9553 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9554" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9555 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009556 let liststar = s:NetrwGlob(direntry.'/','*',1)
9557 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009558 let w:netrw_treedict[direntry]= liststar + listdotstar
9559" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9560
9561 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9562" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9563 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009564 let liststar = s:NetrwGlob(direntry.'/','*',1)
9565 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009566" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9567
9568 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009569" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009570 endif
9571 endfor
9572" call Dret("s:NetrwRefreshTreeDict")
9573endfun
9574
9575" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009576" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009577" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009578fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009579 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00009580
9581 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009582 if !exists("w:netrw_treetop")
9583 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009584 let s:netrw_treetop= w:netrw_treetop
Tom Benham4d618002024-10-31 10:47:23 +01009585 " use \V in case the directory contains specials chars like '$' or '~'
9586 elseif (w:netrw_treetop =~ ('^'.'\V'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop))
9587 \ || a:dirname !~ ('^'.'\V'.w:netrw_treetop)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009588 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009589 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009590 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009591 if exists("w:netrw_treetop")
9592 let s:netrw_treetop= w:netrw_treetop
9593 else
9594 let w:netrw_treetop= getcwd()
9595 let s:netrw_treetop= w:netrw_treetop
9596 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009597
Bram Moolenaar446cb832008-06-24 21:56:24 +00009598 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009599 " insure that we have a treedict, albeit empty
Bram Moolenaar446cb832008-06-24 21:56:24 +00009600 let w:netrw_treedict= {}
9601 endif
9602
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009603 " update the dictionary for the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009604 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009605 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009606 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009607
9608 " if past banner, record word
9609 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9610 let fname= expand("<cword>")
9611 else
9612 let fname= ""
9613 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009614
9615 " display from treetop on down
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009616 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009617
9618 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9619 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009620 1d
9621 endwhile
9622
Bram Moolenaar13600302014-05-22 18:26:40 +02009623 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009624
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009625 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009626 endif
9627endfun
9628
9629" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009630" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009631" Normally, treetop is w:netrw_treetop, but a
9632" user of the function ( netrw#SetTreetop() )
9633" wipes that out prior to calling this function
9634fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009635" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9636 if line(".") < w:netrw_bannercnt + 2
9637 let treedir= a:treetop
9638 if treedir !~ '/$'
9639 let treedir= treedir.'/'
9640 endif
9641" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9642 return treedir
9643 endif
9644
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009645 let svpos = winsaveview()
9646" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009647 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009648" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009649 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009650" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9651 let curline= getline('.')
9652" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9653 if curline =~ '/$'
9654" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9655 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9656" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9657 elseif curline =~ '@\s\+-->'
9658" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9659 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9660 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9661" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009662 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009663" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009664 let treedir= ""
9665 endif
9666 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009667" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9668" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009669 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9670 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9671 let treedir= dirname.treedir
9672 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009673" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009674 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009675" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009676 if a:treetop =~ '/$'
9677 let treedir= a:treetop.treedir
9678 else
9679 let treedir= a:treetop.'/'.treedir
9680 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009681" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009682 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009683" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009684" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9685 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009686" call Dret("s:NetrwTreePath <".treedir.">")
9687 return treedir
9688endfun
9689
9690" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009691" s:NetrwWideListing: {{{2
9692fun! s:NetrwWideListing()
9693
9694 if w:netrw_liststyle == s:WIDELIST
9695" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9696 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009697 " cpf: characters per filename
9698 " fpl: filenames per line
9699 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009700 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009701 let dict={}
9702 " save the unnamed register and register 0-9 and a
9703 let dict.a=[getreg('a'), getregtype('a')]
9704 for i in range(0, 9)
9705 let dict[i] = [getreg(i), getregtype(i)]
9706 endfor
9707 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009708" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009709 let b:netrw_cpf= 0
9710 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009711 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009712 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9713 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009714 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009715 " restore stored registers
9716 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009717" call Dret("NetrwWideListing")
9718 return
9719 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009720 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009721 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009722" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009723
9724 " determine qty files per line (fpl)
9725 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9726 if w:netrw_fpl <= 0
9727 let w:netrw_fpl= 1
9728 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009729" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009730
9731 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009732 " fpc: files per column of wide listing
9733 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009734 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009735 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9736 let newcolstart = w:netrw_bannercnt + fpc
9737 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009738" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009739 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009740" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009741 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009742 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009743 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009744 while line("$") >= newcolstart
9745 if newcolend > line("$") | let newcolend= line("$") | endif
9746 let newcolqty= newcolend - newcolstart
9747 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009748 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009749 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009750 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009751 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009752 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009753 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009754 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009755 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009756 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009757 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009758" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009759 if @* != keepregstar | sil! let @* = keepregstar | endif
9760 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009761 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009762 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9763 NetrwKeepj call histdel("/",-1)
9764 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9765 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009766" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009767 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009768 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009769" 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 +00009770" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009771 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009772 else
9773 if hasmapto("w","n")
9774 sil! nunmap <buffer> w
9775 endif
9776 if hasmapto("b","n")
9777 sil! nunmap <buffer> b
9778 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009779 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009780endfun
9781
9782" ---------------------------------------------------------------------
9783" s:PerformListing: {{{2
9784fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009785" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9786" 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 +02009787" 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>"))
9788 sil! NetrwKeepj %d _
9789" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009790
Bram Moolenaar15146672011-10-20 22:22:38 +02009791 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009792" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009793 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009794
Bram Moolenaar85850f32019-07-19 22:05:51 +02009795 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009796 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009797" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009798
9799" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009800" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009801" endif " Decho
9802
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009803" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009804 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9805 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009806" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9807 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009808 endif
9809
9810 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009811 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009812
9813 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009814 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009815" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009816 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009817 if exists("g:netrw_pchk")
9818 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9819 " failure detections.
9820 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009821 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009822 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9823 endif
9824 if exists("g:netrw_pchk")
9825 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9826 else
9827 let curdir= b:netrw_curdir
9828 endif
9829 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9830 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9831 else
9832 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009833 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009834 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009835 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009836 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009837" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009838 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009839 let w:netrw_bannercnt= 1
9840 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009841" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9842" 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 +00009843
Bram Moolenaar85850f32019-07-19 22:05:51 +02009844 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009845 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009846 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009847 let sortby= sortby." reversed"
9848 endif
9849
9850 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009851 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009852" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009853 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009854" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009855 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009856 NetrwKeepj put ='\" Sorted by '.sortby
9857 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009858 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9859 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009860" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009861 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009862 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009863 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9864 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009865 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009866" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009867" 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 +00009868 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009869
Bram Moolenaar85850f32019-07-19 22:05:51 +02009870 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009871 if g:netrw_banner
9872 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009873" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009874 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009875 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009876 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009877 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009878 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009879 endif
9880 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009881 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009882" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009883 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009884 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009885 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009886
9887 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009888 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009889" 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 +01009890 if g:netrw_list_hide != "" && g:netrw_hide
9891 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009892 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009893 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009894 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009895 endif
9896 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009897 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009898 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009899
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009900" 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 +01009901 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009902" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009903 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009904" 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 +01009905 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009906 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009907" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009908" 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 +00009909 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009910
9911 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009912 if g:netrw_banner
9913 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009914 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009915" 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 +01009916" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009917" 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 +01009918 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009919
Bram Moolenaar446cb832008-06-24 21:56:24 +00009920 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009921" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009922 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009923 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009924 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009925 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009926 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009927" 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 +01009928" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9929 return
9930 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009931 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009932
9933 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009934 if !exists("w:netrw_bannercnt")
9935 let w:netrw_bannercnt= 0
9936 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009937" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
9938" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
9939" 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 +01009940
Bram Moolenaar5c736222010-01-06 20:54:52 +01009941 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009942" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009943" 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 +00009944 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009945 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009946 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009947 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009948" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009949
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009950 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009951 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +02009952" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009953 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009954
Bram Moolenaar5c736222010-01-06 20:54:52 +01009955 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009956" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009957 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +02009958 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009959 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009960 else
9961 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009962 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009963 endif
9964 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009965
Bram Moolenaar446cb832008-06-24 21:56:24 +00009966 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009967" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009968 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
9969 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009970
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009971 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +02009972 " exten: sort by extension
9973 " The histdel(...,-1) calls remove the last search from the search history
9974" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009975 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
9976 NetrwKeepj call histdel("/",-1)
9977 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
9978 NetrwKeepj call histdel("/",-1)
9979 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
9980 NetrwKeepj call histdel("/",-1)
9981 if !g:netrw_banner || w:netrw_bannercnt < line("$")
9982" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009983 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009984 " normal direction sorting
9985 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
9986 else
9987 " reverse direction sorting
9988 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
9989 endif
9990 endif
9991 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
9992 NetrwKeepj call histdel("/",-1)
9993
Bram Moolenaar446cb832008-06-24 21:56:24 +00009994 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01009995 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009996" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009997 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009998" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009999 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010000 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010001" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010002 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010003 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010004" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010005 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10006 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010007 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010008 endif
10009
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010010 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010011" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010012 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010013 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010014 call histdel("/",-1)
10015 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010016 endif
10017 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010018" 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 +000010019
10020 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010021" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10022" 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 +010010023 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010024" 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 +010010025 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010026" 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 +000010027
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010028 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010029 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010030" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010031 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010032 endif
10033
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010034 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010035 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010036" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10037 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010038 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010039" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10040 else
10041" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10042" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10043" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10044" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010045 endif
10046
10047 " record previous current directory
10048 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010049" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010050
10051 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010052" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10053" 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 +010010054 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010055" 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 +020010056 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010057" 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 +000010058
10059 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010060" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010061 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010062" 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 +010010063 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010064" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010065 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10066 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010067" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010068" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010069
Bram Moolenaar8d043172014-01-23 14:24:41 +010010070 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010071" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10072" 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 +010010073" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10074 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010075 unlet s:treecurpos
10076 endif
10077
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010078" 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>"))
10079" 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 +000010080" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10081endfun
10082
10083" ---------------------------------------------------------------------
10084" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010085fun! s:SetupNetrwStatusLine(statline)
10086" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10087
10088 if !exists("s:netrw_setup_statline")
10089 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010090" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010091
10092 if !exists("s:netrw_users_stl")
10093 let s:netrw_users_stl= &stl
10094 endif
10095 if !exists("s:netrw_users_ls")
10096 let s:netrw_users_ls= &laststatus
10097 endif
10098
10099 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +020010100 let dict={}
10101 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +000010102 redir @a
10103 try
10104 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010105 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010106 if &bg == "dark"
10107 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10108 else
10109 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10110 endif
10111 endtry
10112 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +020010113 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010114 endif
10115
10116 " set up status line (may use User9 highlighting)
10117 " insure that windows have a statusline
10118 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010119 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010120 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010121" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010122 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010123
10124" call Dret("SetupNetrwStatusLine : stl=".&stl)
10125endfun
10126
Bram Moolenaar85850f32019-07-19 22:05:51 +020010127" =========================================
10128" Remote Directory Browsing Support: {{{1
10129" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010130
10131" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010132" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10133" This function assumes that a long listing will be received. Size, time,
10134" and reverse sorts will be requested of the server but not otherwise
10135" enforced here.
10136fun! s:NetrwRemoteFtpCmd(path,listcmd)
10137" 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 +010010138" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010139 " sanity check: {{{3
10140 if !exists("w:netrw_method")
10141 if exists("b:netrw_method")
10142 let w:netrw_method= b:netrw_method
10143 else
10144 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10145" call Dret("NetrwRemoteFtpCmd")
10146 return
10147 endif
10148 endif
10149
10150 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10151 let ffkeep= &ff
10152 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010153" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010154
10155 " clear off any older non-banner lines " {{{3
10156 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010157" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10158 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010159
10160 ".........................................
10161 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10162 " ftp + <.netrc>: Method #2
10163 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010164 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010165 endif
10166 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010167 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010168" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010169 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010170 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010171" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010172 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010173" 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>"))
10174 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 +010010175 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010176" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10177 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 +010010178 endif
10179
10180 ".........................................
10181 elseif w:netrw_method == 3 " {{{3
10182 " ftp + machine,id,passwd,filename: Method #3
10183 setl ff=unix
10184 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010185 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010186 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010187 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010188 endif
10189
10190 " handle userid and password
10191 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010192" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010193 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10194 call NetUserPass("ftp:".host)
10195 endif
10196 if exists("g:netrw_uid") && g:netrw_uid != ""
10197 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010198 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010199 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010200 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010201 endif
10202 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010203 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010204 endif
10205 endif
10206
10207 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010208 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010209 endif
10210 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010211 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010212" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010213 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010214 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010215
10216 " perform ftp:
10217 " -i : turns off interactive prompting from ftp
10218 " -n unix : DON'T use <.netrc>, even though it exists
10219 " -n win32: quit being obnoxious about password
10220 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010221" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010222 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010223" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010224" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10225" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010226 endif
10227
10228 ".........................................
10229 elseif w:netrw_method == 9 " {{{3
10230 " sftp username@machine: Method #9
10231 " s:netrw_sftp_cmd
10232 setl ff=unix
10233
10234 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010235 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010236" call Dret("NetrwRemoteFtpCmd")
10237 return
10238
10239 ".........................................
10240 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010241 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010242 endif
10243
10244 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010245 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010246 sil! NetrwKeepj %s/\r$//e
10247 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010248 endif
10249 if a:listcmd == "dir"
10250 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010251 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10252 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10253 NetrwKeepj call histdel("/",-1)
10254 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010255 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 +010010256 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10257 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010258 endif
10259 endif
10260
10261 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10262 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010263 exe 'NetrwKeepj '.w:netrw_bannercnt
10264 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010265 endif
10266 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010267 exe 'NetrwKeepj '.w:netrw_bannercnt
10268 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010269 endif
10270
10271 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010272 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010273" call Dret("NetrwRemoteFtpCmd")
10274endfun
10275
10276" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010277" s:NetrwRemoteListing: {{{2
10278fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010279" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010280
Bram Moolenaara6878372014-03-22 21:02:50 +010010281 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10282 let w:netrw_bannercnt= s:bannercnt
10283 endif
10284 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010285 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010286 endif
10287
Bram Moolenaar446cb832008-06-24 21:56:24 +000010288 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010289
Bram Moolenaar446cb832008-06-24 21:56:24 +000010290 " sanity check:
10291 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010292" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010293 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010294" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010295 if !exists("g:netrw_quiet")
10296 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10297 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010298 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010299" call Dret("s:NetrwRemoteListing -1")
10300 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010301 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010302
Bram Moolenaar8d043172014-01-23 14:24:41 +010010303 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010304" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010305 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010306 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010307 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 +000010308 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010309 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 +000010310 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010311 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010312
Bram Moolenaar85850f32019-07-19 22:05:51 +020010313 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010314" call Dret("s:NetrwRemoteListing -1")
10315 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010316 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010317" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010318
Bram Moolenaar446cb832008-06-24 21:56:24 +000010319 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010320" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010321 let w:netrw_method= b:netrw_method
10322 endif
10323
Bram Moolenaar13600302014-05-22 18:26:40 +020010324 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010325 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010326" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010327 let s:method = "ftp"
10328 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010329 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010330 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010331 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010332 let listcmd= g:netrw_ftp_sizelist_cmd
10333 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010334" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010335 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010336" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010337
Bram Moolenaara6878372014-03-22 21:02:50 +010010338 " report on missing file or directory messages
10339 if search('[Nn]o such file or directory\|Failed to change directory')
10340 let mesg= getline(".")
10341 if exists("w:netrw_bannercnt")
10342 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010343 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010344 setl noma
10345 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010346 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010347 call netrw#ErrorMsg(s:WARNING,mesg,96)
10348" call Dret("s:NetrwRemoteListing : -1")
10349 return -1
10350 endif
10351
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010352 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 +000010353 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010354" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010355 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010356
10357 " cleanup
10358 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010359 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10360 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010361 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010362 sil! NetrwKeepj %s/\r$//e
10363 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010364
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010365 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010366 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010367 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010368 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010369" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010370 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010371" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010372 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010373 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010374 exe "sil! NetrwKeepj ".line1
10375 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010376
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010377" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010378 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010379" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010380 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10381 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010382 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010383" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010384 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10385 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10386 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10387 NetrwKeepj call histdel("/",-1)
10388 NetrwKeepj call histdel("/",-1)
10389 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010390 endif
10391 endif
10392
Bram Moolenaar13600302014-05-22 18:26:40 +020010393 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010394 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010395" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010396 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010397" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010398 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010399" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10400 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010401 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010402 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10403 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10404 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10405 NetrwKeepj call histdel("/",-1)
10406 NetrwKeepj call histdel("/",-1)
10407 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010408 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010409 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10410 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010411 endif
10412 else
10413 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010414" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010415 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010416 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010417" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10418 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10419" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010420 endif
10421 endif
10422
10423 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010424 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010425" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010426 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10427 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010428 endif
10429 endif
10430
10431 if w:netrw_liststyle == s:LONGLIST
10432 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010433" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010434
10435 if s:method == "ftp"
10436 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010437 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010438 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010439 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010440 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010441 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010442 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010443 sil! NetrwKeepj 1
10444 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010445 let line2= line(".")
10446 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010447 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010448 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010449 endif
10450 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010451 exe "sil! NetrwKeepj ".line1
10452 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010453 endif
10454
10455 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010456" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010457 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 +000010458 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010459" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010460 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010461 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010462 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10463 NetrwKeepj call histdel("/",-1)
10464 NetrwKeepj call histdel("/",-1)
10465 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010466 endif
10467 endif
10468
10469" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010470" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010471" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010472
10473" call Dret("s:NetrwRemoteListing 0")
10474 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010475endfun
10476
Bram Moolenaar446cb832008-06-24 21:56:24 +000010477" ---------------------------------------------------------------------
10478" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10479fun! s:NetrwRemoteRm(usrhost,path) range
10480" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010481" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010482 let svpos= winsaveview()
10483" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010484
10485 let all= 0
10486 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10487 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010488" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010489 for fname in s:netrwmarkfilelist_{bufnr("%")}
10490 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010491 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010492 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010493 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010494 let all= 1
10495 endif
10496 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010497 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010498
10499 else
10500 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010501" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010502
10503 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010504 let keepsol = &l:sol
10505 setl nosol
10506 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010507
10508 " remove multiple files and directories
10509 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010510 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010511 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010512 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010513 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010514 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010515 let all= 1
10516 endif
10517 let ctr= ctr + 1
10518 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010519 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010520 endif
10521
10522 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010523" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010524 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010525" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10526 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010527
10528" call Dret("s:NetrwRemoteRm")
10529endfun
10530
10531" ---------------------------------------------------------------------
10532" s:NetrwRemoteRmFile: {{{2
10533fun! s:NetrwRemoteRmFile(path,rmfile,all)
10534" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10535
10536 let all= a:all
10537 let ok = ""
10538
10539 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10540 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010541" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010542 if !all
10543 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010544" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010545 call inputsave()
10546 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10547 call inputrestore()
10548 echohl NONE
10549 if ok == ""
10550 let ok="no"
10551 endif
10552 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010553 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010554 let all= 1
10555 endif
10556 endif
10557
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010558 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010559" 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 +000010560 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010561" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010562 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010563 if path =~ '^\a\{3,}://'
10564 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010565 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010566 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010567 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10568 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010569" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010570 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010571" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010572 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010573 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010574 let ok="q"
10575 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010576 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010577" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10578" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10579" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010580 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010581 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010582 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010583 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010584 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010585" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010586 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010587 if v:shell_error != 0
10588 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010589 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 +010010590 else
10591 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10592 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010593 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010594 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010595 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010596" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010597 endif
10598 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010599 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010600" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010601 endif
10602
10603 else
10604 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010605" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010606 if !all
10607 call inputsave()
10608 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10609 call inputrestore()
10610 if ok == ""
10611 let ok="no"
10612 endif
10613 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010614 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010615 let all= 1
10616 endif
10617 endif
10618
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010619 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010620 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010621 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010622 else
10623 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010624 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10625" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010626 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010627" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010628
10629 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010630" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10631 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10632" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010633 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010634" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010635
10636 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010637 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010638 endif
10639 endif
10640 endif
10641
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010642 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010643" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010644 endif
10645 endif
10646
10647" call Dret("s:NetrwRemoteRmFile ".ok)
10648 return ok
10649endfun
10650
10651" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010652" s:NetrwRemoteRename: rename a remote file or directory {{{2
10653fun! s:NetrwRemoteRename(usrhost,path) range
10654" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10655
10656 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010657 let svpos = winsaveview()
10658" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010659 let ctr = a:firstline
10660 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10661
10662 " rename files given by the markfilelist
10663 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10664 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010665" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010666 if exists("subfrom")
10667 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010668" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010669 else
10670 call inputsave()
10671 let newname= input("Moving ".oldname." to : ",oldname)
10672 call inputrestore()
10673 if newname =~ '^s/'
10674 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10675 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10676 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010677" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010678 endif
10679 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010680
Bram Moolenaar446cb832008-06-24 21:56:24 +000010681 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010682 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010683 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010684 let oldname= s:ShellEscape(a:path.oldname)
10685 let newname= s:ShellEscape(a:path.newname)
10686" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010687 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010688 endif
10689
10690 endfor
10691 call s:NetrwUnMarkFile(1)
10692
10693 else
10694
10695 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010696 let keepsol= &l:sol
10697 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010698 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010699 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010700
10701 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010702" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010703
10704 call inputsave()
10705 let newname= input("Moving ".oldname." to : ",oldname)
10706 call inputrestore()
10707
10708 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10709 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10710 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010711 let oldname= s:ShellEscape(a:path.oldname)
10712 let newname= s:ShellEscape(a:path.newname)
10713" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010714 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010715 endif
10716
10717 let ctr= ctr + 1
10718 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010719 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010720 endif
10721
10722 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010723 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010724" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10725 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010726
10727" call Dret("NetrwRemoteRename")
10728endfun
10729
Bram Moolenaar85850f32019-07-19 22:05:51 +020010730" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010731" Local Directory Browsing Support: {{{1
10732" ==========================================
10733
10734" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010735" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010736" Should accept: file://localhost/etc/fstab
10737" file:///etc/fstab
10738" file:///c:/WINDOWS/clock.avi
10739" file:///c|/WINDOWS/clock.avi
10740" file://localhost/c:/WINDOWS/clock.avi
10741" file://localhost/c|/WINDOWS/clock.avi
10742" file://c:/foo.txt
10743" file:///c:/foo.txt
10744" 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 +020010745fun! netrw#FileUrlEdit(fname)
10746" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010747 let fname = a:fname
10748 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010749" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010750 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010751" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010752 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010753 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010754 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010755" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010756 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010757" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010758 endif
10759 endif
10760 let fname2396 = netrw#RFC2396(fname)
10761 let fname2396e= fnameescape(fname2396)
10762 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010763 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010764" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010765 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010766" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010767 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10768 endif
10769 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010770
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010771" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10772" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010773 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010774 exe 'NetrwKeepj keepalt edit '.plainfname
10775 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10776
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010777" 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 +020010778" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010779 exe "sil doau BufReadPost ".fname2396e
10780endfun
10781
10782" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010783" netrw#LocalBrowseCheck: {{{2
10784fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010785 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010786 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10787 "
10788 " unfortunate interaction -- split window debugging can't be used here, must use
10789 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10790 " another call to LocalBrowseCheck() when attempts to write
10791 " to the DBG buffer are made.
10792 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010793 " The &ft == "netrw" test was installed because the BufEnter event
10794 " would hit when re-entering netrw windows, creating unexpected
10795 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010796" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010797" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010798" 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 +010010799 " getting E930: Cannot use :redir inside execute
10800"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010801" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10802" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010803
Bram Moolenaar97d62492012-11-15 21:28:22 +010010804 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010805 if isdirectory(s:NetrwFile(a:dirname))
10806" 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 +010010807
Bram Moolenaar97d62492012-11-15 21:28:22 +010010808 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010809" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10810" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010811 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010812
Bram Moolenaar446cb832008-06-24 21:56:24 +000010813 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010814" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010815 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010816
Bram Moolenaar5c736222010-01-06 20:54:52 +010010817 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010818" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010819 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010820 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010821 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010822" 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 +010010823" call Dret("netrw#LocalBrowseCheck")
10824 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010825 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010826
Bram Moolenaar85850f32019-07-19 22:05:51 +020010827 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010828 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10829 " AND IF the listing style is not a tree listing
10830 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010831" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010832 let ibuf = 1
10833 let buflast = bufnr("$")
10834 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010835 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10836 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010837 endif
10838 let ibuf= ibuf + 1
10839 endwhile
10840 endif
10841 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010842" 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>"))
10843" 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 +000010844 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010845" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010846endfun
10847
10848" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010849" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010850" performed any shell command. The idea is to cause all local-browsing
10851" buffers to be refreshed after a user has executed some shell command,
10852" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010853fun! s:LocalBrowseRefresh()
10854" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010855" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10856" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010857
Bram Moolenaar446cb832008-06-24 21:56:24 +000010858 " determine which buffers currently reside in a tab
10859 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010860" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010861 return
10862 endif
10863 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010864" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010865 return
10866 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010867 if !empty(getcmdwintype())
10868 " cannot move away from cmdline window, see :h E11
10869 return
10870 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010871 if exists("s:netrw_events") && s:netrw_events == 1
10872 " s:LocalFastBrowser gets called (indirectly) from a
10873 let s:netrw_events= 2
10874" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10875 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010876 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010877 let itab = 1
10878 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010879 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010880 while itab <= tabpagenr("$")
10881 let buftablist = buftablist + tabpagebuflist()
10882 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010883 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010884 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010885" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10886" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010887 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10888 " | refresh any netrw window
10889 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010890 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010891 let ibl = 0
10892 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010893" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010894 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10895 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010896 " (ibuf not shown in a current window AND
10897 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010898" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10899 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010900 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010901" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010902 continue
10903 elseif index(tabpagebuflist(),ibuf) != -1
10904 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010905" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010906 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010907 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010908 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10909 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10910 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10911 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010912" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010913 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10914 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10915 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010916 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010917 endif
10918 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010919" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010920 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010921" call Decho("restore window: win_gotoid(".curwinid.")")
10922 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010923 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010924
Bram Moolenaara6878372014-03-22 21:02:50 +010010925" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010926endfun
10927
10928" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010929" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10930"
10931" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010932" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010933" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10934" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010935" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010936"
10937" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
10938" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010010939" (re-using a buffer may not be as accurate)
10940"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010941" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010010942" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
10943" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
10944" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
10945" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010946fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020010947" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
10948" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
10949" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
10950" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010951
10952 " initialize browselist, a list of buffer numbers that the local browser has used
10953 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010954" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010955 let s:netrw_browselist= []
10956 endif
10957
10958 " append current buffer to fastbrowse list
10959 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010960" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010961 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010962" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010963 endif
10964
10965 " enable autocmd events to handle refreshing/removing local browser buffers
10966 " If local browse buffer is currently showing: refresh it
10967 " If local browse buffer is currently hidden : wipe it
10968 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
10969 " =1 : medium speed, re-use directory listing for remote only
10970 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010010971 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
10972 let s:netrw_events= 1
10973 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010974 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020010975 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010976" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010977 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010978 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010979" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010980 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010981 endif
10982 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010010983
10984 " user must have changed fastbrowse to its fast setting, so remove
10985 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010010986 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010987" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010988 unlet s:netrw_events
10989 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010990 au!
10991 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010010992 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010993 endif
10994
Bram Moolenaar85850f32019-07-19 22:05:51 +020010995" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010996endfun
10997
10998" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010999" s:LocalListing: does the job of "ls" for local directories {{{2
11000fun! s:LocalListing()
11001" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011002" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11003" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11004" 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 +010011005
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011006" if exists("b:netrw_curdir") |call Decho('b:netrw_curdir<'.b:netrw_curdir.">") |else|call Decho("b:netrw_curdir doesn't exist",'~'.expand("<slnum>")) |endif
11007" if exists("g:netrw_sort_by")|call Decho('g:netrw_sort_by<'.g:netrw_sort_by.">")|else|call Decho("g:netrw_sort_by doesn't exist",'~'.expand("<slnum>"))|endif
11008" 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 +010011009
11010 " get the list of files contained in the current directory
11011 let dirname = b:netrw_curdir
11012 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011013 let filelist = s:NetrwGlob(dirname,"*",0)
11014 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011015" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011016
Nir Lichtman1e34b952024-05-08 19:19:34 +020011017 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011018" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011019 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11020 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011021" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011022 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011023" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011024 endif
11025
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011026" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011027" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011028" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011029
11030 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11031 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11032 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011033" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11034" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011035 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011036" 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 +010011037
11038 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011039" call Decho(" ",'~'.expand("<slnum>"))
11040" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011041
11042 if getftype(filename) == "link"
11043 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011044" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011045 let pfile= filename."@"
11046
11047 elseif getftype(filename) == "socket"
11048 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011049" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011050 let pfile= filename."="
11051
11052 elseif getftype(filename) == "fifo"
11053 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011054" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011055 let pfile= filename."|"
11056
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011057 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011058 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011059" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011060 let pfile= filename."/"
11061
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011062 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011063 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011064 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11065 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011066" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011067 let pfile= filename."*"
11068 else
11069 " normal file
11070 let pfile= filename
11071 endif
11072 elseif executable(filename)
11073 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011074" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011075 let pfile= filename."*"
11076 else
11077 " normal file
11078 let pfile= filename
11079 endif
11080
11081 else
11082 " normal file
11083 let pfile= filename
11084 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011085" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011086
11087 if pfile =~ '//$'
11088 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011089" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011090 endif
11091 let pfile= strpart(pfile,dirnamelen)
11092 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011093" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11094" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011095
11096 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011097 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11098 let sz = getfsize(filename)
11099 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11100 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011101
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011102 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011103 let sz= s:NetrwHumanReadable(sz)
11104 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011105 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011106 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011107" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011108 endif
11109
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011110 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011111 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011112 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011113" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011114" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011115 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011116 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011117" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011118 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011119 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011120
11121 elseif g:netrw_sort_by =~ "^s"
11122 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011123" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011124" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011125 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011126 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011127" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011128 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011129 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011130
11131 else
11132 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011133" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011134" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011135 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011136 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011137" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011138 endfor
11139
11140 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011141 sil! NetrwKeepj g/^$/d
11142 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011143 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011144" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011145 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11146
11147" call Dret("s:LocalListing")
11148endfun
11149
11150" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011151" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11152fun! s:NetrwLocalExecute(cmd)
11153" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11154 let ykeep= @@
11155 " sanity check
11156 if !executable(a:cmd)
11157 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11158 let @@= ykeep
11159" call Dret("s:NetrwLocalExecute")
11160 return
11161 endif
11162
11163 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011164" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011165 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011166" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011167
11168 " strip any ansi escape sequences off
11169 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11170
11171 " show user the result(s)
11172 echomsg result
11173 let @@= ykeep
11174
11175" call Dret("s:NetrwLocalExecute")
11176endfun
11177
11178" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011179" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011180fun! s:NetrwLocalRename(path) range
11181" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11182
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011183 if !exists("w:netrw_bannercnt")
11184 let w:netrw_bannercnt= b:netrw_bannercnt
11185 endif
11186
Bram Moolenaar97d62492012-11-15 21:28:22 +010011187 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011188 let ykeep = @@
11189 let ctr = a:firstline
11190 let svpos = winsaveview()
11191 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011192" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011193
11194 " rename files given by the markfilelist
11195 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11196 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011197" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011198 if exists("subfrom")
11199 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011200" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011201 else
11202 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011203 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011204 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011205 if newname =~ ''
11206 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11207 let newname = substitute(newname,'^.*','','')
11208 elseif newname =~ ''
11209 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11210 let newname = substitute(newname,'[^/]*','','')
11211 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011212 if newname =~ '^s/'
11213 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11214 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011215" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011216 let newname = substitute(oldname,subfrom,subto,'')
11217 endif
11218 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011219 if !all && filereadable(newname)
11220 call inputsave()
11221 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11222 call inputrestore()
11223 if response == "all"
11224 let all= 1
11225 elseif response != "y" && response != "yes"
11226 " refresh the directory
11227" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11228 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11229" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11230 NetrwKeepj call winrestview(svpos)
11231 let @@= ykeep
11232" call Dret("NetrwLocalRename")
11233 return
11234 endif
11235 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011236 call rename(oldname,newname)
11237 endfor
11238 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011239
Bram Moolenaar97d62492012-11-15 21:28:22 +010011240 else
11241
11242 " attempt to rename files/directories
11243 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011244 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011245
11246 " sanity checks
11247 if line(".") < w:netrw_bannercnt
11248 let ctr= ctr + 1
11249 continue
11250 endif
11251 let curword= s:NetrwGetWord()
11252 if curword == "./" || curword == "../"
11253 let ctr= ctr + 1
11254 continue
11255 endif
11256
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011257 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011258 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011259" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011260
11261 call inputsave()
11262 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11263 call inputrestore()
11264
11265 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011266" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011267
11268 let ctr= ctr + 1
11269 endwhile
11270 endif
11271
11272 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011273" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011274 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011275" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11276 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011277 let @@= ykeep
11278
11279" call Dret("NetrwLocalRename")
11280endfun
11281
11282" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011283" s:NetrwLocalRm: {{{2
11284fun! s:NetrwLocalRm(path) range
11285" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011286" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011287
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011288 if !exists("w:netrw_bannercnt")
11289 let w:netrw_bannercnt= b:netrw_bannercnt
11290 endif
11291
Bram Moolenaar446cb832008-06-24 21:56:24 +000011292 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011293 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011294 let ret = 0
11295 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011296 let svpos = winsaveview()
11297" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011298
11299 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11300 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011301" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011302 for fname in s:netrwmarkfilelist_{bufnr("%")}
11303 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011304 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011305 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011306 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011307 let all= 1
11308 endif
11309 endfor
11310 call s:NetrwUnMarkFile(1)
11311
11312 else
11313 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011314" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011315
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011316 let keepsol= &l:sol
11317 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011318 let ctr = a:firstline
11319 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011320 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011321
11322 " sanity checks
11323 if line(".") < w:netrw_bannercnt
11324 let ctr= ctr + 1
11325 continue
11326 endif
11327 let curword= s:NetrwGetWord()
11328 if curword == "./" || curword == "../"
11329 let ctr= ctr + 1
11330 continue
11331 endif
11332 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011333 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011334 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011335 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011336 let all= 1
11337 endif
11338 let ctr= ctr + 1
11339 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011340 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011341 endif
11342
11343 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011344" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011345 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011346 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011347" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11348 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011349 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011350 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011351
11352" call Dret("s:NetrwLocalRm")
11353endfun
11354
11355" ---------------------------------------------------------------------
11356" s:NetrwLocalRmFile: remove file fname given the path {{{2
11357" Give confirmation prompt unless all==1
11358fun! s:NetrwLocalRmFile(path,fname,all)
11359" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011360
Bram Moolenaar446cb832008-06-24 21:56:24 +000011361 let all= a:all
11362 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011363 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020011364 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011365" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011366
11367 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11368 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011369" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011370 if !all
11371 echohl Statement
11372 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011373 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011374 call inputrestore()
11375 echohl NONE
11376 if ok == ""
11377 let ok="no"
11378 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011379" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011380 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011381" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011382 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011383 let all= 1
11384 endif
11385 endif
11386
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011387 if all || ok =~# '^y\%[es]$' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011388 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011389" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011390 endif
11391
11392 else
11393 " attempt to remove directory
11394 if !all
11395 echohl Statement
11396 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011397 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011398 call inputrestore()
11399 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11400 if ok == ""
11401 let ok="no"
11402 endif
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011403 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011404 let all= 1
11405 endif
11406 endif
11407 let rmfile= substitute(rmfile,'[\/]$','','e')
11408
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011409 if all || ok =~# '^y\%[es]$' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011410 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011411 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011412 endif
11413 endif
11414 endif
11415
11416" call Dret("s:NetrwLocalRmFile ".ok)
11417 return ok
11418endfun
11419
Bram Moolenaar85850f32019-07-19 22:05:51 +020011420" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011421" Support Functions: {{{1
11422
Bram Moolenaar488c6512005-08-11 20:09:58 +000011423" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011424" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11425" 0: marked file list of current buffer
11426" 1: marked file target
11427fun! netrw#Access(ilist)
11428 if a:ilist == 0
11429 if exists("s:netrwmarkfilelist_".bufnr('%'))
11430 return s:netrwmarkfilelist_{bufnr('%')}
11431 else
11432 return "no-list-buf#".bufnr('%')
11433 endif
11434 elseif a:ilist == 1
11435 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011436 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011437endfun
11438
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011439" ---------------------------------------------------------------------
11440" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11441fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011442 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011443endfun
11444
Bram Moolenaara6878372014-03-22 21:02:50 +010011445" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011446" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11447" I expect this function to be used in
11448" :PChkAssert netrw#Expose("netrwmarkfilelist")
11449" for example.
11450fun! netrw#Expose(varname)
11451" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011452 if exists("s:".a:varname)
11453 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011454" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011455 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011456" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011457 if type(retval) == 3
11458 let retval = copy(retval)
11459 let i = 0
11460 while i < len(retval)
11461 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11462 let i = i + 1
11463 endwhile
11464 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011465" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011466 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011467 else
11468" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011469 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011470 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011471" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011472 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011473 endif
11474
11475" call Dret("netrw#Expose ".string(retval))
11476 return retval
11477endfun
11478
11479" ---------------------------------------------------------------------
11480" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11481fun! netrw#Modify(varname,newvalue)
11482" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11483 exe "let s:".a:varname."= ".string(a:newvalue)
11484" call Dret("netrw#Modify")
11485endfun
11486
11487" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011488" netrw#RFC2396: converts %xx into characters {{{2
11489fun! netrw#RFC2396(fname)
11490" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011491 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011492" call Dret("netrw#RFC2396 ".fname)
11493 return fname
11494endfun
11495
11496" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011497" netrw#UserMaps: supports user-specified maps {{{2
11498" see :help function()
11499"
11500" g:Netrw_UserMaps is a List with members such as:
11501" [[keymap sequence, function reference],...]
11502"
11503" The referenced function may return a string,
11504" refresh : refresh the display
11505" -other- : this string will be executed
11506" or it may return a List of strings.
11507"
11508" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011509" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011510" Related functions:
11511" netrw#Expose(varname) -- see s:varname variables
11512" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11513" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11514fun! netrw#UserMaps(islocal)
11515" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11516" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11517
11518 " set up usermaplist
11519 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11520" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11521 for umap in g:Netrw_UserMaps
11522" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11523" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11524 " if umap[0] is a string and umap[1] is a string holding a function name
11525 if type(umap[0]) == 1 && type(umap[1]) == 1
11526" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11527 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11528 else
11529 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11530 endif
11531 endfor
11532 endif
11533" call Dret("netrw#UserMaps")
11534endfun
11535
11536" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011537" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11538fun! netrw#WinPath(path)
11539" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011540 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011541 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011542 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011543 " remove trailing slash (Win95)
11544 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11545 " remove escaped spaces
11546 let path = substitute(path, '\ ', ' ', 'g')
11547 " convert slashes to backslashes
11548 let path = substitute(path, '/', '\', 'g')
11549 else
11550 let path= a:path
11551 endif
11552" call Dret("netrw#WinPath <".path.">")
11553 return path
11554endfun
11555
11556" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020011557" s:StripTrailingSlash: removes trailing slashes from a path {{{2
11558fun! s:StripTrailingSlash(path)
11559 " remove trailing slash
11560 return substitute(a:path, '[/\\]$', '', 'g')
11561endfun
11562
Travis Sheltone34d0e32024-07-30 21:08:56 +020011563" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011564" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11565" cb : bl2mf=0 add marked files to buffer list
11566" cB : bl2mf=1 use bufferlist to mark files
11567" (mnemonic: cb = copy (marked files) to buffer list)
11568fun! s:NetrwBadd(islocal,bl2mf)
11569" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11570 if a:bl2mf
11571 " cB: add buffer list to marked files
11572 redir => bufl
11573 ls
11574 redir END
11575 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11576 for fname in bufl
11577 call s:NetrwMarkFile(a:islocal,fname)
11578 endfor
11579 else
11580 " cb: add marked files to buffer list
11581 for fname in s:netrwmarkfilelist_{bufnr("%")}
11582" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11583 exe "badd ".fnameescape(fname)
11584 endfor
11585 let curbufnr = bufnr("%")
11586 let curdir = s:NetrwGetCurdir(a:islocal)
11587 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11588 endif
11589" call Dret("s:NetrwBadd")
11590endfun
11591
11592" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011593" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11594fun! s:ComposePath(base,subdir)
11595" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11596
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011597 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011598" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011599 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011600 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011601 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011602 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011603 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011604 endif
11605
Bram Moolenaar85850f32019-07-19 22:05:51 +020011606 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011607 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011608" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011609 let ret= a:subdir
11610
Nir Lichtman1e34b952024-05-08 19:19:34 +020011611 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011612" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011613 if a:base =~ '[/\\]$'
11614 let ret= a:base.a:subdir
11615 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011616 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011617 endif
11618
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011619 elseif a:base =~ '^\a\{3,}://'
11620" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011621 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11622 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11623 if a:subdir == '../'
11624 if curpath =~ '[^/]/[^/]\+/$'
11625 let curpath= substitute(curpath,'[^/]\+/$','','')
11626 else
11627 let curpath=""
11628 endif
11629 let ret= urlbase.curpath
11630 else
11631 let ret= urlbase.curpath.a:subdir
11632 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011633" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11634" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11635" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011636
11637 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011638" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011639 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11640 if a:base =~ '^//'
11641 " keeping initial '//' for the benefit of network share listing support
11642 let ret= '/'.ret
11643 endif
11644 let ret= simplify(ret)
11645 endif
11646
11647" call Dret("s:ComposePath ".ret)
11648 return ret
11649endfun
11650
11651" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011652" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11653" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11654fun! s:DeleteBookmark(fname)
11655" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11656 call s:MergeBookmarks()
11657
11658 if exists("g:netrw_bookmarklist")
11659 let indx= index(g:netrw_bookmarklist,a:fname)
11660 if indx == -1
11661 let indx= 0
11662 while indx < len(g:netrw_bookmarklist)
11663 if g:netrw_bookmarklist[indx] =~ a:fname
11664 call remove(g:netrw_bookmarklist,indx)
11665 let indx= indx - 1
11666 endif
11667 let indx= indx + 1
11668 endwhile
11669 else
11670 " remove exact match
11671 call remove(g:netrw_bookmarklist,indx)
11672 endif
11673 endif
11674
11675" call Dret("s:DeleteBookmark")
11676endfun
11677
11678" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011679" s:FileReadable: o/s independent filereadable {{{2
11680fun! s:FileReadable(fname)
11681" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11682
11683 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011684 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011685 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011686 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011687 endif
11688
11689" call Dret("s:FileReadable ".ret)
11690 return ret
11691endfun
11692
11693" ---------------------------------------------------------------------
11694" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11695" Places correct suffix on end of temporary filename,
11696" using the suffix provided with fname
11697fun! s:GetTempfile(fname)
11698" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11699
11700 if !exists("b:netrw_tmpfile")
11701 " get a brand new temporary filename
11702 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011703" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011704
Bram Moolenaarc236c162008-07-13 17:41:49 +000011705 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011706" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011707
Bram Moolenaar9964e462007-05-05 17:54:07 +000011708 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011709 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11710" 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 +010011711 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011712" call Dret("s:GetTempfile getcwd<".getcwd().">")
11713 return ""
11714 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011715
Bram Moolenaar9964e462007-05-05 17:54:07 +000011716 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011717 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011718" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011719
Bram Moolenaar9964e462007-05-05 17:54:07 +000011720 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011721 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011722 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011723 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011724 if !exists("+shellslash") || !&ssl
11725 let tmpfile = substitute(tmpfile,'/','\','g')
11726 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011727 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011728 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011729 endif
11730 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011731" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011732 else
11733 " re-use temporary filename
11734 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011735" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011736 endif
11737
11738 " use fname's suffix for the temporary file
11739 if a:fname != ""
11740 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011741" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011742 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011743 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011744 elseif a:fname =~ '.txz$'
11745 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011746 else
11747 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11748 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011749" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011750 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011751" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011752 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011753" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011754 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11755 endif
11756 endif
11757
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011758" 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 +000011759" call Dret("s:GetTempfile <".tmpfile.">")
11760 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011761endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011762
11763" ---------------------------------------------------------------------
11764" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011765" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011766fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011767" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011768 if s:user == ""
11769 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11770 else
11771 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11772 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011773 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011774 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011775 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011776 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011777 else
11778 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11779 endif
11780" call Dret("s:MakeSshCmd <".sshcmd.">")
11781 return sshcmd
11782endfun
11783
11784" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011785" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11786fun! s:MakeBookmark(fname)
11787" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11788
11789 if !exists("g:netrw_bookmarklist")
11790 let g:netrw_bookmarklist= []
11791 endif
11792
11793 if index(g:netrw_bookmarklist,a:fname) == -1
11794 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011795 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011796 call add(g:netrw_bookmarklist,a:fname.'/')
11797 elseif a:fname !~ '/'
11798 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11799 else
11800 call add(g:netrw_bookmarklist,a:fname)
11801 endif
11802 call sort(g:netrw_bookmarklist)
11803 endif
11804
11805" call Dret("s:MakeBookmark")
11806endfun
11807
11808" ---------------------------------------------------------------------
11809" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11810fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011811" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011812 " get bookmarks from .netrwbook file
11813 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011814 if filereadable(s:NetrwFile(savefile))
11815" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011816 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011817" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011818 NetrwKeepj call delete(savefile)
11819 endif
11820" call Dret("s:MergeBookmarks")
11821endfun
11822
11823" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011824" s:NetrwBMShow: {{{2
11825fun! s:NetrwBMShow()
11826" call Dfunc("s:NetrwBMShow()")
11827 redir => bmshowraw
11828 menu
11829 redir END
11830 let bmshowlist = split(bmshowraw,'\n')
11831 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011832 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011833 if bmshowfuncs != []
11834 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011835 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011836 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011837 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011838 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011839 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011840" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11841endfun
11842
11843" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011844" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011845fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011846 if !exists("w:netrw_liststyle")
11847 let w:netrw_liststyle= g:netrw_liststyle
11848 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011849" 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 +020011850
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011851" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11852
Bram Moolenaaradc21822011-04-01 18:03:16 +020011853 if &ft != "netrw"
11854 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11855 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011856" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011857
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011858 elseif g:netrw_cursor == 8
11859 if w:netrw_liststyle == s:WIDELIST
11860 setl cursorline
11861 setl cursorcolumn
11862 else
11863 setl cursorline
11864 endif
11865 elseif g:netrw_cursor == 7
11866 setl cursorline
11867 elseif g:netrw_cursor == 6
11868 if w:netrw_liststyle == s:WIDELIST
11869 setl cursorline
11870 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011871 elseif g:netrw_cursor == 4
11872 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011873" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011874 setl cursorline
11875 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011876
11877 elseif g:netrw_cursor == 3
11878 " thin-long-tree: cursorline, user's cursorcolumn
11879 " wide : cursorline, cursorcolumn
11880 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011881" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011882 setl cursorline
11883 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011884 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011885" 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 +020011886 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011887 endif
11888
11889 elseif g:netrw_cursor == 2
11890 " thin-long-tree: cursorline, user's cursorcolumn
11891 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011892" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011893 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011894
11895 elseif g:netrw_cursor == 1
11896 " thin-long-tree: user's cursorline, user's cursorcolumn
11897 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011898 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011899" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011900 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011901 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011902" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011903 endif
11904
11905 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011906 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011907" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011908 let &l:cursorline = s:netrw_usercul
11909 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011910 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011911
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011912" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011913" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011914endfun
11915
11916" ---------------------------------------------------------------------
11917" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11918fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011919" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011920 if exists("s:netrw_usercul")
11921 let &l:cursorline = s:netrw_usercul
11922 endif
11923 if exists("s:netrw_usercuc")
11924 let &l:cursorcolumn = s:netrw_usercuc
11925 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011926" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011927" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11928endfun
11929
Christian Brabandt62f7b552024-06-23 20:23:40 +020011930" s:RestoreRegister: restores all registers given in the dict {{{2
11931fun! s:RestoreRegister(dict)
11932 for [key, val] in items(a:dict)
11933 if key == 'unnamed'
11934 let key = ''
11935 endif
11936 call setreg(key, val[0], val[1])
11937 endfor
11938endfun
11939
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011940" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011941" s:NetrwDelete: Deletes a file. {{{2
11942" Uses Steve Hall's idea to insure that Windows paths stay
11943" acceptable. No effect on Unix paths.
11944" Examples of use: let result= s:NetrwDelete(path)
11945fun! s:NetrwDelete(path)
11946" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11947
Bram Moolenaar5c736222010-01-06 20:54:52 +010011948 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011949 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000011950 if exists("+shellslash")
11951 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011952 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011953 let result = delete(path)
11954 let &shellslash = sskeep
11955 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011956" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011957 let result= delete(path)
11958 endif
11959 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011960" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011961 let result= delete(path)
11962 endif
11963 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011964 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011965 endif
11966
11967" call Dret("s:NetrwDelete ".result)
11968 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000011969endfun
11970
11971" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011972" s:NetrwBufRemover: removes a buffer that: {{{2s
11973" has buffer-id > 1
11974" is unlisted
11975" is unnamed
11976" does not appear in any window
11977fun! s:NetrwBufRemover(bufid)
11978" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
11979" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
11980" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
11981" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
11982" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
11983
yasuda4dbb2662023-10-04 20:50:35 +020011984 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011985" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020011986 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011987 endif
11988
11989" call Dret("s:NetrwBufRemover")
11990endfun
11991
11992" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011993" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010011994fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011995" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011996" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011997
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011998 " Clean out the last buffer:
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011999 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12000 " If so, delete it.
12001 call s:NetrwBufRemover(bufnr("$"))
12002
Bram Moolenaar446cb832008-06-24 21:56:24 +000012003 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012004" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012005 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12006 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12007 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12008 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12009 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12010 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12011 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12012 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12013 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12014 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12015 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12016 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12017 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12018 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12019 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12020 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12021
Bram Moolenaar85850f32019-07-19 22:05:51 +020012022 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012023" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012024 " when tree listing uses file TreeListing... a new buffer is made.
12025 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012026 " COMBAK: this causes a problem, see P43
12027" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012028 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012029 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012030 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012031" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012032 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012033
Bram Moolenaar446cb832008-06-24 21:56:24 +000012034 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012035" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012036 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12037 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12038 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12039 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12040 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12041 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12042 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12043 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12044 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12045 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12046 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12047 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12048 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12049 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12050 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12051 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12052
Bram Moolenaar5c736222010-01-06 20:54:52 +010012053 if a:0 > 0
12054 let b:netrw_curdir= a:1
12055 if b:netrw_curdir =~ '/$'
12056 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012057 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012058 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012059 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012060 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12061 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012062 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012063 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012064 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012065 endif
12066 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012067 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12068 let &l:bexpr = "netrw#BalloonHelp()"
12069 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012070
Bram Moolenaar8d043172014-01-23 14:24:41 +010012071" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012072endfun
12073
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012074" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012075" s:NetrwExe: executes a string using "!" {{{2
12076fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012077" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Konfekt3d7e5672024-10-27 22:16:49 +010012078 if has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012079" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012080 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12081 set shell& shellcmdflag& shellxquote& shellxescape&
12082 set shellquote& shellpipe& shellredir& shellslash&
Konfekt3d7e5672024-10-27 22:16:49 +010012083 try
12084 exe a:cmd
12085 finally
12086 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12087 endtry
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012088 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012089" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012090 exe a:cmd
12091 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012092 if v:shell_error
12093 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12094 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012095" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012096endfun
12097
12098" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012099" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12100fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012101 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012102" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012103 let curbuf = bufnr("%")
12104 let curwin = winnr()
12105 let iwin = 1
12106 while iwin <= winnr("$")
12107 exe iwin."wincmd w"
12108 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12109 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12110 let winvars= w:
12111 break
12112 endif
12113 let iwin= iwin + 1
12114 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012115 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012116 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012117" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012118 for k in keys(winvars)
12119 let w:{k}= winvars[k]
12120 endfor
12121 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012122" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012123 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012124endfun
12125
Bram Moolenaara6878372014-03-22 21:02:50 +010012126" ---------------------------------------------------------------------
12127" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012128" Returns: 0=success
12129" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012130fun! s:NetrwLcd(newdir)
12131" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012132" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012133
Bram Moolenaar85850f32019-07-19 22:05:51 +020012134 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012135 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012136 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012137 catch /^Vim\%((\a\+)\)\=:E344/
12138 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12139 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012140 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012141 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12142 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012143 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012144 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12145 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012146 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012147 endif
12148 endif
12149 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012150 let err472= 1
12151 endtry
12152
12153 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012154 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12155 if exists("w:netrw_prvdir")
12156 let a:newdir= w:netrw_prvdir
12157 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012158 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012159" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012160 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012161" 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 +010012162 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012163 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012164" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12165 return -1
12166 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012167
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012168" call Decho("getcwd <".getcwd().">")
12169" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012170" call Dret("s:NetrwLcd 0")
12171 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012172endfun
12173
Bram Moolenaar9964e462007-05-05 17:54:07 +000012174" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012175" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12176" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12177fun! s:NetrwSaveWordPosn()
12178" call Dfunc("NetrwSaveWordPosn()")
12179 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12180" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12181endfun
12182
12183" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012184" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12185" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12186fun! s:NetrwHumanReadable(sz)
12187" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12188
12189 if g:netrw_sizestyle == 'h'
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010012190 if a:sz >= 1000000000
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012191 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12192 elseif a:sz >= 10000000
12193 let sz = printf("%d",a:sz/1000000)."m"
12194 elseif a:sz >= 1000000
12195 let sz = printf("%.1f",a:sz/1000000.0)."m"
12196 elseif a:sz >= 10000
12197 let sz = printf("%d",a:sz/1000)."k"
12198 elseif a:sz >= 1000
12199 let sz = printf("%.1f",a:sz/1000.0)."k"
12200 else
12201 let sz= a:sz
12202 endif
12203
12204 elseif g:netrw_sizestyle == 'H'
12205 if a:sz >= 1073741824
12206 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12207 elseif a:sz >= 10485760
12208 let sz = printf("%d",a:sz/1048576)."M"
12209 elseif a:sz >= 1048576
12210 let sz = printf("%.1f",a:sz/1048576.0)."M"
12211 elseif a:sz >= 10240
12212 let sz = printf("%d",a:sz/1024)."K"
12213 elseif a:sz >= 1024
12214 let sz = printf("%.1f",a:sz/1024.0)."K"
12215 else
12216 let sz= a:sz
12217 endif
12218
12219 else
12220 let sz= a:sz
12221 endif
12222
12223" call Dret("s:NetrwHumanReadable ".sz)
12224 return sz
12225endfun
12226
12227" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012228" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12229" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12230fun! s:NetrwRestoreWordPosn()
12231" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012232 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012233" call Dret("NetrwRestoreWordPosn")
12234endfun
12235
12236" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012237" s:RestoreBufVars: {{{2
12238fun! s:RestoreBufVars()
12239" call Dfunc("s:RestoreBufVars()")
12240
12241 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12242 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12243 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12244 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12245 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12246 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12247
12248" call Dret("s:RestoreBufVars")
12249endfun
12250
12251" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012252" s:RemotePathAnalysis: {{{2
12253fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012254" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012255
Bram Moolenaara6878372014-03-22 21:02:50 +010012256 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012257 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012258 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012259 let s:user = substitute(a:dirname,dirpat,'\3','')
12260 let s:machine = substitute(a:dirname,dirpat,'\4','')
12261 let s:port = substitute(a:dirname,dirpat,'\5','')
12262 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012263 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012264 if s:machine =~ '@'
12265 let dirpat = '^\(.*\)@\(.\{-}\)$'
12266 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12267 let s:machine = substitute(s:machine,dirpat,'\2','')
12268 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012269
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012270" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12271" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12272" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12273" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12274" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12275" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012276
12277" call Dret("s:RemotePathAnalysis")
12278endfun
12279
12280" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012281" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12282" Returns status
12283" Runs system() on
12284" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012285" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012286fun! s:RemoteSystem(cmd)
12287" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12288 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012289 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 +000012290 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012291 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012292 else
12293 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12294 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12295 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012296 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012297 else
12298 let cmd= cmd.' '
12299 endif
12300 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012301" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012302 let ret= system(cmd)
12303 endif
12304" call Dret("s:RemoteSystem ".ret)
12305 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012306endfun
12307
12308" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012309" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012310fun! s:RestoreWinVars()
12311" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012312 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012313 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12314 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12315 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12316 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12317 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12318 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12319 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12320 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12321 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12322 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12323 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12324 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012325 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12326 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012327 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12328 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12329 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12330" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012331endfun
12332
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012333" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012334" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12335"
12336" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12337" is true) and a command, :Rexplore, which call this function.
12338"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012339" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012340"
12341" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012342fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012343 if exists("s:netrwdrag")
12344 return
12345 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012346" 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 +010012347" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12348" 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 +010012349
12350 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012351 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012352" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012353 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012354 unlet w:netrw_rexfile
12355" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012356 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012357" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012358" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12359" 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 +020012360 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012361
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012362 " ---------------------------
12363 " :Rex issued while in a file
12364 " ---------------------------
12365
Bram Moolenaara6878372014-03-22 21:02:50 +010012366 " record current file so :Rex can return to it from netrw
12367 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012368" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012369
12370 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012371" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012372 return
12373 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012374" 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 +020012375 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012376 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012377 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012378 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012379 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012380 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012381 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012382 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012383 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012384" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12385 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012386" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12387 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012388 if exists("s:rexposn_".bufnr('%'))
12389 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012390 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012391 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012392" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012393 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012394
Bram Moolenaar85850f32019-07-19 22:05:51 +020012395 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12396 if exists("s:explore_match")
12397 exe "2match netrwMarkFile /".s:explore_match."/"
12398 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012399 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012400
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012401" 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 +010012402" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012403endfun
12404
12405" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012406" s:SaveBufVars: save selected b: variables to s: variables {{{2
12407" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012408fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012409" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012410
12411 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12412 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12413 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12414 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12415 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12416 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12417
12418" call Dret("s:SaveBufVars")
12419endfun
12420
12421" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012422" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12423fun! s:SavePosn(posndict)
12424" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12425
Bram Moolenaar85850f32019-07-19 22:05:51 +020012426 if !exists("a:posndict[bufnr('%')]")
12427 let a:posndict[bufnr("%")]= []
12428 endif
12429" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12430 call add(a:posndict[bufnr("%")],winsaveview())
12431" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012432
12433" call Dret("s:SavePosn posndict")
12434 return a:posndict
12435endfun
12436
12437" ---------------------------------------------------------------------
12438" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12439fun! s:RestorePosn(posndict)
12440" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012441 if exists("a:posndict")
12442 if has_key(a:posndict,bufnr("%"))
12443" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12444 let posnlen= len(a:posndict[bufnr("%")])
12445 if posnlen > 0
12446 let posnlen= posnlen - 1
12447" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12448 call winrestview(a:posndict[bufnr("%")][posnlen])
12449 call remove(a:posndict[bufnr("%")],posnlen)
12450" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12451 endif
12452 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012453 endif
12454" call Dret("s:RestorePosn")
12455endfun
12456
12457" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012458" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012459fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012460" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012461 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12462 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12463 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12464 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12465 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12466 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12467 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12468 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12469 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12470 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12471 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12472 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12473 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12474 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12475 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12476 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12477 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12478 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12479" call Dret("s:SaveWinVars")
12480endfun
12481
12482" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012483" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012484" To allow separate windows to have their own activities, such as
12485" Explore **/pattern, several variables have been made window-oriented.
12486" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012487" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012488" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012489fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012490" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012491 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12492 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12493 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12494 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12495 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12496 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12497 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12498 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12499 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12500 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12501" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012502endfun
12503
12504" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012505" s:SetRexDir: set directory for :Rexplore {{{2
12506fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012507" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012508 let w:netrw_rexdir = a:dirname
12509 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012510 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012511" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12512" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012513" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012514" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012515" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012516endfun
12517
12518" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012519" s:ShowLink: used to modify thin and tree listings to show links {{{2
12520fun! s:ShowLink()
12521" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012522" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12523" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012524 if exists("b:netrw_curdir")
12525 norm! $?\a
12526 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12527 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012528" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12529" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12530" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12531 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012532 let dirlen = strlen(b:netrw_curdir)
12533 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012534" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012535 endif
12536 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012537" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12538" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012539 setl noro ma
12540 call setline(".",modline)
12541 setl ro noma nomod
12542 endif
12543" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12544endfun
12545
12546" ---------------------------------------------------------------------
12547" s:ShowStyle: {{{2
12548fun! s:ShowStyle()
12549 if !exists("w:netrw_liststyle")
12550 let liststyle= g:netrw_liststyle
12551 else
12552 let liststyle= w:netrw_liststyle
12553 endif
12554 if liststyle == s:THINLIST
12555 return s:THINLIST.":thin"
12556 elseif liststyle == s:LONGLIST
12557 return s:LONGLIST.":long"
12558 elseif liststyle == s:WIDELIST
12559 return s:WIDELIST.":wide"
12560 elseif liststyle == s:TREELIST
12561 return s:TREELIST.":tree"
12562 else
12563 return 'n/a'
12564 endif
12565endfun
12566
12567" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012568" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12569" Solution from Nicolai Weibull, vim docs (:help strlen()),
12570" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012571fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012572" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12573
12574 if v:version >= 703 && exists("*strdisplaywidth")
12575 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012576
Bram Moolenaar8d043172014-01-23 14:24:41 +010012577 elseif type(g:Align_xstrlen) == 1
12578 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12579 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012580
Bram Moolenaar8d043172014-01-23 14:24:41 +010012581 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012582 " number of codepoints (Latin a + combining circumflex is two codepoints)
12583 " (comment from TM, solution from NW)
12584 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012585
Bram Moolenaar8d043172014-01-23 14:24:41 +010012586 elseif g:Align_xstrlen == 2
12587 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012588 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12589 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012590 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012591
Bram Moolenaar8d043172014-01-23 14:24:41 +010012592 elseif g:Align_xstrlen == 3
12593 " virtual length (counting, for instance, tabs as anything between 1 and
12594 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012595 " preceded by lam, one otherwise, etc.)
12596 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012597 let modkeep= &l:mod
12598 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012599 call setline(line("."),a:x)
12600 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012601 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012602 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012603 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012604
Bram Moolenaar446cb832008-06-24 21:56:24 +000012605 else
12606 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012607 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012608 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012609" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012610 return ret
12611endfun
12612
12613" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012614" s:ShellEscape: shellescape(), or special windows handling {{{2
12615fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012616 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012617 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010012618 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012619 let f = a:0 > 0 ? a:1 : 0
12620 return shellescape(a:s, f)
12621endfun
12622
12623" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012624" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012625fun! s:TreeListMove(dir)
12626" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012627 let curline = getline('.')
12628 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12629 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12630 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12631 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12632 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12633 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12634" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12635" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12636" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12637" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12638" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12639 " COMBAK : need to handle when on a directory
12640 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012641 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012642 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012643 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012644 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012645" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012646 elseif a:dir == '[]' && nxtline != ''
12647 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012648" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012649 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12650 if nl != 0
12651 NetrwKeepj norm! k
12652 else
12653 NetrwKeepj norm! G
12654 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012655" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012656 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012657 endif
12658
12659" call Dret("s:TreeListMove")
12660endfun
12661
12662" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012663" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12664" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12665" can't be called except via emenu. But due to locale, that menu line may not be called
12666" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12667fun! s:UpdateBuffersMenu()
12668" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012669 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012670 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012671 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012672 catch /^Vim\%((\a\+)\)\=:E/
12673 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012674 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012675 endtry
12676 endif
12677" call Dret("s:UpdateBuffersMenu")
12678endfun
12679
12680" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012681" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012682" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012683fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012684" call Dfunc("s:UseBufWinVars()")
12685 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012686 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12687 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12688 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12689 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12690 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12691 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12692 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12693 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12694 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 +000012695" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012696endfun
12697
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012698" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012699" s:UserMaps: supports user-defined UserMaps {{{2
12700" * calls a user-supplied funcref(islocal,curdir)
12701" * interprets result
12702" See netrw#UserMaps()
12703fun! s:UserMaps(islocal,funcname)
12704" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12705
12706 if !exists("b:netrw_curdir")
12707 let b:netrw_curdir= getcwd()
12708 endif
12709 let Funcref = function(a:funcname)
12710 let result = Funcref(a:islocal)
12711
12712 if type(result) == 1
12713 " if result from user's funcref is a string...
12714" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12715 if result == "refresh"
12716" call Decho("refreshing display",'~'.expand("<slnum>"))
12717 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12718 elseif result != ""
12719" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12720 exe result
12721 endif
12722
12723 elseif type(result) == 3
12724 " if result from user's funcref is a List...
12725" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12726 for action in result
12727 if action == "refresh"
12728" call Decho("refreshing display",'~'.expand("<slnum>"))
12729 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12730 elseif action != ""
12731" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12732 exe action
12733 endif
12734 endfor
12735 endif
12736
12737" call Dret("s:UserMaps")
12738endfun
12739
Bram Moolenaar85850f32019-07-19 22:05:51 +020012740" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012741" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012742" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012743let &cpo= s:keepcpo
12744unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012745
Bram Moolenaar85850f32019-07-19 22:05:51 +020012746" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012747" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012748" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012749" vim:ts=8 fdm=marker