blob: b4a70e173a4af5fcc47a8c5f02d5cad19b9c1332 [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
Christian Brabandtcb0c1132023-11-21 18:48:16 +00007" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
K.Takata8750e3c2023-11-22 18:20:01 +09008" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
Christian Brabandt8fad5d52024-02-29 18:12:30 +01009" 2024 Feb 19 by Vim Project: (announce adoption)
10" 2024 Feb 29 by Vim Project: handle symlinks in tree mode correctly
Christian Brabandt08d24012024-04-03 22:44:27 +020011" 2024 Apr 03 by Vim Project: detect filetypes for remote edited files
Nir Lichtman1e34b952024-05-08 19:19:34 +020012" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
Nir Lichtmance2ad9f2024-05-09 20:20:36 +020013" 2024 May 09 by Vim Project: remove hard-coded private.ppk
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020014" 2024 May 10 by Vim Project: recursively delete directories by default
Christian Brabandt43f2edc2024-05-13 20:56:43 +020015" 2024 May 13 by Vim Project: prefer scp over pscp
Christian Brabandt98b73eb2024-06-04 18:15:57 +020016" 2024 Jun 04 by Vim Project: set bufhidden if buffer changed, nohidden is set and buffer shall be switched (#14915)
Christian Brabandt14879472024-06-13 21:25:35 +020017" 2024 Jun 13 by Vim Project: glob() on Windows fails when a directory name contains [] (#14952)
Enno3146d632024-07-04 19:44:42 +020018" 2024 Jun 23 by Vim Project: save ad restore registers when liststyle = WIDELIST (#15077, #15114)
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)
Travis Sheltone34d0e32024-07-30 21:08:56 +020028" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010029" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000030" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010031" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000032" Permission is hereby granted to use and distribute this code,
33" with or without modifications, provided that this copyright
34" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000035" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000036" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000037" expressed or implied. By using this plugin, you agree that
38" in no event will the copyright holder be liable for any damages
39" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010040"
41" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
42" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
43"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020044"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000045"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000046" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000047" (James 1:22 RSV)
48" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000049" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000050if &cp || exists("g:loaded_netrw")
51 finish
52endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020053
54" Check that vim has patches that netrw requires.
55" Patches needed for v7.4: 1557, and 213.
56" (netrw will benefit from vim's having patch#656, too)
57let s:needspatches=[1557,213]
58if exists("s:needspatches")
59 for ptch in s:needspatches
60 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
61 if !exists("s:needpatch{ptch}")
62 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
63 endif
64 let s:needpatch{ptch}= 1
65 finish
66 endif
67 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020068endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020069
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010070let g:loaded_netrw = "v173"
Bram Moolenaar446cb832008-06-24 21:56:24 +000071
Bram Moolenaar1afcace2005-11-25 19:54:28 +000072let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010073setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020074"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010075"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010076"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000077
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000078" ======================
79" Netrw Variables: {{{1
80" ======================
81
Bram Moolenaar071d4272004-06-13 20:20:40 +000082" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020083" netrw#ErrorMsg: {{{2
84" 0=note = s:NOTE
85" 1=warning = s:WARNING
86" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010087" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
88" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
89" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010090" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020091fun! netrw#ErrorMsg(level,msg,errnum)
92" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
93
94 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020095" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020096 return
97 endif
98
99 if a:level == 1
100 let level= "**warning** (netrw) "
101 elseif a:level == 2
102 let level= "**error** (netrw) "
103 else
104 let level= "**note** (netrw) "
105 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100106" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200107
Damienb4d11642024-08-15 22:00:45 +0200108 if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200109 " use popup window
110 if type(a:msg) == 3
111 let msg = [level]+a:msg
112 else
113 let msg= level.a:msg
114 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200115 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200116 let s:popuperr_text= ""
117 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200118 " (default) netrw creates a one-line window to show error/warning
119 " messages (reliably displayed)
120
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100121 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200122 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100123" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200124
125 " getting messages out reliably is just plain difficult!
126 " This attempt splits the current window, creating a one line window.
127 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100128" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200129 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100130" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200131 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100132 if type(a:msg) == 3
133 for msg in a:msg
134 NetrwKeepj call setline(line("$")+1,level.msg)
135 endfor
136 else
137 NetrwKeepj call setline(line("$")+1,level.a:msg)
138 endif
139 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200140 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100141" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200142 bo 1split
143 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200144 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200145 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100146 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100147" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200148 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100149 if type(a:msg) == 3
150 for msg in a:msg
151 NetrwKeepj call setline(line("$")+1,level.msg)
152 endfor
153 else
154 NetrwKeepj call setline(line("$"),level.a:msg)
155 endif
156 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200157 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100158" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200159 if &fo !~ '[ta]'
160 syn clear
161 syn match netrwMesgNote "^\*\*note\*\*"
162 syn match netrwMesgWarning "^\*\*warning\*\*"
163 syn match netrwMesgError "^\*\*error\*\*"
164 hi link netrwMesgWarning WarningMsg
165 hi link netrwMesgError Error
166 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100167" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200168 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200169
170 else
171 " (optional) netrw will show messages using echomsg. Even if the
172 " message doesn't appear, at least it'll be recallable via :messages
173" redraw!
174 if a:level == s:WARNING
175 echohl WarningMsg
176 elseif a:level == s:ERROR
177 echohl Error
178 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100179
180 if type(a:msg) == 3
181 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100182 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100183 endfor
184 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100185 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100186 endif
187
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100188" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200189 echohl None
190 endif
191
192" call Dret("netrw#ErrorMsg")
193endfun
194
195" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100196" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100197" Loosely, varname = value.
198fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100199" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100200 if !exists(a:varname)
201 if type(a:value) == 0
202 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200203 elseif type(a:value) == 1 && a:value =~ '^[{[]'
204 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100205 elseif type(a:value) == 1
206 exe "let ".a:varname."="."'".a:value."'"
207 else
208 exe "let ".a:varname."=".a:value
209 endif
210 endif
211endfun
212
213" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000214" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200215call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000216if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100217 call s:NetrwInit("s:THINLIST",0)
218 call s:NetrwInit("s:LONGLIST",1)
219 call s:NetrwInit("s:WIDELIST",2)
220 call s:NetrwInit("s:TREELIST",3)
221 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000222endif
223
Damien7c754112024-08-15 21:58:57 +0200224let s:NOTE = 0
225let s:WARNING = 1
226let s:ERROR = 2
227call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
228
Bram Moolenaar9964e462007-05-05 17:54:07 +0000229" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200230" Default option values: {{{2
231let g:netrw_localcopycmdopt = ""
232let g:netrw_localcopydircmdopt = ""
233let g:netrw_localmkdiropt = ""
234let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200235
236" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000237" Default values for netrw's global protocol variables {{{2
Damienb4d11642024-08-15 22:00:45 +0200238if exists("*popup_atcursor")
239\ && has("syntax")
240\ && exists("g:syntax_on")
241\ && has("mouse")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200242 call s:NetrwInit("g:netrw_use_errorwindow",2)
243else
244 call s:NetrwInit("g:netrw_use_errorwindow",1)
245endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200246
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000247if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100248 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000249 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100250 elseif executable("curl")
251 let g:netrw_dav_cmd = "curl"
252 else
253 let g:netrw_dav_cmd = ""
254 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000255endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000256if !exists("g:netrw_fetch_cmd")
257 if executable("fetch")
258 let g:netrw_fetch_cmd = "fetch -o"
259 else
260 let g:netrw_fetch_cmd = ""
261 endif
262endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100263if !exists("g:netrw_file_cmd")
264 if executable("elinks")
265 call s:NetrwInit("g:netrw_file_cmd","elinks")
266 elseif executable("links")
267 call s:NetrwInit("g:netrw_file_cmd","links")
268 endif
269endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000270if !exists("g:netrw_ftp_cmd")
271 let g:netrw_ftp_cmd = "ftp"
272endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200273let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200274if !exists("g:netrw_ftp_options")
275 let g:netrw_ftp_options= "-i -n"
276endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000277if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100278 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100279 let g:netrw_http_cmd = "wget"
280 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100281 elseif executable("curl")
282 let g:netrw_http_cmd = "curl"
283 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200284 elseif executable("elinks")
285 let g:netrw_http_cmd = "elinks"
286 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000287 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100288 let g:netrw_http_cmd = "fetch"
289 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200290 elseif executable("links")
291 let g:netrw_http_cmd = "links"
292 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000293 else
294 let g:netrw_http_cmd = ""
295 endif
296endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100297call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100298call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100299call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
300call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200301call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200302if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200303 if executable("scp")
304 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
305 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200306 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200307 else
308 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
309 endif
310endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100311call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
312call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000313
Nir Lichtman1e34b952024-05-08 19:19:34 +0200314if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000315 \ && exists("g:netrw_use_nt_rcp")
316 \ && g:netrw_use_nt_rcp
317 \ && executable( $SystemRoot .'/system32/rcp.exe')
318 let s:netrw_has_nt_rcp = 1
319 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000320else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000321 let s:netrw_has_nt_rcp = 0
322 let s:netrw_rcpmode = ''
323endif
324
325" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000326" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000327" Cygwin Detection ------- {{{3
328if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200329 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
330 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000331 else
332 let g:netrw_cygwin= 0
333 endif
334endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000335" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100336call s:NetrwInit("g:netrw_alto" , &sb)
337call s:NetrwInit("g:netrw_altv" , &spr)
338call s:NetrwInit("g:netrw_banner" , 1)
339call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200340call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100341call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200342call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100343call s:NetrwInit("g:netrw_compress" , "gzip")
344call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200345if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
346 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
347 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000348endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200349call s:NetrwInit("g:netrw_cursor" , 2)
350let s:netrw_usercul = &cursorline
351let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200352"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100353call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000354" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200355call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200356call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200357call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100358call s:NetrwInit("g:netrw_dirhistmax" , 10)
359call s:NetrwInit("g:netrw_fastbrowse" , 1)
360call 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 +0000361if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000362 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
363 let g:netrw_ftp_list_cmd = "ls -lF"
364 let g:netrw_ftp_timelist_cmd = "ls -tlF"
365 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000366 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000367 let g:netrw_ftp_list_cmd = "dir"
368 let g:netrw_ftp_timelist_cmd = "dir"
369 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000370 endif
371endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100372call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000373" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100374call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000375if !exists("g:netrw_ignorenetrc")
376 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
377 let g:netrw_ignorenetrc= 1
378 else
379 let g:netrw_ignorenetrc= 0
380 endif
381endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100382call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000383if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000384 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100385 if exists("g:netrw_list_cmd_options")
386 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
387 else
388 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
389 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000390 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200391 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100392 if exists("g:netrw_list_cmd_options")
393 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
394 else
395 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
396 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000397 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100398" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000399 let g:netrw_list_cmd= ""
400 endif
401endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100402call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000403" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200404if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200405 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200406 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
407endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100408if !exists("g:netrw_localcmdshell")
409 let g:netrw_localcmdshell= ""
410endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000411if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200412 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000413 if g:netrw_cygwin
414 let g:netrw_localcopycmd= "cp"
415 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000416 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200417 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000418 endif
419 elseif has("unix") || has("macunix")
420 let g:netrw_localcopycmd= "cp"
421 else
422 let g:netrw_localcopycmd= ""
423 endif
424endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100425if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200426 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100427 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200428 let g:netrw_localcopydircmd = "cp"
429 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100430 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000431 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200432 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100433 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200434 elseif has("unix")
435 let g:netrw_localcopydircmd = "cp"
436 let g:netrw_localcopydircmdopt= " -R"
437 elseif has("macunix")
438 let g:netrw_localcopydircmd = "cp"
439 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100440 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200441 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100442 endif
443endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200444if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100445 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200446 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
447endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200448if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200449 if g:netrw_cygwin
450 call s:NetrwInit("g:netrw_localmkdir","mkdir")
451 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000452 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200453 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200454 endif
455else
456 call s:NetrwInit("g:netrw_localmkdir","mkdir")
457endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200458call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200459if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200460 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200461 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
462endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000463if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200464 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000465 if g:netrw_cygwin
466 let g:netrw_localmovecmd= "mv"
467 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000468 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200469 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000470 endif
471 elseif has("unix") || has("macunix")
472 let g:netrw_localmovecmd= "mv"
473 else
474 let g:netrw_localmovecmd= ""
475 endif
476endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100477" following serves as an example for how to insert a version&patch specific test
478"if v:version < 704 || (v:version == 704 && !has("patch1107"))
479"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100480call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
481" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000482if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000483 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000484endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000485if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000486 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
487endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000488" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100489call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
490call s:NetrwInit("g:netrw_maxfilenamelen", 32)
491call s:NetrwInit("g:netrw_menu" , 1)
492call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200493call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100494call s:NetrwInit("g:netrw_retmap" , 0)
495if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
496 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200497elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100498 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
499else
500 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000501endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100502call s:NetrwInit("g:netrw_preview" , 0)
503call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100504call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100505call s:NetrwInit("g:netrw_sshport" , "-p")
506call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
507call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
508call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100509call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
510" Default values - q-s ---------- {{{3
511call s:NetrwInit("g:netrw_quickhelp",0)
512let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100513 \ "(create new) %:file d:directory",
514 \ "(windows split&open) o:horz v:vert p:preview",
515 \ "i:style qf:file info O:obtain r:reverse",
516 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
517 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
518 \ "(history) qb:list u:go up U:go down",
519 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100520" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
521call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100522if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
523 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
524else
525 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
526endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100527call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
528call s:NetrwInit("g:netrw_sort_options" , "")
529call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000530if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100531 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200532 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100533 else
534 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000535 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000536endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100537call s:NetrwInit("g:netrw_special_syntax" , 0)
538call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200539call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100540call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100541call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000542" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100543call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200544if !exists("g:netrw_xstrlen")
545 if exists("g:Align_xstrlen")
546 let g:netrw_xstrlen= g:Align_xstrlen
547 elseif exists("g:drawit_xstrlen")
548 let g:netrw_xstrlen= g:drawit_xstrlen
549 elseif &enc == "latin1" || !has("multi_byte")
550 let g:netrw_xstrlen= 0
551 else
552 let g:netrw_xstrlen= 1
553 endif
554endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100555call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200556call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100557call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200558if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000559" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000560" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100561call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200562if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200563 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200564else
Bram Moolenaarff034192013-04-24 18:51:19 +0200565 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200566endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200567call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100568call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
569call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100570if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100571 let s:treedepthstring= "│ "
572else
573 let s:treedepthstring= "| "
574endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200575call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000576
577" BufEnter event ignored by decho when following variable is true
578" Has a side effect that doau BufReadPost doesn't work, so
579" files read by network transfer aren't appropriately highlighted.
580"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000581
Bram Moolenaaradc21822011-04-01 18:03:16 +0200582" ======================
583" Netrw Initialization: {{{1
584" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200585if 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 +0100586" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100587 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200588" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100589 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100590 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
591 au VimEnter * let s:initbeval= &beval
592"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100593" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
594" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
595" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
596" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
597" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
598" 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 +0200599endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200600au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200601
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200602if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100603 com! -nargs=* NetrwKeepj keepj <args>
604else
605 let g:netrw_keepj= ""
606 com! -nargs=* NetrwKeepj <args>
607endif
608
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000609" ==============================
610" Netrw Utility Functions: {{{1
611" ==============================
612
Bram Moolenaaradc21822011-04-01 18:03:16 +0200613" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100614" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100615if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100616" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100617 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100618 if &ft != "netrw"
619 return ""
620 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200621 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
622 " popup error window is still showing
623 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
624 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
625 " text under mouse hasn't changed; only close window when it changes
626 call popup_close(s:popuperr_id)
627 unlet s:popuperr_text
628 else
629 let s:popuperr_text= v:beval_text
630 endif
631 let mesg= ""
632 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 +0100633 let mesg= ""
634 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
635 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
636 elseif getline(v:beval_lnum) =~ '^"\s*/'
637 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
638 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100639 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100640 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
641 let mesg = "S: edit sorting sequence"
642 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
643 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
644 elseif v:beval_text == "Quick" || v:beval_text == "Help"
645 let mesg = "Help: press <F1>"
646 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
647 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
648 else
649 let mesg= ""
650 endif
651 return mesg
652 endfun
653"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100654" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
655" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
656" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
657" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
658" 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 +0200659endif
660
Bram Moolenaar071d4272004-06-13 20:20:40 +0000661" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200662" netrw#Explore: launch the local browser in the directory of the current file {{{2
663" indx: == -1: Nexplore
664" == -2: Pexplore
665" == +: this is overloaded:
666" * If Nexplore/Pexplore is in use, then this refers to the
667" indx'th item in the w:netrw_explore_list[] of items which
668" matched the */pattern **/pattern *//pattern **//pattern
669" * If Hexplore or Vexplore, then this will override
670" g:netrw_winsize to specify the qty of rows or columns the
671" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100672" 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 +0200673" dosplit==1: the window will be split before running the local browser
674" style == 0: Explore style == 1: Explore!
675" == 2: Hexplore style == 3: Hexplore!
676" == 4: Vexplore style == 5: Vexplore!
677" == 6: Texplore
678fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100679" 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 +0100680" 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 +0200681 if !exists("b:netrw_curdir")
682 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100683" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200684 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100685
686 " record current file for Rexplore's benefit
687 if &ft != "netrw"
688 let w:netrw_rexfile= expand("%:p")
689 endif
690
691 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200692 let curdir = simplify(b:netrw_curdir)
693 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200694 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200695 let curdir= substitute(curdir,'\','/','g')
696 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100697" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100698
699 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
700 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
701 " try Explore again.
702 if a:0 > 0
703" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100704 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
705 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
706 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
707 \ '~'.expand("<slnum>"))
708 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200709 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
710 if a1 != a:1
711 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
712 return
713 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100714 endif
715 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200716
717 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200718 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100719" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100720 sil! let keepregstar = @*
721 sil! let keepregplus = @+
722 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200723 sil! let keepregslash= @/
724
Bram Moolenaar8d043172014-01-23 14:24:41 +0100725 " if dosplit
726 " -or- file has been modified AND file not hidden when abandoned
727 " -or- Texplore used
728 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaarff034192013-04-24 18:51:19 +0200729 call s:SaveWinVars()
730 let winsz= g:netrw_winsize
731 if a:indx > 0
732 let winsz= a:indx
733 endif
734
735 if a:style == 0 " Explore, Sexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200736 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200737 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200738 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200739
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200740 elseif a:style == 1 " Explore!, Sexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200741 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200742 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200743 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200744
745 elseif a:style == 2 " Hexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200746 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200747 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200748 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200749
750 elseif a:style == 3 " Hexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200751 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200752 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200753 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200754
755 elseif a:style == 4 " Vexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200756 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200757 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200758 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200759
760 elseif a:style == 5 " Vexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200761 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200762 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200763 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200764
765 elseif a:style == 6 " Texplore
766 call s:SaveBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200767 exe "keepalt tabnew ".fnameescape(curdir)
768 call s:RestoreBufVars()
769 endif
770 call s:RestoreWinVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200771 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100772 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200773
774 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100775" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200776 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100777" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200778 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100779" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200780 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100781" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200782 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
783 if dirname !~ '/$'
784 let dirname= dirname."/"
785 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100786" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200787 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100788" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200789 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100790" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200791 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100792" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200793 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100794" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200795 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100796" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200797 let dirname= a:1
798 endif
799 else
800 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100801" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200802 call s:NetrwClearExplore()
803" call Dret("netrw#Explore : cleared list")
804 return
805 endif
806
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100807" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200808 if dirname =~ '\.\./\=$'
809 let dirname= simplify(fnamemodify(dirname,':p:h'))
810 elseif dirname =~ '\.\.' || dirname == '.'
811 let dirname= simplify(fnamemodify(dirname,':p'))
812 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100813" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200814
815 if dirname =~ '^\*//'
816 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100817" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200818 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
819 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100820" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200821 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
822
823 elseif dirname =~ '^\*\*//'
824 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100825" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200826 let pattern= substitute(dirname,'^\*\*//','','')
827 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100828" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200829
830 elseif dirname =~ '/\*\*/'
831 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100832" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200833 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200834 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200835 let b:netrw_curdir = prefixdir
836 else
837 let b:netrw_curdir= getcwd().'/'.prefixdir
838 endif
839 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
840 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100841" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
842" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200843
844 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200845 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200846 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100847" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200848
849 elseif dirname=~ '^\*\*/'
850 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
851 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100852" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200853
854 else
855 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100856" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200857 endif
858
859 if starpat == 0 && a:indx >= 0
860 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100861" 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 +0200862 if dirname == ""
863 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100864" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200865 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200866 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200867 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200868 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200869 if dirname == ""
870 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200871 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100872 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100873 " depending on whether backslashes have been converted to forward slashes by earlier code).
874 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200875 let dirname= b:netrw_curdir."/".dirname
876 endif
877 elseif dirname !~ '^/'
878 let dirname= b:netrw_curdir."/".dirname
879 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100880" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200881 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100882" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
883" 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 +0200884 endif
885 if exists("w:netrw_bannercnt")
886 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
887 " If one wants to return the same place in the netrw window, use :Rex instead.
888 exe w:netrw_bannercnt
889 endif
890
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100891" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200892 " ---------------------------------------------------------------------
893 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
894" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100895" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200896" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100897" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200898" endif
899 " ---------------------------------------------------------------------
900
901 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
902 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
903 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
904 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
905 elseif a:indx <= 0
906 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100907" 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 +0200908 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100909" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200910 let s:didstarstar= 1
911 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
912 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
913 endif
914
915 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100916" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200917 if !exists("w:netrw_explore_indx")
918 let w:netrw_explore_indx= 0
919 endif
920
921 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100922" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200923
924 if indx == -1
925 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100926" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200927 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100928 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 +0200929 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100930" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100931 if @* != keepregstar | sil! let @* = keepregstar | endif
932 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100933 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200934 sil! let @/ = keepregslash
935" call Dret("netrw#Explore")
936 return
937 endif
938 let indx= w:netrw_explore_indx
939 if indx < 0 | let indx= 0 | endif
940 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
941 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100942" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200943 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
944 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100945" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200946 endwhile
947 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100948" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200949
950 elseif indx == -2
951 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100952" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200953 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100954 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 +0200955 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100956" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100957 if @* != keepregstar | sil! let @* = keepregstar | endif
958 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100959 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200960 sil! let @/ = keepregslash
961" call Dret("netrw#Explore")
962 return
963 endif
964 let indx= w:netrw_explore_indx
965 if indx < 0 | let indx= 0 | endif
966 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
967 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100968" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200969 while indx >= 0 && curfile == w:netrw_explore_list[indx]
970 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100971" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200972 endwhile
973 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100974" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200975
976 else
977 " Explore -- initialize
978 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100979" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100980 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200981 let w:netrw_explore_indx= 0
982 if !exists("b:netrw_curdir")
983 let b:netrw_curdir= getcwd()
984 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100985" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200986
987 " switch on starpat to build the w:netrw_explore_list of files
988 if starpat == 1
989 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100990" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
991" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200992 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100993 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200994 catch /^Vim\%((\a\+)\)\=:E480/
995 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
996" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
997 return
998 endtry
999 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1000 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1001
1002 elseif starpat == 2
1003 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001004" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1005" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001006 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001007 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001008 catch /^Vim\%((\a\+)\)\=:E480/
1009 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1010 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001011 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001012" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001013 if @* != keepregstar | sil! let @* = keepregstar | endif
1014 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001015 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001016 sil! let @/ = keepregslash
1017" call Dret("netrw#Explore : no files matched pattern")
1018 return
1019 endtry
1020 let s:netrw_curdir = b:netrw_curdir
1021 let w:netrw_explore_list = getqflist()
1022 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1023 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1024
1025 elseif starpat == 3
1026 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001027" 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 +02001028 let filepat= substitute(dirname,'^\*/','','')
1029 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001030" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1031" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001032 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1033 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1034
1035 elseif starpat == 4
1036 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001037" 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 +02001038 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1039 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1040 endif " switch on starpat to build w:netrw_explore_list
1041
1042 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001043" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1044" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001045
1046 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001047 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001048 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001049" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001050 if @* != keepregstar | sil! let @* = keepregstar | endif
1051 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001052 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001053 sil! let @/ = keepregslash
1054" call Dret("netrw#Explore : no files matched")
1055 return
1056 endif
1057 endif " if indx ... endif
1058
1059 " NetrwStatusLine support - for exploring support
1060 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001061" 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 +02001062
1063 " wrap the indx around, but issue a note
1064 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001065" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001066 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1067 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001068 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001069 endif
1070
1071 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001072" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001073 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001074" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001075
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001076" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001077 call netrw#LocalBrowseCheck(newdir)
1078 if !exists("w:netrw_liststyle")
1079 let w:netrw_liststyle= g:netrw_liststyle
1080 endif
1081 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001082 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001083 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001084 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001085 endif
1086 let w:netrw_explore_mtchcnt = indx + 1
1087 let w:netrw_explore_bufnr = bufnr("%")
1088 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001089 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001090" 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 +02001091
1092 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001093" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001094 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001095 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 +02001096 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001097 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001098" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001099 if @* != keepregstar | sil! let @* = keepregstar | endif
1100 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001101 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001102 sil! let @/ = keepregslash
1103" call Dret("netrw#Explore : missing +path_extra")
1104 return
1105 endif
1106
1107 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001108" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001109 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1110 sil! unlet w:netrw_treedict
1111 sil! unlet w:netrw_treetop
1112 endif
1113 let newdir= dirname
1114 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001115 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001116 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001117 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001118 endif
1119 endif
1120
1121 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001122" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1123" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001124 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001125" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001126 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001127 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001128" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001129 let s:explore_prvdir = b:netrw_curdir
1130 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001131 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001132 if b:netrw_curdir !~ '/$'
1133 let dirlen= dirlen + 1
1134 endif
1135 let prvfname= ""
1136 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001137" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001138 if fname =~ '^'.b:netrw_curdir
1139 if s:explore_match == ""
1140 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1141 else
1142 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1143 endif
1144 elseif fname !~ '^/' && fname != prvfname
1145 if s:explore_match == ""
1146 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1147 else
1148 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1149 endif
1150 endif
1151 let prvfname= fname
1152 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001153" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001154 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1155 exe "2match netrwMarkFile /".s:explore_match."/"
1156 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001157 endif
1158 echo "<s-up>==Pexplore <s-down>==Nexplore"
1159 else
1160 2match none
1161 if exists("s:explore_match") | unlet s:explore_match | endif
1162 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001163" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001164 endif
1165
Bram Moolenaara6878372014-03-22 21:02:50 +01001166 " since Explore may be used to initialize netrw's browser,
1167 " there's no danger of a late FocusGained event on initialization.
1168 " Consequently, set s:netrw_events to 2.
1169 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001170 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001171" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001172 if @* != keepregstar | sil! let @* = keepregstar | endif
1173 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001174 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001175 sil! let @/ = keepregslash
1176" call Dret("netrw#Explore : @/<".@/.">")
1177endfun
1178
1179" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001180" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001181" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1182" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1183" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1184" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1185" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001186fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001187" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001188 let curwin= winnr()
1189
Bram Moolenaara6878372014-03-22 21:02:50 +01001190 if a:0 > 0 && a:1 != ""
1191 " if a netrw window is already on the left-side of the tab
1192 " and a directory has been specified, explore with that
1193 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001194" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001195 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001196" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001197 exe "1wincmd w"
1198 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001199" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001200 exe "Explore ".fnameescape(a1)
1201 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001202 let s:lexplore_win= curwin
1203 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001204 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001205" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001206 unlet t:netrw_lexposn
1207 endif
1208" call Dret("netrw#Lexplore")
1209 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001210 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001211 exe curwin."wincmd w"
1212 else
1213 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001214" call Decho("no input arguments")
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 Moolenaar85850f32019-07-19 22:05:51 +02001220" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001221 else
1222 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001223" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001224 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001225" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001226
1227 if lexwinnr > 0
1228 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001229" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001230 exe lexwinnr."wincmd w"
1231 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001232 let t:netrw_lexposn = winsaveview()
1233" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001234" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001235 close
1236 if lexwinnr < curwin
1237 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001238 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001239 if lexwinnr != curwin
1240 exe curwin."wincmd w"
1241 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001242 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001243" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001244
1245 else
1246 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001247" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001248 exe "1wincmd w"
1249 let keep_altv = g:netrw_altv
1250 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001251 if a:count != 0
1252 let netrw_winsize = g:netrw_winsize
1253 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001254 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001255 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001256" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001257 exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001258" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001259 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001260" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001261 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001262 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001263 elseif curfile =~ '^\a\{3,}://'
1264" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001265 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001266 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001267" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001268 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001269 endif
1270 if a:count != 0
1271 let g:netrw_winsize = netrw_winsize
1272 endif
1273 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001274 let g:netrw_altv = keep_altv
1275 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001276 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1277 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001278 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001279 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001280" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1281" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001282 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001283" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001284" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1285 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001286 unlet t:netrw_lexposn
1287 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001288 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001289
1290 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001291 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001292 if a:rightside
1293 let g:netrw_chgwin= 1
1294 else
1295 let g:netrw_chgwin= 2
1296 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001297" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001298 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001299
Bram Moolenaar8d043172014-01-23 14:24:41 +01001300" call Dret("netrw#Lexplore")
1301endfun
1302
1303" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001304" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001305" supports :NetrwClean -- remove netrw from first directory on runtimepath
1306" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001307fun! netrw#Clean(sys)
1308" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001309
1310 if a:sys
1311 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1312 else
1313 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1314 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001315" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001316 let diddel= 0
1317 let diddir= ""
1318
1319 if choice == 1
1320 for dir in split(&rtp,',')
1321 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001322" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001323 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1324 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1325 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1326 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1327 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1328 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 +00001329 let diddir= dir
1330 let diddel= diddel + 1
1331 if !a:sys|break|endif
1332 endif
1333 endfor
1334 endif
1335
1336 echohl WarningMsg
1337 if diddel == 0
1338 echomsg "netrw is either not installed or not removable"
1339 elseif diddel == 1
1340 echomsg "removed one copy of netrw from <".diddir.">"
1341 else
1342 echomsg "removed ".diddel." copies of netrw"
1343 endif
1344 echohl None
1345
Bram Moolenaara6878372014-03-22 21:02:50 +01001346" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001347endfun
1348
Bram Moolenaar5c736222010-01-06 20:54:52 +01001349" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001350" netrw#MakeTgt: make a target out of the directory name provided {{{2
1351fun! netrw#MakeTgt(dname)
1352" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1353 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001354 let svpos = winsaveview()
1355" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001356 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1357" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001358 if s:netrwmftgt_islocal
1359 let netrwmftgt= simplify(a:dname)
1360 else
1361 let netrwmftgt= a:dname
1362 endif
1363 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1364 " re-selected target, so just clear it
1365 unlet s:netrwmftgt s:netrwmftgt_islocal
1366 else
1367 let s:netrwmftgt= netrwmftgt
1368 endif
1369 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001370 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001371 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001372" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1373 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001374" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001375endfun
1376
Bram Moolenaara6878372014-03-22 21:02:50 +01001377" ---------------------------------------------------------------------
1378" netrw#Obtain: {{{2
1379" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001380" islocal=0 obtain from remote source
1381" =1 obtain from local source
1382" fname : a filename or a list of filenames
1383" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001384fun! netrw#Obtain(islocal,fname,...)
1385" 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 +02001386 " NetrwStatusLine support - for obtaining support
1387
1388 if type(a:fname) == 1
1389 let fnamelist= [ a:fname ]
1390 elseif type(a:fname) == 3
1391 let fnamelist= a:fname
1392 else
1393 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 +01001394" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001395 return
1396 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001397" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001398 if a:0 > 0
1399 let tgtdir= a:1
1400 else
1401 let tgtdir= getcwd()
1402 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001403" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001404
1405 if exists("b:netrw_islocal") && b:netrw_islocal
1406 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001407" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001408 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1409 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001410 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001411 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001412" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001413 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001414" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001415 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001416 if v:shell_error != 0
1417 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 +01001418" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001419 return
1420 endif
1421 endfor
1422 else
1423 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001424" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1425 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1426" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001427 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001428 if v:shell_error != 0
1429 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 +01001430" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001431 return
1432 endif
1433 endif
1434 elseif !exists("b:netrw_curdir")
1435 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1436 else
1437 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1438 endif
1439
1440 else
1441 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001442" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001443 if type(a:fname) == 1
1444 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1445 endif
1446 call s:NetrwMethod(b:netrw_curdir)
1447
1448 if b:netrw_method == 4
1449 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001450" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001451 if exists("g:netrw_port") && g:netrw_port != ""
1452 let useport= " ".g:netrw_scpport." ".g:netrw_port
1453 else
1454 let useport= ""
1455 endif
1456 if b:netrw_fname =~ '/'
1457 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1458 else
1459 let path= ""
1460 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001461 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001462 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 +02001463
1464 elseif b:netrw_method == 2
1465 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001466" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001467 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001468 let tmpbufnr= bufnr("%")
1469 setl ff=unix
1470 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001471 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001472" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001473 endif
1474
1475 if exists("b:netrw_fname") && b:netrw_fname != ""
1476 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001477" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001478 endif
1479
1480 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001481 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001482" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001483 endif
1484 for fname in fnamelist
1485 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001486" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001487 endfor
1488 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001489 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 +02001490 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001491 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001492 endif
1493 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1494 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1495 let debugkeep= &debug
1496 setl debug=msg
1497 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1498 let &debug= debugkeep
1499 endif
1500
1501 elseif b:netrw_method == 3
1502 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001503" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001504 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001505 let tmpbufnr= bufnr("%")
1506 setl ff=unix
1507
1508 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001509 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001510" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001511 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001512 NetrwKeepj put ='open '.g:netrw_machine
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("g:netrw_uid") && g:netrw_uid != ""
1517 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001518 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001519" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001520 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001521 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001522 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001523" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001524 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001525 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001526" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001527 endif
1528 endif
1529
1530 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001531 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001532" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001533 endif
1534
1535 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001536 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001537" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001538 endif
1539
1540 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001541 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001542" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001543 endif
1544
1545 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001546 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001547" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001548 endif
1549 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001550 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001551 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001552" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001553
1554 " perform ftp:
1555 " -i : turns off interactive prompting from ftp
1556 " -n unix : DON'T use <.netrc>, even though it exists
1557 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001558 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1559 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001560 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001561 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1562 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001563" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001564 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001565 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001566 endif
1567 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001568
1569 elseif b:netrw_method == 9
1570 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001571" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001572 if a:fname =~ '/'
1573 let localfile= substitute(a:fname,'^.*/','','')
1574 else
1575 let localfile= a:fname
1576 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001577 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 +02001578
Bram Moolenaarff034192013-04-24 18:51:19 +02001579 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001580 " probably a badly formed url; protocol not recognized
1581" call Dret("netrw#Obtain : unsupported method")
1582 return
1583
1584 else
1585 " protocol recognized but not supported for Obtain (yet?)
1586 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001587 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001588 endif
1589" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001590 return
1591 endif
1592
1593 " restore status line
1594 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001595 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001596 endif
1597
1598 endif
1599
1600 " cleanup
1601 if exists("tmpbufnr")
1602 if bufnr("%") != tmpbufnr
1603 exe tmpbufnr."bw!"
1604 else
1605 q!
1606 endif
1607 endif
1608
Bram Moolenaara6878372014-03-22 21:02:50 +01001609" call Dret("netrw#Obtain")
1610endfun
1611
1612" ---------------------------------------------------------------------
1613" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1614fun! netrw#Nread(mode,fname)
1615" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001616 let svpos= winsaveview()
1617" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001618 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001619" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1620 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001621
1622 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1623 if exists("w:netrw_bannercnt")
1624 " start with cursor just after the banner
1625 exe w:netrw_bannercnt
1626 endif
1627 endif
1628" call Dret("netrw#Nread")
1629endfun
1630
1631" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001632" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1633" Options get restored by s:NetrwOptionsRestore()
1634"
1635" Option handling:
1636" * save user's options (s:NetrwOptionsSave)
1637" * set netrw-safe options (s:NetrwOptionsSafe)
1638" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1639" * restore user's options (s:netrwOPtionsRestore)
1640" - restore a user option when != safe option (s:NetrwRestoreSetting)
1641" vt: (variable type) normally its either "w:" or "s:"
1642fun! s:NetrwOptionsSave(vt)
1643" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1644" 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 +02001645" 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>"))
1646" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001647
1648 if !exists("{a:vt}netrw_optionsave")
1649 let {a:vt}netrw_optionsave= 1
1650 else
1651" call Dret("s:NetrwOptionsSave : options already saved")
1652 return
1653 endif
1654" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1655
1656 " Save current settings and current directory
1657" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1658 let s:yykeep = @@
1659 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1660 let {a:vt}netrw_aikeep = &l:ai
1661 let {a:vt}netrw_awkeep = &l:aw
1662 let {a:vt}netrw_bhkeep = &l:bh
1663 let {a:vt}netrw_blkeep = &l:bl
1664 let {a:vt}netrw_btkeep = &l:bt
1665 let {a:vt}netrw_bombkeep = &l:bomb
1666 let {a:vt}netrw_cedit = &cedit
1667 let {a:vt}netrw_cikeep = &l:ci
1668 let {a:vt}netrw_cinkeep = &l:cin
1669 let {a:vt}netrw_cinokeep = &l:cino
1670 let {a:vt}netrw_comkeep = &l:com
1671 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001672 let {a:vt}netrw_cuckeep = &l:cuc
1673 let {a:vt}netrw_culkeep = &l:cul
1674" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001675 let {a:vt}netrw_diffkeep = &l:diff
1676 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001677 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1678 let {a:vt}netrw_ffkeep = &l:ff
1679 endif
1680 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1681 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001682 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001683 let {a:vt}netrw_hidkeep = &l:hidden
1684 let {a:vt}netrw_imkeep = &l:im
1685 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001686 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001687 let {a:vt}netrw_lskeep = &l:ls
1688 let {a:vt}netrw_makeep = &l:ma
1689 let {a:vt}netrw_magickeep = &l:magic
1690 let {a:vt}netrw_modkeep = &l:mod
1691 let {a:vt}netrw_nukeep = &l:nu
1692 let {a:vt}netrw_rnukeep = &l:rnu
1693 let {a:vt}netrw_repkeep = &l:report
1694 let {a:vt}netrw_rokeep = &l:ro
1695 let {a:vt}netrw_selkeep = &l:sel
1696 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001697 if !g:netrw_use_noswf
1698 let {a:vt}netrw_swfkeep = &l:swf
1699 endif
1700 let {a:vt}netrw_tskeep = &l:ts
1701 let {a:vt}netrw_twkeep = &l:tw " textwidth
1702 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1703 let {a:vt}netrw_wrapkeep = &l:wrap
1704 let {a:vt}netrw_writekeep = &l:write
1705
1706 " save a few selected netrw-related variables
1707" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1708 if g:netrw_keepdir
1709 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001710" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001711 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001712 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001713 sil! let {a:vt}netrw_starkeep = @*
1714 sil! let {a:vt}netrw_pluskeep = @+
1715 endif
1716 sil! let {a:vt}netrw_slashkeep= @/
1717
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001718" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001719" 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>"))
1720" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1721endfun
1722
1723" ---------------------------------------------------------------------
1724" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1725" Use s:NetrwSaveOptions() to save user settings
1726" Use s:NetrwOptionsRestore() to restore user settings
1727fun! s:NetrwOptionsSafe(islocal)
1728" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1729" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1730" 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>"))
1731 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1732 call s:NetrwSetSafeSetting("&l:ai",0)
1733 call s:NetrwSetSafeSetting("&l:aw",0)
1734 call s:NetrwSetSafeSetting("&l:bl",0)
1735 call s:NetrwSetSafeSetting("&l:bomb",0)
1736 if a:islocal
1737 call s:NetrwSetSafeSetting("&l:bt","nofile")
1738 else
1739 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1740 endif
1741 call s:NetrwSetSafeSetting("&l:ci",0)
1742 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001743 if g:netrw_fastbrowse > a:islocal
1744 call s:NetrwSetSafeSetting("&l:bh","hide")
1745 else
1746 call s:NetrwSetSafeSetting("&l:bh","delete")
1747 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001748 call s:NetrwSetSafeSetting("&l:cino","")
1749 call s:NetrwSetSafeSetting("&l:com","")
1750 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1751 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1752 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001753 if &go =~ 'a' | set go-=a | endif
1754 if &go =~ 'A' | set go-=A | endif
1755 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001756 call s:NetrwSetSafeSetting("&l:hid",0)
1757 call s:NetrwSetSafeSetting("&l:im",0)
1758 setl isk+=@ isk+=* isk+=/
1759 call s:NetrwSetSafeSetting("&l:magic",1)
1760 if g:netrw_use_noswf
1761 call s:NetrwSetSafeSetting("swf",0)
1762 endif
1763 call s:NetrwSetSafeSetting("&l:report",10000)
1764 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1765 call s:NetrwSetSafeSetting("&l:spell",0)
1766 call s:NetrwSetSafeSetting("&l:tw",0)
1767 call s:NetrwSetSafeSetting("&l:wig","")
1768 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001769
1770 " set up cuc and cul based on g:netrw_cursor and listing style
1771 " COMBAK -- cuc cul related
1772 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001773
1774 " allow the user to override safe options
1775" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1776 if &ft == "netrw"
1777" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1778 keepalt NetrwKeepj doau FileType netrw
1779 endif
1780
1781" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1782" 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>"))
1783" call Dret("s:NetrwOptionsSafe")
1784endfun
1785
1786" ---------------------------------------------------------------------
1787" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1788fun! s:NetrwOptionsRestore(vt)
1789" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001790" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001791" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001792 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001793" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Christian Brabandt08d24012024-04-03 22:44:27 +02001794
1795 " filereadable() returns zero for remote files (e.g. scp://localhost//etc/fstab)
1796 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+/'
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001797" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001798 filetype detect
1799" 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>"))
1800 else
1801 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001802 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001803" 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 +02001804" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001805 return
1806 endif
1807 unlet {a:vt}netrw_optionsave
1808
1809 if exists("+acd")
1810 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001811" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001812 let curdir = getcwd()
1813 let &l:acd = {a:vt}netrw_acdkeep
1814 unlet {a:vt}netrw_acdkeep
1815 if &l:acd
1816 call s:NetrwLcd(curdir)
1817 endif
1818 endif
1819 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001820" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001821 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1822 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1823 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1824 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1825 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001826" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001827 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1828 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1829 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1830 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1831 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001832" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001833 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1834 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1835 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1836 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1837 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001838 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001839" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1840 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1841 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001842 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001843 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1844" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1845 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1846 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1847" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1848 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1849" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1850 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1851 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001852 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001853 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1854 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1855" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1856 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1857 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1858 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1859 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1860" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001861 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001862 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1863 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1864 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001865 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001866" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001867 call s:NetrwRestoreSetting("s:yykeep","@@")
1868 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1869 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1870 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1871 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1872
Bram Moolenaara6878372014-03-22 21:02:50 +01001873 if exists("{a:vt}netrw_swfkeep")
1874 if &directory == ""
1875 " user hasn't specified a swapfile directory;
1876 " netrw will temporarily set the swapfile directory
1877 " to the current directory as returned by getcwd().
1878 let &l:directory= getcwd()
1879 sil! let &l:swf = {a:vt}netrw_swfkeep
1880 setl directory=
1881 unlet {a:vt}netrw_swfkeep
1882 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001883 if !g:netrw_use_noswf
1884 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1885 sil! let &l:swf= {a:vt}netrw_swfkeep
1886 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001887 unlet {a:vt}netrw_swfkeep
1888 endif
1889 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001890 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001891 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1892 if exists("{a:vt}netrw_dirkeep")
1893 call s:NetrwLcd(dirkeep)
1894 unlet {a:vt}netrw_dirkeep
1895 endif
1896 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001897 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001898" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001899 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1900 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001901 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001902 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001903
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001904" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1905" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1906" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1907" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1908" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001909 " Moved the filetype detect here from NetrwGetFile() because remote files
1910 " were having their filetype detect-generated settings overwritten by
1911 " NetrwOptionRestore.
1912 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001913" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1914 filetype detect
1915" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001916 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001917" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001918" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001919" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001920endfun
1921
1922" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001923" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1924" but only when the options' value and the safe setting differ
1925" Doing this means that netrw will not come up as having changed a
1926" setting last when it really didn't actually change it.
1927"
1928" Called from s:NetrwOptionsSafe
1929" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1930fun! s:NetrwSetSafeSetting(setting,safesetting)
1931" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001932
Bram Moolenaar85850f32019-07-19 22:05:51 +02001933 if a:setting =~ '^&'
1934" call Decho("fyi: a:setting starts with &")
1935 exe "let settingval= ".a:setting
1936" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001937
Bram Moolenaar85850f32019-07-19 22:05:51 +02001938 if settingval != a:safesetting
1939" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1940 if type(a:safesetting) == 0
1941 exe "let ".a:setting."=".a:safesetting
1942 elseif type(a:safesetting) == 1
1943 exe "let ".a:setting."= '".a:safesetting."'"
1944 else
1945 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1946 endif
1947 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001948 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001949
Bram Moolenaar85850f32019-07-19 22:05:51 +02001950" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001951endfun
1952
1953" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001954" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1955" but only if the setting value differs from the associated keepvar.
1956" Doing this means that netrw will not come up as having changed a
1957" setting last when it really didn't actually change it.
1958"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001959" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001960" keepvars are set up by s:NetrwOptionsSave
1961fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001962""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001963
Bram Moolenaar85850f32019-07-19 22:05:51 +02001964 " typically called from s:NetrwOptionsRestore
1965 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1966 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001967 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001968 if exists(a:keepvar)
1969 exe "let keepvarval= ".a:keepvar
1970 exe "let setting= ".a:setting
1971
1972"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1973"" call Decho("fyi: keepvarval=".keepvarval)
1974"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1975
1976 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001977"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001978 if type(a:setting) == 0
1979 exe "let ".a:setting."= ".keepvarval
1980 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001981 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001982 else
1983 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1984 endif
1985 endif
1986
1987 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001988 endif
1989
Bram Moolenaar85850f32019-07-19 22:05:51 +02001990"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001991endfun
1992
1993" ---------------------------------------------------------------------
1994" NetrwStatusLine: {{{2
1995fun! NetrwStatusLine()
1996
1997" vvv NetrwStatusLine() debugging vvv
1998" let g:stlmsg=""
1999" if !exists("w:netrw_explore_bufnr")
2000" let g:stlmsg="!X<explore_bufnr>"
2001" elseif w:netrw_explore_bufnr != bufnr("%")
2002" let g:stlmsg="explore_bufnr!=".bufnr("%")
2003" endif
2004" if !exists("w:netrw_explore_line")
2005" let g:stlmsg=" !X<explore_line>"
2006" elseif w:netrw_explore_line != line(".")
2007" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2008" endif
2009" if !exists("w:netrw_explore_list")
2010" let g:stlmsg=" !X<explore_list>"
2011" endif
2012" ^^^ NetrwStatusLine() debugging ^^^
2013
2014 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")
2015 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09002016 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02002017 let &laststatus = s:netrw_users_ls
2018 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2019 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2020 return ""
2021 else
2022 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2023 endif
2024endfun
2025
Bram Moolenaar85850f32019-07-19 22:05:51 +02002026" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002027" Netrw Transfer Functions: {{{1
2028" ===============================
2029
Bram Moolenaar071d4272004-06-13 20:20:40 +00002030" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002031" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002032" mode: =0 read remote file and insert before current line
2033" =1 read remote file and insert after current line
2034" =2 replace with remote file
2035" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002036fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002037" 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 +00002038
Bram Moolenaar5c736222010-01-06 20:54:52 +01002039 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002040 call s:NetrwOptionsSave("w:")
2041 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002042 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002043 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2044 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2045 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002046" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002047
Bram Moolenaar5c736222010-01-06 20:54:52 +01002048 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002049 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002050 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002051 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002052 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002053 elseif a:mode == 2 " replace with remote file
2054 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002055 elseif a:mode == 3 " skip read of file (leave as temporary)
2056 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002057 else
2058 exe a:mode
2059 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002060 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002061 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002062" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002063
Bram Moolenaar5c736222010-01-06 20:54:52 +01002064 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002065 let tmpfile= s:GetTempfile("")
2066 if tmpfile == ""
2067" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002068 return
2069 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002070
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002071 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002072
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002073 " attempt to repeat with previous host-file-etc
2074 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002075" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002076 let choice = b:netrw_lastfile
2077 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002078
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002079 else
2080 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002081" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002082
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002083 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002084 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002085 echomsg 'NetRead Usage:'
2086 echomsg ':Nread machine:path uses rcp'
2087 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2088 echomsg ':Nread "machine id password path" uses ftp'
2089 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2090 echomsg ':Nread fetch://machine/path uses fetch'
2091 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2092 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002093 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002094 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002095 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2096 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2097 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2098 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002099 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002100 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002101
Bram Moolenaar9964e462007-05-05 17:54:07 +00002102 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002103 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002104" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002105 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002106 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002107 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002108 else
2109 " case "... ... ..."
2110 let choice = strpart(choice,1,strlen(choice)-1)
2111 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002112
Bram Moolenaar9964e462007-05-05 17:54:07 +00002113 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002114 let wholechoice = wholechoice . " " . choice
2115 let ichoice = ichoice + 1
2116 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002117 if !exists("g:netrw_quiet")
2118 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2119 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002120" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002121 return
2122 endif
2123 let choice= a:{ichoice}
2124 endwhile
2125 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2126 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002127 endif
2128 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002129
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002130" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002131 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002132
Bram Moolenaar5c736222010-01-06 20:54:52 +01002133 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002134 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002135 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002136" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002137 return
2138 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002139 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002140
Bram Moolenaar8d043172014-01-23 14:24:41 +01002141 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002142" 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 +02002143 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002144" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002145 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002146" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002147 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002148 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002149
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002150 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002151 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002152 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002153 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2154 echo "(netrw) Processing your read request..."
2155 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002156
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002157 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002158 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002159 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002160" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002161 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002162 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002163 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002164 " ER: the tmpfile is full path: rcp sees C:\... as host C
2165 if s:netrw_has_nt_rcp == 1
2166 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2167 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2168 else
2169 " Any way needed it machine contains a '.'
2170 let uid_machine = g:netrw_machine .'.'. $USERNAME
2171 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002172 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002173 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2174 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2175 else
2176 let uid_machine = g:netrw_machine
2177 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002178 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002179 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 +00002180 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002181 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002182
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002183 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002184 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002185 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002186" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002187 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002188 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002189 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002190 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002191 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002192" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002193 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002194 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002195" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002196 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002197 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002198" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002199 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002200 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 +00002201 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002202 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002203 endif
2204 " 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 +00002205 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002206 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002207 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002208 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002209 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002210 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002211 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002212 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002213 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2214 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002215 q!
2216 endif
2217 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002218 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002219 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002220
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002221 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002222 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002223 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2224 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002225" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002226 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002227 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002228 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002229 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002230 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002231 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002232" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002233 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002234 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002235" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002236 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002237
Bram Moolenaar97d62492012-11-15 21:28:22 +01002238 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002239 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002240 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002241" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002242 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002243 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002244 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002245" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002246 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002247 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002248" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002249 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002250 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002251
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002252 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002253 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002254" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002255 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002256 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002257 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002258" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002259 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002260 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002261" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002262
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002263 " perform ftp:
2264 " -i : turns off interactive prompting from ftp
2265 " -n unix : DON'T use <.netrc>, even though it exists
2266 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002267 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002268 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002269 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2270 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002271" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002272 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002273 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002274 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002275 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002276 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002277 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002278 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002279
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002280 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002281 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002282 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002283" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002284 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002285 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002286 else
2287 let useport= ""
2288 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002289 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2290 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002291 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002292 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2293 else
2294 let tmpfile_get = tmpfile
2295 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002296 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 +00002297 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002298 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002299
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002300 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002301 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002302 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002303" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002304 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002305 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002306 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002307 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002308" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002309 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002310 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002311
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002312 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2313 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002314" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002315 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002316 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 +00002317 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002318 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 +00002319 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002320 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002321
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002322 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002323 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002324" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002325 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2326 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002327" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2328" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2329 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 +00002330 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002331" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002332 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002333 endif
2334 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002335" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002336 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002337
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002338 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002339 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002340 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002341" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002342
Bram Moolenaar5c736222010-01-06 20:54:52 +01002343 if !executable(g:netrw_dav_cmd)
2344 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2345" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2346 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002347 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002348 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002349 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 +01002350 else
2351 " Construct execution string (four lines) which will be passed through filter
2352 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2353 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002354 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002355 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002356 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002357 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002358 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002359 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002360 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002361 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002362 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002363 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2364 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002365
Bram Moolenaar5c736222010-01-06 20:54:52 +01002366 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002367 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002368 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002369 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002370 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002371 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002372 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002373
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002374 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002375 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002376 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002377" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002378 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 +00002379 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002380 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002381
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002382 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002383 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002384 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002385 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002386" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002387 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002388 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002389 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002390 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002391" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002392 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002393 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002394 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002395 let netrw_option= "http"
2396 else
2397 let netrw_option= "ftp"
2398 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002399" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002400
Bram Moolenaar446cb832008-06-24 21:56:24 +00002401 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002402 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 +00002403 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002404 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 +00002405 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002406
Bram Moolenaar446cb832008-06-24 21:56:24 +00002407 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002408 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002409" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002410 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002411
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002412 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002413 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002414 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002415" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2416 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 +00002417 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002418 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002419
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002420 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002421 " NetRead: (file) NetRead Method #10 {{{3
2422 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002423" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2424 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002425 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2426 let b:netrw_lastfile = choice
2427
2428 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002429 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002430 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002431 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002432 endif
2433 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002434
Bram Moolenaar5c736222010-01-06 20:54:52 +01002435 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002436 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002437" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002438 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002439 unlet b:netrw_fname
2440 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002441 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 +01002442" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002443 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002444 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002445 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002446
Bram Moolenaar9964e462007-05-05 17:54:07 +00002447" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002448endfun
2449
2450" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002451" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002452fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002453" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002454
Bram Moolenaar5c736222010-01-06 20:54:52 +01002455 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002456 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002457 call s:NetrwOptionsSave("w:")
2458 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002459
Bram Moolenaar5c736222010-01-06 20:54:52 +01002460 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002461 let tmpfile= s:GetTempfile("")
2462 if tmpfile == ""
2463" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002464 return
2465 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002466
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002467 if a:0 == 0
2468 let ichoice = 0
2469 else
2470 let ichoice = 1
2471 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002472
Bram Moolenaar9964e462007-05-05 17:54:07 +00002473 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002474" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002475 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002476 " For binary writes, always write entire file.
2477 " (line numbers don't really make sense for that).
2478 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002479" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002480 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002481 elseif g:netrw_cygwin
2482 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002483 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002484" 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 +01002485 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002486 else
2487 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002488" 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 +01002489 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002490 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002491
Bram Moolenaar9964e462007-05-05 17:54:07 +00002492 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002493 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002494 " on the temporary file's name. Deletion of the temporary file during
2495 " cleanup then causes an error message.
2496 0file!
2497 endif
2498
Bram Moolenaar5c736222010-01-06 20:54:52 +01002499 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002500 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002501
Bram Moolenaar9964e462007-05-05 17:54:07 +00002502 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002503 " attempt to repeat with previous host-file-etc
2504 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002505" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002506 let choice = b:netrw_lastfile
2507 let ichoice= ichoice + 1
2508 else
2509 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002510
Bram Moolenaar8d043172014-01-23 14:24:41 +01002511 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002512 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002513 echomsg 'NetWrite Usage:"'
2514 echomsg ':Nwrite machine:path uses rcp'
2515 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2516 echomsg ':Nwrite "machine id password path" uses ftp'
2517 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2518 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2519 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2520 echomsg ':Nwrite rcp://machine/path uses rcp'
2521 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2522 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2523 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002524 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002525 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002526
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002527 elseif match(choice,"^\"") != -1
2528 if match(choice,"\"$") != -1
2529 " case "..."
2530 let choice=strpart(choice,1,strlen(choice)-2)
2531 else
2532 " case "... ... ..."
2533 let choice = strpart(choice,1,strlen(choice)-1)
2534 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002535
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002536 while match(choice,"\"$") == -1
2537 let wholechoice= wholechoice . " " . choice
2538 let ichoice = ichoice + 1
2539 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002540 if !exists("g:netrw_quiet")
2541 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2542 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002543" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002544 return
2545 endif
2546 let choice= a:{ichoice}
2547 endwhile
2548 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2549 endif
2550 endif
2551 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002552 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002553" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002554
Bram Moolenaar9964e462007-05-05 17:54:07 +00002555 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002556 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002557 if !exists("b:netrw_method") || b:netrw_method < 0
2558" call Dfunc("netrw#NetWrite : unsupported method")
2559 return
2560 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002561
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002562 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002563 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002564 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002565 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2566 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002567" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002568 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002569
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002570 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002571 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002572 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002573" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002574 if s:netrw_has_nt_rcp == 1
2575 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2576 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2577 else
2578 let uid_machine = g:netrw_machine .'.'. $USERNAME
2579 endif
2580 else
2581 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2582 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2583 else
2584 let uid_machine = g:netrw_machine
2585 endif
2586 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002587 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 +00002588 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002589
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002590 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002591 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002592 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002593" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002594 let netrw_fname = b:netrw_fname
2595
2596 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2597 let bhkeep = &l:bh
2598 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002599 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002600 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002601
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002602" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002603 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002604 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002605" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002606 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002607 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002608" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002609 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002610 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002611" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002612 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002613 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 +00002614 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002615" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2616 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617 endif
2618 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2619 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002620 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002621 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002622 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002623 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002624 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002625
2626 " remove enew buffer (quietly)
2627 let filtbuf= bufnr("%")
2628 exe curbuf."b!"
2629 let &l:bh = bhkeep
2630 exe filtbuf."bw!"
2631
Bram Moolenaar071d4272004-06-13 20:20:40 +00002632 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002633
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002634 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002635 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002636 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002637 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002638" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002639 let netrw_fname = b:netrw_fname
2640 let bhkeep = &l:bh
2641
2642 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2643 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002644 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002645 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002646 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002647
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002648 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002649 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002650" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002651 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002652 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002653" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002654 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002655 if exists("g:netrw_uid") && g:netrw_uid != ""
2656 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002657 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002658" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002659 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002660 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002661 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002662" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002663 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002664 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002665" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002666 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002667 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002668 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002669" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002670 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002671 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002672" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002673 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002674 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002675" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002676 " save choice/id/password for future use
2677 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002678
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002679 " perform ftp:
2680 " -i : turns off interactive prompting from ftp
2681 " -n unix : DON'T use <.netrc>, even though it exists
2682 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002683 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002684 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002685 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2686 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002687 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002688 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002689 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002690 let mod=1
2691 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002692
2693 " remove enew buffer (quietly)
2694 let filtbuf= bufnr("%")
2695 exe curbuf."b!"
2696 let &l:bh= bhkeep
2697 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002698
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002699 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002700 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002701 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002702" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002703 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002704 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002705 else
2706 let useport= ""
2707 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002708 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 +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: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002713 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002714" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002715 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2716 if executable(curl)
2717 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002718 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 +01002719 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002720 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002721 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002722
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002723 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002724 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002725 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002726" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002727
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002728 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002729 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2730 let bhkeep = &l:bh
2731
2732 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2733 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002734 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002735 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002736
Bram Moolenaarff034192013-04-24 18:51:19 +02002737 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002738 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002739 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002740 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002741 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002742 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002743 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002744 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002745 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002746 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002747
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002748 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002749 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002750 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002751
2752 " remove enew buffer (quietly)
2753 let filtbuf= bufnr("%")
2754 exe curbuf."b!"
2755 let &l:bh = bhkeep
2756 exe filtbuf."bw!"
2757
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002758 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002759
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002760 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002761 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002762 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002763" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002764 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 +00002765 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002766
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002767 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002768 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002769 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002770" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002771 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2773 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2774 else
2775 let uid_machine = g:netrw_machine
2776 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002777
2778 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2779 let bhkeep = &l:bh
2780 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002781 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002782 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002783
Bram Moolenaarff034192013-04-24 18:51:19 +02002784 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002785 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002786" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002787 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002788 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002789 let filtbuf= bufnr("%")
2790 exe curbuf."b!"
2791 let &l:bh = bhkeep
2792 exe filtbuf."bw!"
2793 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002794
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002795 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002796 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002797 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002798 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002799 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002801 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002802
Bram Moolenaar5c736222010-01-06 20:54:52 +01002803 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002804" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002805 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002806" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002807 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002808 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002809 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002810
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002811 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002812 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002813 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002814" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02002815 elseif !exists("leavemod")
2816 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002817" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002818 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002819" 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 +00002820 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002821
Bram Moolenaar9964e462007-05-05 17:54:07 +00002822" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002823endfun
2824
2825" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002826" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002827" uses NetRead to get a copy of the file into a temporarily file,
2828" then sources that file,
2829" then removes that file.
2830fun! netrw#NetSource(...)
2831" call Dfunc("netrw#NetSource() a:0=".a:0)
2832 if a:0 > 0 && a:1 == '?'
2833 " give help
2834 echomsg 'NetSource Usage:'
2835 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2836 echomsg ':Nsource fetch://machine/path uses fetch'
2837 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002838 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002839 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2840 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2841 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2842 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2843 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002844 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002845 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002846 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002847 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002848" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002849 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002850" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002851 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002852" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002853 if delete(s:netrw_tmpfile)
2854 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2855 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002856 unlet s:netrw_tmpfile
2857 else
2858 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2859 endif
2860 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002861 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002862 endif
2863" call Dret("netrw#NetSource")
2864endfun
2865
Bram Moolenaar8d043172014-01-23 14:24:41 +01002866" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002867" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2868" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002869fun! netrw#SetTreetop(iscmd,...)
2870" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2871" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002872
Bram Moolenaar85850f32019-07-19 22:05:51 +02002873 " iscmd==0: netrw#SetTreetop called using gn mapping
2874 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2875" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002876 " clear out the current tree
2877 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002878" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002879 let inittreetop= w:netrw_treetop
2880 unlet w:netrw_treetop
2881 endif
2882 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002883" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002884 unlet w:netrw_treedict
2885 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002886" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002887
Bram Moolenaar85850f32019-07-19 22:05:51 +02002888 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002889 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002890" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002891 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002892 if isdirectory(s:NetrwFile(a:1))
2893" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002894 let treedir = a:1
2895 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002896 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002897 let treedir = b:netrw_curdir."/".a:1
2898 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002899" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002900 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002901 " normally the cursor is left in the message window.
2902 " However, here this results in the directory being listed in the message window, which is not wanted.
2903 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002904 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002905 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002906 let treedir = "."
2907 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002908 endif
2909 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002910" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002911
2912 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002913 let islocal= expand("%") !~ '^\a\{3,}://'
2914" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002915
2916 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002917 if islocal
2918 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2919 else
2920 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2921 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002922
Bram Moolenaara6878372014-03-22 21:02:50 +01002923" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002924endfun
2925
Bram Moolenaar9964e462007-05-05 17:54:07 +00002926" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002927" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002928" readcmd == %r : replace buffer with newly read file
2929" == 0r : read file at top of buffer
2930" == r : read file after current line
2931" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002932fun! s:NetrwGetFile(readcmd, tfile, method)
2933" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002934
2935 " readcmd=='t': simply do nothing
2936 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002937" 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 +01002938" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002939 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002940 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002941
Bram Moolenaar9964e462007-05-05 17:54:07 +00002942 " get name of remote filename (ie. url and all)
2943 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002944" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002945
Bram Moolenaar9964e462007-05-05 17:54:07 +00002946 if exists("*NetReadFixup")
2947 " for the use of NetReadFixup (not otherwise used internally)
2948 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002949 endif
2950
Bram Moolenaar9964e462007-05-05 17:54:07 +00002951 if a:readcmd[0] == '%'
2952 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002953" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002954
2955 " rename the current buffer to the temp file (ie. tfile)
2956 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002957 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002958 else
2959 let tfile= a:tfile
2960 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002961 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002962
2963 " edit temporary file (ie. read the temporary file in)
2964 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002965" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002966 call zip#Browse(tfile)
2967 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002968" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002969 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002970 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002971" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002972 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002973 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002974" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002975 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002976 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002977" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002978 call tar#Browse(tfile)
2979 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002980" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002981 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002982 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002983" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002984 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002985 endif
2986
2987 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002988 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002989
Bram Moolenaar71badf92023-04-22 22:40:14 +01002990 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002991 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002992 " Note that isk must not include a "/" for scripts.vim
2993 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002994" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2995" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002996" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002997" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
2998 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01002999 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01003000 filetype detect
3001" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09003002 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003003" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003004 let line1 = 1
3005 let line2 = line("$")
3006
Bram Moolenaar8d043172014-01-23 14:24:41 +01003007 elseif !&ma
3008 " 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 +01003009 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003010" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003011 return
3012
Bram Moolenaar9964e462007-05-05 17:54:07 +00003013 elseif s:FileReadable(a:tfile)
3014 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003015" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003016 let curline = line(".")
3017 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003018" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003019 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003020 let line1= curline + 1
3021 let line2= line("$") - lastline + 1
3022
3023 else
3024 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003025" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3026" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003027 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003028" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003029 return
3030 endif
3031
3032 " User-provided (ie. optional) fix-it-up command
3033 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003034" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003035 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003036" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003037" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003038 endif
3039
Bram Moolenaaradc21822011-04-01 18:03:16 +02003040 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003041 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003042 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003043 endif
3044
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003045" 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 +00003046
3047 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003048" redraw!
3049
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003050" 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 +00003051" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003052endfun
3053
Bram Moolenaar9964e462007-05-05 17:54:07 +00003054" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003055" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003056" Input:
3057" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3058" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003059" b:netrw_method= 1: rcp
3060" 2: ftp + <.netrc>
3061" 3: ftp + machine, id, password, and [path]filename
3062" 4: scp
3063" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003064" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003065" 7: rsync
3066" 8: fetch
3067" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003068" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003069" g:netrw_machine= hostname
3070" b:netrw_fname = filename
3071" g:netrw_port = optional port number (for ftp)
3072" g:netrw_choice = copy of input url (choice)
3073fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003074" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003075
Bram Moolenaar251e1912011-06-19 05:09:16 +02003076 " sanity check: choice should have at least three slashes in it
3077 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3078 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3079 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003080" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003081 return
3082 endif
3083
Bram Moolenaar5c736222010-01-06 20:54:52 +01003084 " record current g:netrw_machine, if any
3085 " curmachine used if protocol == ftp and no .netrc
3086 if exists("g:netrw_machine")
3087 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003088" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003089 else
3090 let curmachine= "N O T A HOST"
3091 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003092 if exists("g:netrw_port")
3093 let netrw_port= g:netrw_port
3094 endif
3095
3096 " insure that netrw_ftp_cmd starts off every method determination
3097 " with the current g:netrw_ftp_cmd
3098 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003099
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003100 " initialization
3101 let b:netrw_method = 0
3102 let g:netrw_machine = ""
3103 let b:netrw_fname = ""
3104 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003105 let g:netrw_choice = a:choice
3106
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003107 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003108 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003109 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3110 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003111 " rcpurm : rcp://[user@]host/filename Use rcp
3112 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003113 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003114 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003115 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003116 " rsyncurm : rsync://host[:port]/path Use rsync
3117 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3118 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003119 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003120 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3121 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003122 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3123 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003124 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003125 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003126 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003127 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003128 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003129 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003130 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003131 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003132
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003133" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003134 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003135 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003136 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003137" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003138 let b:netrw_method = 1
3139 let userid = substitute(a:choice,rcpurm,'\1',"")
3140 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3141 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003142 if userid != ""
3143 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003145
Bram Moolenaaradc21822011-04-01 18:03:16 +02003146 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003147 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003148" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003149 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003150 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3151 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3152 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003153
Bram Moolenaar15146672011-10-20 22:22:38 +02003154 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003155 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003156" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003157 let b:netrw_method = 5
3158 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3159 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003160 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003161
Bram Moolenaaradc21822011-04-01 18:03:16 +02003162 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003163 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003164" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003165 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003166 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003167 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3168 else
3169 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3170 endif
3171 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003172
Bram Moolenaaradc21822011-04-01 18:03:16 +02003173 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003174 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003175" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003176 let b:netrw_method = 7
3177 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3178 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003179
Bram Moolenaaradc21822011-04-01 18:03:16 +02003180 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003181 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003182" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003183 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003184 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3185 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3186 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003187" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003188 if userid != ""
3189 let g:netrw_uid= userid
3190 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003191
Bram Moolenaaradc21822011-04-01 18:03:16 +02003192 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003193 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003194 call NetUserPass("ftp:".g:netrw_machine)
3195 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003196 " if there's a change in hostname, require password re-entry
3197 unlet s:netrw_passwd
3198 endif
3199 if exists("netrw_port")
3200 unlet netrw_port
3201 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003202 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003203
Bram Moolenaar446cb832008-06-24 21:56:24 +00003204 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003205 let b:netrw_method = 3
3206 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003207 let host= substitute(g:netrw_machine,'\..*$','','')
3208 if exists("s:netrw_hup[host]")
3209 call NetUserPass("ftp:".host)
3210
Nir Lichtman1e34b952024-05-08 19:19:34 +02003211 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003212" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3213" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003214 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003215 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003216" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003217 endif
3218 let b:netrw_method= 2
3219 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003220" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003221 let b:netrw_method= 2
3222 else
3223 if !exists("g:netrw_uid") || g:netrw_uid == ""
3224 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003225 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003226 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003227 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003228 endif
3229 let b:netrw_method= 3
3230 endif
3231 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003232
Bram Moolenaaradc21822011-04-01 18:03:16 +02003233 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003234 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003235" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003236 let b:netrw_method = 8
3237 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3238 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3239 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3240 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003241
Bram Moolenaaradc21822011-04-01 18:03:16 +02003242 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003243 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003244" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003245 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003246 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3247 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003248 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003249 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003250 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003251
Bram Moolenaaradc21822011-04-01 18:03:16 +02003252 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003253 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003254" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003255 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003256 let b:netrw_method = 3
3257 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3258 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003259
Bram Moolenaar9964e462007-05-05 17:54:07 +00003260 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003261 let b:netrw_method = 2
3262 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3263 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3264 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003265
Bram Moolenaaradc21822011-04-01 18:03:16 +02003266 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003267 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003268" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003269 let b:netrw_method = 9
3270 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3271 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003272
Bram Moolenaaradc21822011-04-01 18:03:16 +02003273 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003274 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003275" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003276 let b:netrw_method = 1
3277 let userid = substitute(a:choice,rcphf,'\2',"")
3278 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3279 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003280" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3281" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3282" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3283" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003284 if userid != ""
3285 let g:netrw_uid= userid
3286 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003287
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003288 " Method#10: file://user@hostname/...path-to-file {{{3
3289 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003290" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003291 let b:netrw_method = 10
3292 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003293" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003294
Bram Moolenaaradc21822011-04-01 18:03:16 +02003295 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003296 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003297 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003298 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003299 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003300 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003301 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003302 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003303
Bram Moolenaar81695252004-12-29 20:58:21 +00003304 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003305 " remove any leading [:#] from port number
3306 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3307 elseif exists("netrw_port")
3308 " retain port number as implicit for subsequent ftp operations
3309 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003310 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003311
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003312" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3313" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3314" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3315" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003316" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003317" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003318" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003319" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003320" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003321" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003322" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003323" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003324endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003325
Bram Moolenaar9964e462007-05-05 17:54:07 +00003326" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003327" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003328" Usage: :call NetUserPass() -- will prompt for userid and password
3329" :call NetUserPass("uid") -- will prompt for password
3330" :call NetUserPass("uid","password") -- sets global userid and password
3331" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3332" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003333fun! NetUserPass(...)
3334
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003335" call Dfunc("NetUserPass() a:0=".a:0)
3336
3337 if !exists('s:netrw_hup')
3338 let s:netrw_hup= {}
3339 endif
3340
Bram Moolenaar071d4272004-06-13 20:20:40 +00003341 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003342 " case: no input arguments
3343
3344 " change host and username if not previously entered; get new password
3345 if !exists("g:netrw_machine")
3346 let g:netrw_machine= input('Enter hostname: ')
3347 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003349 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003350 let g:netrw_uid= input('Enter username: ')
3351 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003352 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003353 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003354
3355 " set up hup database
3356 let host = substitute(g:netrw_machine,'\..*$','','')
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
3363 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003364 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003365
3366 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003367 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003368 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003369" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003370 let host = substitute(a:1,'^ftp:','','')
3371 let host = substitute(host,'\..*','','')
3372 if exists("s:netrw_hup[host]")
3373 let g:netrw_uid = s:netrw_hup[host].uid
3374 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003375" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3376" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003377 else
3378 let g:netrw_uid = input("Enter UserId: ")
3379 let s:netrw_passwd = inputsecret("Enter Password: ")
3380 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003381
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003382 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003383 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003384" 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 +02003385 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003386 if g:netrw_machine =~ '[0-9.]\+'
3387 let host= g:netrw_machine
3388 else
3389 let host= substitute(g:netrw_machine,'\..*$','','')
3390 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003391 else
3392 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003393 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003394 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003395" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003396 if exists("g:netrw_passwd")
3397 " ask for password if one not previously entered
3398 let s:netrw_passwd= g:netrw_passwd
3399 else
3400 let s:netrw_passwd = inputsecret("Enter Password: ")
3401 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003402 endif
3403
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003404" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003405 if exists("host")
3406 if !exists('s:netrw_hup[host]')
3407 let s:netrw_hup[host]= {}
3408 endif
3409 let s:netrw_hup[host].uid = g:netrw_uid
3410 let s:netrw_hup[host].passwd = s:netrw_passwd
3411 endif
3412
3413 elseif a:0 == 2
3414 let g:netrw_uid = a:1
3415 let s:netrw_passwd = a:2
3416
3417 elseif a:0 == 3
3418 " enter hostname, user-id, and password into the hup dictionary
3419 let host = substitute(a:1,'^\a\+:','','')
3420 let host = substitute(host,'\..*$','','')
3421 if !exists('s:netrw_hup[host]')
3422 let s:netrw_hup[host]= {}
3423 endif
3424 let s:netrw_hup[host].uid = a:2
3425 let s:netrw_hup[host].passwd = a:3
3426 let g:netrw_uid = s:netrw_hup[host].uid
3427 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003428" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3429" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003430 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003431
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003432" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003433endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003434
Bram Moolenaar85850f32019-07-19 22:05:51 +02003435" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003436" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003437" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003438
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003439" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003440" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3441fun! s:ExplorePatHls(pattern)
3442" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3443 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003444" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003445 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003446" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003447 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3448" call Dret("s:ExplorePatHls repat<".repat.">")
3449 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003450endfun
3451
3452" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003453" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003454" 0: (user: <mb>) bookmark current directory
3455" 1: (user: <gb>) change to the bookmarked directory
3456" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003457" 3: (browsing) records current directory history
3458" 4: (user: <u>) go up (previous) directory, using history
3459" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003460" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003461fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003462" 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 +02003463 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3464" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3465 return
3466 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003467
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003468 let ykeep = @@
3469 let curbufnr = bufnr("%")
3470
Bram Moolenaar9964e462007-05-05 17:54:07 +00003471 if a:chg == 0
3472 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003473" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003474 if exists("s:netrwmarkfilelist_{curbufnr}")
3475 call s:NetrwBookmark(0)
3476 echo "bookmarked marked files"
3477 else
3478 call s:MakeBookmark(a:curdir)
3479 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003480 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003481
KSR-Yasudaf4498252023-10-06 03:34:17 +09003482 try
3483 call s:NetrwBookHistSave()
3484 catch
3485 endtry
3486
Bram Moolenaar9964e462007-05-05 17:54:07 +00003487 elseif a:chg == 1
3488 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003489" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003490 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003491" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003492 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003493 else
3494 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3495 endif
3496
3497 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003498" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003499 let didwork= 0
3500 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003501" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003502 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003503" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003504 let cnt= 1
3505 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003506" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003507 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003508 let didwork = 1
3509 let cnt = cnt + 1
3510 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003511 endif
3512
3513 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003514 " Note: history is saved only when PerformListing is done;
3515 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3516 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003517 let first = 1
3518 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003519 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003520 while ( first || cnt != g:netrw_dirhistcnt )
3521" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003522 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003523" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003524 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003525 let didwork= 1
3526 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003527 let histcnt = histcnt + 1
3528 let first = 0
3529 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003530 if cnt < 0
3531 let cnt= cnt + g:netrw_dirhistmax
3532 endif
3533 endwhile
3534 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003535 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003536 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003537 if didwork
3538 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3539 endif
3540
3541 elseif a:chg == 3
3542 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003543" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003544 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 +02003545 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003546 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3547 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003548 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003549" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003550 endif
3551
3552 elseif a:chg == 4
3553 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003554" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003555 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003556 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3557 if g:netrw_dirhistcnt < 0
3558 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003559 endif
3560 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003561 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003562 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003563 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3564" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003565 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003566 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003567" call Decho("setl ma noro",'~'.expand("<slnum>"))
3568 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003569 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003570" call Decho("setl nomod",'~'.expand("<slnum>"))
3571" 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 +00003572 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003573" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3574 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003575 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003576 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003577 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003578 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003579 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003580 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003581 echo "Sorry, no predecessor directory exists yet"
3582 endif
3583
3584 elseif a:chg == 5
3585 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003586" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003587 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003588 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3589 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3590" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003591 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003592" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003593 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003594 sil! NetrwKeepj %d _
3595" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3596" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003597 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003598" 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 +02003599 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003600" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3601 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003602 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003603 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3604 if g:netrw_dirhistcnt < 0
3605 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003606 endif
3607 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003608 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003609 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003610 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003611 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003612 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003613
3614 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003615" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003616 if exists("s:netrwmarkfilelist_{curbufnr}")
3617 call s:NetrwBookmark(1)
3618 echo "removed marked files from bookmarks"
3619 else
3620 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003621 let iremove = v:count
3622 let dremove = g:netrw_bookmarklist[iremove - 1]
3623" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003624 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003625" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3626 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3627 echo "removed ".dremove." from g:netrw_bookmarklist"
3628" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003629 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003630" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003631
3632 try
3633 call s:NetrwBookHistSave()
3634 catch
3635 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003636 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003637 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003638 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003639 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003640" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003641endfun
3642
3643" ---------------------------------------------------------------------
3644" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003645" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003646" Sister function: s:NetrwBookHistSave()
3647fun! s:NetrwBookHistRead()
3648" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003649 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003650" 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 +02003651 return
3652 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003653 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003654
3655 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003656 if !exists("s:netrw_initbookhist")
3657 let home = s:NetrwHome()
3658 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003659 if filereadable(s:NetrwFile(savefile))
3660" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003661 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003662 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003663
3664 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003665 if g:netrw_dirhistmax > 0
3666 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003667 if filereadable(s:NetrwFile(savefile))
3668" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003669 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003670 endif
3671 let s:netrw_initbookhist= 1
3672 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003673 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003674 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003675
Bram Moolenaar97d62492012-11-15 21:28:22 +01003676 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003677" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3678" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003679" call Dret("s:NetrwBookHistRead")
3680endfun
3681
3682" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003683" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003684" Sister function: s:NetrwBookHistRead()
3685" I used to do this via viminfo but that appears to
3686" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003687" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3688" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003689" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003690fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003691" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003692 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003693" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003694 return
3695 endif
3696
Bram Moolenaar5c736222010-01-06 20:54:52 +01003697 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003698" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003699 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003700
3701 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003702 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003703" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003704 if g:netrw_use_noswf
3705 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3706 else
3707 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3708 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003709 setl nocin noai noci magic nospell nohid wig= noaw
3710 setl ma noro write
3711 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003712 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003713
Bram Moolenaar85850f32019-07-19 22:05:51 +02003714 " rename enew'd file: .netrwhist -- no attempt to merge
3715 " record dirhistmax and current dirhistcnt
3716 " save history
3717" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003718 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003719 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003720 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3721 if g:netrw_dirhistmax > 0
3722 let lastline = line("$")
3723 let cnt = g:netrw_dirhistcnt
3724 let first = 1
3725 while ( first || cnt != g:netrw_dirhistcnt )
3726 let lastline= lastline + 1
3727 if exists("g:netrw_dirhist_{cnt}")
3728 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3729" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3730 endif
3731 let first = 0
3732 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3733 if cnt < 0
3734 let cnt= cnt + g:netrw_dirhistmax
3735 endif
3736 endwhile
3737 exe "sil! w! ".savefile
3738" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3739 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003740
Bram Moolenaar85850f32019-07-19 22:05:51 +02003741 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003742 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003743 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003744" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003745 " merge and write .netrwbook
3746 let savefile= s:NetrwHome()."/.netrwbook"
3747
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003748 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003749 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003750 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003751 for bdm in booklist
3752 if index(g:netrw_bookmarklist,bdm) == -1
3753 call add(g:netrw_bookmarklist,bdm)
3754 endif
3755 endfor
3756 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003757 endif
3758
3759 " construct and save .netrwbook
3760 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003761 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003762" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003763 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003764
3765 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003766 let bgone= bufnr("%")
3767 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003768 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003769
3770" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003771endfun
3772
3773" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003774" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3775" list of the contents of a local or remote directory. It is assumed that the
3776" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3777" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003778" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003779fun! s:NetrwBrowse(islocal,dirname)
3780 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003781" 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 +02003782" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3783" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3784" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003785
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003786 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3787 " This is useful when one edits a local file, then :e ., then :Rex
3788 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3789 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003790" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003791 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003792
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003793 " s:NetrwBrowse : initialize history {{{3
3794 if !exists("s:netrw_initbookhist")
3795 NetrwKeepj call s:NetrwBookHistRead()
3796 endif
3797
3798 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003799 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003800 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003801" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003802 else
3803 let dirname= a:dirname
3804 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003805
Bram Moolenaar85850f32019-07-19 22:05:51 +02003806 " repoint t:netrw_lexbufnr if appropriate
3807 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3808" call Decho("set repointlexbufnr to true!")
3809 let repointlexbufnr= 1
3810 endif
3811
3812 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003813 if exists("s:netrw_skipbrowse")
3814 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003815" 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 +01003816" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003817 return
3818 endif
3819 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003820 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003821" call Dret("s:NetrwBrowse : missing shellescape()")
3822 return
3823 endif
3824 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003825 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003826" call Dret("s:NetrwBrowse : missing fnameescape()")
3827 return
3828 endif
3829
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003830 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003831 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003832
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003833 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003834 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3835 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3836" call Decho("clearing marked files",'~'.expand("<slnum>"))
3837 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3838 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003839 endif
3840
3841 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003842 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003843" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3844" 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 +02003845 if s:NetrwLcd(dirname)
3846" call Dret("s:NetrwBrowse : lcd failure")
3847 return
3848 endif
3849 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003850" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003851
Bram Moolenaar5c736222010-01-06 20:54:52 +01003852 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003853 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003854" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003855 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003856" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003857 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003858 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003859 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003860" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003861
3862 " remove any filetype indicator from end of dirname, except for the
3863 " "this is a directory" indicator (/).
3864 " There shouldn't be one of those here, anyway.
3865 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003866" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003867 call s:RemotePathAnalysis(dirname)
3868
3869 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3870 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003871 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003872 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003873" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003874 let b:netrw_curdir = dirname
3875 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003876 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003877 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3878 sil call netrw#NetRead(2,url)
3879 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003880" call Decho("url<".url.">",'~'.expand("<slnum>"))
3881" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3882" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003883 if s:path =~ '.bz2'
3884 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3885 elseif s:path =~ '.gz'
3886 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3887 elseif s:path =~ '.gz'
3888 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3889 else
3890 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3891 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003892 endif
3893
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003894 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003895 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003896 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003897" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003898 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003899" 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 +00003900
Bram Moolenaar446cb832008-06-24 21:56:24 +00003901" call Dret("s:NetrwBrowse : file<".s:fname.">")
3902 return
3903 endif
3904
Bram Moolenaaradc21822011-04-01 18:03:16 +02003905 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003906 call s:UseBufWinVars()
3907
3908 " set up some variables {{{3
3909 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003910 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003911 let s:last_sort_by = g:netrw_sort_by
3912
3913 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003914 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003915
Bram Moolenaar97d62492012-11-15 21:28:22 +01003916 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003917" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003918 let svpos = winsaveview()
3919" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003920 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003921
Bram Moolenaar446cb832008-06-24 21:56:24 +00003922 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003923 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3924 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3925" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3926" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3927 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3928 else
3929" " call Decho("2match none",'~'.expand("<slnum>"))
3930 2match none
3931 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003932 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003933 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003934 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003935" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003936 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003937" 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 +01003938" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003939 return
3940 endif
3941
3942 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003943" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003944 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003945 if b:netrw_curdir =~ '[/\\]$'
3946 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3947 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003948 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003949 let b:netrw_curdir= b:netrw_curdir."/"
3950 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003951 if b:netrw_curdir == ''
3952 if has("amiga")
3953 " On the Amiga, the empty string connotes the current directory
3954 let b:netrw_curdir= getcwd()
3955 else
3956 " under unix, when the root directory is encountered, the result
3957 " from the preceding substitute is an empty string.
3958 let b:netrw_curdir= '/'
3959 endif
3960 endif
3961 if !a:islocal && b:netrw_curdir !~ '/$'
3962 let b:netrw_curdir= b:netrw_curdir.'/'
3963 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003964" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003965
3966 " ------------
3967 " (local only) {{{3
3968 " ------------
3969 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003970" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003971
3972 " Set up ShellCmdPost handling. Append current buffer to browselist
3973 call s:LocalFastBrowser()
3974
3975 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3976 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003977" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3978" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003979 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003980 if s:NetrwLcd(b:netrw_curdir)
3981" call Dret("s:NetrwBrowse : lcd failure")
3982 return
3983 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003984 endif
3985 endif
3986
3987 " --------------------------------
3988 " remote handling: {{{3
3989 " --------------------------------
3990 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003991" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003992
Bram Moolenaar97d62492012-11-15 21:28:22 +01003993 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003994" 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 +02003995 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003996 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003997" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003998 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3999 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4000 if dirname !~ '/$'
4001 let dirname= dirname.'/'
4002 endif
4003 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004004" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004005 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004006 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004007" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004008 endif
4009
4010 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4011 if dirname !~ dirpat
4012 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004013 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004014 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004015 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004016" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004017 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004018" 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 +00004019" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4020 return
4021 endif
4022 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004023" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004024 endif " (additional remote handling)
4025
Bram Moolenaar85850f32019-07-19 22:05:51 +02004026 " -------------------------------
4027 " Perform Directory Listing: {{{3
4028 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004029 NetrwKeepj call s:NetrwMaps(a:islocal)
4030 NetrwKeepj call s:NetrwCommands(a:islocal)
4031 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004032
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004033 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004034 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004035" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4036
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004037 " If there is a rexposn: restore position with rexposn
4038 " Otherwise : set rexposn
4039 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004040" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4041 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4042 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4043 NetrwKeepj exe w:netrw_bannercnt
4044 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004045 else
4046 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4047 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004048 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004049 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004050" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004051 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004052 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004053
Bram Moolenaar85850f32019-07-19 22:05:51 +02004054 " repoint t:netrw_lexbufnr if appropriate
4055 if exists("repointlexbufnr")
4056 let t:netrw_lexbufnr= bufnr("%")
4057" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4058 endif
4059
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004060 " restore position
4061 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004062" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4063 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004064 endif
4065
Bram Moolenaara6878372014-03-22 21:02:50 +01004066 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004067 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4068 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004069" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4070" 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 +02004071" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004072 return
4073endfun
4074
4075" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004076" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4077" may not apply correctly; ie. netrw's idea of the current directory may
4078" differ from vim's. This function insures that netrw's idea of the current
4079" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004080" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004081fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004082" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4083" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4084" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4085" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4086" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004087
4088 " clean up any leading treedepthstring
4089 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4090 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004091" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004092 else
4093 let fname= a:fname
4094 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004095
4096 if g:netrw_keepdir
4097 " vim's idea of the current directory possibly may differ from netrw's
4098 if !exists("b:netrw_curdir")
4099 let b:netrw_curdir= getcwd()
4100 endif
4101
Nir Lichtman1e34b952024-05-08 19:19:34 +02004102 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004103 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004104 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004105 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004106" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004107 else
4108 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004109 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004110" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004111 endif
4112
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004113 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004114 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004115 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004116" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004117 else
4118 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004119 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004120" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004121 endif
4122 else
4123 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004124 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004125" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4126" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4127" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004128 endif
4129
Bram Moolenaar85850f32019-07-19 22:05:51 +02004130" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004131 return ret
4132endfun
4133
4134" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004135" s:NetrwFileInfo: supports qf (query for file information) {{{2
4136fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004137" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004138 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004139 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004140 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004141 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004142 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004143 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004144 let lsopt= "-lsadh --si"
4145 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004146" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004147 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004148
4149 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004150 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004151" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004152
Bram Moolenaara6878372014-03-22 21:02:50 +01004153 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004154 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004155" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004156
4157 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004158 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004159" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004160
Bram Moolenaar446cb832008-06-24 21:56:24 +00004161 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004162" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004163 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004164" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004165 endif
4166 else
4167 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004168" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4169 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004170 let fname= substitute(a:fname,".$","","")
4171 else
4172 let fname= a:fname
4173 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004174 let t = getftime(s:NetrwFile(fname))
4175 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004176 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004177 let sz= s:NetrwHumanReadable(sz)
4178 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004179 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4180" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004181 endif
4182 else
4183 echo "sorry, \"qf\" not supported yet for remote files"
4184 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004185 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004186" call Dret("s:NetrwFileInfo")
4187endfun
4188
4189" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004190" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4191fun! s:NetrwFullPath(filename)
4192" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4193 let filename= a:filename
4194 if filename !~ '^/'
4195 let filename= resolve(getcwd().'/'.filename)
4196 endif
4197 if filename != "/" && filename =~ '/$'
4198 let filename= substitute(filename,'/$','','')
4199 endif
4200" " call Dret("s:NetrwFullPath <".filename.">")
4201 return filename
4202endfun
4203
4204" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004205" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004206" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004207" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004208" 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 +00004209fun! s:NetrwGetBuffer(islocal,dirname)
4210" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004211" 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 +02004212" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4213" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004214 let dirname= a:dirname
4215
4216 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004217" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004218 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004219" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004220 let s:netrwbuf= {}
4221 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004222" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4223" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4224
4225 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4226 let bufnum = -1
4227
4228 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4229 if has_key(s:netrwbuf,"NetrwTreeListing")
4230 let bufnum= s:netrwbuf["NetrwTreeListing"]
4231 else
4232 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4233 endif
4234" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4235 if !bufexists(bufnum)
4236 call remove(s:netrwbuf,"NetrwTreeListing"])
4237 let bufnum= -1
4238 endif
4239 elseif bufnr("NetrwTreeListing") != -1
4240 let bufnum= bufnr("NetrwTreeListing")
4241" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4242 else
4243" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4244 let bufnum= -1
4245 endif
4246
4247 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004248 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004249" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004250 if !bufexists(bufnum)
4251 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4252 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004253 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004254
Bram Moolenaar446cb832008-06-24 21:56:24 +00004255 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004256" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004257 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004258 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004259" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4260
Bram Moolenaar71badf92023-04-22 22:40:14 +01004261 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004262 " IF the buffer already has the desired name
4263 " AND it is empty
4264 let curbuf = bufname("%")
4265 if curbuf == '.'
4266 let curbuf = getcwd()
4267 endif
4268" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004269" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004270" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4271" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4272" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4273" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4274 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004275" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4276 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004277 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004278" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004279 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004280 " 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 +00004281
4282 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004283 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004284" 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 +00004285 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004286" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004287 " name the buffer
4288 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4289 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004290" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004291 let w:netrw_treebufnr = bufnr("%")
4292 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004293 if g:netrw_use_noswf
4294 setl nobl bt=nofile noswf
4295 else
4296 setl nobl bt=nofile
4297 endif
4298 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4299 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4300 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4301 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004302" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004303 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004304 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004305 " enter the new buffer into the s:netrwbuf dictionary
4306 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4307" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4308" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004309 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004310" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004311
4312 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004313" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004314 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004315 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004316 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004317
4318 if &ft == "netrw"
4319" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4320 exe "sil! NetrwKeepj noswapfile b ".bufnum
4321" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004322 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004323" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4324 call s:NetrwEditBuf(bufnum)
4325" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004326 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004327" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004328 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004329 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004330 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004331
4332 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004333 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004334
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004335 if line("$") <= 1 && getline(1) == ""
4336 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004337 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004338" 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>"))
4339" 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 +01004340" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4341 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004342
Bram Moolenaar97d62492012-11-15 21:28:22 +01004343 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004344" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004345 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004346 sil NetrwKeepj %d _
4347" 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>"))
4348" 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 +01004349" 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 +00004350 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004351
Bram Moolenaar446cb832008-06-24 21:56:24 +00004352 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004353" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4354" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004355 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004356 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004357 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004358" 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>"))
4359" 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 +01004360" 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 +00004361 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004362
Bram Moolenaar446cb832008-06-24 21:56:24 +00004363 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004364" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4365" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4366" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004367 return 1
4368 endif
4369 endif
4370
4371 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4372 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4373 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4374 " med 1 D H
4375 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004376" 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 +00004377 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004378 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004379 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004380
4381 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004382" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4383" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4384 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004385
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004386" 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>"))
4387" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4388" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004389 return 0
4390endfun
4391
4392" ---------------------------------------------------------------------
4393" s:NetrwGetcwd: get the current directory. {{{2
4394" Change backslashes to forward slashes, if any.
4395" If doesc is true, escape certain troublesome characters
4396fun! s:NetrwGetcwd(doesc)
4397" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4398 let curdir= substitute(getcwd(),'\\','/','ge')
4399 if curdir !~ '[\/]$'
4400 let curdir= curdir.'/'
4401 endif
4402 if a:doesc
4403 let curdir= fnameescape(curdir)
4404 endif
4405" call Dret("NetrwGetcwd <".curdir.">")
4406 return curdir
4407endfun
4408
4409" ---------------------------------------------------------------------
4410" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4411fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004412" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4413" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4414 let keepsol= &l:sol
4415 setl nosol
4416
Bram Moolenaar446cb832008-06-24 21:56:24 +00004417 call s:UseBufWinVars()
4418
4419 " insure that w:netrw_liststyle is set up
4420 if !exists("w:netrw_liststyle")
4421 if exists("g:netrw_liststyle")
4422 let w:netrw_liststyle= g:netrw_liststyle
4423 else
4424 let w:netrw_liststyle= s:THINLIST
4425 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004426" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004427 endif
4428
4429 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4430 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004431" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004432 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004433 let dirname= "./"
4434 let curline= getline('.')
4435
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004436 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004437 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004438 let s:netrw_skipbrowse= 1
4439 echo 'Pressing "s" also works'
4440
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004441 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004442 let s:netrw_skipbrowse= 1
4443 echo 'Press "S" to edit sorting sequence'
4444
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004445 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004446 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004447 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004448
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004449 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004450 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004451 let s:netrw_skipbrowse= 1
4452 echo 'Pressing "a" also works'
4453
4454 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004455 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004456 endif
4457
4458 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004459" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004460 NetrwKeepj norm! 0
4461 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004462
4463 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004464" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004465 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004466 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4467
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004468 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004469" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004470 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004471 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004472
4473 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004474" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004475 let dirname= getline('.')
4476
4477 if !exists("b:netrw_cpf")
4478 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004479 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 +01004480 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004481" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004482 endif
4483
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004484" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004485 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004486" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4487" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004488 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004489 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004490 else
4491 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004492 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004493 endif
Enno3146d632024-07-04 19:44:42 +02004494
4495 let dict={}
4496 " save the unnamed register and register 0-9 and a
4497 let dict.a=[getreg('a'), getregtype('a')]
4498 for i in range(0, 9)
4499 let dict[i] = [getreg(i), getregtype(i)]
4500 endfor
4501 let dict.unnamed = [getreg(''), getregtype('')]
4502
Bram Moolenaarc236c162008-07-13 17:41:49 +00004503 let eofname= filestart + b:netrw_cpf + 1
4504 if eofname <= col("$")
4505 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004506 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004507 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004508 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004509 endif
Enno3146d632024-07-04 19:44:42 +02004510
Bram Moolenaar446cb832008-06-24 21:56:24 +00004511 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004512 call s:RestoreRegister(dict)
4513
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004514" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004515 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004516" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004517 endif
4518
4519 " symlinks are indicated by a trailing "@". Remove it before further processing.
4520 let dirname= substitute(dirname,"@$","","")
4521
4522 " executables are indicated by a trailing "*". Remove it before further processing.
4523 let dirname= substitute(dirname,"\*$","","")
4524
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004525 let &l:sol= keepsol
4526
Bram Moolenaar446cb832008-06-24 21:56:24 +00004527" call Dret("s:NetrwGetWord <".dirname.">")
4528 return dirname
4529endfun
4530
4531" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004532" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4533" g:netrw_bufsettings will be used after the listing is produced.
4534" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004535fun! s:NetrwListSettings(islocal)
4536" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004537" 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 +00004538 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004539" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4540 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4541 setl bt=nofile nobl ma nonu nowrap noro nornu
4542 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004543 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004544 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004545 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004546" call Dredir("ls!","s:NetrwListSettings")
4547" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004548 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004549 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004550 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004551 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004552 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004553 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004554 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004555" 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 +00004556" call Dret("s:NetrwListSettings")
4557endfun
4558
4559" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004560" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004561" islocal=0: remote browsing
4562" =1: local browsing
4563fun! s:NetrwListStyle(islocal)
4564" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004565
Bram Moolenaar97d62492012-11-15 21:28:22 +01004566 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004567 let fname = s:NetrwGetWord()
4568 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004569 let svpos = winsaveview()
4570" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004571 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004572" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4573" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4574" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004575
Bram Moolenaar85850f32019-07-19 22:05:51 +02004576 " repoint t:netrw_lexbufnr if appropriate
4577 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4578" call Decho("set repointlexbufnr to true!")
4579 let repointlexbufnr= 1
4580 endif
4581
Bram Moolenaar446cb832008-06-24 21:56:24 +00004582 if w:netrw_liststyle == s:THINLIST
4583 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004584" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004585 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4586
4587 elseif w:netrw_liststyle == s:LONGLIST
4588 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004589" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004590 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4591
4592 elseif w:netrw_liststyle == s:WIDELIST
4593 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004594" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004595 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4596
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004597 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004598" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004599 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4600
4601 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004602 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004603 let g:netrw_liststyle = s:THINLIST
4604 let w:netrw_liststyle = g:netrw_liststyle
4605 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4606 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004607 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004608" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004609
4610 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004611" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4612 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004613 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004614" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004615 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004616" 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 +00004617
4618 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004619" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004620 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004621 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004622
Bram Moolenaar85850f32019-07-19 22:05:51 +02004623 " repoint t:netrw_lexbufnr if appropriate
4624 if exists("repointlexbufnr")
4625 let t:netrw_lexbufnr= bufnr("%")
4626" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4627 endif
4628
Bram Moolenaar13600302014-05-22 18:26:40 +02004629 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004630" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4631 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004632 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004633
4634" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4635endfun
4636
4637" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004638" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4639fun! s:NetrwBannerCtrl(islocal)
4640" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4641
Bram Moolenaar97d62492012-11-15 21:28:22 +01004642 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004643 " toggle the banner (enable/suppress)
4644 let g:netrw_banner= !g:netrw_banner
4645
4646 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004647 let svpos= winsaveview()
4648" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004649 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4650
4651 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004652 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4653 let fname= s:NetrwGetWord()
4654 sil NetrwKeepj $
4655 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4656" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4657 if result <= 0 && exists("w:netrw_bannercnt")
4658 exe "NetrwKeepj ".w:netrw_bannercnt
4659 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004660 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004661 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004662" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4663endfun
4664
4665" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004666" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4667"
4668" No bang: enters files/directories into Netrw's bookmark system
4669" No argument and in netrw buffer:
4670" if there are marked files: bookmark marked files
4671" otherwise : bookmark file/directory under cursor
4672" No argument and not in netrw buffer: bookmarks current open file
4673" Has arguments: globs them individually and bookmarks them
4674"
4675" With bang: deletes files/directories from Netrw's bookmark system
4676fun! s:NetrwBookmark(del,...)
4677" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4678 if a:0 == 0
4679 if &ft == "netrw"
4680 let curbufnr = bufnr("%")
4681
4682 if exists("s:netrwmarkfilelist_{curbufnr}")
4683 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004684" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004685 let svpos = winsaveview()
4686" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004687 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004688 for fname in s:netrwmarkfilelist_{curbufnr}
4689 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4690 endfor
4691 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4692 call s:NetrwUnmarkList(curbufnr,curdir)
4693 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004694" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4695 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004696 else
4697 let fname= s:NetrwGetWord()
4698 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4699 endif
4700
4701 else
4702 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004703" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004704 let fname= expand("%")
4705 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4706 endif
4707
4708 else
4709 " bookmark specified files
4710 " attempts to infer if working remote or local
4711 " by deciding if the current file begins with an url
4712 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004713 let islocal= expand("%") !~ '^\a\{3,}://'
4714" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004715 let i = 1
4716 while i <= a:0
4717 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004718 if v:version > 704 || (v:version == 704 && has("patch656"))
4719 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004720 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004721 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004722 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004723 else
4724 let mbfiles= [a:{i}]
4725 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004726" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004727 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004728" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004729 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4730 endfor
4731 let i= i + 1
4732 endwhile
4733 endif
4734
4735 " update the menu
4736 call s:NetrwBookmarkMenu()
4737
4738" call Dret("s:NetrwBookmark")
4739endfun
4740
4741" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004742" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4743" .2.[cnt] for bookmarks, and
4744" .3.[cnt] for history
4745" (see s:NetrwMenu())
4746fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004747 if !exists("s:netrw_menucnt")
4748 return
4749 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004750" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004751
4752 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004753 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004754 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004755" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004756 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4757 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004758 endif
4759 if !exists("s:netrw_initbookhist")
4760 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004761 endif
4762
4763 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004764 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004765 let cnt= 1
4766 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004767" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004768 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004769
4770 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004771 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004772
4773 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004774 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 +01004775 let cnt= cnt + 1
4776 endfor
4777
4778 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004779
4780 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004781 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004782 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004783 let first = 1
4784 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004785 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004786 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004787 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004788 if exists("g:netrw_dirhist_{cnt}")
4789 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004790" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004791 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4792 endif
4793 let first = 0
4794 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4795 if cnt < 0
4796 let cnt= cnt + g:netrw_dirhistmax
4797 endif
4798 endwhile
4799 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004800
Bram Moolenaar9964e462007-05-05 17:54:07 +00004801 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004802" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004803endfun
4804
4805" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004806" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4807" directory and a new directory name. Also, if the
4808" "new directory name" is actually a file,
4809" NetrwBrowseChgDir() edits the file.
4810fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004811" 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 +01004812" 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 +00004813
Bram Moolenaar97d62492012-11-15 21:28:22 +01004814 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004815 if !exists("b:netrw_curdir")
4816 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4817 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004818 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004819" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4820" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004821" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004822" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004823 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004824 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004825" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004826
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004827 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004828" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004829 call s:SavePosn(s:netrw_posn)
4830 NetrwKeepj call s:NetrwOptionsSave("s:")
4831 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004832 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004833 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004834 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004835 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004836 endif
4837 let newdir = a:newdir
4838 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004839 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004840" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004841" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004842" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004843
4844 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004845" 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 +01004846 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004847" 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 +01004848 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004849 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004850" 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 +01004851 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004852" 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 +02004853 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004854 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004855 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004856 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004857" 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 +01004858 endif
4859 endif
4860" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004861" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004862 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004863
Bram Moolenaar446cb832008-06-24 21:56:24 +00004864 " set up o/s-dependent directory recognition pattern
4865 if has("amiga")
4866 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004867 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004868 let dirpat= '[\/]$'
4869 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004870" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004871
4872 if dirname !~ dirpat
4873 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004874 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004875 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004876" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004877 endif
4878
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004879" 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 +01004880 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004881 " ------------------------------
4882 " NetrwBrowseChgDir: edit a file {{{3
4883 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004884" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004885
Bram Moolenaar97d62492012-11-15 21:28:22 +01004886 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004887 let s:rexposn_{bufnr("%")}= winsaveview()
4888" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004889" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4890" 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 +01004891
Bram Moolenaar446cb832008-06-24 21:56:24 +00004892 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004893" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4894" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004895" let newdir = s:NetrwTreePath(s:netrw_treetop)
4896" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004897 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004898 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4899" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4900 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004901 if dirname =~ '/$'
4902 let dirname= dirname.newdir
4903 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004904 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004905 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004906" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4907" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004908 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004909" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004910 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004911 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004912 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004913 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004914" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004915 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004916 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004917" 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 +02004918 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004919 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004920 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004921" " 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 +01004922 if type(g:netrw_browse_split) == 3
4923 " open file in server
4924 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004925" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004926 call s:NetrwServerEdit(a:islocal,dirname)
4927" call Dret("s:NetrwBrowseChgDir")
4928 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004929
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004930 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004931 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004932" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004933 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4934 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004935 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004936 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004937 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004938 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004939
Bram Moolenaar446cb832008-06-24 21:56:24 +00004940 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004941 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004942" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004943 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4944 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004945 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004946 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004947 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004948 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004949
Bram Moolenaar446cb832008-06-24 21:56:24 +00004950 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004951 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004952" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004953 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004954 if !exists("b:netrw_curdir")
4955 let b:netrw_curdir= getcwd()
4956 endif
4957 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004958
Bram Moolenaar446cb832008-06-24 21:56:24 +00004959 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004960 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004961" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004962 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004963 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004964" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004965 return
4966 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004967 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004968
Bram Moolenaar9964e462007-05-05 17:54:07 +00004969 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004970 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004971" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004972 call s:NetrwMenu(0)
4973 " optional change to window
4974 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004975" 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 +02004976 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004977 " if g:netrw_chgwin is set to one more than the last window, then
4978 " vertically split the last window to make that window available.
4979 let curwin= winnr()
4980 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4981 vs
4982 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004983 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004984 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004985 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004986 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004987 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004988
Bram Moolenaar9964e462007-05-05 17:54:07 +00004989 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004990
Bram Moolenaar446cb832008-06-24 21:56:24 +00004991 " the point where netrw actually edits the (local) file
4992 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004993 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004994 if !&mod
4995 " if e the new file would fail due to &mod, then don't change any of the flags
4996 let dolockout= 1
4997 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004998 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004999" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005000 " some like c-^ to return to the last edited file
5001 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005002 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
5003 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01005004 call s:NetrwEditFile("e","",dirname)
5005" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005006 " COMBAK -- cuc cul related
5007 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005008 if &hidden || &bufhidden == "hide"
5009 " file came from vim's hidden storage. Don't "restore" options with it.
5010 let dorestore= 0
5011 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005012 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005013" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005014 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005015
5016 " handle g:Netrw_funcref -- call external-to-netrw functions
5017 " This code will handle g:Netrw_funcref as an individual function reference
5018 " or as a list of function references. It will ignore anything that's not
5019 " a function reference. See :help Funcref for information about function references.
5020 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005021" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005022 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005023" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005024 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005025 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005026" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005027 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005028 if type(Fncref) == 2
5029 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005030 endif
5031 endfor
5032 endif
5033 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005034 endif
5035
5036 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005037 " ----------------------------------------------------
5038 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5039 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005040" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005041 let dirname = newdir
5042 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005043 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005044 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005045
5046 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005047 " ---------------------------------------------
5048 " NetrwBrowseChgDir: refresh the directory list {{{3
5049 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005050" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005051 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005052 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005053
5054 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005055 " --------------------------------------
5056 " NetrwBrowseChgDir: go up one directory {{{3
5057 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005058" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005059
5060 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5061 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005062" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5063" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005064 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005065 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005066 endif
5067
5068 if has("amiga")
5069 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005070" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005071 if a:islocal
5072 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5073 let dirname= substitute(dirname,'/$','','')
5074 else
5075 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5076 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005077" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005078
Nir Lichtman1e34b952024-05-08 19:19:34 +02005079 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005080 " windows
5081 if a:islocal
5082 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5083 if dirname == ""
5084 let dirname= '/'
5085 endif
5086 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005087 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005088 endif
5089 if dirname =~ '^\a:$'
5090 let dirname= dirname.'/'
5091 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005092" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005093
Bram Moolenaar446cb832008-06-24 21:56:24 +00005094 else
5095 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005096" 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 +00005097 if a:islocal
5098 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5099 if dirname == ""
5100 let dirname= '/'
5101 endif
5102 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005103 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005104 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005105" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005106 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005107 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005108 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005109
5110 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005111 " --------------------------------------
5112 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5113 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005114" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005115 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5116" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005117 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005118 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005119" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5120 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005121 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005122 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005123" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005124 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005125 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005126" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005127
5128 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005129" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005130 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005131" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005132 let haskey= 1
5133 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005134" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005135 endif
5136
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005137 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005138" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005139 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005140 if has_key(w:netrw_treedict,treedir."/")
5141 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005142" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005143 let haskey = 1
5144 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005145" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005146 endif
5147 endif
5148
5149 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005150" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005151 if !haskey && treedir =~ '/$'
5152 let treedir= substitute(treedir,'/$','','')
5153 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005154" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005155 let haskey = 1
5156 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005157" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005158 endif
5159 endif
5160
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005161" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005162 if haskey
5163 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005164" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005165 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005166" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5167" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005168 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005169 else
5170 " go down one directory
5171 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005172" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5173" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005174 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005175 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005176" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005177 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005178
5179 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005180 " ----------------------------------------
5181 " NetrwBrowseChgDir: Go down one directory {{{3
5182 " ----------------------------------------
5183 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005184" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005185 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005186 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005187 endif
5188
Bram Moolenaar97d62492012-11-15 21:28:22 +01005189 " --------------------------------------
5190 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5191 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005192 if dorestore
5193 " dorestore is zero'd when a local file was hidden or bufhidden;
5194 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005195" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005196 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005197" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005198" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005199 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005200 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005201" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005202 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005203" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5204" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005205 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005206" 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 +02005207 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005208" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5209" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005210 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005211" 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 +02005212 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005213 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005214 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005215 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005216
Bram Moolenaar446cb832008-06-24 21:56:24 +00005217" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5218 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005219endfun
5220
5221" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005222" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5223" for thin, long, and wide: cursor placed just after banner
5224" for tree, keeps cursor on current filename
5225fun! s:NetrwBrowseUpDir(islocal)
5226" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005227 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5228 " this test needed because occasionally this function seems to be incorrectly called
5229 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005230 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005231 " directories.
5232" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5233 return
5234 endif
5235
Bram Moolenaara6878372014-03-22 21:02:50 +01005236 norm! 0
5237 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005238" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005239 let curline= getline(".")
5240 let swwline= winline() - 1
5241 if exists("w:netrw_treetop")
5242 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005243 elseif exists("b:netrw_curdir")
5244 let w:netrw_treetop= b:netrw_curdir
5245 else
5246 let w:netrw_treetop= getcwd()
5247 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005248 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005249 let curfile = getline(".")
5250 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005251 if a:islocal
5252 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5253 else
5254 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5255 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005256" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5257" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5258 if w:netrw_treetop == '/'
5259 keepj call search('^\M'.curfile,"w")
5260 elseif curfile == '../'
5261 keepj call search('^\M'.curfile,"wb")
5262 else
5263" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5264 while 1
5265 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5266 let treepath= s:NetrwTreePath(w:netrw_treetop)
5267" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5268 if treepath == curpath
5269 break
5270 endif
5271 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005272 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005273
Bram Moolenaara6878372014-03-22 21:02:50 +01005274 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005275" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005276 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005277 if exists("b:netrw_curdir")
5278 let curdir= b:netrw_curdir
5279 else
5280 let curdir= expand(getcwd())
5281 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005282 if a:islocal
5283 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5284 else
5285 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5286 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005287 call s:RestorePosn(s:netrw_posn)
5288 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005289 let curdir= '\<'. escape(curdir, '~'). '/'
5290 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005291 endif
5292" call Dret("s:NetrwBrowseUpDir")
5293endfun
5294
5295" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005296" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005297" given filename; typically this means given their extension.
5298" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005299fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005300 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005301" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005302
Bram Moolenaar91359012019-11-30 17:57:03 +01005303 if a:remote == 0 && isdirectory(a:fname)
5304 " if its really just a local directory, then do a "gf" instead
5305" call Decho("remote≡0 and a:fname<".a:fname."> ".(isdirectory(a:fname)? "is a directory" : "is not a directory"),'~'.expand("<slnum>"))
Bram Moolenaar29634562020-01-09 21:46:04 +01005306" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5307 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005308" call Dret("netrw#BrowseX")
5309 return
5310 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5311 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5312" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5313" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5314" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5315" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5316 norm! gf
5317" call Dret("netrw#BrowseX")
5318 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005319 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005320" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005321
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005322 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5323 let remote = a:remote
5324 else
5325 let remote = 0
5326 endif
5327
Bram Moolenaar97d62492012-11-15 21:28:22 +01005328 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005329 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005330" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005331
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005332 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5333 let awkeep = &aw
5334 set noaw
5335
Bram Moolenaar5c736222010-01-06 20:54:52 +01005336 " special core dump handler
5337 if a:fname =~ '/core\(\.\d\+\)\=$'
5338 if exists("g:Netrw_corehandler")
5339 if type(g:Netrw_corehandler) == 2
5340 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005341" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005342 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005343 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005344 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005345" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005346 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005347 if type(Fncref) == 2
5348 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005349 endif
5350 endfor
5351 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005352" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005353 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005354 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005355 let &aw= awkeep
5356" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005357 return
5358 endif
5359 endif
5360
Bram Moolenaar446cb832008-06-24 21:56:24 +00005361 " set up the filename
5362 " (lower case the extension, make a local copy of a remote file)
5363 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005364 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005365 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005366 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005367 if exten =~ "[\\/]"
5368 let exten= ""
5369 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005370" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005371
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005372 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005373 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005374" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005375 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005376 call netrw#NetRead(3,a:fname)
5377 " attempt to rename tempfile
5378 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005379 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005380" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5381" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005382 if s:netrw_tmpfile != newname && newname != ""
5383 if rename(s:netrw_tmpfile,newname) == 0
5384 " renaming succeeded
5385" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5386 let fname= newname
5387 else
5388 " renaming failed
5389" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5390 let fname= s:netrw_tmpfile
5391 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005392 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005393 let fname= s:netrw_tmpfile
5394 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005395 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005396" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005397 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005398 " special ~ handler for local
5399 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005400" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5401 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005402 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005403 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005404" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5405" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005406
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005407 " set up redirection (avoids browser messages)
5408 " by default, g:netrw_suppress_gx_mesg is true
5409 if g:netrw_suppress_gx_mesg
5410 if &srr =~ "%s"
Nir Lichtman1e34b952024-05-08 19:19:34 +02005411 if has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005412 let redir= substitute(&srr,"%s","nul","")
5413 else
5414 let redir= substitute(&srr,"%s","/dev/null","")
5415 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005416 elseif has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005417 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005418 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005419 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005420 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005421 else
5422 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005423 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005424" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005425
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005426 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005427 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005428" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005429 if g:netrw_browsex_viewer =~ '\s'
5430 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5431 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5432 let oviewer = ''
5433 let cnt = 1
5434 while !executable(viewer) && viewer != oviewer
5435 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5436 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5437 let cnt = cnt + 1
5438 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005439" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005440 endwhile
5441 else
5442 let viewer = g:netrw_browsex_viewer
5443 let viewopt = ""
5444 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005445" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005446 endif
5447
5448 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005449" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005450 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005451" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005452 let ret= netrwFileHandlers#Invoke(exten,fname)
5453
5454 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005455" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005456 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005457 let ret= v:shell_error
5458
Nir Lichtman1e34b952024-05-08 19:19:34 +02005459 elseif has("win32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005460" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005461 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005462 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005463 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005464 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005465 else
5466 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5467 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005468 let ret= v:shell_error
5469
Bram Moolenaar97d62492012-11-15 21:28:22 +01005470 elseif has("win32unix")
5471 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005472" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005473 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005474" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005475 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005476 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005477" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005478 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005479 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005480" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005481 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005482 else
5483 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5484 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005485 let ret= v:shell_error
5486
Bram Moolenaar85850f32019-07-19 22:05:51 +02005487 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005488" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5489 if a:fname =~ '^https\=://'
5490 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5491 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005492" call Decho("fname<".fname.">")
5493" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005494 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5495
5496 else
5497 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5498 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005499 let ret= v:shell_error
5500
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005501 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5502" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5503 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5504 let ret= v:shell_error
5505
5506 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5507" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5508 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5509 let ret= v:shell_error
5510
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005511 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005512" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005513 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005514 let ret= v:shell_error
5515
5516 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005517" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005518 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005519 let ret= v:shell_error
5520
5521 else
5522 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005523" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005524 let ret= netrwFileHandlers#Invoke(exten,fname)
5525 endif
5526
5527 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5528 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005529" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005530 let ret= netrwFileHandlers#Invoke(exten,fname)
5531 endif
5532
Bram Moolenaarc236c162008-07-13 17:41:49 +00005533 " restoring redraw! after external file handlers
5534 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005535
5536 " cleanup: remove temporary file,
5537 " delete current buffer if success with handler,
5538 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005539 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005540 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005541" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005542"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005543" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005544" endif
5545
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005546 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005547 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005548 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005549 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005550 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005551 if use_ctrlo
5552 exe "sil! NetrwKeepj norm! \<c-o>"
5553 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005554 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005555" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005556 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005557 let @@ = ykeep
5558 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005559
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005560" call Dret("netrw#BrowseX")
5561endfun
5562
5563" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005564" netrw#GX: gets word under cursor for gx support {{{2
5565" See also: netrw#BrowseXVis
5566" netrw#BrowseX
5567fun! netrw#GX()
5568" call Dfunc("netrw#GX()")
5569 if &ft == "netrw"
5570 let fname= s:NetrwGetWord()
5571 else
5572 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5573 endif
5574" call Dret("netrw#GX <".fname.">")
5575 return fname
5576endfun
5577
5578" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005579" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5580fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005581 let dict={}
5582 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005583 norm! gv"ay
5584 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005585 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005586 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005587endfun
5588
5589" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005590" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5591" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5592" to become an unlisted buffer, so in that case don't bwipe it.
5593fun! s:NetrwBufRename(newname)
5594" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5595" call Dredir("ls!","s:NetrwBufRename (before rename)")
5596 let oldbufname= bufname(bufnr("%"))
5597" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5598
5599 if oldbufname != a:newname
5600" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5601 let b:junk= 1
5602" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5603 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005604" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005605 let oldbufnr= bufnr(oldbufname)
5606" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5607" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5608 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5609" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5610 exe "bwipe! ".oldbufnr
5611" else " Decho
5612" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005613" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5614" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5615" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005616 endif
5617" call Dredir("ls!","s:NetrwBufRename (after rename)")
5618" else " Decho
5619" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5620 endif
5621
5622" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5623endfun
5624
5625" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005626" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005627fun! netrw#CheckIfRemote(...)
5628" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5629 if a:0 > 0
5630 let curfile= a:1
5631 else
5632 let curfile= expand("%")
5633 endif
5634" call Decho("curfile<".curfile.">")
5635 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005636" call Dret("netrw#CheckIfRemote 1")
5637 return 1
5638 else
5639" call Dret("netrw#CheckIfRemote 0")
5640 return 0
5641 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005642endfun
5643
5644" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005645" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5646fun! s:NetrwChgPerm(islocal,curdir)
5647" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005648 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005649 call inputsave()
5650 let newperm= input("Enter new permission: ")
5651 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005652 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5653 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5654" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005655 call system(chgperm)
5656 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005657 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005658 endif
5659 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005660 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005661 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005662 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005663" call Dret("s:NetrwChgPerm")
5664endfun
5665
5666" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005667" s:CheckIfKde: checks if kdeinit is running {{{2
5668" Returns 0: kdeinit not running
5669" 1: kdeinit is running
5670fun! s:CheckIfKde()
5671" call Dfunc("s:CheckIfKde()")
5672 " seems kde systems often have gnome-open due to dependencies, even though
5673 " gnome-open's subsidiary display tools are largely absent. Kde systems
5674 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5675 if !exists("s:haskdeinit")
5676 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005677 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005678 if v:shell_error
5679 let s:haskdeinit = 0
5680 endif
5681 else
5682 let s:haskdeinit= 0
5683 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005684" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005685 endif
5686
5687" call Dret("s:CheckIfKde ".s:haskdeinit)
5688 return s:haskdeinit
5689endfun
5690
5691" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005692" s:NetrwClearExplore: clear explore variables (if any) {{{2
5693fun! s:NetrwClearExplore()
5694" call Dfunc("s:NetrwClearExplore()")
5695 2match none
5696 if exists("s:explore_match") |unlet s:explore_match |endif
5697 if exists("s:explore_indx") |unlet s:explore_indx |endif
5698 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5699 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5700 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5701 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5702 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5703 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5704 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5705" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005706" call Dret("s:NetrwClearExplore")
5707endfun
5708
5709" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005710" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5711fun! s:NetrwEditBuf(bufnum)
5712" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5713 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5714" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5715 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5716 else
5717" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005718 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005719 endif
5720" call Dret("s:NetrwEditBuf")
5721endfun
5722
5723" ---------------------------------------------------------------------
5724" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5725" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5726fun! s:NetrwEditFile(cmd,opt,fname)
5727" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5728 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5729" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5730 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5731 else
5732" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005733 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5734 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5735 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005736 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5737 endif
5738" call Dret("s:NetrwEditFile")
5739endfun
5740
5741" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005742" s:NetrwExploreListUniq: {{{2
5743fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005744" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005745
5746 " this assumes that the list is already sorted
5747 let newexplist= []
5748 for member in a:explist
5749 if !exists("uniqmember") || member != uniqmember
5750 let uniqmember = member
5751 let newexplist = newexplist + [ member ]
5752 endif
5753 endfor
5754
Bram Moolenaar15146672011-10-20 22:22:38 +02005755" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005756 return newexplist
5757endfun
5758
5759" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005760" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5761fun! s:NetrwForceChgDir(islocal,newdir)
5762" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005763 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005764 if a:newdir !~ '/$'
5765 " ok, looks like force is needed to get directory-style treatment
5766 if a:newdir =~ '@$'
5767 let newdir= substitute(a:newdir,'@$','/','')
5768 elseif a:newdir =~ '[*=|\\]$'
5769 let newdir= substitute(a:newdir,'.$','/','')
5770 else
5771 let newdir= a:newdir.'/'
5772 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005773" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005774 else
5775 " should already be getting treatment as a directory
5776 let newdir= a:newdir
5777 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005778 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005779 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005780 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005781" call Dret("s:NetrwForceChgDir")
5782endfun
5783
5784" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005785" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005786" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5787" expr : this is the expression to follow the directory. Will use s:ComposePath()
5788" pare =1: remove the current directory from the resulting glob() filelist
5789" =0: leave the current directory in the resulting glob() filelist
5790fun! s:NetrwGlob(direntry,expr,pare)
5791" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005792 if netrw#CheckIfRemote()
5793 keepalt 1sp
5794 keepalt enew
5795 let keep_liststyle = w:netrw_liststyle
5796 let w:netrw_liststyle = s:THINLIST
5797 if s:NetrwRemoteListing() == 0
5798 keepj keepalt %s@/@@
5799 let filelist= getline(1,$)
5800 q!
5801 else
5802 " remote listing error -- leave treedict unchanged
5803 let filelist= w:netrw_treedict[a:direntry]
5804 endif
5805 let w:netrw_liststyle= keep_liststyle
5806 else
Christian Brabandt14879472024-06-13 21:25:35 +02005807 let path= s:ComposePath(fnameescape(a:direntry),a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005808 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005809 " escape [ so it is not detected as wildcard character, see :h wildcard
5810 let path= substitute(path, '[', '[[]', 'g')
5811 endif
5812 if v:version > 704 || (v:version == 704 && has("patch656"))
5813 let filelist= glob(path,0,1,1)
5814 else
5815 let filelist= glob(path,0,1)
5816 endif
5817 if a:pare
5818 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5819 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005820 endif
5821" call Dret("s:NetrwGlob ".string(filelist))
5822 return filelist
5823endfun
5824
5825" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005826" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5827fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005828" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005829 if a:newfile =~ '[/@*=|\\]$'
5830 let newfile= substitute(a:newfile,'.$','','')
5831 else
5832 let newfile= a:newfile
5833 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005834 if a:islocal
5835 call s:NetrwBrowseChgDir(a:islocal,newfile)
5836 else
5837 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5838 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005839" call Dret("s:NetrwForceFile")
5840endfun
5841
5842" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005843" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5844" and switches the hiding mode. The actual hiding is done by
5845" s:NetrwListHide().
5846" g:netrw_hide= 0: show all
5847" 1: show not-hidden files
5848" 2: show hidden files only
5849fun! s:NetrwHide(islocal)
5850" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005851 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005852 let svpos= winsaveview()
5853" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005854
5855 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005856" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5857" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005858
5859 " hide the files in the markfile list
5860 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005861" 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 +00005862 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5863 " remove fname from hiding list
5864 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5865 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5866 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005867" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005868 else
5869 " append fname to hiding list
5870 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5871 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5872 else
5873 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5874 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005875" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005876 endif
5877 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005878 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005879 let g:netrw_hide= 1
5880
5881 else
5882
5883 " switch between show-all/show-not-hidden/show-hidden
5884 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005885 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005886 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005887 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005888 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005889" call Dret("NetrwHide")
5890 return
5891 endif
5892 endif
5893
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005894 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005895" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5896 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005897 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005898" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005899endfun
5900
5901" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005902" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5903fun! s:NetrwHideEdit(islocal)
5904" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5905
5906 let ykeep= @@
5907 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005908 let svpos= winsaveview()
5909" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005910
5911 " get new hiding list from user
5912 call inputsave()
5913 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5914 call inputrestore()
5915 let g:netrw_list_hide= newhide
5916" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5917
5918 " refresh the listing
5919 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5920
5921 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005922" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5923 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005924 let @@= ykeep
5925
5926" call Dret("NetrwHideEdit")
5927endfun
5928
5929" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005930" s:NetrwHidden: invoked by "gh" {{{2
5931fun! s:NetrwHidden(islocal)
5932" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005933 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005934 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005935 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005936" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005937
5938 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005939 " remove .file pattern from hiding list
5940" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005941 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005942 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005943" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005944 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5945 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005946" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005947 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5948 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005949 if g:netrw_list_hide =~ '^,'
5950 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5951 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005952
5953 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005954 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005955" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5956 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005957 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005958" call Dret("s:NetrwHidden")
5959endfun
5960
5961" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005962" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5963fun! s:NetrwHome()
5964 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005965 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005966 else
5967 " go to vim plugin home
5968 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005969 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005970 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005971 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005972 let home= basehome."/.vim"
5973 break
5974 endif
5975 endfor
5976 if home == ""
5977 " just pick the first directory
5978 let home= substitute(&rtp,',.*$','','')
5979 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005980 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005981 let home= substitute(home,'/','\\','g')
5982 endif
5983 endif
5984 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005985 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005986" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005987 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005988" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005989 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005990 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005991" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005992 call mkdir(home)
5993 endif
5994 endif
5995 let g:netrw_home= home
5996 return home
5997endfun
5998
5999" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006000" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
6001fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006002 if exists("s:netrwdrag")
6003 return
6004 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006005 if &ft != "netrw"
6006 return
6007 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006008" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006009
Bram Moolenaar97d62492012-11-15 21:28:22 +01006010 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006011 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02006012 while getchar(0) != 0
6013 "clear the input stream
6014 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006015 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006016 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006017 let mouse_lnum = v:mouse_lnum
6018 let wlastline = line('w$')
6019 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006020" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6021" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006022 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6023 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006024 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006025" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6026 return
6027 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006028 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006029 " 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 +01006030 " without this test when its disabled.
6031 " 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 +01006032" 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 +01006033 if v:mouse_col > virtcol('.')
6034 let @@= ykeep
6035" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6036 return
6037 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006038
Bram Moolenaar446cb832008-06-24 21:56:24 +00006039 if a:islocal
6040 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006041 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006042 endif
6043 else
6044 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006045 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006046 endif
6047 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006048 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006049" call Dret("s:NetrwLeftmouse")
6050endfun
6051
6052" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006053" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6054fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006055 if &ft != "netrw"
6056 return
6057 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006058" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6059 call s:NetrwMarkFileTgt(a:islocal)
6060" call Dret("s:NetrwCLeftmouse")
6061endfun
6062
6063" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006064" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6065" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006066" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006067" a:islocal=2 : <c-r> used, remote
6068" a:islocal=3 : <c-r> used, local
6069fun! s:NetrwServerEdit(islocal,fname)
6070" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6071 let islocal = a:islocal%2 " =0: remote =1: local
6072 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006073" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006074
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006075 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006076 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006077 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006078" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006079 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006080 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006081 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6082 unlet s:netrw_browse_split_{winnr()}
6083 endif
6084 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6085" call Dret("s:NetrwServerEdit")
6086 return
6087 endif
6088
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006089" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006090 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006091" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006092
6093 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006094" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006095 let srvrname = g:netrw_browse_split[0]
6096 let tabnum = g:netrw_browse_split[1]
6097 let winnum = g:netrw_browse_split[2]
6098
6099 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006100" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006101
6102 if !ctrlr
6103 " user must have closed the server window and the user did not use <c-r>, but
6104 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006105" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006106 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006107 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006108 endif
6109 let g:netrw_browse_split= 0
6110 if exists("s:netrw_browse_split_".winnr())
6111 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6112 endif
6113 call s:NetrwBrowseChgDir(islocal,a:fname)
6114" call Dret("s:NetrwServerEdit")
6115 return
6116
6117 elseif has("win32") && executable("start")
6118 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006119" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006120 call system("start gvim --servername ".srvrname)
6121
6122 else
6123 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006124" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006125 call system("gvim --servername ".srvrname)
6126 endif
6127 endif
6128
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006129" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006130 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6131 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006132 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006133
6134 else
6135
6136 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6137
6138 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006139" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006140 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006141 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006142 endif
6143 let g:netrw_browse_split= 0
6144 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6145" call Dret("s:NetrwServerEdit")
6146 return
6147
6148 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006149" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006150 if has("win32") && executable("start")
6151 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006152" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006153 call system("start gvim --servername ".g:netrw_servername)
6154 else
6155 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006156" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006157 call system("gvim --servername ".g:netrw_servername)
6158 endif
6159 endif
6160 endif
6161
6162 while 1
6163 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006164" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6165 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006166 break
6167 catch /^Vim\%((\a\+)\)\=:E241/
6168 sleep 200m
6169 endtry
6170 endwhile
6171
6172 if exists("g:netrw_browse_split")
6173 if type(g:netrw_browse_split) != 3
6174 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6175 endif
6176 unlet g:netrw_browse_split
6177 endif
6178 let g:netrw_browse_split= [g:netrw_servername,1,1]
6179 endif
6180
6181 else
6182 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6183 endif
6184
6185" call Dret("s:NetrwServerEdit")
6186endfun
6187
6188" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006189" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6190fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006191 if &ft != "netrw"
6192 return
6193 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006194" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006195
Bram Moolenaar8d043172014-01-23 14:24:41 +01006196 let s:ngw= s:NetrwGetWord()
6197 call s:NetrwMarkFile(a:islocal,s:ngw)
6198
6199" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006200endfun
6201
6202" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006203" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6204" Used to mark multiple files.
6205fun! s:NetrwSLeftdrag(islocal)
6206" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6207 if !exists("s:netrwdrag")
6208 let s:netrwdrag = winnr()
6209 if a:islocal
6210 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006211 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006212 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006213 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006214 endif
6215 let ngw = s:NetrwGetWord()
6216 if !exists("s:ngw") || s:ngw != ngw
6217 call s:NetrwMarkFile(a:islocal,ngw)
6218 endif
6219 let s:ngw= ngw
6220" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6221endfun
6222
6223" ---------------------------------------------------------------------
6224" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6225fun! s:NetrwSLeftrelease(islocal)
6226" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6227 if exists("s:netrwdrag")
6228 nunmap <s-leftrelease>
6229 let ngw = s:NetrwGetWord()
6230 if !exists("s:ngw") || s:ngw != ngw
6231 call s:NetrwMarkFile(a:islocal,ngw)
6232 endif
6233 if exists("s:ngw")
6234 unlet s:ngw
6235 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006236 unlet s:netrwdrag
6237 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006238" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006239endfun
6240
6241" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006242" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6243" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006244fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006245" 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 +02006246" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006247 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006248
6249 " 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 +02006250 " How-it-works: take the hiding command, convert it into a range.
6251 " Duplicate characters don't matter.
6252 " Remove all such characters from the '/~@#...890' string.
6253 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006254" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006255 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006256 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006257" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006258
6259 while listhide != ""
6260 if listhide =~ ','
6261 let hide = substitute(listhide,',.*$','','e')
6262 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6263 else
6264 let hide = listhide
6265 let listhide = ""
6266 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006267" 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 +01006268 if g:netrw_sort_by =~ '^[ts]'
6269 if hide =~ '^\^'
6270" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6271 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6272 elseif hide =~ '^\\(\^'
6273 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6274 endif
6275" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6276 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006277
6278 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006279" 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 +00006280 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006281" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006282 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006283 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006284" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006285 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006286 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006287" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006288 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006289
Bram Moolenaar446cb832008-06-24 21:56:24 +00006290 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006291 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006292" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006293 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006294" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006295 endif
6296
Bram Moolenaaradc21822011-04-01 18:03:16 +02006297 " remove any blank lines that have somehow remained.
6298 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006299 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006300
Bram Moolenaar97d62492012-11-15 21:28:22 +01006301 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006302" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006303endfun
6304
6305" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006306" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006307" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006308fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006309" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006310
Bram Moolenaar97d62492012-11-15 21:28:22 +01006311 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006312 " get name of new directory from user. A bare <CR> will skip.
6313 " if its currently a directory, also request will be skipped, but with
6314 " a message.
6315 call inputsave()
6316 let newdirname= input("Please give directory name: ")
6317 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006318" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006319
6320 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006321 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006322" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006323 return
6324 endif
6325
6326 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006327" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006328
6329 " Local mkdir:
6330 " sanity checks
6331 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006332" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6333 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006334 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006335 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006336 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006337 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006338" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006339 return
6340 endif
6341 if s:FileReadable(fullnewdir)
6342 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006343 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006344 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006345 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006346" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006347 return
6348 endif
6349
6350 " requested new local directory is neither a pre-existing file or
6351 " directory, so make it!
6352 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006353 if has("unix")
6354 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6355 else
6356 call mkdir(fullnewdir,"p")
6357 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006358 else
6359 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006360 if s:NetrwLcd(b:netrw_curdir)
6361" call Dret("s:NetrwMakeDir : lcd failure")
6362 return
6363 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006364" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006365 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006366 if v:shell_error != 0
6367 let @@= ykeep
6368 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 +01006369" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006370 return
6371 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006372 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006373" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006374 if s:NetrwLcd(netrw_origdir)
6375" call Dret("s:NetrwBrowse : lcd failure")
6376 return
6377 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006378 endif
6379 endif
6380
6381 if v:shell_error == 0
6382 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006383" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006384 let svpos= winsaveview()
6385" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006386 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006387" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6388 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006389 elseif !exists("g:netrw_quiet")
6390 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6391 endif
6392" redraw!
6393
6394 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006395 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006396" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006397 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6398 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006399 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006400 if v:shell_error == 0
6401 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006402 let svpos= winsaveview()
6403" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006404 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006405" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6406 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006407 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006408 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006409 endif
6410" redraw!
6411
6412 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006413 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006414 let svpos= winsaveview()
6415" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006416" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006417 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006418" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006419 let remotepath= b:netrw_fname
6420 else
6421 let remotepath= ""
6422 endif
6423 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006424 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006425" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6426 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006427
Bram Moolenaar446cb832008-06-24 21:56:24 +00006428 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006429 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006430 let svpos= winsaveview()
6431" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006432" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006433 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006434" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006435 let remotepath= b:netrw_fname
6436 else
6437 let remotepath= ""
6438 endif
6439 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006440 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006441" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6442 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006443 endif
6444
Bram Moolenaar97d62492012-11-15 21:28:22 +01006445 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006446" call Dret("s:NetrwMakeDir")
6447endfun
6448
6449" ---------------------------------------------------------------------
6450" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6451fun! s:TreeSqueezeDir(islocal)
6452" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6453 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6454 " its a tree-listing style
6455 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006456 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006457 let depth = strchars(substitute(curdepth,' ','','g'))
6458 let srch = -1
6459" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6460" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006461" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006462" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6463 if depth >= 2
6464 NetrwKeepj norm! 0
6465 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6466 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6467" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6468" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6469 elseif depth == 1
6470 NetrwKeepj norm! 0
6471 let treedepthchr= substitute(s:treedepthstring,' ','','')
6472 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6473" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6474 endif
6475 if srch > 0
6476" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6477 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6478 exe srch
6479 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006480 endif
6481" call Dret("s:TreeSqueezeDir")
6482endfun
6483
6484" ---------------------------------------------------------------------
6485" s:NetrwMaps: {{{2
6486fun! s:NetrwMaps(islocal)
6487" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6488
Bram Moolenaar85850f32019-07-19 22:05:51 +02006489 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006490 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006491" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006492 if !hasmapto("<Plug>NetrwReturn")
6493 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006494" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006495 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6496 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006497" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006498 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6499 endif
6500 endif
6501 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006502" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006503 endif
6504
Bram Moolenaar85850f32019-07-19 22:05:51 +02006505 " generate default <Plug> maps {{{3
6506 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006507 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006508 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6509 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6510 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6511 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6512 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6513 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6514 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6515 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6516 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6517 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6518" ---------------------------------------------------------------------
6519" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6520" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6521" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6522" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6523" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6524" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6525" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6526" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6527" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6528" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6529" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6530" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6531" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6532" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6533" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6534" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6535" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6536" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6537" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6538" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6539" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6540" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6541" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6542" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6543" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6544" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6545" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6546" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6547" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6548" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6549" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6550" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6551" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6552" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6553" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6554" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6555" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6556" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6557" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6558" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6559" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6560" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6561" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6562" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6563" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6564" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6565" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6566
Bram Moolenaara6878372014-03-22 21:02:50 +01006567 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006568" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006569 " local normal-mode maps {{{3
6570 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6571 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6572 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6573 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6574 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6575 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6576 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6577 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6578 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6579 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6580 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6581" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006582 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6583 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6584 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006585 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006586 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006587 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6588 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6589 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6590 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006591 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6592 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6593 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6594 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6595 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6596 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6597 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6598 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6599 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6600 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6601 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6602 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6603 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006604 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006605 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006606 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6607 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6608 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6609 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6610 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006611 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006612 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006613 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6614 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006615 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6616 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6617 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006618 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006619 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006620 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6621 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006622 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006623 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006624 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6625 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6626 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006627 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6628 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006629
6630 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 +01006631 if !hasmapto('<Plug>NetrwHideEdit')
6632 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006633 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006634 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006635 if !hasmapto('<Plug>NetrwRefresh')
6636 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006637 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006638 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 +01006639 if s:didstarstar || !mapcheck("<s-down>","n")
6640 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006641 endif
6642 if s:didstarstar || !mapcheck("<s-up>","n")
6643 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006644 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006645 if !hasmapto('<Plug>NetrwTreeSqueeze')
6646 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006647 endif
6648 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006649 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6650 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006651 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6652 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6653 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6654 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6655 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6656 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6657 imap <buffer> <leftmouse> <Plug>ILeftmouse
6658 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006659 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6660 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6661 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6662 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6663 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006664 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006665 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6666 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006667 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006668 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6669 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6670 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6671 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6672 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6673 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6674 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006675 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6676
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006677 " support user-specified maps
6678 call netrw#UserMaps(1)
6679
Bram Moolenaar85850f32019-07-19 22:05:51 +02006680 else
6681 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006682" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006683 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006684 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6685 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6686 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6687 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6688 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6689 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6690 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6691 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6692 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6693 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6694 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6695" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006696 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6697 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6698 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6699 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6700 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6701 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6702 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6703 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006704 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006705 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006706 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6707 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6708 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6709 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6710 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6711 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6712 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6713 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6714 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6715 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6716 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006717 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006718 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006719 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6720 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6721 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6722 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6723 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006724 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6725 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6726 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6727 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006728 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006729 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6730 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006731 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006732 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 +01006733 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6734 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6735 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6736 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6737 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6738 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6739 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6740 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6741 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006742 if !hasmapto('<Plug>NetrwHideEdit')
6743 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006744 endif
6745 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6746 if !hasmapto('<Plug>NetrwRefresh')
6747 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006748 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006749 if !hasmapto('<Plug>NetrwTreeSqueeze')
6750 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006751 endif
6752 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006753
6754 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006755 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006756
6757 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6758 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006759 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006760 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006761 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006762 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006763 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006764 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006765 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006766 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006767 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006768 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006769 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6770 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6771 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006772 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006773 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006774 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6775 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006776 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006777 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6778 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6779 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6780 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6781 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6782 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6783 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006784 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006785
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006786 " support user-specified maps
6787 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006788 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006789
6790" call Dret("s:NetrwMaps")
6791endfun
6792
6793" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006794" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006795" If -buffer, the command is only available from within netrw buffers
6796" Otherwise, the command is available from any window, so long as netrw
6797" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006798fun! s:NetrwCommands(islocal)
6799" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6800
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006801 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6802 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006803 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 +01006804 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006805 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006806 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006807 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006808 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006809 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006810
6811" call Dret("s:NetrwCommands")
6812endfun
6813
6814" ---------------------------------------------------------------------
6815" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6816" glob()ing only works with local files
6817fun! s:NetrwMarkFiles(islocal,...)
6818" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006819 let curdir = s:NetrwGetCurdir(a:islocal)
6820 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006821 while i <= a:0
6822 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006823 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006824 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006825 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006826 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006827 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006828 else
6829 let mffiles= [a:{i}]
6830 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006831" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006832 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006833" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006834 call s:NetrwMarkFile(a:islocal,mffile)
6835 endfor
6836 let i= i + 1
6837 endwhile
6838" call Dret("s:NetrwMarkFiles")
6839endfun
6840
6841" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006842" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006843fun! s:NetrwMarkTarget(...)
6844" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6845 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006846 let curdir = s:NetrwGetCurdir(1)
6847 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006848 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006849 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6850 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006851 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006852" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006853 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006854 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6855 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006856 let svpos = winsaveview()
6857" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006858 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006859" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6860 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006861" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006862endfun
6863
6864" ---------------------------------------------------------------------
6865" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6866" mark and unmark files. If a markfile list exists,
6867" then the rename and delete functions will use it instead
6868" of whatever may happen to be under the cursor at that
6869" moment. When the mouse and gui are available,
6870" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006871"
6872" Creates two lists
6873" s:netrwmarkfilelist -- holds complete paths to all marked files
6874" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6875"
6876" Creates a marked file match string
6877" s:netrwmarfilemtch_# -- used with 2match to display marked files
6878"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006879" Creates a buffer version of islocal
6880" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006881fun! s:NetrwMarkFile(islocal,fname)
6882" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006883" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006884
6885 " sanity check
6886 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006887" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006888 return
6889 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006890 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006891
Bram Moolenaar97d62492012-11-15 21:28:22 +01006892 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006893 let curbufnr= bufnr("%")
yasudac18a9d52024-09-19 18:09:51 +02006894 let leader= '\%(^\|\s\)\zs'
Bram Moolenaara6878372014-03-22 21:02:50 +01006895 if a:fname =~ '\a$'
6896 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6897 else
6898 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6899 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006900
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006901 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006902 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006903" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6904" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6905" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006906 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006907
6908 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006909 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006910" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006911 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006912 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006913
6914 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006915 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006916" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006917 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6918 if s:netrwmarkfilelist_{curbufnr} == []
6919 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006920" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006921 call s:NetrwUnmarkList(curbufnr,curdir)
6922 else
6923 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006924" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006925 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006926 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006927 for fname in s:netrwmarkfilelist_{curbufnr}
6928 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006929 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006930 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006931 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006932 endif
6933 let first= 0
6934 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006935" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006936 endif
6937 endif
6938
6939 else
6940 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006941" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006942
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006943" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006944 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006945 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6946" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006947
6948 " build initial markfile matching pattern
6949 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006950 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006951 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006952 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006953 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006954" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006955 endif
6956
6957 " handle global markfilelist
6958 if exists("s:netrwmarkfilelist")
6959 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6960 if index(s:netrwmarkfilelist,dname) == -1
6961 " append new filename to global markfilelist
6962 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006963" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006964 else
6965 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006966" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6967" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006968 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006969" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006970 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006971" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006972 unlet s:netrwmarkfilelist
6973 endif
6974 endif
6975 else
6976 " initialize new global-directory markfilelist
6977 let s:netrwmarkfilelist= []
6978 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006979" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006980 endif
6981
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006982 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006983 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6984 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6985" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6986 if exists("g:did_drchip_netrwlist_syntax")
6987 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6988 endif
6989 else
6990" " call Decho("2match none",'~'.expand("<slnum>"))
6991 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006992 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006993 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006994 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006995" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6996" 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 +00006997endfun
6998
6999" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007000" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
7001" mA: move the argument list to marked file list (tomflist=1)
7002" Uses the global marked file list
7003fun! s:NetrwMarkFileArgList(islocal,tomflist)
7004" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
7005
7006 let svpos = winsaveview()
7007" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7008 let curdir = s:NetrwGetCurdir(a:islocal)
7009 let curbufnr = bufnr("%")
7010
7011 if a:tomflist
7012 " mA: move argument list to marked file list
7013 while argc()
7014 let fname= argv(0)
7015" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7016 exe "argdel ".fnameescape(fname)
7017 call s:NetrwMarkFile(a:islocal,fname)
7018 endwhile
7019
7020 else
7021 " ma: move marked file list to argument list
7022 if exists("s:netrwmarkfilelist")
7023
7024 " for every filename in the marked list
7025 for fname in s:netrwmarkfilelist
7026" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7027 exe "argadd ".fnameescape(fname)
7028 endfor " for every file in the marked list
7029
7030 " unmark list and refresh
7031 call s:NetrwUnmarkList(curbufnr,curdir)
7032 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7033" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7034 NetrwKeepj call winrestview(svpos)
7035 endif
7036 endif
7037
7038" call Dret("s:NetrwMarkFileArgList")
7039endfun
7040
7041" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007042" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7043" compress/decompress files using the programs
7044" in g:netrw_compress and g:netrw_uncompress,
7045" using g:netrw_compress_suffix to know which to
7046" do. By default:
7047" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007048" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007049fun! s:NetrwMarkFileCompress(islocal)
7050" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007051 let svpos = winsaveview()
7052" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007053 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007054 let curbufnr = bufnr("%")
7055
Bram Moolenaarff034192013-04-24 18:51:19 +02007056 " sanity check
7057 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007058 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007059" call Dret("s:NetrwMarkFileCompress")
7060 return
7061 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007062" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007063
Bram Moolenaar446cb832008-06-24 21:56:24 +00007064 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007065
7066 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007067 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007068 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007069" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007070 if exists("g:netrw_decompress['".sfx."']")
7071 " fname has a suffix indicating that its compressed; apply associated decompression routine
7072 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007073" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007074 let exe= netrw#WinPath(exe)
7075 if a:islocal
7076 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007077 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007078 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007079 call system(exe." ".fname)
7080 if v:shell_error
7081 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007082 endif
7083 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007084 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7085 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007086 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007087
Bram Moolenaarff034192013-04-24 18:51:19 +02007088 endif
7089 unlet sfx
7090
Bram Moolenaar446cb832008-06-24 21:56:24 +00007091 if exists("exe")
7092 unlet exe
7093 elseif a:islocal
7094 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007095 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007096 if v:shell_error
7097 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7098 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007099 else
7100 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007101 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007102 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007103 endfor " for every file in the marked list
7104
Bram Moolenaar446cb832008-06-24 21:56:24 +00007105 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007106 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007107" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7108 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007109 endif
7110" call Dret("s:NetrwMarkFileCompress")
7111endfun
7112
7113" ---------------------------------------------------------------------
7114" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7115" If no marked files, then set up directory as the
7116" target. Currently does not support copying entire
7117" directories. Uses the local-buffer marked file list.
7118" Returns 1=success (used by NetrwMarkFileMove())
7119" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007120fun! s:NetrwMarkFileCopy(islocal,...)
7121" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7122
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007123 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007124 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007125 if b:netrw_curdir !~ '/$'
7126 if !exists("b:netrw_curdir")
7127 let b:netrw_curdir= curdir
7128 endif
7129 let b:netrw_curdir= b:netrw_curdir."/"
7130 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007131
Bram Moolenaarff034192013-04-24 18:51:19 +02007132 " sanity check
7133 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007134 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007135" call Dret("s:NetrwMarkFileCopy")
7136 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007137 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007138" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007139
Bram Moolenaar446cb832008-06-24 21:56:24 +00007140 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007141 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007142" call Dret("s:NetrwMarkFileCopy 0")
7143 return 0
7144 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007145" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007146
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007147 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007148 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007149" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007150 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007151 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7152" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7153 return
7154 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007155
7156 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02007157 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007158 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7159 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007160" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007161 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007162 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7163 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007164" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007165 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007166 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007167 let oldname = a:1
7168 else
7169 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007170" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007171 let s:recursive= 1
7172 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7173 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7174 if ret == 0
7175 break
7176 endif
7177 endfor
7178 unlet s:recursive
7179 call s:NetrwUnmarkList(curbufnr,curdir)
7180" call Dret("s:NetrwMarkFileCopy ".ret)
7181 return ret
7182 endif
7183
7184 call inputsave()
7185 let newname= input("Copy ".oldname." to : ",oldname,"file")
7186 call inputrestore()
7187 if newname == ""
7188" call Dret("s:NetrwMarkFileCopy 0")
7189 return 0
7190 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007191 let args= s:ShellEscape(oldname)
7192 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007193 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007194 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7195 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007196 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007197 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007198 let args= substitute(args,'/','\\','g')
7199 let tgt = substitute(tgt, '/','\\','g')
7200 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007201 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7202 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7203 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7204 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7205" call Decho("args <".args.">",'~'.expand("<slnum>"))
7206" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007207 if isdirectory(s:NetrwFile(args))
7208" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007209 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007210" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007211 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007212 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7213 " contents to a target. One must append the source directory name to the target to get xcopy to
7214 " do the right thing.
7215 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007216" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007217 endif
7218 else
7219 let copycmd= g:netrw_localcopycmd
7220 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007221 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007222 let copycmd = substitute(copycmd,'\s.*$','','')
7223 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007224 let copycmd = netrw#WinPath(copycmd).copycmdargs
7225 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007226 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007227 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007228" call Decho("args <".args.">",'~'.expand("<slnum>"))
7229" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7230" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7231" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007232 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007233 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02007234 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007235 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 +01007236 else
7237 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7238 endif
7239" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007240 return 0
7241 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007242
7243 elseif a:islocal && !s:netrwmftgt_islocal
7244 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007245" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007246 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007247
7248 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007249 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007250" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007251 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007252
7253 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007254 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007255" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007256 let curdir = getcwd()
7257 let tmpdir = s:GetTempfile("")
7258 if tmpdir !~ '/'
7259 let tmpdir= curdir."/".tmpdir
7260 endif
7261 if exists("*mkdir")
7262 call mkdir(tmpdir)
7263 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007264 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007265 if v:shell_error != 0
7266 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 +01007267" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007268 return
7269 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007270 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007271 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007272 if s:NetrwLcd(tmpdir)
7273" call Dret("s:NetrwMarkFileCopy : lcd failure")
7274 return
7275 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007276 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007277 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007278 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007279 if getcwd() == tmpdir
7280 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007281 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007282 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007283 if s:NetrwLcd(curdir)
7284" call Dret("s:NetrwMarkFileCopy : lcd failure")
7285 return
7286 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007287 if delete(tmpdir,"d")
7288 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007289 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007290 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007291 if s:NetrwLcd(curdir)
7292" call Dret("s:NetrwMarkFileCopy : lcd failure")
7293 return
7294 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007295 endif
7296 endif
7297 endif
7298
7299 " -------
7300 " cleanup
7301 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007302" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007303 " remove markings from local buffer
7304 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007305" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7306" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7307" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7308" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7309" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7310" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7311 if exists("s:recursive")
7312" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7313 else
7314" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007315 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007316 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007317 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007318 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007319 else
7320 " refresh local and targets for fast browsing
7321 if !exists("s:recursive")
7322 " remove markings from local buffer
7323" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7324 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7325 endif
7326
7327 " refresh buffers
7328 if s:netrwmftgt_islocal
7329" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7330 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7331 endif
7332 if a:islocal && s:netrwmftgt != curdir
7333" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7334 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7335 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007336 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007337
Bram Moolenaar446cb832008-06-24 21:56:24 +00007338" call Dret("s:NetrwMarkFileCopy 1")
7339 return 1
7340endfun
7341
7342" ---------------------------------------------------------------------
7343" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7344" invoke vim's diff mode on the marked files.
7345" Either two or three files can be so handled.
7346" Uses the global marked file list.
7347fun! s:NetrwMarkFileDiff(islocal)
7348" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7349 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007350
Bram Moolenaarff034192013-04-24 18:51:19 +02007351 " sanity check
7352 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007353 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007354" call Dret("s:NetrwMarkFileDiff")
7355 return
7356 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007357 let curdir= s:NetrwGetCurdir(a:islocal)
7358" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007359
Bram Moolenaara6878372014-03-22 21:02:50 +01007360 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007361 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007362 for fname in s:netrwmarkfilelist
7363 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007364 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007365" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007366 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007367 diffthis
7368 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007369 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007370" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007371 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007372 diffthis
7373 else
7374 break
7375 endif
7376 endfor
7377 call s:NetrwUnmarkList(curbufnr,curdir)
7378 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007379
Bram Moolenaar446cb832008-06-24 21:56:24 +00007380" call Dret("s:NetrwMarkFileDiff")
7381endfun
7382
7383" ---------------------------------------------------------------------
7384" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7385" Uses global markfilelist
7386fun! s:NetrwMarkFileEdit(islocal)
7387" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7388
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007389 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007390 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007391
7392 " sanity check
7393 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007394 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007395" call Dret("s:NetrwMarkFileEdit")
7396 return
7397 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007398" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007399
Bram Moolenaar446cb832008-06-24 21:56:24 +00007400 if exists("s:netrwmarkfilelist_{curbufnr}")
7401 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007402 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007403 " unmark markedfile list
7404" call s:NetrwUnmarkList(curbufnr,curdir)
7405 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007406" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007407 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007408 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007409 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007410
Bram Moolenaar446cb832008-06-24 21:56:24 +00007411" call Dret("s:NetrwMarkFileEdit")
7412endfun
7413
7414" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007415" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007416fun! s:NetrwMarkFileQFEL(islocal,qfel)
7417" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7418 call s:NetrwUnmarkAll()
7419 let curbufnr= bufnr("%")
7420
7421 if !empty(a:qfel)
7422 for entry in a:qfel
7423 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007424" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007425 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007426" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007427 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7428 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7429 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7430 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007431" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007432 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7433 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007434" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007435 endif
7436 endfor
7437 echo "(use me to edit marked files)"
7438 else
7439 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7440 endif
7441
7442" call Dret("s:NetrwMarkFileQFEL")
7443endfun
7444
7445" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007446" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7447" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7448" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7449fun! s:NetrwMarkFileExe(islocal,enbloc)
7450" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007451 let svpos = winsaveview()
7452" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007453 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007454 let curbufnr = bufnr("%")
7455
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007456 if a:enbloc == 0
7457 " individually apply command to files, one at a time
7458 " sanity check
7459 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7460 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7461" call Dret("s:NetrwMarkFileExe")
7462 return
7463 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007464" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007465
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007466 if exists("s:netrwmarkfilelist_{curbufnr}")
7467 " get the command
7468 call inputsave()
7469 let cmd= input("Enter command: ","","file")
7470 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007471" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007472 if cmd == ""
7473" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7474 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007475 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007476
7477 " apply command to marked files, individually. Substitute: filename -> %
7478 " If no %, then append a space and the filename to the command
7479 for fname in s:netrwmarkfilelist_{curbufnr}
7480 if a:islocal
7481 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007482 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007483 endif
7484 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007485 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007486 endif
7487 if cmd =~ '%'
7488 let xcmd= substitute(cmd,'%',fname,'g')
7489 else
7490 let xcmd= cmd.' '.fname
7491 endif
7492 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007493" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007494 let ret= system(xcmd)
7495 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007496" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007497 let ret= s:RemoteSystem(xcmd)
7498 endif
7499 if v:shell_error < 0
7500 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7501 break
7502 else
yasudac75dad02024-08-22 21:06:32 +02007503 if ret !=# ''
7504 echo "\n"
7505 " skip trailing new line
7506 echo ret[0:-2]
7507 else
7508 echo ret
7509 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007510 endif
7511 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007512
7513 " unmark marked file list
7514 call s:NetrwUnmarkList(curbufnr,curdir)
7515
7516 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007517 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007518" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7519 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007520 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007521 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007522 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007523
7524 else " apply command to global list of files, en bloc
7525
7526 call inputsave()
7527 let cmd= input("Enter command: ","","file")
7528 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007529" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007530 if cmd == ""
7531" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7532 return
7533 endif
7534 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007535 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007536 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007537 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007538 endif
7539 if a:islocal
7540 call system(cmd)
7541 if v:shell_error < 0
7542 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7543 endif
7544 else
7545 let ret= s:RemoteSystem(cmd)
7546 endif
7547 call s:NetrwUnmarkAll()
7548
7549 " refresh the listing
7550 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007551" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7552 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007553
7554 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007555
Bram Moolenaar446cb832008-06-24 21:56:24 +00007556" call Dret("s:NetrwMarkFileExe")
7557endfun
7558
7559" ---------------------------------------------------------------------
7560" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7561" as the marked file(s) (toggles suffix presence)
7562" Uses the local marked file list.
7563fun! s:NetrwMarkHideSfx(islocal)
7564" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007565 let svpos = winsaveview()
7566" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007567 let curbufnr = bufnr("%")
7568
7569 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7570 if exists("s:netrwmarkfilelist_{curbufnr}")
7571
7572 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007573" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007574 " construct suffix pattern
7575 if fname =~ '\.'
7576 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7577 else
7578 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7579 endif
7580 " determine if its in the hiding list or not
7581 let inhidelist= 0
7582 if g:netrw_list_hide != ""
7583 let itemnum = 0
7584 let hidelist= split(g:netrw_list_hide,',')
7585 for hidepat in hidelist
7586 if sfxpat == hidepat
7587 let inhidelist= 1
7588 break
7589 endif
7590 let itemnum= itemnum + 1
7591 endfor
7592 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007593" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007594 if inhidelist
7595 " remove sfxpat from list
7596 call remove(hidelist,itemnum)
7597 let g:netrw_list_hide= join(hidelist,",")
7598 elseif g:netrw_list_hide != ""
7599 " append sfxpat to non-empty list
7600 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7601 else
7602 " set hiding list to sfxpat
7603 let g:netrw_list_hide= sfxpat
7604 endif
7605 endfor
7606
7607 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007608 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007609" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7610 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007611 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007612 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007613 endif
7614
7615" call Dret("s:NetrwMarkHideSfx")
7616endfun
7617
7618" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007619" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007620" Uses the local marked-file list.
7621fun! s:NetrwMarkFileVimCmd(islocal)
7622" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007623 let svpos = winsaveview()
7624" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007625 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007626 let curbufnr = bufnr("%")
7627
Bram Moolenaarff034192013-04-24 18:51:19 +02007628 " sanity check
7629 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007630 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007631" call Dret("s:NetrwMarkFileVimCmd")
7632 return
7633 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007634" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007635
Bram Moolenaar15146672011-10-20 22:22:38 +02007636 if exists("s:netrwmarkfilelist_{curbufnr}")
7637 " get the command
7638 call inputsave()
7639 let cmd= input("Enter vim command: ","","file")
7640 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007641" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007642 if cmd == ""
7643" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7644 return
7645 endif
7646
7647 " apply command to marked files. Substitute: filename -> %
7648 " If no %, then append a space and the filename to the command
7649 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007650" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007651 if a:islocal
7652 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007653 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007654" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007655 exe cmd
7656 exe "sil! keepalt wq!"
7657 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007658" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007659 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007660 endif
7661 endfor
7662
7663 " unmark marked file list
7664 call s:NetrwUnmarkList(curbufnr,curdir)
7665
7666 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007667 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007668" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7669 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007670 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007671 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007672 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007673
Bram Moolenaar15146672011-10-20 22:22:38 +02007674" call Dret("s:NetrwMarkFileVimCmd")
7675endfun
7676
7677" ---------------------------------------------------------------------
7678" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7679" as the marked file(s) (toggles suffix presence)
7680" Uses the local marked file list.
7681fun! s:NetrwMarkHideSfx(islocal)
7682" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007683 let svpos = winsaveview()
7684" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007685 let curbufnr = bufnr("%")
7686
7687 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7688 if exists("s:netrwmarkfilelist_{curbufnr}")
7689
7690 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007691" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007692 " construct suffix pattern
7693 if fname =~ '\.'
7694 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7695 else
7696 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7697 endif
7698 " determine if its in the hiding list or not
7699 let inhidelist= 0
7700 if g:netrw_list_hide != ""
7701 let itemnum = 0
7702 let hidelist= split(g:netrw_list_hide,',')
7703 for hidepat in hidelist
7704 if sfxpat == hidepat
7705 let inhidelist= 1
7706 break
7707 endif
7708 let itemnum= itemnum + 1
7709 endfor
7710 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007711" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007712 if inhidelist
7713 " remove sfxpat from list
7714 call remove(hidelist,itemnum)
7715 let g:netrw_list_hide= join(hidelist,",")
7716 elseif g:netrw_list_hide != ""
7717 " append sfxpat to non-empty list
7718 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7719 else
7720 " set hiding list to sfxpat
7721 let g:netrw_list_hide= sfxpat
7722 endif
7723 endfor
7724
7725 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007726 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007727" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7728 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007729 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007730 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007731 endif
7732
7733" call Dret("s:NetrwMarkHideSfx")
7734endfun
7735
7736" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007737" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7738" Uses the global markfilelist
7739fun! s:NetrwMarkFileGrep(islocal)
7740" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007741 let svpos = winsaveview()
7742" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007743 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007744 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007745
7746 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007747" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007748 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007749" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007750 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007751 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007752" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007753 let netrwmarkfilelist= "*"
7754 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007755
Bram Moolenaarff034192013-04-24 18:51:19 +02007756 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007757" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007758 call inputsave()
7759 let pat= input("Enter pattern: ","")
7760 call inputrestore()
7761 let patbang = ""
7762 if pat =~ '^!'
7763 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007764 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007765 endif
7766 if pat =~ '^\i'
7767 let pat = escape(pat,'/')
7768 let pat = '/'.pat.'/'
7769 else
7770 let nonisi = pat[0]
7771 endif
7772
7773 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007774" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007775 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007776 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007777 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007778 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007779" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7780 return
7781 endtry
7782 echo "(use :cn, :cp to navigate, :Rex to return)"
7783
7784 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007785" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7786 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007787
7788 if exists("nonisi")
7789 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007790" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007791 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007792 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007793 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007794 endif
7795
7796" call Dret("s:NetrwMarkFileGrep")
7797endfun
7798
7799" ---------------------------------------------------------------------
7800" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7801" uses the global marked file list
7802" s:netrwmfloc= 0: target directory is remote
7803" = 1: target directory is local
7804fun! s:NetrwMarkFileMove(islocal)
7805" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007806 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007807 let curbufnr = bufnr("%")
7808
7809 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007810 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007811 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007812" call Dret("s:NetrwMarkFileMove")
7813 return
7814 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007815" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007816
Bram Moolenaar446cb832008-06-24 21:56:24 +00007817 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007818 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007819" call Dret("s:NetrwMarkFileCopy 0")
7820 return 0
7821 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007822" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007823
7824 if a:islocal && s:netrwmftgt_islocal
7825 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007826" call Decho("move from local to local",'~'.expand("<slnum>"))
7827" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007828 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007829 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7830" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7831 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007832 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007833 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007834" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007835 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007836 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007837" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007838 if g:netrw_localmovecmd =~ '\s'
7839 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7840 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7841 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007842" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007843 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007844 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007845" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007846 endif
7847 else
7848 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007849" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007850 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007851 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007852 if g:netrw_keepdir
7853 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7854 let fname= b:netrw_curdir."/".fname
7855 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007856 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007857 let fname= substitute(fname,'/','\\','g')
7858 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007859" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007860 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007861 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007862 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007863 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 +01007864 else
7865 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7866 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007867 break
7868 endif
7869 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007870
7871 elseif a:islocal && !s:netrwmftgt_islocal
7872 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007873" call Decho("move from local to remote",'~'.expand("<slnum>"))
7874" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007875 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007876 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007877" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007878 for fname in mflist
7879 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7880 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7881 endfor
7882 unlet mflist
7883
7884 elseif !a:islocal && s:netrwmftgt_islocal
7885 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007886" call Decho("move from remote to local",'~'.expand("<slnum>"))
7887" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007888 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007889 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007890" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007891 for fname in mflist
7892 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7893 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7894 endfor
7895 unlet mflist
7896
7897 elseif !a:islocal && !s:netrwmftgt_islocal
7898 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007899" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7900" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007901 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007902 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007903" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007904 for fname in mflist
7905 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7906 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7907 endfor
7908 unlet mflist
7909 endif
7910
7911 " -------
7912 " cleanup
7913 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007914" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007915
7916 " remove markings from local buffer
7917 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7918
7919 " refresh buffers
7920 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007921" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007922 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007923 endif
7924 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007925" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007926 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007927 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007928 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007929" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007930 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007931 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007932
Bram Moolenaar446cb832008-06-24 21:56:24 +00007933" call Dret("s:NetrwMarkFileMove")
7934endfun
7935
7936" ---------------------------------------------------------------------
7937" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7938" using the hardcopy command. Local marked-file list only.
7939fun! s:NetrwMarkFilePrint(islocal)
7940" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7941 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007942
7943 " sanity check
7944 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007945 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007946" call Dret("s:NetrwMarkFilePrint")
7947 return
7948 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007949" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7950 let curdir= s:NetrwGetCurdir(a:islocal)
7951
Bram Moolenaar446cb832008-06-24 21:56:24 +00007952 if exists("s:netrwmarkfilelist_{curbufnr}")
7953 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007954 call s:NetrwUnmarkList(curbufnr,curdir)
7955 for fname in netrwmarkfilelist
7956 if a:islocal
7957 if g:netrw_keepdir
7958 let fname= s:ComposePath(curdir,fname)
7959 endif
7960 else
7961 let fname= curdir.fname
7962 endif
7963 1split
7964 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007965" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007966 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007967" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007968 hardcopy
7969 q
7970 endfor
7971 2match none
7972 endif
7973" call Dret("s:NetrwMarkFilePrint")
7974endfun
7975
7976" ---------------------------------------------------------------------
7977" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7978" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007979" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007980fun! s:NetrwMarkFileRegexp(islocal)
7981" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7982
7983 " get the regular expression
7984 call inputsave()
7985 let regexp= input("Enter regexp: ","","file")
7986 call inputrestore()
7987
7988 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007989 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007990" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007991 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007992" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007993 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007994 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007995 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007996 else
7997 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007998 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007999 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008000" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008001
8002 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01008003 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02008004 if fname =~ '^'.fnameescape(curdir)
8005" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
8006 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
8007 else
8008" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
8009 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
8010 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008011 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008012
8013 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008014" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008015
8016 " convert displayed listing into a filelist
8017 let eikeep = &ei
8018 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008019 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008020 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008021" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008022 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008023 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008024 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008025 sil NetrwKeepj norm! "ap
8026 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008027 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008028 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008029 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008030 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008031 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008032 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008033 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008034 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008035 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008036 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008037 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8038 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008039 call histdel("/",-1)
8040 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008041 endif
8042 " convert regexp into the more usual glob-style format
8043 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008044" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008045 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008046 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008047 let filelist= getline(1,line("$"))
8048 q!
8049 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008050 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008051 endfor
8052 unlet filelist
8053 let @a = areg
8054 let &ei = eikeep
8055 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008056 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008057
8058" call Dret("s:NetrwMarkFileRegexp")
8059endfun
8060
8061" ---------------------------------------------------------------------
8062" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8063" Uses the local marked file list.
8064fun! s:NetrwMarkFileSource(islocal)
8065" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8066 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008067
8068 " sanity check
8069 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008070 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008071" call Dret("s:NetrwMarkFileSource")
8072 return
8073 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008074" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8075 let curdir= s:NetrwGetCurdir(a:islocal)
8076
Bram Moolenaar446cb832008-06-24 21:56:24 +00008077 if exists("s:netrwmarkfilelist_{curbufnr}")
8078 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008079 call s:NetrwUnmarkList(curbufnr,curdir)
8080 for fname in netrwmarkfilelist
8081 if a:islocal
8082 if g:netrw_keepdir
8083 let fname= s:ComposePath(curdir,fname)
8084 endif
8085 else
8086 let fname= curdir.fname
8087 endif
8088 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008089" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008090 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008091 endfor
8092 2match none
8093 endif
8094" call Dret("s:NetrwMarkFileSource")
8095endfun
8096
8097" ---------------------------------------------------------------------
8098" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8099" Uses the global markfilelist
8100fun! s:NetrwMarkFileTag(islocal)
8101" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008102 let svpos = winsaveview()
8103" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008104 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008105 let curbufnr = bufnr("%")
8106
Bram Moolenaarff034192013-04-24 18:51:19 +02008107 " sanity check
8108 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008109 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008110" call Dret("s:NetrwMarkFileTag")
8111 return
8112 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008113" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008114
Bram Moolenaar446cb832008-06-24 21:56:24 +00008115 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008116" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8117 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008118 call s:NetrwUnmarkAll()
8119
8120 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008121
8122" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8123 call system(g:netrw_ctags." ".netrwmarkfilelist)
8124 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008125 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8126 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008127
Bram Moolenaar446cb832008-06-24 21:56:24 +00008128 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008129 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008130 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008131 let curdir= b:netrw_curdir
8132 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008133 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008134 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008135" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008136 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008137 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008138 wq!
8139 endif
8140 2match none
8141 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008142" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8143 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008144 endif
8145
8146" call Dret("s:NetrwMarkFileTag")
8147endfun
8148
8149" ---------------------------------------------------------------------
8150" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008151" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008152" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008153" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008154" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008155fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008156" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8157 let svpos = winsaveview()
8158" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008159 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008160 let hadtgt = exists("s:netrwmftgt")
8161 if !exists("w:netrw_bannercnt")
8162 let w:netrw_bannercnt= b:netrw_bannercnt
8163 endif
8164
8165 " set up target
8166 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008167" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008168 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8169 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008170" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008171 unlet s:netrwmftgt s:netrwmftgt_islocal
8172 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008173 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008174 endif
8175 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008176" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8177 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008178" call Dret("s:NetrwMarkFileTgt : removed target")
8179 return
8180 else
8181 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008182" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008183 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008184
8185 else
8186 " get word under cursor.
8187 " * If directory, use it for the target.
8188 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008189" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008190 let curword= s:NetrwGetWord()
8191 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008192 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008193 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008194" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008195 elseif !a:islocal && tgtdir =~ '/$'
8196 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008197" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008198 else
8199 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008200" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008201 endif
8202 endif
8203 if a:islocal
8204 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8205 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008206" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008207 endif
8208 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008209 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008210 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8211 endif
8212 let s:netrwmftgt_islocal= a:islocal
8213
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008214 " need to do refresh so that the banner will be updated
8215 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008216 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008217" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008218 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008219 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008220" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008221 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008222 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8223 else
8224 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8225 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008226" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8227 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008228 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008229 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008230 endif
8231
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008232" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8233" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008234" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8235endfun
8236
8237" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008238" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8239fun! s:NetrwGetCurdir(islocal)
8240" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8241
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008242 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008243 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8244" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8245 elseif !exists("b:netrw_curdir")
8246 let b:netrw_curdir= getcwd()
8247" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8248 endif
8249
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008250" 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 +01008251 if b:netrw_curdir !~ '\<\a\{3,}://'
8252 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008253" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008254 if g:netrw_keepdir == 0
8255 call s:NetrwLcd(curdir)
8256 endif
8257 endif
8258
8259" call Dret("s:NetrwGetCurdir <".curdir.">")
8260 return b:netrw_curdir
8261endfun
8262
8263" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008264" s:NetrwOpenFile: query user for a filename and open it {{{2
8265fun! s:NetrwOpenFile(islocal)
8266" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008267 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008268 call inputsave()
8269 let fname= input("Enter filename: ")
8270 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008271" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8272
8273 " determine if Lexplore is in use
8274 if exists("t:netrw_lexbufnr")
8275 " check if t:netrw_lexbufnr refers to a netrw window
8276" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8277 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8278 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8279" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8280 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8281 exe "NetrwKeepj e ".fnameescape(fname)
8282 let @@= ykeep
8283" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8284 endif
8285 endif
8286
8287 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008288 if fname !~ '[/\\]'
8289 if exists("b:netrw_curdir")
8290 if exists("g:netrw_quiet")
8291 let netrw_quiet_keep = g:netrw_quiet
8292 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008293 let g:netrw_quiet = 1
8294 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008295 let s:rexposn_{bufnr("%")}= winsaveview()
8296" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008297 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008298 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008299 else
8300 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8301 endif
8302 if exists("netrw_quiet_keep")
8303 let g:netrw_quiet= netrw_quiet_keep
8304 else
8305 unlet g:netrw_quiet
8306 endif
8307 endif
8308 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008309 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008310 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008311 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008312" call Dret("s:NetrwOpenFile")
8313endfun
8314
8315" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008316" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8317" For the mapping to this function be made via
8318" netrwPlugin, you'll need to have had
8319" g:netrw_usetab set to non-zero.
8320fun! netrw#Shrink()
8321" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8322 let curwin = winnr()
8323 let wiwkeep = &wiw
8324 set wiw=1
8325
8326 if &ft == "netrw"
8327 if winwidth(0) > g:netrw_wiw
8328 let t:netrw_winwidth= winwidth(0)
8329 exe "vert resize ".g:netrw_wiw
8330 wincmd l
8331 if winnr() == curwin
8332 wincmd h
8333 endif
8334" call Decho("vert resize 0",'~'.expand("<slnum>"))
8335 else
8336 exe "vert resize ".t:netrw_winwidth
8337" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8338 endif
8339
8340 elseif exists("t:netrw_lexbufnr")
8341 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8342 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8343 let t:netrw_winwidth= winwidth(0)
8344 exe "vert resize ".g:netrw_wiw
8345 wincmd l
8346 if winnr() == curwin
8347 wincmd h
8348 endif
8349" call Decho("vert resize 0",'~'.expand("<slnum>"))
8350 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8351 exe "vert resize ".t:netrw_winwidth
8352" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8353 else
8354 call netrw#Lexplore(0,0)
8355 endif
8356
8357 else
8358 call netrw#Lexplore(0,0)
8359 endif
8360 let wiw= wiwkeep
8361
8362" call Dret("netrw#Shrink")
8363endfun
8364
8365" ---------------------------------------------------------------------
8366" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8367fun! s:NetSortSequence(islocal)
8368" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8369
8370 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008371 let svpos= winsaveview()
8372" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008373 call inputsave()
8374 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8375 call inputrestore()
8376
8377 " refresh the listing
8378 let g:netrw_sort_sequence= newsortseq
8379 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008380" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8381 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008382 let @@= ykeep
8383
8384" call Dret("NetSortSequence")
8385endfun
8386
8387" ---------------------------------------------------------------------
8388" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8389" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008390" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008391fun! s:NetrwUnmarkList(curbufnr,curdir)
8392" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8393
8394 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008395 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008396 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8397 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8398 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8399 call remove(s:netrwmarkfilelist,idx) " remove from global list
8400 endfor
8401 if s:netrwmarkfilelist == []
8402 unlet s:netrwmarkfilelist
8403 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008404
Bram Moolenaar446cb832008-06-24 21:56:24 +00008405 " getting rid of the local marked-file lists is easy
8406 unlet s:netrwmarkfilelist_{a:curbufnr}
8407 endif
8408 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8409 unlet s:netrwmarkfilemtch_{a:curbufnr}
8410 endif
8411 2match none
8412" call Dret("s:NetrwUnmarkList")
8413endfun
8414
8415" ---------------------------------------------------------------------
8416" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8417fun! s:NetrwUnmarkAll()
8418" call Dfunc("s:NetrwUnmarkAll()")
8419 if exists("s:netrwmarkfilelist")
8420 unlet s:netrwmarkfilelist
8421 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008422 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008423 2match none
8424" call Dret("s:NetrwUnmarkAll")
8425endfun
8426
8427" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008428" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008429fun! s:NetrwUnmarkAll2()
8430" call Dfunc("s:NetrwUnmarkAll2()")
8431 redir => netrwmarkfilelist_let
8432 let
8433 redir END
8434 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008435 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008436 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8437 for flist in netrwmarkfilelist_list
8438 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8439 unlet s:netrwmarkfilelist_{curbufnr}
8440 unlet s:netrwmarkfilemtch_{curbufnr}
8441 endfor
8442" call Dret("s:NetrwUnmarkAll2")
8443endfun
8444
8445" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008446" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8447"
8448" Marked files are in two types of lists:
8449" s:netrwmarkfilelist -- holds complete paths to all marked files
8450" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8451"
8452" Marked files suitable for use with 2match are in:
8453" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008454fun! s:NetrwUnMarkFile(islocal)
8455" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008456 let svpos = winsaveview()
8457" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008458 let curbufnr = bufnr("%")
8459
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008460 " unmark marked file list
8461 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8462 if exists("s:netrwmarkfilelist")
8463" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008464 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008465 endif
8466
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008467 let ibuf= 1
8468 while ibuf < bufnr("$")
8469 if exists("s:netrwmarkfilelist_".ibuf)
8470 unlet s:netrwmarkfilelist_{ibuf}
8471 unlet s:netrwmarkfilemtch_{ibuf}
8472 endif
8473 let ibuf = ibuf + 1
8474 endwhile
8475 2match none
8476
Bram Moolenaar446cb832008-06-24 21:56:24 +00008477" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008478"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8479call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008480" call Dret("s:NetrwUnMarkFile")
8481endfun
8482
8483" ---------------------------------------------------------------------
8484" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8485fun! s:NetrwMenu(domenu)
8486
8487 if !exists("g:NetrwMenuPriority")
8488 let g:NetrwMenuPriority= 80
8489 endif
8490
Bram Moolenaaradc21822011-04-01 18:03:16 +02008491 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008492" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8493
8494 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008495" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008496 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008497 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8498 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8499 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8500 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8501 if g:netrw_dirhistmax > 0
8502 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8503 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8504 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8505 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8506 else
8507 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8508 endif
8509 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8510 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8511 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8512 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8513 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8514 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8515 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8516 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8517 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8518 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8519 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8520 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8521 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8522 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8523 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 +01008524 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 +02008525 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8527 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8528 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8529 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8530 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8531 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8532 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8537 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8538 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8539 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8540 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8541 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8542 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8543 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8544 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8545 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8546 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8547 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8548 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8549 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8550 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8551 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8552 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8553 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8554 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>'
8555 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>'
8556 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>'
8557 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8558 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>'
8559 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>'
8560 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 +01008561 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 +02008562 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8563 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008564 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008565 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8566 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008567
8568 elseif !a:domenu
8569 let s:netrwcnt = 0
8570 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008571 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008572 exe curwin."wincmd w"
8573
8574 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008575" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008576 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008577" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008578 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008579 endif
8580 endif
8581" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008582 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008583 endif
8584
8585endfun
8586
8587" ---------------------------------------------------------------------
8588" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8589" Used by the O maps (as <SID>NetrwObtain())
8590fun! s:NetrwObtain(islocal)
8591" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8592
Bram Moolenaar97d62492012-11-15 21:28:22 +01008593 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008594 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008595 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008596 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008597 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8598 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008599 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008600 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008601 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008602
8603" call Dret("NetrwObtain")
8604endfun
8605
8606" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008607" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8608" If there's only one window, then the window will first be split.
8609" Returns:
8610" choice = 0 : didn't have to choose
8611" choice = 1 : saved modified file in window first
8612" choice = 2 : didn't save modified file, opened window
8613" choice = 3 : cancel open
8614fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008615" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008616
Bram Moolenaar97d62492012-11-15 21:28:22 +01008617 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008618 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008619 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008620" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008621
8622 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008623 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008624 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008625" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8626" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8627 let curword = s:NetrwGetWord()
8628 let choice = 0
8629 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8630" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008631 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008632" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008633 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008634" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008635" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008636" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008637
Bram Moolenaar8d043172014-01-23 14:24:41 +01008638 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008639 if lastwinnr == 1
8640 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008641" 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 +02008642 " g:netrw_preview=0: preview window shown in a horizontally split window
8643 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008644 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008645 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008646 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008647" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008648 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008649 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008650 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008651 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008652" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008653 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008654 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008655 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008656" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008657
8658 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008659" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008660 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008661" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008662 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008663" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008664 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008665" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008666 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008667" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008668" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008669" call Decho("COMBAK#12: mod=".&mod)
8670
8671 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8672 " whoops -- user trying to open file in the Lexplore window.
8673 " Use Lexplore's opening-file window instead.
8674" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8675" exe g:netrw_chgwin."wincmd w"
8676 wincmd p
8677 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8678 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008679
8680 " prevwinnr: the window number of the "prev" window
8681 " prevbufnr: the buffer number of the buffer in the "prev" window
8682 " bnrcnt : the qty of windows open on the "prev" buffer
8683 let prevwinnr = winnr()
8684 let prevbufnr = bufnr("%")
8685 let prevbufname = bufname("%")
8686 let prevmod = &mod
8687 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008688" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008689 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008690" 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 +01008691" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008692
8693 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008694 " and it doesn't appear in any other extant window, then ask the
8695 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008696 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008697" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008698 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008699" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008700 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008701" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008702
8703 if bnrcnt == 1 && &hidden == 0
8704 " only one copy of the modified buffer in a window, and
8705 " hidden not set, so overwriting will lose the modified file. Ask first...
8706 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008707" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008708 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008709" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008710
8711 if choice == 1
8712 " Yes -- write file & then browse
8713 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008714 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008715 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008716 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008717 exe origwin."wincmd w"
8718 let &ei = eikeep
8719 let @@ = ykeep
8720" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008721 return choice
8722 endif
8723
8724 elseif choice == 2
8725 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008726" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008727 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008728
8729 else
8730 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008731" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008732 exe origwin."wincmd w"
8733 let &ei= eikeep
8734 let @@ = ykeep
8735" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008736 return choice
8737 endif
8738 endif
8739 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008740 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008741 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008742" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008743
8744 " restore b:netrw_curdir (window split/enew may have lost it)
8745 let b:netrw_curdir= curdir
8746 if a:islocal < 2
8747 if a:islocal
8748 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8749 else
8750 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8751 endif
8752 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008753 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008754" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008755 return choice
8756endfun
8757
8758" ---------------------------------------------------------------------
8759" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8760" Always assumed to be local -> remote
8761" call s:NetrwUpload(filename, target)
8762" call s:NetrwUpload(filename, target, fromdirectory)
8763fun! s:NetrwUpload(fname,tgt,...)
8764" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8765
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008766 if a:tgt =~ '^\a\{3,}://'
8767 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008768 else
8769 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8770 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008771" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008772
8773 if a:0 > 0
8774 let fromdir= a:1
8775 else
8776 let fromdir= getcwd()
8777 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008778" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008779
8780 if type(a:fname) == 1
8781 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008782" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008783 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008784" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8785 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8786" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008787 if a:tgt =~ '/$'
8788 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008789" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008790 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008791 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008792" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008793 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008794" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008795 endif
8796 q!
8797
8798 elseif type(a:fname) == 3
8799 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008800" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008801 let curdir= getcwd()
8802 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008803 if s:NetrwLcd(fromdir)
8804" call Dret("s:NetrwUpload : lcd failure")
8805 return
8806 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008807 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008808 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008809 if exists("g:netrw_port") && g:netrw_port != ""
8810 let useport= " ".g:netrw_scpport." ".g:netrw_port
8811 else
8812 let useport= ""
8813 endif
8814 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8815 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008816 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 +02008817 if s:NetrwLcd(curdir)
8818" call Dret("s:NetrwUpload : lcd failure")
8819 return
8820 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008821
8822 elseif a:tgt =~ '^ftp:'
8823 call s:NetrwMethod(a:tgt)
8824
8825 if b:netrw_method == 2
8826 " handle uploading a list of files via ftp+.netrc
8827 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008828 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008829" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008830
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008831 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008832" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008833
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
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008839 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008840" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008841
Bram Moolenaaradc21822011-04-01 18:03:16 +02008842 if tgtdir == ""
8843 let tgtdir= '/'
8844 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008845 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008846" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008847
8848 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008849 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8850" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008851 endfor
8852
8853 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008854 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 +00008855 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008856" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8857 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008858 endif
8859 " 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 +01008860 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008861 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008862 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8863 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8864 else
8865 bw!|q
8866 endif
8867
8868 elseif b:netrw_method == 3
8869 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8870 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008871 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008872 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008873 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008874
8875 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008876 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008877" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008878 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008879 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008880" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008881 endif
8882
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008883 if exists("g:netrw_uid") && g:netrw_uid != ""
8884 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008885 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008886" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008887 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008888 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008889 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008890" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008891 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008892 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008893" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008894 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008895 endif
8896
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008897 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008898" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008899
8900 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008901 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008902" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008903 endif
8904
8905 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008906 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008907" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008908 endif
8909
8910 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008911 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008912" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008913 endfor
8914
8915 " perform ftp:
8916 " -i : turns off interactive prompting from ftp
8917 " -n unix : DON'T use <.netrc>, even though it exists
8918 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008919 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008920 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008921 " 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 +01008922 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008923 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008924 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8925 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008926 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008927 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8928 let &debug = debugkeep
8929 let mod = 1
8930 else
8931 bw!|q
8932 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008933 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008934" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008935 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008936 endif
8937 else
8938 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8939 endif
8940 endif
8941
8942" call Dret("s:NetrwUpload")
8943endfun
8944
8945" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008946" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008947fun! s:NetrwPreview(path) range
8948" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008949" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8950" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008951 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008952 NetrwKeepj call s:NetrwOptionsSave("s:")
8953 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8954 NetrwKeepj call s:NetrwOptionsSafe(1)
8955 else
8956 NetrwKeepj call s:NetrwOptionsSafe(0)
8957 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008958 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008959" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008960 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008961" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8962 if g:netrw_preview
8963 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008964 let pvhkeep = &pvh
8965 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8966 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008967" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8968 else
8969 " horizontal split
8970 let pvhkeep = &pvh
8971 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8972 let &pvh = winheight(0) - winsz
8973" 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 +02008974 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008975 " g:netrw_preview g:netrw_alto
8976 " 1 : vert 1: top -- preview window is vertically split off and on the left
8977 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8978 " 0 : 1: top -- preview window is horizontally split off and on the top
8979 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8980 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008981 " 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 +02008982 " the BufEnter event set up in netrwPlugin.vim
8983" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8984 let eikeep = &ei
8985 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008986 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008987 let &ei= eikeep
8988" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008989 if exists("pvhkeep")
8990 let &pvh= pvhkeep
8991 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008992 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008993 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008994 endif
8995 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008996 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 +00008997 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008998 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008999 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009000" call Dret("NetrwPreview")
9001endfun
9002
9003" ---------------------------------------------------------------------
9004" s:NetrwRefresh: {{{2
9005fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009006" 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 +00009007 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02009008 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009009" call Decho("setl ma noro",'~'.expand("<slnum>"))
9010" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009011 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02009012 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
9013 if !exists("w:netrw_treetop")
9014 if exists("b:netrw_curdir")
9015 let w:netrw_treetop= b:netrw_curdir
9016 else
9017 let w:netrw_treetop= getcwd()
9018 endif
9019 endif
9020 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9021 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009022
9023 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009024 let screenposn = winsaveview()
9025" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009026
9027" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9028" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9029 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009030 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009031 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009032 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009033 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009034 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009035
9036 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009037" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9038 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009039
9040 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009041 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9042 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9043" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9044 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9045 else
9046" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9047 2match none
9048 endif
9049 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009050
Bram Moolenaar97d62492012-11-15 21:28:22 +01009051" restore
9052 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009053" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009054endfun
9055
9056" ---------------------------------------------------------------------
9057" s:NetrwRefreshDir: refreshes a directory by name {{{2
9058" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009059" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009060fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009061" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009062 if g:netrw_fastbrowse == 0
9063 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009064" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009065 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009066" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009067
9068 if tgtwin > 0
9069 " tgtwin is being displayed, so refresh it
9070 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009071" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009072 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009073 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009074 exe curwin."wincmd w"
9075
9076 elseif bufnr(a:dirname) > 0
9077 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009078" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9079 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009080 endif
9081
9082 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009083" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009084 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009085 endif
9086" call Dret("s:NetrwRefreshDir")
9087endfun
9088
9089" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009090" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9091" window number to do its editing in.
9092" Supports [count]C where the count, if present, is used to specify
9093" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009094fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009095" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009096 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009097" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009098 if a:1 == "" " :NetrwC win#
9099 let g:netrw_chgwin= winnr()
9100 else " :NetrwC
9101 let g:netrw_chgwin= a:1
9102 endif
9103 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009104 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009105 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009106 let g:netrw_chgwin= winnr()
9107 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009108 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009109" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009110endfun
9111
9112" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009113" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9114" What this function does is to compute a priority for the patterns
9115" in the g:netrw_sort_sequence. It applies a substitute to any
9116" "files" that satisfy each pattern, putting the priority / in
9117" front. An "*" pattern handles the default priority.
9118fun! s:NetrwSetSort()
9119" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009120 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009121 if w:netrw_liststyle == s:LONGLIST
9122 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9123 else
9124 let seqlist = g:netrw_sort_sequence
9125 endif
9126 " sanity check -- insure that * appears somewhere
9127 if seqlist == ""
9128 let seqlist= '*'
9129 elseif seqlist !~ '\*'
9130 let seqlist= seqlist.',*'
9131 endif
9132 let priority = 1
9133 while seqlist != ""
9134 if seqlist =~ ','
9135 let seq = substitute(seqlist,',.*$','','e')
9136 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9137 else
9138 let seq = seqlist
9139 let seqlist = ""
9140 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009141 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009142 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009143 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009144 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009145 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009146 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009147 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009148" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009149
9150 " sanity check
9151 if w:netrw_bannercnt > line("$")
9152 " apparently no files were left after a Hiding pattern was used
9153" call Dret("SetSort : no files left after hiding")
9154 return
9155 endif
9156 if seq == '*'
9157 let starpriority= spriority
9158 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009159 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009160 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009161 " sometimes multiple sorting patterns will match the same file or directory.
9162 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009163 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9164 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009165 endif
9166 let priority = priority + 1
9167 endwhile
9168 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009169 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9170 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009171 endif
9172
9173 " Following line associated with priority -- items that satisfy a priority
9174 " pattern get prefixed by ###/ which permits easy sorting by priority.
9175 " Sometimes files can satisfy multiple priority patterns -- only the latest
9176 " priority pattern needs to be retained. So, at this point, these excess
9177 " priority prefixes need to be removed, but not directories that happen to
9178 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009179 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9180 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009181 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009182
9183" call Dret("SetSort")
9184endfun
9185
Bram Moolenaarff034192013-04-24 18:51:19 +02009186" ---------------------------------------------------------------------
9187" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9188" Implements [count]Tb (bookhist<b>)
9189" [count]Th (bookhist<h>)
9190" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009191fun! s:NetrwSetTgt(islocal,bookhist,choice)
9192" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009193
9194 if a:bookhist == 'b'
9195 " supports choosing a bookmark as a target using a qb-generated list
9196 let choice= a:choice - 1
9197 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009198 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009199 else
9200 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9201 endif
9202
9203 elseif a:bookhist == 'h'
9204 " supports choosing a history stack entry as a target using a qb-generated list
9205 let choice= (a:choice % g:netrw_dirhistmax) + 1
9206 if exists("g:netrw_dirhist_".choice)
9207 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009208 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009209 else
9210 echomsg "Sorry, history#".a:choice." not available!"
9211 endif
9212 endif
9213
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009214 " refresh the display
9215 if !exists("b:netrw_curdir")
9216 let b:netrw_curdir= getcwd()
9217 endif
9218 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9219
Bram Moolenaarff034192013-04-24 18:51:19 +02009220" call Dret("s:NetrwSetTgt")
9221endfun
9222
Bram Moolenaar446cb832008-06-24 21:56:24 +00009223" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009224" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009225fun! s:NetrwSortStyle(islocal)
9226" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009227 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009228 let svpos= winsaveview()
9229" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009230
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009231 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 +01009232 NetrwKeepj norm! 0
9233 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009234" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9235 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009236
9237" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9238endfun
9239
9240" ---------------------------------------------------------------------
9241" s:NetrwSplit: mode {{{2
9242" =0 : net and o
9243" =1 : net and t
9244" =2 : net and v
9245" =3 : local and o
9246" =4 : local and t
9247" =5 : local and v
9248fun! s:NetrwSplit(mode)
9249" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9250
Bram Moolenaar97d62492012-11-15 21:28:22 +01009251 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009252 call s:SaveWinVars()
9253
9254 if a:mode == 0
9255 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009256 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(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_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009259 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
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 s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009263 unlet s:didsplit
9264
9265 elseif a:mode == 1
9266 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009267 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009268" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009269 tabnew
9270 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009271 NetrwKeepj call s:RestoreWinVars()
9272 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009273 unlet s:didsplit
9274
9275 elseif a:mode == 2
9276 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009277 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009278 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009279" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009280 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009281 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009282 NetrwKeepj call s:RestoreWinVars()
9283 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009284 unlet s:didsplit
9285
9286 elseif a:mode == 3
9287 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009288 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009289 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009290" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009291 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009292 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009293 NetrwKeepj call s:RestoreWinVars()
9294 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009295 unlet s:didsplit
9296
9297 elseif a:mode == 4
9298 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009299 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009300 let eikeep = &ei
9301 let netrw_winnr = winnr()
9302 let netrw_line = line(".")
9303 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009304 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009305 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009306 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009307 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9308 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009309 let &ei = eikeep
9310 let netrw_curdir = s:NetrwTreeDir(0)
9311" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009312 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009313 let b:netrw_curdir = netrw_curdir
9314 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009315 NetrwKeepj call s:RestoreWinVars()
9316 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009317 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009318 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009319 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9320 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009321 let &ei= eikeep
9322 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009323 unlet s:didsplit
9324
9325 elseif a:mode == 5
9326 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009327 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009328 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009329" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009330 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009331 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009332 NetrwKeepj call s:RestoreWinVars()
9333 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009334 unlet s:didsplit
9335
9336 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009337 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009338 endif
9339
Bram Moolenaar97d62492012-11-15 21:28:22 +01009340 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009341" call Dret("s:NetrwSplit")
9342endfun
9343
9344" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009345" s:NetrwTgtMenu: {{{2
9346fun! s:NetrwTgtMenu()
9347 if !exists("s:netrw_menucnt")
9348 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009349 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009350" call Dfunc("s:NetrwTgtMenu()")
9351
9352 " the following test assures that gvim is running, has menus available, and has menus enabled.
9353 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9354 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009355" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009356 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9357 endif
9358 if !exists("s:netrw_initbookhist")
9359 call s:NetrwBookHistRead()
9360 endif
9361
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009362 " try to cull duplicate entries
9363 let tgtdict={}
9364
Bram Moolenaarff034192013-04-24 18:51:19 +02009365 " target bookmarked places
9366 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009367" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009368 let cnt= 1
9369 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009370 if has_key(tgtdict,bmd)
9371 let cnt= cnt + 1
9372 continue
9373 endif
9374 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009375 let ebmd= escape(bmd,g:netrw_menu_escape)
9376 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009377" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009378 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 +02009379 let cnt= cnt + 1
9380 endfor
9381 endif
9382
9383 " target directory browsing history
9384 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009385" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009386 let histcnt = 1
9387 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009388 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009389 if exists("g:netrw_dirhist_{histcnt}")
9390 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009391 if has_key(tgtdict,histentry)
9392 let histcnt = histcnt + 1
9393 continue
9394 endif
9395 let tgtdict[histentry] = histcnt
9396 let ehistentry = escape(histentry,g:netrw_menu_escape)
9397" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009398 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 +02009399 endif
9400 let histcnt = histcnt + 1
9401 endwhile
9402 endif
9403 endif
9404" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009405endfun
9406
9407" ---------------------------------------------------------------------
9408" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9409" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009410fun! s:NetrwTreeDir(islocal)
9411" 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 +02009412" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009413" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9414" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9415" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009416" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009417
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009418 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009419 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009420" 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 +01009421 let treedir= s:treedir
9422 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009423 unlet s:prevwinopen
9424" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009425 return treedir
9426 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009427 if exists("s:prevwinopen")
9428 unlet s:prevwinopen
9429 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009430" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009431
Bram Moolenaar8d043172014-01-23 14:24:41 +01009432 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9433 let b:netrw_curdir= getcwd()
9434 endif
9435 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009436" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009437" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009438
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009439 let s:treecurpos= winsaveview()
9440" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009441" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009442
9443 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009444" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9445" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009446" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009447
9448 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009449 let curline= substitute(getline('.'),"\t -->.*$",'','')
9450 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009451" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009452 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009453" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9454 elseif curline =~ '@$'
9455" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009456 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009457" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009458 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009459" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009460 let treedir= ""
9461 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009462" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009463
9464 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009465" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9466" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009467" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009468 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009469" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009470 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009471" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9472 sil! NetrwKeepj %d _
9473" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009474 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009475" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009476" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009477 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009478" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009479
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009480" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009481" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009482" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009483
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009484 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9485" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9486" let newdir = w:netrw_treetop.'/'.potentialdir
9487" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9488" let treedir = s:NetrwTreePath(newdir)
9489" let w:netrw_treetop = newdir
9490" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9491" else
9492" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009493 if a:islocal && curline =~ '@$'
9494 if isdirectory(s:NetrwFile(potentialdir))
9495 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9496 let w:netrw_treetop = treedir
9497 endif
9498 else
9499 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9500 let treedir = s:NetrwTreePath(w:netrw_treetop)
9501 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009502 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009503" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009504
9505 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009506 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009507" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009508" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009509
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009510" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009511 return treedir
9512endfun
9513
9514" ---------------------------------------------------------------------
9515" s:NetrwTreeDisplay: recursive tree display {{{2
9516fun! s:NetrwTreeDisplay(dir,depth)
9517" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9518
9519 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009520 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009521
9522 " install ../ and shortdir
9523 if a:depth == ""
9524 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009525" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009526 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009527 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009528 if a:dir == w:netrw_treetop
9529 let shortdir= a:dir
9530 else
9531 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9532 endif
9533 call setline(line("$")+1,a:depth.shortdir)
9534 else
9535 let shortdir= substitute(a:dir,'^.*/','','e')
9536 call setline(line("$")+1,a:depth.shortdir.'/')
9537 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009538" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009539 " append a / to dir if its missing one
9540 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009541
9542 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009543 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009544" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009545
Bram Moolenaar85850f32019-07-19 22:05:51 +02009546 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9547 if g:netrw_hide == 1
9548 " hide given patterns
9549 let listhide= split(g:netrw_list_hide,',')
9550" call Decho("listhide=".string(listhide))
9551 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009552 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009553 endfor
9554
9555 elseif g:netrw_hide == 2
9556 " show given patterns (only)
9557 let listhide= split(g:netrw_list_hide,',')
9558" call Decho("listhide=".string(listhide))
9559 let entries=[]
9560 for entry in w:netrw_treedict[dir]
9561 for pat in listhide
9562 if entry =~ pat
9563 call add(entries,entry)
9564 break
9565 endif
9566 endfor
9567 endfor
9568 let w:netrw_treedict[dir]= entries
9569 endif
9570 if depth != ""
9571 " always remove "." and ".." entries when there's depth
9572 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9573 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9574 endif
9575
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009576" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009577 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009578 if dir =~ '/$'
9579 let direntry= substitute(dir.entry,'[@/]$','','e')
9580 else
9581 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9582 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009583" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009584 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009585" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009586 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009587 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009588" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9589 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9590 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9591" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009592 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009593 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009594" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009595 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009596 endif
9597 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009598" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009599
Bram Moolenaar446cb832008-06-24 21:56:24 +00009600" call Dret("NetrwTreeDisplay")
9601endfun
9602
9603" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009604" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9605fun! s:NetrwRefreshTreeDict(dir)
9606" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009607 if !exists("w:netrw_treedict")
9608" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9609 return
9610 endif
9611
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009612 for entry in w:netrw_treedict[a:dir]
9613 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9614" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9615
9616 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9617" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9618 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009619 let liststar = s:NetrwGlob(direntry,'*',1)
9620 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009621 let w:netrw_treedict[direntry] = liststar + listdotstar
9622" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9623
9624 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9625" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9626 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009627 let liststar = s:NetrwGlob(direntry.'/','*',1)
9628 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009629 let w:netrw_treedict[direntry]= liststar + listdotstar
9630" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9631
9632 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9633" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9634 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009635 let liststar = s:NetrwGlob(direntry.'/','*',1)
9636 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009637" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9638
9639 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009640" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009641 endif
9642 endfor
9643" call Dret("s:NetrwRefreshTreeDict")
9644endfun
9645
9646" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009647" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009648" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009649fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009650 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009651" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009652" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9653" call Decho("win#".winnr().": w:netrw_treetop ".(exists("w:netrw_treetop")? "exists" : "doesn't exist")." w:netrw_treedict ".(exists("w:netrw_treedict")? "exists" : "doesn't exit"),'~'.expand("<slnum>"))
9654" 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 +00009655
9656 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009657 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009658" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009659 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009660 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009661" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009662 elseif (w:netrw_treetop =~ ('^'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop)) || a:dirname !~ ('^'.w:netrw_treetop)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009663" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009664 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009665 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009666" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009667 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009668 if exists("w:netrw_treetop")
9669 let s:netrw_treetop= w:netrw_treetop
9670 else
9671 let w:netrw_treetop= getcwd()
9672 let s:netrw_treetop= w:netrw_treetop
9673 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009674
Bram Moolenaar446cb832008-06-24 21:56:24 +00009675 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009676 " insure that we have a treedict, albeit empty
9677" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009678 let w:netrw_treedict= {}
9679 endif
9680
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009681 " update the dictionary for the current directory
9682" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009683" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009684 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009685 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009686" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009687 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009688
9689 " if past banner, record word
9690 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9691 let fname= expand("<cword>")
9692 else
9693 let fname= ""
9694 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009695" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9696" 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 +00009697
9698 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009699" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009700 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009701" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009702
9703 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9704 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009705" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009706 1d
9707 endwhile
9708
Bram Moolenaar13600302014-05-22 18:26:40 +02009709 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009710
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009711" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009712 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009713 endif
9714endfun
9715
9716" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009717" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009718" Normally, treetop is w:netrw_treetop, but a
9719" user of the function ( netrw#SetTreetop() )
9720" wipes that out prior to calling this function
9721fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009722" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9723 if line(".") < w:netrw_bannercnt + 2
9724 let treedir= a:treetop
9725 if treedir !~ '/$'
9726 let treedir= treedir.'/'
9727 endif
9728" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9729 return treedir
9730 endif
9731
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009732 let svpos = winsaveview()
9733" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009734 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009735" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009736 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009737" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9738 let curline= getline('.')
9739" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9740 if curline =~ '/$'
9741" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9742 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9743" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9744 elseif curline =~ '@\s\+-->'
9745" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9746 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9747 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9748" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009749 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009750" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009751 let treedir= ""
9752 endif
9753 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009754" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9755" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009756 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9757 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9758 let treedir= dirname.treedir
9759 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009760" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009761 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009762" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009763 if a:treetop =~ '/$'
9764 let treedir= a:treetop.treedir
9765 else
9766 let treedir= a:treetop.'/'.treedir
9767 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009768" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009769 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009770" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009771" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9772 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009773" call Dret("s:NetrwTreePath <".treedir.">")
9774 return treedir
9775endfun
9776
9777" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009778" s:NetrwWideListing: {{{2
9779fun! s:NetrwWideListing()
9780
9781 if w:netrw_liststyle == s:WIDELIST
9782" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9783 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009784 " cpf: characters per filename
9785 " fpl: filenames per line
9786 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009787 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009788 let dict={}
9789 " save the unnamed register and register 0-9 and a
9790 let dict.a=[getreg('a'), getregtype('a')]
9791 for i in range(0, 9)
9792 let dict[i] = [getreg(i), getregtype(i)]
9793 endfor
9794 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009795" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009796 let b:netrw_cpf= 0
9797 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009798 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009799 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9800 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009801 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009802 " restore stored registers
9803 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009804" call Dret("NetrwWideListing")
9805 return
9806 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009807 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009808 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009809" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009810
9811 " determine qty files per line (fpl)
9812 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9813 if w:netrw_fpl <= 0
9814 let w:netrw_fpl= 1
9815 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009816" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009817
9818 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009819 " fpc: files per column of wide listing
9820 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009821 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009822 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9823 let newcolstart = w:netrw_bannercnt + fpc
9824 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009825" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009826 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009827" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009828 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009829 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009830 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009831 while line("$") >= newcolstart
9832 if newcolend > line("$") | let newcolend= line("$") | endif
9833 let newcolqty= newcolend - newcolstart
9834 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009835 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009836 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009837 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009838 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009839 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009840 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009841 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009842 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009843 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009844 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009845" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009846 if @* != keepregstar | sil! let @* = keepregstar | endif
9847 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009848 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009849 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9850 NetrwKeepj call histdel("/",-1)
9851 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9852 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009853" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009854 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009855 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009856" 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 +00009857" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009858 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009859 else
9860 if hasmapto("w","n")
9861 sil! nunmap <buffer> w
9862 endif
9863 if hasmapto("b","n")
9864 sil! nunmap <buffer> b
9865 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009866 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009867endfun
9868
9869" ---------------------------------------------------------------------
9870" s:PerformListing: {{{2
9871fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009872" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9873" 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 +02009874" 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>"))
9875 sil! NetrwKeepj %d _
9876" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009877
Bram Moolenaar15146672011-10-20 22:22:38 +02009878 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009879" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009880 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009881
Bram Moolenaar85850f32019-07-19 22:05:51 +02009882 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009883 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009884" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009885
9886" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009887" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009888" endif " Decho
9889
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009890" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009891 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9892 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009893" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9894 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009895 endif
9896
9897 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009898 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009899
9900 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009901 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009902" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009903 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009904 if exists("g:netrw_pchk")
9905 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9906 " failure detections.
9907 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009908 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009909 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9910 endif
9911 if exists("g:netrw_pchk")
9912 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9913 else
9914 let curdir= b:netrw_curdir
9915 endif
9916 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9917 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9918 else
9919 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009920 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009921 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009922 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009923 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009924" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009925 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009926 let w:netrw_bannercnt= 1
9927 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009928" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9929" 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 +00009930
Bram Moolenaar85850f32019-07-19 22:05:51 +02009931 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009932 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009933 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009934 let sortby= sortby." reversed"
9935 endif
9936
9937 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009938 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009939" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009940 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009941" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009942 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009943 NetrwKeepj put ='\" Sorted by '.sortby
9944 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009945 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9946 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009947" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009948 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009949 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009950 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9951 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009952 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009953" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009954" 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 +00009955 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009956
Bram Moolenaar85850f32019-07-19 22:05:51 +02009957 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009958 if g:netrw_banner
9959 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009960" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009961 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009962 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009963 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009964 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009965 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009966 endif
9967 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009968 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009969" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009970 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009971 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009972 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009973
9974 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009975 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009976" 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 +01009977 if g:netrw_list_hide != "" && g:netrw_hide
9978 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009979 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009980 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009981 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009982 endif
9983 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009984 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009985 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009986
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009987" 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 +01009988 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009989" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009990 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009991" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009992 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009993 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009994" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009995" 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 +00009996 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009997
9998 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009999 if g:netrw_banner
10000 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010001 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010002" 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 +010010003" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010004" 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 +010010005 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010006
Bram Moolenaar446cb832008-06-24 21:56:24 +000010007 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010008" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010009 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010010 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010011 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010012 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +010010013 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010014" 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 +010010015" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
10016 return
10017 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010018 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010019
10020 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010021 if !exists("w:netrw_bannercnt")
10022 let w:netrw_bannercnt= 0
10023 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010024" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10025" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10026" 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 +010010027
Bram Moolenaar5c736222010-01-06 20:54:52 +010010028 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010029" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010030" 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 +000010031 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010032 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010033 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010034 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010035" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010036
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010037 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010038 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010039" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010040 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010041
Bram Moolenaar5c736222010-01-06 20:54:52 +010010042 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010043" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010044 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010045 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010046 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010047 else
10048 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010049 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010050 endif
10051 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010052
Bram Moolenaar446cb832008-06-24 21:56:24 +000010053 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010054" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010055 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10056 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010057
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010058 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010059 " exten: sort by extension
10060 " The histdel(...,-1) calls remove the last search from the search history
10061" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010062 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10063 NetrwKeepj call histdel("/",-1)
10064 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10065 NetrwKeepj call histdel("/",-1)
10066 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10067 NetrwKeepj call histdel("/",-1)
10068 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10069" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010070 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010071 " normal direction sorting
10072 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10073 else
10074 " reverse direction sorting
10075 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10076 endif
10077 endif
10078 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10079 NetrwKeepj call histdel("/",-1)
10080
Bram Moolenaar446cb832008-06-24 21:56:24 +000010081 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010082 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010083" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010084 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010085" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010086 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010087 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010088" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010089 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010090 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010091" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010092 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10093 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010094 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010095 endif
10096
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010097 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010098" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010099 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010100 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010101 call histdel("/",-1)
10102 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010103 endif
10104 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010105" 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 +000010106
10107 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010108" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10109" 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 +010010110 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010111" 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 +010010112 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010113" 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 +000010114
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010115 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010116 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010117" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010118 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010119 endif
10120
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010121 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010122 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010123" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10124 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010125 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010126" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10127 else
10128" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10129" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10130" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10131" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010132 endif
10133
10134 " record previous current directory
10135 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010136" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010137
10138 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010139" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10140" 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 +010010141 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010142" 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 +020010143 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010144" 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 +000010145
10146 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010147" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010148 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010149" 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 +010010150 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010151" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010152 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10153 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010154" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010155" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010156
Bram Moolenaar8d043172014-01-23 14:24:41 +010010157 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010158" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10159" 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 +010010160" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10161 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010162 unlet s:treecurpos
10163 endif
10164
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010165" 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>"))
10166" 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 +000010167" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10168endfun
10169
10170" ---------------------------------------------------------------------
10171" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010172fun! s:SetupNetrwStatusLine(statline)
10173" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10174
10175 if !exists("s:netrw_setup_statline")
10176 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010177" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010178
10179 if !exists("s:netrw_users_stl")
10180 let s:netrw_users_stl= &stl
10181 endif
10182 if !exists("s:netrw_users_ls")
10183 let s:netrw_users_ls= &laststatus
10184 endif
10185
10186 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +020010187 let dict={}
10188 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +000010189 redir @a
10190 try
10191 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010192 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010193 if &bg == "dark"
10194 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10195 else
10196 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10197 endif
10198 endtry
10199 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +020010200 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010201 endif
10202
10203 " set up status line (may use User9 highlighting)
10204 " insure that windows have a statusline
10205 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010206 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010207 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010208" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010209 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010210
10211" call Dret("SetupNetrwStatusLine : stl=".&stl)
10212endfun
10213
Bram Moolenaar85850f32019-07-19 22:05:51 +020010214" =========================================
10215" Remote Directory Browsing Support: {{{1
10216" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010217
10218" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010219" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10220" This function assumes that a long listing will be received. Size, time,
10221" and reverse sorts will be requested of the server but not otherwise
10222" enforced here.
10223fun! s:NetrwRemoteFtpCmd(path,listcmd)
10224" 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 +010010225" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010226 " sanity check: {{{3
10227 if !exists("w:netrw_method")
10228 if exists("b:netrw_method")
10229 let w:netrw_method= b:netrw_method
10230 else
10231 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10232" call Dret("NetrwRemoteFtpCmd")
10233 return
10234 endif
10235 endif
10236
10237 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10238 let ffkeep= &ff
10239 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010240" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010241
10242 " clear off any older non-banner lines " {{{3
10243 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010244" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10245 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010246
10247 ".........................................
10248 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10249 " ftp + <.netrc>: Method #2
10250 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010251 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010252 endif
10253 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010254 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010255" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010256 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010257 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010258" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010259 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010260" 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>"))
10261 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 +010010262 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010263" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10264 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 +010010265 endif
10266
10267 ".........................................
10268 elseif w:netrw_method == 3 " {{{3
10269 " ftp + machine,id,passwd,filename: Method #3
10270 setl ff=unix
10271 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010272 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010273 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010274 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010275 endif
10276
10277 " handle userid and password
10278 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010279" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010280 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10281 call NetUserPass("ftp:".host)
10282 endif
10283 if exists("g:netrw_uid") && g:netrw_uid != ""
10284 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010285 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010286 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010287 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010288 endif
10289 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010290 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010291 endif
10292 endif
10293
10294 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010295 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010296 endif
10297 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010298 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010299" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010300 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010301 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010302
10303 " perform ftp:
10304 " -i : turns off interactive prompting from ftp
10305 " -n unix : DON'T use <.netrc>, even though it exists
10306 " -n win32: quit being obnoxious about password
10307 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010308" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010309 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010310" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010311" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10312" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010313 endif
10314
10315 ".........................................
10316 elseif w:netrw_method == 9 " {{{3
10317 " sftp username@machine: Method #9
10318 " s:netrw_sftp_cmd
10319 setl ff=unix
10320
10321 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010322 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010323" call Dret("NetrwRemoteFtpCmd")
10324 return
10325
10326 ".........................................
10327 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010328 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010329 endif
10330
10331 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010332 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010333 sil! NetrwKeepj %s/\r$//e
10334 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010335 endif
10336 if a:listcmd == "dir"
10337 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010338 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10339 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10340 NetrwKeepj call histdel("/",-1)
10341 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010342 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 +010010343 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10344 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010345 endif
10346 endif
10347
10348 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10349 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010350 exe 'NetrwKeepj '.w:netrw_bannercnt
10351 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010352 endif
10353 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010354 exe 'NetrwKeepj '.w:netrw_bannercnt
10355 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010356 endif
10357
10358 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010359 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010360" call Dret("NetrwRemoteFtpCmd")
10361endfun
10362
10363" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010364" s:NetrwRemoteListing: {{{2
10365fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010366" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010367
Bram Moolenaara6878372014-03-22 21:02:50 +010010368 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10369 let w:netrw_bannercnt= s:bannercnt
10370 endif
10371 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010372 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010373 endif
10374
Bram Moolenaar446cb832008-06-24 21:56:24 +000010375 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010376
Bram Moolenaar446cb832008-06-24 21:56:24 +000010377 " sanity check:
10378 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010379" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010380 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010381" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010382 if !exists("g:netrw_quiet")
10383 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10384 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010385 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010386" call Dret("s:NetrwRemoteListing -1")
10387 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010388 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010389
Bram Moolenaar8d043172014-01-23 14:24:41 +010010390 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010391" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010392 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010393 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010394 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 +000010395 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010396 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 +000010397 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010398 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010399
Bram Moolenaar85850f32019-07-19 22:05:51 +020010400 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010401" call Dret("s:NetrwRemoteListing -1")
10402 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010403 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010404" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010405
Bram Moolenaar446cb832008-06-24 21:56:24 +000010406 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010407" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010408 let w:netrw_method= b:netrw_method
10409 endif
10410
Bram Moolenaar13600302014-05-22 18:26:40 +020010411 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010412 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010413" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010414 let s:method = "ftp"
10415 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010416 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010417 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010418 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010419 let listcmd= g:netrw_ftp_sizelist_cmd
10420 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010421" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010422 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010423" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010424
Bram Moolenaara6878372014-03-22 21:02:50 +010010425 " report on missing file or directory messages
10426 if search('[Nn]o such file or directory\|Failed to change directory')
10427 let mesg= getline(".")
10428 if exists("w:netrw_bannercnt")
10429 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010430 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010431 setl noma
10432 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010433 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010434 call netrw#ErrorMsg(s:WARNING,mesg,96)
10435" call Dret("s:NetrwRemoteListing : -1")
10436 return -1
10437 endif
10438
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010439 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 +000010440 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010441" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010442 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010443
10444 " cleanup
10445 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010446 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10447 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010448 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010449 sil! NetrwKeepj %s/\r$//e
10450 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010451
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010452 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010453 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010454 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010455 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010456" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010457 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010458" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010459 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010460 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010461 exe "sil! NetrwKeepj ".line1
10462 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010463
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010464" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010465 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010466" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010467 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10468 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010469 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010470" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010471 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10472 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10473 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10474 NetrwKeepj call histdel("/",-1)
10475 NetrwKeepj call histdel("/",-1)
10476 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010477 endif
10478 endif
10479
Bram Moolenaar13600302014-05-22 18:26:40 +020010480 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010481 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010482" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010483 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010484" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010485 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010486" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10487 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010488 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010489 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10490 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10491 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10492 NetrwKeepj call histdel("/",-1)
10493 NetrwKeepj call histdel("/",-1)
10494 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010495 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010496 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10497 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010498 endif
10499 else
10500 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010501" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010502 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010503 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010504" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10505 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10506" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010507 endif
10508 endif
10509
10510 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010511 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010512" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010513 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10514 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010515 endif
10516 endif
10517
10518 if w:netrw_liststyle == s:LONGLIST
10519 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010520" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010521
10522 if s:method == "ftp"
10523 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010524 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010525 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010526 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010527 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010528 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010529 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010530 sil! NetrwKeepj 1
10531 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010532 let line2= line(".")
10533 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010534 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010535 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010536 endif
10537 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010538 exe "sil! NetrwKeepj ".line1
10539 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010540 endif
10541
10542 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010543" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010544 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 +000010545 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010546" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010547 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010548 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010549 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10550 NetrwKeepj call histdel("/",-1)
10551 NetrwKeepj call histdel("/",-1)
10552 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010553 endif
10554 endif
10555
10556" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010557" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010558" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010559
10560" call Dret("s:NetrwRemoteListing 0")
10561 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010562endfun
10563
Bram Moolenaar446cb832008-06-24 21:56:24 +000010564" ---------------------------------------------------------------------
10565" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10566fun! s:NetrwRemoteRm(usrhost,path) range
10567" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010568" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010569 let svpos= winsaveview()
10570" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010571
10572 let all= 0
10573 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10574 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010575" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010576 for fname in s:netrwmarkfilelist_{bufnr("%")}
10577 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010578 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010579 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010580 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010581 let all= 1
10582 endif
10583 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010584 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010585
10586 else
10587 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010588" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010589
10590 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010591 let keepsol = &l:sol
10592 setl nosol
10593 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010594
10595 " remove multiple files and directories
10596 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010597 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010598 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010599 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010600 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010601 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010602 let all= 1
10603 endif
10604 let ctr= ctr + 1
10605 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010606 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010607 endif
10608
10609 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010610" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010611 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010612" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10613 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010614
10615" call Dret("s:NetrwRemoteRm")
10616endfun
10617
10618" ---------------------------------------------------------------------
10619" s:NetrwRemoteRmFile: {{{2
10620fun! s:NetrwRemoteRmFile(path,rmfile,all)
10621" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10622
10623 let all= a:all
10624 let ok = ""
10625
10626 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10627 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010628" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010629 if !all
10630 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010631" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010632 call inputsave()
10633 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10634 call inputrestore()
10635 echohl NONE
10636 if ok == ""
10637 let ok="no"
10638 endif
10639 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010640 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010641 let all= 1
10642 endif
10643 endif
10644
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010645 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010646" 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 +000010647 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010648" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010649 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010650 if path =~ '^\a\{3,}://'
10651 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010652 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010653 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010654 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10655 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010656" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010657 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010658" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010659 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010660 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010661 let ok="q"
10662 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010663 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010664" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10665" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10666" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010667 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010668 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010669 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010670 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010671 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010672" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010673 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010674 if v:shell_error != 0
10675 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010676 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 +010010677 else
10678 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10679 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010680 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010681 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010682 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010683" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010684 endif
10685 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010686 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010687" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010688 endif
10689
10690 else
10691 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010692" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010693 if !all
10694 call inputsave()
10695 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10696 call inputrestore()
10697 if ok == ""
10698 let ok="no"
10699 endif
10700 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010701 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010702 let all= 1
10703 endif
10704 endif
10705
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010706 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010707 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010708 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010709 else
10710 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010711 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10712" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010713 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010714" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010715
10716 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010717" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10718 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10719" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010720 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010721" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010722
10723 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010724 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010725 endif
10726 endif
10727 endif
10728
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010729 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010730" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010731 endif
10732 endif
10733
10734" call Dret("s:NetrwRemoteRmFile ".ok)
10735 return ok
10736endfun
10737
10738" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010739" s:NetrwRemoteRename: rename a remote file or directory {{{2
10740fun! s:NetrwRemoteRename(usrhost,path) range
10741" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10742
10743 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010744 let svpos = winsaveview()
10745" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010746 let ctr = a:firstline
10747 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10748
10749 " rename files given by the markfilelist
10750 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10751 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010752" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010753 if exists("subfrom")
10754 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010755" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010756 else
10757 call inputsave()
10758 let newname= input("Moving ".oldname." to : ",oldname)
10759 call inputrestore()
10760 if newname =~ '^s/'
10761 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10762 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10763 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010764" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010765 endif
10766 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010767
Bram Moolenaar446cb832008-06-24 21:56:24 +000010768 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010769 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010770 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010771 let oldname= s:ShellEscape(a:path.oldname)
10772 let newname= s:ShellEscape(a:path.newname)
10773" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010774 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010775 endif
10776
10777 endfor
10778 call s:NetrwUnMarkFile(1)
10779
10780 else
10781
10782 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010783 let keepsol= &l:sol
10784 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010785 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010786 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010787
10788 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010789" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010790
10791 call inputsave()
10792 let newname= input("Moving ".oldname." to : ",oldname)
10793 call inputrestore()
10794
10795 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10796 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10797 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010798 let oldname= s:ShellEscape(a:path.oldname)
10799 let newname= s:ShellEscape(a:path.newname)
10800" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010801 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010802 endif
10803
10804 let ctr= ctr + 1
10805 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010806 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010807 endif
10808
10809 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010810 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010811" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10812 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010813
10814" call Dret("NetrwRemoteRename")
10815endfun
10816
Bram Moolenaar85850f32019-07-19 22:05:51 +020010817" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010818" Local Directory Browsing Support: {{{1
10819" ==========================================
10820
10821" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010822" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010823" Should accept: file://localhost/etc/fstab
10824" file:///etc/fstab
10825" file:///c:/WINDOWS/clock.avi
10826" file:///c|/WINDOWS/clock.avi
10827" file://localhost/c:/WINDOWS/clock.avi
10828" file://localhost/c|/WINDOWS/clock.avi
10829" file://c:/foo.txt
10830" file:///c:/foo.txt
10831" 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 +020010832fun! netrw#FileUrlEdit(fname)
10833" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010834 let fname = a:fname
10835 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010836" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010837 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010838" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010839 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010840 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010841 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010842" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010843 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010844" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010845 endif
10846 endif
10847 let fname2396 = netrw#RFC2396(fname)
10848 let fname2396e= fnameescape(fname2396)
10849 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010850 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010851" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010852 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010853" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010854 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10855 endif
10856 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010857
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010858" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10859" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010860 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010861 exe 'NetrwKeepj keepalt edit '.plainfname
10862 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10863
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010864" 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 +020010865" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010866 exe "sil doau BufReadPost ".fname2396e
10867endfun
10868
10869" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010870" netrw#LocalBrowseCheck: {{{2
10871fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010872 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010873 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10874 "
10875 " unfortunate interaction -- split window debugging can't be used here, must use
10876 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10877 " another call to LocalBrowseCheck() when attempts to write
10878 " to the DBG buffer are made.
10879 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010880 " The &ft == "netrw" test was installed because the BufEnter event
10881 " would hit when re-entering netrw windows, creating unexpected
10882 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010883" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010884" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010885" 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 +010010886 " getting E930: Cannot use :redir inside execute
10887"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010888" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10889" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010890
Bram Moolenaar97d62492012-11-15 21:28:22 +010010891 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010892 if isdirectory(s:NetrwFile(a:dirname))
10893" 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 +010010894
Bram Moolenaar97d62492012-11-15 21:28:22 +010010895 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010896" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10897" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010898 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010899
Bram Moolenaar446cb832008-06-24 21:56:24 +000010900 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010901" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010902 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010903
Bram Moolenaar5c736222010-01-06 20:54:52 +010010904 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010905" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010906 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010907 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010908 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010909" 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 +010010910" call Dret("netrw#LocalBrowseCheck")
10911 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010912 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010913
Bram Moolenaar85850f32019-07-19 22:05:51 +020010914 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010915 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10916 " AND IF the listing style is not a tree listing
10917 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010918" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010919 let ibuf = 1
10920 let buflast = bufnr("$")
10921 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010922 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10923 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010924 endif
10925 let ibuf= ibuf + 1
10926 endwhile
10927 endif
10928 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010929" 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>"))
10930" 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 +000010931 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010932" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010933endfun
10934
10935" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010936" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010937" performed any shell command. The idea is to cause all local-browsing
10938" buffers to be refreshed after a user has executed some shell command,
10939" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010940fun! s:LocalBrowseRefresh()
10941" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010942" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10943" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010944
Bram Moolenaar446cb832008-06-24 21:56:24 +000010945 " determine which buffers currently reside in a tab
10946 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010947" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010948 return
10949 endif
10950 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010951" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010952 return
10953 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010954 if !empty(getcmdwintype())
10955 " cannot move away from cmdline window, see :h E11
10956 return
10957 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010958 if exists("s:netrw_events") && s:netrw_events == 1
10959 " s:LocalFastBrowser gets called (indirectly) from a
10960 let s:netrw_events= 2
10961" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10962 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010963 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010964 let itab = 1
10965 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010966 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010967 while itab <= tabpagenr("$")
10968 let buftablist = buftablist + tabpagebuflist()
10969 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010970 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010971 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010972" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10973" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010974 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10975 " | refresh any netrw window
10976 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010977 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010978 let ibl = 0
10979 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010980" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010981 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10982 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010983 " (ibuf not shown in a current window AND
10984 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010985" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10986 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010987 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010988" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010989 continue
10990 elseif index(tabpagebuflist(),ibuf) != -1
10991 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010992" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010993 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010994 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010995 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10996 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10997 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10998 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010999" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011000 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
11001 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
11002 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011003 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011004 endif
11005 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011006" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011007 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020011008" call Decho("restore window: win_gotoid(".curwinid.")")
11009 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011010 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011011
Bram Moolenaara6878372014-03-22 21:02:50 +010011012" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011013endfun
11014
11015" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011016" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
11017"
11018" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011019" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010011020" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
11021" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011022" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011023"
11024" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11025" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011026" (re-using a buffer may not be as accurate)
11027"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011028" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011029" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11030" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11031" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11032" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011033fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011034" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11035" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11036" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11037" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011038
11039 " initialize browselist, a list of buffer numbers that the local browser has used
11040 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011041" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011042 let s:netrw_browselist= []
11043 endif
11044
11045 " append current buffer to fastbrowse list
11046 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011047" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011048 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011049" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011050 endif
11051
11052 " enable autocmd events to handle refreshing/removing local browser buffers
11053 " If local browse buffer is currently showing: refresh it
11054 " If local browse buffer is currently hidden : wipe it
11055 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11056 " =1 : medium speed, re-use directory listing for remote only
11057 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011058 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11059 let s:netrw_events= 1
11060 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011061 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020011062 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011063" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011064 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011065 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011066" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011067 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011068 endif
11069 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011070
11071 " user must have changed fastbrowse to its fast setting, so remove
11072 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011073 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011074" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011075 unlet s:netrw_events
11076 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011077 au!
11078 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011079 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011080 endif
11081
Bram Moolenaar85850f32019-07-19 22:05:51 +020011082" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011083endfun
11084
11085" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011086" s:LocalListing: does the job of "ls" for local directories {{{2
11087fun! s:LocalListing()
11088" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011089" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11090" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11091" 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 +010011092
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011093" 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
11094" 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
11095" 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 +010011096
11097 " get the list of files contained in the current directory
11098 let dirname = b:netrw_curdir
11099 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011100 let filelist = s:NetrwGlob(dirname,"*",0)
11101 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011102" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011103
Nir Lichtman1e34b952024-05-08 19:19:34 +020011104 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011105" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011106 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11107 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011108" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011109 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011110" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011111 endif
11112
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011113" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011114" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011115" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011116
11117 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11118 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11119 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011120" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11121" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011122 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011123" 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 +010011124
11125 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011126" call Decho(" ",'~'.expand("<slnum>"))
11127" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011128
11129 if getftype(filename) == "link"
11130 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011131" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011132 let pfile= filename."@"
11133
11134 elseif getftype(filename) == "socket"
11135 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011136" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011137 let pfile= filename."="
11138
11139 elseif getftype(filename) == "fifo"
11140 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011141" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011142 let pfile= filename."|"
11143
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011144 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011145 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011146" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011147 let pfile= filename."/"
11148
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011149 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011150 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011151 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11152 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011153" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011154 let pfile= filename."*"
11155 else
11156 " normal file
11157 let pfile= filename
11158 endif
11159 elseif executable(filename)
11160 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011161" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011162 let pfile= filename."*"
11163 else
11164 " normal file
11165 let pfile= filename
11166 endif
11167
11168 else
11169 " normal file
11170 let pfile= filename
11171 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011172" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011173
11174 if pfile =~ '//$'
11175 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011176" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011177 endif
11178 let pfile= strpart(pfile,dirnamelen)
11179 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011180" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11181" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011182
11183 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011184 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11185 let sz = getfsize(filename)
11186 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11187 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011188
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011189 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011190 let sz= s:NetrwHumanReadable(sz)
11191 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011192 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011193 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011194" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011195 endif
11196
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011197 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011198 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011199 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011200" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011201" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011202 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011203 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011204" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011205 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011206 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011207
11208 elseif g:netrw_sort_by =~ "^s"
11209 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011210" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011211" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011212 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011213 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011214" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011215 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011216 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011217
11218 else
11219 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011220" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011221" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011222 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011223 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011224" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011225 endfor
11226
11227 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011228 sil! NetrwKeepj g/^$/d
11229 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011230 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011231" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011232 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11233
11234" call Dret("s:LocalListing")
11235endfun
11236
11237" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011238" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11239fun! s:NetrwLocalExecute(cmd)
11240" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11241 let ykeep= @@
11242 " sanity check
11243 if !executable(a:cmd)
11244 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11245 let @@= ykeep
11246" call Dret("s:NetrwLocalExecute")
11247 return
11248 endif
11249
11250 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011251" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011252 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011253" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011254
11255 " strip any ansi escape sequences off
11256 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11257
11258 " show user the result(s)
11259 echomsg result
11260 let @@= ykeep
11261
11262" call Dret("s:NetrwLocalExecute")
11263endfun
11264
11265" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011266" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011267fun! s:NetrwLocalRename(path) range
11268" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11269
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011270 if !exists("w:netrw_bannercnt")
11271 let w:netrw_bannercnt= b:netrw_bannercnt
11272 endif
11273
Bram Moolenaar97d62492012-11-15 21:28:22 +010011274 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011275 let ykeep = @@
11276 let ctr = a:firstline
11277 let svpos = winsaveview()
11278 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011279" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011280
11281 " rename files given by the markfilelist
11282 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11283 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011284" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011285 if exists("subfrom")
11286 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011287" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011288 else
11289 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011290 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011291 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011292 if newname =~ ''
11293 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11294 let newname = substitute(newname,'^.*','','')
11295 elseif newname =~ ''
11296 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11297 let newname = substitute(newname,'[^/]*','','')
11298 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011299 if newname =~ '^s/'
11300 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11301 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011302" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011303 let newname = substitute(oldname,subfrom,subto,'')
11304 endif
11305 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011306 if !all && filereadable(newname)
11307 call inputsave()
11308 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11309 call inputrestore()
11310 if response == "all"
11311 let all= 1
11312 elseif response != "y" && response != "yes"
11313 " refresh the directory
11314" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11315 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11316" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11317 NetrwKeepj call winrestview(svpos)
11318 let @@= ykeep
11319" call Dret("NetrwLocalRename")
11320 return
11321 endif
11322 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011323 call rename(oldname,newname)
11324 endfor
11325 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011326
Bram Moolenaar97d62492012-11-15 21:28:22 +010011327 else
11328
11329 " attempt to rename files/directories
11330 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011331 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011332
11333 " sanity checks
11334 if line(".") < w:netrw_bannercnt
11335 let ctr= ctr + 1
11336 continue
11337 endif
11338 let curword= s:NetrwGetWord()
11339 if curword == "./" || curword == "../"
11340 let ctr= ctr + 1
11341 continue
11342 endif
11343
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011344 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011345 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011346" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011347
11348 call inputsave()
11349 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11350 call inputrestore()
11351
11352 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011353" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011354
11355 let ctr= ctr + 1
11356 endwhile
11357 endif
11358
11359 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011360" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011361 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011362" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11363 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011364 let @@= ykeep
11365
11366" call Dret("NetrwLocalRename")
11367endfun
11368
11369" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011370" s:NetrwLocalRm: {{{2
11371fun! s:NetrwLocalRm(path) range
11372" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011373" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011374
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011375 if !exists("w:netrw_bannercnt")
11376 let w:netrw_bannercnt= b:netrw_bannercnt
11377 endif
11378
Bram Moolenaar446cb832008-06-24 21:56:24 +000011379 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011380 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011381 let ret = 0
11382 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011383 let svpos = winsaveview()
11384" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011385
11386 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11387 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011388" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011389 for fname in s:netrwmarkfilelist_{bufnr("%")}
11390 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011391 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011392 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011393 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011394 let all= 1
11395 endif
11396 endfor
11397 call s:NetrwUnMarkFile(1)
11398
11399 else
11400 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011401" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011402
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011403 let keepsol= &l:sol
11404 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011405 let ctr = a:firstline
11406 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011407 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011408
11409 " sanity checks
11410 if line(".") < w:netrw_bannercnt
11411 let ctr= ctr + 1
11412 continue
11413 endif
11414 let curword= s:NetrwGetWord()
11415 if curword == "./" || curword == "../"
11416 let ctr= ctr + 1
11417 continue
11418 endif
11419 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011420 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011421 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011422 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011423 let all= 1
11424 endif
11425 let ctr= ctr + 1
11426 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011427 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011428 endif
11429
11430 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011431" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011432 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011433 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011434" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11435 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011436 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011437 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011438
11439" call Dret("s:NetrwLocalRm")
11440endfun
11441
11442" ---------------------------------------------------------------------
11443" s:NetrwLocalRmFile: remove file fname given the path {{{2
11444" Give confirmation prompt unless all==1
11445fun! s:NetrwLocalRmFile(path,fname,all)
11446" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011447
Bram Moolenaar446cb832008-06-24 21:56:24 +000011448 let all= a:all
11449 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011450 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020011451 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011452" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011453
11454 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11455 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011456" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011457 if !all
11458 echohl Statement
11459 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011460 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011461 call inputrestore()
11462 echohl NONE
11463 if ok == ""
11464 let ok="no"
11465 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011466" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011467 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011468" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011469 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011470 let all= 1
11471 endif
11472 endif
11473
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011474 if all || ok =~# '^y\%[es]$' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011475 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011476" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011477 endif
11478
11479 else
11480 " attempt to remove directory
11481 if !all
11482 echohl Statement
11483 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011484 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011485 call inputrestore()
11486 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11487 if ok == ""
11488 let ok="no"
11489 endif
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011490 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011491 let all= 1
11492 endif
11493 endif
11494 let rmfile= substitute(rmfile,'[\/]$','','e')
11495
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011496 if all || ok =~# '^y\%[es]$' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011497 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011498 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011499 endif
11500 endif
11501 endif
11502
11503" call Dret("s:NetrwLocalRmFile ".ok)
11504 return ok
11505endfun
11506
Bram Moolenaar85850f32019-07-19 22:05:51 +020011507" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011508" Support Functions: {{{1
11509
Bram Moolenaar488c6512005-08-11 20:09:58 +000011510" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011511" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11512" 0: marked file list of current buffer
11513" 1: marked file target
11514fun! netrw#Access(ilist)
11515 if a:ilist == 0
11516 if exists("s:netrwmarkfilelist_".bufnr('%'))
11517 return s:netrwmarkfilelist_{bufnr('%')}
11518 else
11519 return "no-list-buf#".bufnr('%')
11520 endif
11521 elseif a:ilist == 1
11522 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011523 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011524endfun
11525
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011526" ---------------------------------------------------------------------
11527" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11528fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011529 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011530endfun
11531
Bram Moolenaara6878372014-03-22 21:02:50 +010011532" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011533" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11534" I expect this function to be used in
11535" :PChkAssert netrw#Expose("netrwmarkfilelist")
11536" for example.
11537fun! netrw#Expose(varname)
11538" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011539 if exists("s:".a:varname)
11540 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011541" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011542 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011543" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011544 if type(retval) == 3
11545 let retval = copy(retval)
11546 let i = 0
11547 while i < len(retval)
11548 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11549 let i = i + 1
11550 endwhile
11551 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011552" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011553 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011554 else
11555" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011556 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011557 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011558" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011559 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011560 endif
11561
11562" call Dret("netrw#Expose ".string(retval))
11563 return retval
11564endfun
11565
11566" ---------------------------------------------------------------------
11567" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11568fun! netrw#Modify(varname,newvalue)
11569" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11570 exe "let s:".a:varname."= ".string(a:newvalue)
11571" call Dret("netrw#Modify")
11572endfun
11573
11574" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011575" netrw#RFC2396: converts %xx into characters {{{2
11576fun! netrw#RFC2396(fname)
11577" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011578 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011579" call Dret("netrw#RFC2396 ".fname)
11580 return fname
11581endfun
11582
11583" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011584" netrw#UserMaps: supports user-specified maps {{{2
11585" see :help function()
11586"
11587" g:Netrw_UserMaps is a List with members such as:
11588" [[keymap sequence, function reference],...]
11589"
11590" The referenced function may return a string,
11591" refresh : refresh the display
11592" -other- : this string will be executed
11593" or it may return a List of strings.
11594"
11595" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011596" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011597" Related functions:
11598" netrw#Expose(varname) -- see s:varname variables
11599" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11600" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11601fun! netrw#UserMaps(islocal)
11602" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11603" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11604
11605 " set up usermaplist
11606 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11607" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11608 for umap in g:Netrw_UserMaps
11609" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11610" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11611 " if umap[0] is a string and umap[1] is a string holding a function name
11612 if type(umap[0]) == 1 && type(umap[1]) == 1
11613" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11614 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11615 else
11616 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11617 endif
11618 endfor
11619 endif
11620" call Dret("netrw#UserMaps")
11621endfun
11622
11623" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011624" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11625fun! netrw#WinPath(path)
11626" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011627 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011628 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011629 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011630 " remove trailing slash (Win95)
11631 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11632 " remove escaped spaces
11633 let path = substitute(path, '\ ', ' ', 'g')
11634 " convert slashes to backslashes
11635 let path = substitute(path, '/', '\', 'g')
11636 else
11637 let path= a:path
11638 endif
11639" call Dret("netrw#WinPath <".path.">")
11640 return path
11641endfun
11642
11643" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020011644" s:StripTrailingSlash: removes trailing slashes from a path {{{2
11645fun! s:StripTrailingSlash(path)
11646 " remove trailing slash
11647 return substitute(a:path, '[/\\]$', '', 'g')
11648endfun
11649
Travis Sheltone34d0e32024-07-30 21:08:56 +020011650" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011651" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11652" cb : bl2mf=0 add marked files to buffer list
11653" cB : bl2mf=1 use bufferlist to mark files
11654" (mnemonic: cb = copy (marked files) to buffer list)
11655fun! s:NetrwBadd(islocal,bl2mf)
11656" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11657 if a:bl2mf
11658 " cB: add buffer list to marked files
11659 redir => bufl
11660 ls
11661 redir END
11662 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11663 for fname in bufl
11664 call s:NetrwMarkFile(a:islocal,fname)
11665 endfor
11666 else
11667 " cb: add marked files to buffer list
11668 for fname in s:netrwmarkfilelist_{bufnr("%")}
11669" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11670 exe "badd ".fnameescape(fname)
11671 endfor
11672 let curbufnr = bufnr("%")
11673 let curdir = s:NetrwGetCurdir(a:islocal)
11674 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11675 endif
11676" call Dret("s:NetrwBadd")
11677endfun
11678
11679" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011680" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11681fun! s:ComposePath(base,subdir)
11682" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11683
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011684 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011685" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011686 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011687 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011688 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011689 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011690 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011691 endif
11692
Bram Moolenaar85850f32019-07-19 22:05:51 +020011693 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011694 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011695" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011696 let ret= a:subdir
11697
Nir Lichtman1e34b952024-05-08 19:19:34 +020011698 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011699" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011700 if a:base =~ '[/\\]$'
11701 let ret= a:base.a:subdir
11702 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011703 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011704 endif
11705
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011706 elseif a:base =~ '^\a\{3,}://'
11707" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011708 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11709 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11710 if a:subdir == '../'
11711 if curpath =~ '[^/]/[^/]\+/$'
11712 let curpath= substitute(curpath,'[^/]\+/$','','')
11713 else
11714 let curpath=""
11715 endif
11716 let ret= urlbase.curpath
11717 else
11718 let ret= urlbase.curpath.a:subdir
11719 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011720" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11721" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11722" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011723
11724 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011725" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011726 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11727 if a:base =~ '^//'
11728 " keeping initial '//' for the benefit of network share listing support
11729 let ret= '/'.ret
11730 endif
11731 let ret= simplify(ret)
11732 endif
11733
11734" call Dret("s:ComposePath ".ret)
11735 return ret
11736endfun
11737
11738" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011739" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11740" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11741fun! s:DeleteBookmark(fname)
11742" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11743 call s:MergeBookmarks()
11744
11745 if exists("g:netrw_bookmarklist")
11746 let indx= index(g:netrw_bookmarklist,a:fname)
11747 if indx == -1
11748 let indx= 0
11749 while indx < len(g:netrw_bookmarklist)
11750 if g:netrw_bookmarklist[indx] =~ a:fname
11751 call remove(g:netrw_bookmarklist,indx)
11752 let indx= indx - 1
11753 endif
11754 let indx= indx + 1
11755 endwhile
11756 else
11757 " remove exact match
11758 call remove(g:netrw_bookmarklist,indx)
11759 endif
11760 endif
11761
11762" call Dret("s:DeleteBookmark")
11763endfun
11764
11765" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011766" s:FileReadable: o/s independent filereadable {{{2
11767fun! s:FileReadable(fname)
11768" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11769
11770 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011771 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011772 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011773 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011774 endif
11775
11776" call Dret("s:FileReadable ".ret)
11777 return ret
11778endfun
11779
11780" ---------------------------------------------------------------------
11781" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11782" Places correct suffix on end of temporary filename,
11783" using the suffix provided with fname
11784fun! s:GetTempfile(fname)
11785" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11786
11787 if !exists("b:netrw_tmpfile")
11788 " get a brand new temporary filename
11789 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011790" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011791
Bram Moolenaarc236c162008-07-13 17:41:49 +000011792 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011793" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011794
Bram Moolenaar9964e462007-05-05 17:54:07 +000011795 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011796 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11797" 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 +010011798 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011799" call Dret("s:GetTempfile getcwd<".getcwd().">")
11800 return ""
11801 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011802
Bram Moolenaar9964e462007-05-05 17:54:07 +000011803 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011804 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011805" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011806
Bram Moolenaar9964e462007-05-05 17:54:07 +000011807 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011808 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011809 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011810 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011811 if !exists("+shellslash") || !&ssl
11812 let tmpfile = substitute(tmpfile,'/','\','g')
11813 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011814 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011815 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011816 endif
11817 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011818" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011819 else
11820 " re-use temporary filename
11821 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011822" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011823 endif
11824
11825 " use fname's suffix for the temporary file
11826 if a:fname != ""
11827 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011828" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011829 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011830 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011831 elseif a:fname =~ '.txz$'
11832 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011833 else
11834 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11835 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011836" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011837 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011838" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011839 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011840" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011841 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11842 endif
11843 endif
11844
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011845" 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 +000011846" call Dret("s:GetTempfile <".tmpfile.">")
11847 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011848endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011849
11850" ---------------------------------------------------------------------
11851" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011852" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011853fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011854" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011855 if s:user == ""
11856 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11857 else
11858 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11859 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011860 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011861 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011862 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011863 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011864 else
11865 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11866 endif
11867" call Dret("s:MakeSshCmd <".sshcmd.">")
11868 return sshcmd
11869endfun
11870
11871" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011872" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11873fun! s:MakeBookmark(fname)
11874" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11875
11876 if !exists("g:netrw_bookmarklist")
11877 let g:netrw_bookmarklist= []
11878 endif
11879
11880 if index(g:netrw_bookmarklist,a:fname) == -1
11881 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011882 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011883 call add(g:netrw_bookmarklist,a:fname.'/')
11884 elseif a:fname !~ '/'
11885 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11886 else
11887 call add(g:netrw_bookmarklist,a:fname)
11888 endif
11889 call sort(g:netrw_bookmarklist)
11890 endif
11891
11892" call Dret("s:MakeBookmark")
11893endfun
11894
11895" ---------------------------------------------------------------------
11896" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11897fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011898" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011899 " get bookmarks from .netrwbook file
11900 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011901 if filereadable(s:NetrwFile(savefile))
11902" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011903 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011904" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011905 NetrwKeepj call delete(savefile)
11906 endif
11907" call Dret("s:MergeBookmarks")
11908endfun
11909
11910" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011911" s:NetrwBMShow: {{{2
11912fun! s:NetrwBMShow()
11913" call Dfunc("s:NetrwBMShow()")
11914 redir => bmshowraw
11915 menu
11916 redir END
11917 let bmshowlist = split(bmshowraw,'\n')
11918 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011919 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011920 if bmshowfuncs != []
11921 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011922 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011923 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011924 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011925 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011926 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011927" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11928endfun
11929
11930" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011931" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011932fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011933 if !exists("w:netrw_liststyle")
11934 let w:netrw_liststyle= g:netrw_liststyle
11935 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011936" 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 +020011937
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011938" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11939
Bram Moolenaaradc21822011-04-01 18:03:16 +020011940 if &ft != "netrw"
11941 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11942 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011943" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011944
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011945 elseif g:netrw_cursor == 8
11946 if w:netrw_liststyle == s:WIDELIST
11947 setl cursorline
11948 setl cursorcolumn
11949 else
11950 setl cursorline
11951 endif
11952 elseif g:netrw_cursor == 7
11953 setl cursorline
11954 elseif g:netrw_cursor == 6
11955 if w:netrw_liststyle == s:WIDELIST
11956 setl cursorline
11957 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011958 elseif g:netrw_cursor == 4
11959 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011960" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011961 setl cursorline
11962 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011963
11964 elseif g:netrw_cursor == 3
11965 " thin-long-tree: cursorline, user's cursorcolumn
11966 " wide : cursorline, cursorcolumn
11967 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011968" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011969 setl cursorline
11970 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011971 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011972" 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 +020011973 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011974 endif
11975
11976 elseif g:netrw_cursor == 2
11977 " thin-long-tree: cursorline, user's cursorcolumn
11978 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011979" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011980 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011981
11982 elseif g:netrw_cursor == 1
11983 " thin-long-tree: user's cursorline, user's cursorcolumn
11984 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011985 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011986" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011987 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011988 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011989" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011990 endif
11991
11992 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011993 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011994" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011995 let &l:cursorline = s:netrw_usercul
11996 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011997 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011998
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011999" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020012000" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012001endfun
12002
12003" ---------------------------------------------------------------------
12004" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
12005fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010012006" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020012007 if exists("s:netrw_usercul")
12008 let &l:cursorline = s:netrw_usercul
12009 endif
12010 if exists("s:netrw_usercuc")
12011 let &l:cursorcolumn = s:netrw_usercuc
12012 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012013" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012014" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
12015endfun
12016
Christian Brabandt62f7b552024-06-23 20:23:40 +020012017" s:RestoreRegister: restores all registers given in the dict {{{2
12018fun! s:RestoreRegister(dict)
12019 for [key, val] in items(a:dict)
12020 if key == 'unnamed'
12021 let key = ''
12022 endif
12023 call setreg(key, val[0], val[1])
12024 endfor
12025endfun
12026
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012027" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012028" s:NetrwDelete: Deletes a file. {{{2
12029" Uses Steve Hall's idea to insure that Windows paths stay
12030" acceptable. No effect on Unix paths.
12031" Examples of use: let result= s:NetrwDelete(path)
12032fun! s:NetrwDelete(path)
12033" call Dfunc("s:NetrwDelete(path<".a:path.">)")
12034
Bram Moolenaar5c736222010-01-06 20:54:52 +010012035 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012036 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000012037 if exists("+shellslash")
12038 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012039 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012040 let result = delete(path)
12041 let &shellslash = sskeep
12042 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012043" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012044 let result= delete(path)
12045 endif
12046 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012047" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012048 let result= delete(path)
12049 endif
12050 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012051 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012052 endif
12053
12054" call Dret("s:NetrwDelete ".result)
12055 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012056endfun
12057
12058" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012059" s:NetrwBufRemover: removes a buffer that: {{{2s
12060" has buffer-id > 1
12061" is unlisted
12062" is unnamed
12063" does not appear in any window
12064fun! s:NetrwBufRemover(bufid)
12065" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12066" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12067" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12068" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12069" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12070
yasuda4dbb2662023-10-04 20:50:35 +020012071 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012072" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012073 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012074 endif
12075
12076" call Dret("s:NetrwBufRemover")
12077endfun
12078
12079" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012080" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012081fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012082" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012083" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012084
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012085 " Clean out the last buffer:
12086 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12087 " If so, delete it.
12088 call s:NetrwBufRemover(bufnr("$"))
12089
Bram Moolenaar446cb832008-06-24 21:56:24 +000012090 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012091" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012092 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12093 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12094 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12095 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12096 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12097 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12098 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12099 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12100 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12101 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12102 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12103 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12104 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12105 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12106 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12107 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12108
Bram Moolenaar85850f32019-07-19 22:05:51 +020012109 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012110" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012111 " when tree listing uses file TreeListing... a new buffer is made.
12112 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012113 " COMBAK: this causes a problem, see P43
12114" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012115 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012116 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012117 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012118" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012119 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012120
Bram Moolenaar446cb832008-06-24 21:56:24 +000012121 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012122" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012123 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12124 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12125 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12126 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12127 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12128 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12129 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12130 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12131 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12132 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12133 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12134 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12135 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12136 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12137 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12138 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12139
Bram Moolenaar5c736222010-01-06 20:54:52 +010012140 if a:0 > 0
12141 let b:netrw_curdir= a:1
12142 if b:netrw_curdir =~ '/$'
12143 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012144 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012145 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012146 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012147 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12148 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012149 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012150 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012151 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012152 endif
12153 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012154 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12155 let &l:bexpr = "netrw#BalloonHelp()"
12156 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012157
Bram Moolenaar8d043172014-01-23 14:24:41 +010012158" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012159endfun
12160
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012161" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012162" s:NetrwExe: executes a string using "!" {{{2
12163fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012164" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012165 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012166" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012167 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12168 set shell& shellcmdflag& shellxquote& shellxescape&
12169 set shellquote& shellpipe& shellredir& shellslash&
12170 exe a:cmd
12171 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12172 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012173" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012174 exe a:cmd
12175 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012176 if v:shell_error
12177 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12178 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012179" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012180endfun
12181
12182" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012183" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12184fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012185 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012186" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012187 let curbuf = bufnr("%")
12188 let curwin = winnr()
12189 let iwin = 1
12190 while iwin <= winnr("$")
12191 exe iwin."wincmd w"
12192 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12193 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12194 let winvars= w:
12195 break
12196 endif
12197 let iwin= iwin + 1
12198 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012199 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012200 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012201" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012202 for k in keys(winvars)
12203 let w:{k}= winvars[k]
12204 endfor
12205 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012206" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012207 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012208endfun
12209
Bram Moolenaara6878372014-03-22 21:02:50 +010012210" ---------------------------------------------------------------------
12211" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012212" Returns: 0=success
12213" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012214fun! s:NetrwLcd(newdir)
12215" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012216" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012217
Bram Moolenaar85850f32019-07-19 22:05:51 +020012218 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012219 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012220 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012221 catch /^Vim\%((\a\+)\)\=:E344/
12222 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12223 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012224 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012225 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12226 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012227 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012228 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12229 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012230 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012231 endif
12232 endif
12233 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012234 let err472= 1
12235 endtry
12236
12237 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012238 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12239 if exists("w:netrw_prvdir")
12240 let a:newdir= w:netrw_prvdir
12241 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012242 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012243" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012244 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012245" 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 +010012246 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012247 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012248" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12249 return -1
12250 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012251
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012252" call Decho("getcwd <".getcwd().">")
12253" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012254" call Dret("s:NetrwLcd 0")
12255 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012256endfun
12257
Bram Moolenaar9964e462007-05-05 17:54:07 +000012258" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012259" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12260" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12261fun! s:NetrwSaveWordPosn()
12262" call Dfunc("NetrwSaveWordPosn()")
12263 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12264" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12265endfun
12266
12267" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012268" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12269" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12270fun! s:NetrwHumanReadable(sz)
12271" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12272
12273 if g:netrw_sizestyle == 'h'
12274 if a:sz >= 1000000000
12275 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12276 elseif a:sz >= 10000000
12277 let sz = printf("%d",a:sz/1000000)."m"
12278 elseif a:sz >= 1000000
12279 let sz = printf("%.1f",a:sz/1000000.0)."m"
12280 elseif a:sz >= 10000
12281 let sz = printf("%d",a:sz/1000)."k"
12282 elseif a:sz >= 1000
12283 let sz = printf("%.1f",a:sz/1000.0)."k"
12284 else
12285 let sz= a:sz
12286 endif
12287
12288 elseif g:netrw_sizestyle == 'H'
12289 if a:sz >= 1073741824
12290 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12291 elseif a:sz >= 10485760
12292 let sz = printf("%d",a:sz/1048576)."M"
12293 elseif a:sz >= 1048576
12294 let sz = printf("%.1f",a:sz/1048576.0)."M"
12295 elseif a:sz >= 10240
12296 let sz = printf("%d",a:sz/1024)."K"
12297 elseif a:sz >= 1024
12298 let sz = printf("%.1f",a:sz/1024.0)."K"
12299 else
12300 let sz= a:sz
12301 endif
12302
12303 else
12304 let sz= a:sz
12305 endif
12306
12307" call Dret("s:NetrwHumanReadable ".sz)
12308 return sz
12309endfun
12310
12311" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012312" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12313" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12314fun! s:NetrwRestoreWordPosn()
12315" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012316 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012317" call Dret("NetrwRestoreWordPosn")
12318endfun
12319
12320" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012321" s:RestoreBufVars: {{{2
12322fun! s:RestoreBufVars()
12323" call Dfunc("s:RestoreBufVars()")
12324
12325 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12326 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12327 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12328 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12329 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12330 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12331
12332" call Dret("s:RestoreBufVars")
12333endfun
12334
12335" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012336" s:RemotePathAnalysis: {{{2
12337fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012338" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012339
Bram Moolenaara6878372014-03-22 21:02:50 +010012340 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012341 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012342 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012343 let s:user = substitute(a:dirname,dirpat,'\3','')
12344 let s:machine = substitute(a:dirname,dirpat,'\4','')
12345 let s:port = substitute(a:dirname,dirpat,'\5','')
12346 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012347 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012348 if s:machine =~ '@'
12349 let dirpat = '^\(.*\)@\(.\{-}\)$'
12350 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12351 let s:machine = substitute(s:machine,dirpat,'\2','')
12352 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012353
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012354" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12355" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12356" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12357" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12358" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12359" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012360
12361" call Dret("s:RemotePathAnalysis")
12362endfun
12363
12364" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012365" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12366" Returns status
12367" Runs system() on
12368" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012369" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012370fun! s:RemoteSystem(cmd)
12371" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12372 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012373 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 +000012374 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012375 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012376 else
12377 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12378 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12379 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012380 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012381 else
12382 let cmd= cmd.' '
12383 endif
12384 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012385" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012386 let ret= system(cmd)
12387 endif
12388" call Dret("s:RemoteSystem ".ret)
12389 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012390endfun
12391
12392" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012393" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012394fun! s:RestoreWinVars()
12395" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012396 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012397 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12398 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12399 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12400 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12401 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12402 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12403 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12404 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12405 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12406 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12407 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12408 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012409 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12410 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012411 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12412 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12413 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12414" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012415endfun
12416
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012417" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012418" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12419"
12420" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12421" is true) and a command, :Rexplore, which call this function.
12422"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012423" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012424"
12425" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012426fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012427 if exists("s:netrwdrag")
12428 return
12429 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012430" 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 +010012431" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12432" 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 +010012433
12434 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012435 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012436" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012437 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012438 unlet w:netrw_rexfile
12439" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012440 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012441" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012442" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12443" 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 +020012444 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012445
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012446 " ---------------------------
12447 " :Rex issued while in a file
12448 " ---------------------------
12449
Bram Moolenaara6878372014-03-22 21:02:50 +010012450 " record current file so :Rex can return to it from netrw
12451 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012452" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012453
12454 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012455" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012456 return
12457 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012458" 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 +020012459 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012460 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012461 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012462 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012463 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012464 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012465 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012466 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012467 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012468" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12469 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012470" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12471 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012472 if exists("s:rexposn_".bufnr('%'))
12473 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012474 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012475 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012476" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012477 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012478
Bram Moolenaar85850f32019-07-19 22:05:51 +020012479 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12480 if exists("s:explore_match")
12481 exe "2match netrwMarkFile /".s:explore_match."/"
12482 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012483 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012484
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012485" 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 +010012486" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012487endfun
12488
12489" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012490" s:SaveBufVars: save selected b: variables to s: variables {{{2
12491" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012492fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012493" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012494
12495 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12496 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12497 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12498 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12499 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12500 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12501
12502" call Dret("s:SaveBufVars")
12503endfun
12504
12505" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012506" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12507fun! s:SavePosn(posndict)
12508" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12509
Bram Moolenaar85850f32019-07-19 22:05:51 +020012510 if !exists("a:posndict[bufnr('%')]")
12511 let a:posndict[bufnr("%")]= []
12512 endif
12513" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12514 call add(a:posndict[bufnr("%")],winsaveview())
12515" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012516
12517" call Dret("s:SavePosn posndict")
12518 return a:posndict
12519endfun
12520
12521" ---------------------------------------------------------------------
12522" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12523fun! s:RestorePosn(posndict)
12524" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012525 if exists("a:posndict")
12526 if has_key(a:posndict,bufnr("%"))
12527" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12528 let posnlen= len(a:posndict[bufnr("%")])
12529 if posnlen > 0
12530 let posnlen= posnlen - 1
12531" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12532 call winrestview(a:posndict[bufnr("%")][posnlen])
12533 call remove(a:posndict[bufnr("%")],posnlen)
12534" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12535 endif
12536 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012537 endif
12538" call Dret("s:RestorePosn")
12539endfun
12540
12541" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012542" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012543fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012544" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012545 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12546 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12547 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12548 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12549 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12550 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12551 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12552 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12553 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12554 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12555 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12556 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12557 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12558 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12559 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12560 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12561 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12562 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12563" call Dret("s:SaveWinVars")
12564endfun
12565
12566" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012567" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012568" To allow separate windows to have their own activities, such as
12569" Explore **/pattern, several variables have been made window-oriented.
12570" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012571" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012572" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012573fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012574" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012575 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12576 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12577 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12578 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12579 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12580 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12581 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12582 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12583 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12584 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12585" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012586endfun
12587
12588" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012589" s:SetRexDir: set directory for :Rexplore {{{2
12590fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012591" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012592 let w:netrw_rexdir = a:dirname
12593 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012594 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012595" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12596" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012597" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012598" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012599" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012600endfun
12601
12602" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012603" s:ShowLink: used to modify thin and tree listings to show links {{{2
12604fun! s:ShowLink()
12605" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012606" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12607" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012608 if exists("b:netrw_curdir")
12609 norm! $?\a
12610 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12611 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012612" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12613" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12614" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12615 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012616 let dirlen = strlen(b:netrw_curdir)
12617 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012618" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012619 endif
12620 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012621" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12622" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012623 setl noro ma
12624 call setline(".",modline)
12625 setl ro noma nomod
12626 endif
12627" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12628endfun
12629
12630" ---------------------------------------------------------------------
12631" s:ShowStyle: {{{2
12632fun! s:ShowStyle()
12633 if !exists("w:netrw_liststyle")
12634 let liststyle= g:netrw_liststyle
12635 else
12636 let liststyle= w:netrw_liststyle
12637 endif
12638 if liststyle == s:THINLIST
12639 return s:THINLIST.":thin"
12640 elseif liststyle == s:LONGLIST
12641 return s:LONGLIST.":long"
12642 elseif liststyle == s:WIDELIST
12643 return s:WIDELIST.":wide"
12644 elseif liststyle == s:TREELIST
12645 return s:TREELIST.":tree"
12646 else
12647 return 'n/a'
12648 endif
12649endfun
12650
12651" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012652" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12653" Solution from Nicolai Weibull, vim docs (:help strlen()),
12654" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012655fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012656" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12657
12658 if v:version >= 703 && exists("*strdisplaywidth")
12659 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012660
Bram Moolenaar8d043172014-01-23 14:24:41 +010012661 elseif type(g:Align_xstrlen) == 1
12662 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12663 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012664
Bram Moolenaar8d043172014-01-23 14:24:41 +010012665 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012666 " number of codepoints (Latin a + combining circumflex is two codepoints)
12667 " (comment from TM, solution from NW)
12668 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012669
Bram Moolenaar8d043172014-01-23 14:24:41 +010012670 elseif g:Align_xstrlen == 2
12671 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012672 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12673 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012674 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012675
Bram Moolenaar8d043172014-01-23 14:24:41 +010012676 elseif g:Align_xstrlen == 3
12677 " virtual length (counting, for instance, tabs as anything between 1 and
12678 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012679 " preceded by lam, one otherwise, etc.)
12680 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012681 let modkeep= &l:mod
12682 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012683 call setline(line("."),a:x)
12684 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012685 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012686 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012687 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012688
Bram Moolenaar446cb832008-06-24 21:56:24 +000012689 else
12690 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012691 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012692 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012693" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012694 return ret
12695endfun
12696
12697" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012698" s:ShellEscape: shellescape(), or special windows handling {{{2
12699fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012700 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012701 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12702 endif
12703 let f = a:0 > 0 ? a:1 : 0
12704 return shellescape(a:s, f)
12705endfun
12706
12707" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012708" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012709fun! s:TreeListMove(dir)
12710" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012711 let curline = getline('.')
12712 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12713 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12714 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12715 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12716 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12717 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12718" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12719" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12720" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12721" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12722" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12723 " COMBAK : need to handle when on a directory
12724 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012725 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012726 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012727 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012728 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012729" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012730 elseif a:dir == '[]' && nxtline != ''
12731 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012732" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012733 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12734 if nl != 0
12735 NetrwKeepj norm! k
12736 else
12737 NetrwKeepj norm! G
12738 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012739" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012740 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012741 endif
12742
12743" call Dret("s:TreeListMove")
12744endfun
12745
12746" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012747" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12748" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12749" can't be called except via emenu. But due to locale, that menu line may not be called
12750" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12751fun! s:UpdateBuffersMenu()
12752" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012753 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012754 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012755 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012756 catch /^Vim\%((\a\+)\)\=:E/
12757 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012758 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012759 endtry
12760 endif
12761" call Dret("s:UpdateBuffersMenu")
12762endfun
12763
12764" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012765" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012766" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012767fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012768" call Dfunc("s:UseBufWinVars()")
12769 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012770 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12771 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12772 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12773 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12774 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12775 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12776 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12777 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12778 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 +000012779" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012780endfun
12781
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012782" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012783" s:UserMaps: supports user-defined UserMaps {{{2
12784" * calls a user-supplied funcref(islocal,curdir)
12785" * interprets result
12786" See netrw#UserMaps()
12787fun! s:UserMaps(islocal,funcname)
12788" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12789
12790 if !exists("b:netrw_curdir")
12791 let b:netrw_curdir= getcwd()
12792 endif
12793 let Funcref = function(a:funcname)
12794 let result = Funcref(a:islocal)
12795
12796 if type(result) == 1
12797 " if result from user's funcref is a string...
12798" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12799 if result == "refresh"
12800" call Decho("refreshing display",'~'.expand("<slnum>"))
12801 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12802 elseif result != ""
12803" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12804 exe result
12805 endif
12806
12807 elseif type(result) == 3
12808 " if result from user's funcref is a List...
12809" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12810 for action in result
12811 if action == "refresh"
12812" call Decho("refreshing display",'~'.expand("<slnum>"))
12813 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12814 elseif action != ""
12815" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12816 exe action
12817 endif
12818 endfor
12819 endif
12820
12821" call Dret("s:UserMaps")
12822endfun
12823
Bram Moolenaar85850f32019-07-19 22:05:51 +020012824" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012825" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012826" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012827let &cpo= s:keepcpo
12828unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012829
Bram Moolenaar85850f32019-07-19 22:05:51 +020012830" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012831" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012832" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012833" vim:ts=8 fdm=marker