blob: e09716de1f0cc50dc6f6baa92e2f2de310b70a0f [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" netrw.vim: Handles file transfer and remote directory listing across
2" AUTOLOAD SECTION
Christian Brabandtf9ca1392024-02-19 20:37:11 +01003" Maintainer: This runtime file is looking for a new maintainer.
4" Date: May 03, 2023
Christian Brabandtcb0c1132023-11-21 18:48:16 +00005" Version: 173a
Travis Sheltone34d0e32024-07-30 21:08:56 +02006" Last Change: {{{1
Luca Saccarolaa7d45612024-10-21 21:27:03 +02007" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
8" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
Christian Brabandt8fad5d52024-02-29 18:12:30 +01009" 2024 Feb 19 by Vim Project: (announce adoption)
10" 2024 Feb 29 by Vim Project: handle symlinks in tree mode correctly
Christian Brabandt08d24012024-04-03 22:44:27 +020011" 2024 Apr 03 by Vim Project: detect filetypes for remote edited files
Nir Lichtman1e34b952024-05-08 19:19:34 +020012" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
Nir Lichtmance2ad9f2024-05-09 20:20:36 +020013" 2024 May 09 by Vim Project: remove hard-coded private.ppk
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020014" 2024 May 10 by Vim Project: recursively delete directories by default
Christian Brabandt43f2edc2024-05-13 20:56:43 +020015" 2024 May 13 by Vim Project: prefer scp over pscp
Christian Brabandt98b73eb2024-06-04 18:15:57 +020016" 2024 Jun 04 by Vim Project: set bufhidden if buffer changed, nohidden is set and buffer shall be switched (#14915)
Christian Brabandt14879472024-06-13 21:25:35 +020017" 2024 Jun 13 by Vim Project: glob() on Windows fails when a directory name contains [] (#14952)
Enno3146d632024-07-04 19:44:42 +020018" 2024 Jun 23 by Vim Project: save ad restore registers when liststyle = WIDELIST (#15077, #15114)
Damien9d57ea52024-07-22 20:23:48 +020019" 2024 Jul 22 by Vim Project: avoid endless recursion (#15318)
Christian Brabandt581d4a72024-07-23 21:14:06 +020020" 2024 Jul 23 by Vim Project: escape filename before trying to delete it (#15330)
Travis Sheltone34d0e32024-07-30 21:08:56 +020021" 2024 Jul 30 by Vim Project: handle mark-copy to same target directory (#12112)
Ivan Shapovalovc527d902024-08-02 19:43:12 +020022" 2024 Aug 02 by Vim Project: honor g:netrw_alt{o,v} for :{S,H,V}explore (#15417)
Damien7c754112024-08-15 21:58:57 +020023" 2024 Aug 15 by Vim Project: style changes, prevent E121 (#15501)
yasuda38cfa2b2024-08-22 20:54:47 +020024" 2024 Aug 22 by Vim Project: fix mf-selection highlight (#15551)
yasudac75dad02024-08-22 21:06:32 +020025" 2024 Aug 22 by Vim Project: adjust echo output of mx command (#15550)
Christian Brabandt0f5effb2024-09-15 19:17:23 +020026" 2024 Sep 15 by Vim Project: more strict confirmation dialog (#15680)
yasudac18a9d52024-09-19 18:09:51 +020027" 2024 Sep 19 by Vim Project: mf-selection highlight uses wrong pattern (#15700)
Peter Aronoffbe551da2024-09-22 11:29:40 +020028" 2024 Sep 21 by Vim Project: remove extraneous closing bracket (#15718)
Luca Saccarolaa7d45612024-10-21 21:27:03 +020029" 2024 Oct 21 by Vim Project: remove netrwFileHandlers (#15895)
Konfekt3d7e5672024-10-27 22:16:49 +010030" 2024 Oct 27 by Vim Project: clean up gx mapping (#15721)
Travis Sheltone34d0e32024-07-30 21:08:56 +020031" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010032" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000033" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010034" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000035" Permission is hereby granted to use and distribute this code,
36" with or without modifications, provided that this copyright
37" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000038" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000039" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000040" expressed or implied. By using this plugin, you agree that
41" in no event will the copyright holder be liable for any damages
42" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010043"
44" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
45" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
46"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020047"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000048"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000049" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000050" (James 1:22 RSV)
51" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000052" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000053if &cp || exists("g:loaded_netrw")
54 finish
55endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020056
57" Check that vim has patches that netrw requires.
58" Patches needed for v7.4: 1557, and 213.
59" (netrw will benefit from vim's having patch#656, too)
60let s:needspatches=[1557,213]
61if exists("s:needspatches")
62 for ptch in s:needspatches
63 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
64 if !exists("s:needpatch{ptch}")
65 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
66 endif
67 let s:needpatch{ptch}= 1
68 finish
69 endif
70 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020071endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020072
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010073let g:loaded_netrw = "v173"
Bram Moolenaar446cb832008-06-24 21:56:24 +000074
Bram Moolenaar1afcace2005-11-25 19:54:28 +000075let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010076setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020077"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010078"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010079"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000080
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000081" ======================
82" Netrw Variables: {{{1
83" ======================
84
Bram Moolenaar071d4272004-06-13 20:20:40 +000085" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020086" netrw#ErrorMsg: {{{2
87" 0=note = s:NOTE
88" 1=warning = s:WARNING
89" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010090" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
91" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
92" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010093" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020094fun! netrw#ErrorMsg(level,msg,errnum)
95" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
96
97 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020098" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020099 return
100 endif
101
102 if a:level == 1
103 let level= "**warning** (netrw) "
104 elseif a:level == 2
105 let level= "**error** (netrw) "
106 else
107 let level= "**note** (netrw) "
108 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100109" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200110
Damienb4d11642024-08-15 22:00:45 +0200111 if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200112 " use popup window
113 if type(a:msg) == 3
114 let msg = [level]+a:msg
115 else
116 let msg= level.a:msg
117 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200118 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200119 let s:popuperr_text= ""
120 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200121 " (default) netrw creates a one-line window to show error/warning
122 " messages (reliably displayed)
123
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100124 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200125 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100126" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200127
128 " getting messages out reliably is just plain difficult!
129 " This attempt splits the current window, creating a one line window.
130 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100131" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200132 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100133" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200134 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100135 if type(a:msg) == 3
136 for msg in a:msg
137 NetrwKeepj call setline(line("$")+1,level.msg)
138 endfor
139 else
140 NetrwKeepj call setline(line("$")+1,level.a:msg)
141 endif
142 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200143 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100144" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200145 bo 1split
146 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200147 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200148 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100149 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100150" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200151 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100152 if type(a:msg) == 3
153 for msg in a:msg
154 NetrwKeepj call setline(line("$")+1,level.msg)
155 endfor
156 else
157 NetrwKeepj call setline(line("$"),level.a:msg)
158 endif
159 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200160 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100161" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200162 if &fo !~ '[ta]'
163 syn clear
164 syn match netrwMesgNote "^\*\*note\*\*"
165 syn match netrwMesgWarning "^\*\*warning\*\*"
166 syn match netrwMesgError "^\*\*error\*\*"
167 hi link netrwMesgWarning WarningMsg
168 hi link netrwMesgError Error
169 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100170" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200171 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200172
173 else
174 " (optional) netrw will show messages using echomsg. Even if the
175 " message doesn't appear, at least it'll be recallable via :messages
176" redraw!
177 if a:level == s:WARNING
178 echohl WarningMsg
179 elseif a:level == s:ERROR
180 echohl Error
181 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100182
183 if type(a:msg) == 3
184 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100185 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100186 endfor
187 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100188 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100189 endif
190
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100191" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200192 echohl None
193 endif
194
195" call Dret("netrw#ErrorMsg")
196endfun
197
198" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100199" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100200" Loosely, varname = value.
201fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100202" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100203 if !exists(a:varname)
204 if type(a:value) == 0
205 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200206 elseif type(a:value) == 1 && a:value =~ '^[{[]'
207 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100208 elseif type(a:value) == 1
209 exe "let ".a:varname."="."'".a:value."'"
210 else
211 exe "let ".a:varname."=".a:value
212 endif
213 endif
214endfun
215
216" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000217" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200218call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000219if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100220 call s:NetrwInit("s:THINLIST",0)
221 call s:NetrwInit("s:LONGLIST",1)
222 call s:NetrwInit("s:WIDELIST",2)
223 call s:NetrwInit("s:TREELIST",3)
224 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000225endif
226
Damien7c754112024-08-15 21:58:57 +0200227let s:NOTE = 0
228let s:WARNING = 1
229let s:ERROR = 2
230call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
231
Bram Moolenaar9964e462007-05-05 17:54:07 +0000232" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200233" Default option values: {{{2
234let g:netrw_localcopycmdopt = ""
235let g:netrw_localcopydircmdopt = ""
236let g:netrw_localmkdiropt = ""
237let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200238
239" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000240" Default values for netrw's global protocol variables {{{2
Damienb4d11642024-08-15 22:00:45 +0200241if exists("*popup_atcursor")
242\ && has("syntax")
243\ && exists("g:syntax_on")
244\ && has("mouse")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200245 call s:NetrwInit("g:netrw_use_errorwindow",2)
246else
247 call s:NetrwInit("g:netrw_use_errorwindow",1)
248endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200249
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000250if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100251 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000252 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100253 elseif executable("curl")
254 let g:netrw_dav_cmd = "curl"
255 else
256 let g:netrw_dav_cmd = ""
257 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000258endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000259if !exists("g:netrw_fetch_cmd")
260 if executable("fetch")
261 let g:netrw_fetch_cmd = "fetch -o"
262 else
263 let g:netrw_fetch_cmd = ""
264 endif
265endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100266if !exists("g:netrw_file_cmd")
267 if executable("elinks")
268 call s:NetrwInit("g:netrw_file_cmd","elinks")
269 elseif executable("links")
270 call s:NetrwInit("g:netrw_file_cmd","links")
271 endif
272endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000273if !exists("g:netrw_ftp_cmd")
274 let g:netrw_ftp_cmd = "ftp"
275endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200276let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200277if !exists("g:netrw_ftp_options")
278 let g:netrw_ftp_options= "-i -n"
279endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000280if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100281 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100282 let g:netrw_http_cmd = "wget"
283 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100284 elseif executable("curl")
285 let g:netrw_http_cmd = "curl"
286 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200287 elseif executable("elinks")
288 let g:netrw_http_cmd = "elinks"
289 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000290 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100291 let g:netrw_http_cmd = "fetch"
292 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200293 elseif executable("links")
294 let g:netrw_http_cmd = "links"
295 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000296 else
297 let g:netrw_http_cmd = ""
298 endif
299endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100300call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100301call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100302call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
303call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200304call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200305if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200306 if executable("scp")
307 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
308 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200309 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200310 else
311 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
312 endif
313endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100314call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
315call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000316
Nir Lichtman1e34b952024-05-08 19:19:34 +0200317if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000318 \ && exists("g:netrw_use_nt_rcp")
319 \ && g:netrw_use_nt_rcp
320 \ && executable( $SystemRoot .'/system32/rcp.exe')
321 let s:netrw_has_nt_rcp = 1
322 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000323else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000324 let s:netrw_has_nt_rcp = 0
325 let s:netrw_rcpmode = ''
326endif
327
328" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000329" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000330" Cygwin Detection ------- {{{3
331if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200332 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
333 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000334 else
335 let g:netrw_cygwin= 0
336 endif
337endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000338" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100339call s:NetrwInit("g:netrw_alto" , &sb)
340call s:NetrwInit("g:netrw_altv" , &spr)
341call s:NetrwInit("g:netrw_banner" , 1)
342call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200343call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100344call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200345call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100346call s:NetrwInit("g:netrw_compress" , "gzip")
347call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200348if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
349 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
350 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000351endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200352call s:NetrwInit("g:netrw_cursor" , 2)
353let s:netrw_usercul = &cursorline
354let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200355"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100356call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000357" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200358call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200359call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200360call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100361call s:NetrwInit("g:netrw_dirhistmax" , 10)
362call s:NetrwInit("g:netrw_fastbrowse" , 1)
363call 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 +0000364if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000365 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
366 let g:netrw_ftp_list_cmd = "ls -lF"
367 let g:netrw_ftp_timelist_cmd = "ls -tlF"
368 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000369 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000370 let g:netrw_ftp_list_cmd = "dir"
371 let g:netrw_ftp_timelist_cmd = "dir"
372 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000373 endif
374endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100375call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000376" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100377call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000378if !exists("g:netrw_ignorenetrc")
379 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
380 let g:netrw_ignorenetrc= 1
381 else
382 let g:netrw_ignorenetrc= 0
383 endif
384endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100385call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000386if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000387 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100388 if exists("g:netrw_list_cmd_options")
389 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
390 else
391 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
392 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000393 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200394 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100395 if exists("g:netrw_list_cmd_options")
396 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
397 else
398 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
399 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000400 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100401" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000402 let g:netrw_list_cmd= ""
403 endif
404endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100405call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000406" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200407if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200408 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200409 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
410endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100411if !exists("g:netrw_localcmdshell")
412 let g:netrw_localcmdshell= ""
413endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000414if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200415 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000416 if g:netrw_cygwin
417 let g:netrw_localcopycmd= "cp"
418 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000419 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200420 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000421 endif
422 elseif has("unix") || has("macunix")
423 let g:netrw_localcopycmd= "cp"
424 else
425 let g:netrw_localcopycmd= ""
426 endif
427endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100428if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200429 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100430 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200431 let g:netrw_localcopydircmd = "cp"
432 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100433 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000434 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200435 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100436 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200437 elseif has("unix")
438 let g:netrw_localcopydircmd = "cp"
439 let g:netrw_localcopydircmdopt= " -R"
440 elseif has("macunix")
441 let g:netrw_localcopydircmd = "cp"
442 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100443 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200444 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100445 endif
446endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200447if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100448 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200449 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
450endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200451if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200452 if g:netrw_cygwin
453 call s:NetrwInit("g:netrw_localmkdir","mkdir")
454 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000455 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200456 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200457 endif
458else
459 call s:NetrwInit("g:netrw_localmkdir","mkdir")
460endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200461call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200462if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200463 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200464 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
465endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000466if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200467 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000468 if g:netrw_cygwin
469 let g:netrw_localmovecmd= "mv"
470 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000471 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200472 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000473 endif
474 elseif has("unix") || has("macunix")
475 let g:netrw_localmovecmd= "mv"
476 else
477 let g:netrw_localmovecmd= ""
478 endif
479endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100480" following serves as an example for how to insert a version&patch specific test
481"if v:version < 704 || (v:version == 704 && !has("patch1107"))
482"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100483call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
484" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000485if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000486 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000487endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000488if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000489 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
490endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000491" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100492call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
493call s:NetrwInit("g:netrw_maxfilenamelen", 32)
494call s:NetrwInit("g:netrw_menu" , 1)
495call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200496call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100497call s:NetrwInit("g:netrw_retmap" , 0)
498if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
499 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200500elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100501 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
502else
503 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000504endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100505call s:NetrwInit("g:netrw_preview" , 0)
506call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100507call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100508call s:NetrwInit("g:netrw_sshport" , "-p")
509call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
510call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
511call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100512call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
513" Default values - q-s ---------- {{{3
514call s:NetrwInit("g:netrw_quickhelp",0)
515let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100516 \ "(create new) %:file d:directory",
517 \ "(windows split&open) o:horz v:vert p:preview",
518 \ "i:style qf:file info O:obtain r:reverse",
519 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
520 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
521 \ "(history) qb:list u:go up U:go down",
522 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100523" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
524call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100525if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
526 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
527else
528 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
529endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100530call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
531call s:NetrwInit("g:netrw_sort_options" , "")
532call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000533if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100534 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200535 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100536 else
537 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000538 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000539endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100540call s:NetrwInit("g:netrw_special_syntax" , 0)
541call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaara6878372014-03-22 21:02:50 +0100542call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100543call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000544" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100545call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200546if !exists("g:netrw_xstrlen")
547 if exists("g:Align_xstrlen")
548 let g:netrw_xstrlen= g:Align_xstrlen
549 elseif exists("g:drawit_xstrlen")
550 let g:netrw_xstrlen= g:drawit_xstrlen
551 elseif &enc == "latin1" || !has("multi_byte")
552 let g:netrw_xstrlen= 0
553 else
554 let g:netrw_xstrlen= 1
555 endif
556endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100557call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200558call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100559call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200560if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000561" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000562" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100563call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200564if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200565 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200566else
Bram Moolenaarff034192013-04-24 18:51:19 +0200567 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200568endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200569call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100570call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
571call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100572if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100573 let s:treedepthstring= "│ "
574else
575 let s:treedepthstring= "| "
576endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200577call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000578
579" BufEnter event ignored by decho when following variable is true
580" Has a side effect that doau BufReadPost doesn't work, so
581" files read by network transfer aren't appropriately highlighted.
582"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000583
Bram Moolenaaradc21822011-04-01 18:03:16 +0200584" ======================
585" Netrw Initialization: {{{1
586" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200587if 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 +0100588" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100589 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200590" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100591 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100592 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
593 au VimEnter * let s:initbeval= &beval
594"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100595" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
596" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
597" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
598" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
599" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
600" 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 +0200601endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200602au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200603
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200604if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100605 com! -nargs=* NetrwKeepj keepj <args>
606else
607 let g:netrw_keepj= ""
608 com! -nargs=* NetrwKeepj <args>
609endif
610
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000611" ==============================
612" Netrw Utility Functions: {{{1
613" ==============================
614
Bram Moolenaaradc21822011-04-01 18:03:16 +0200615" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100616" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100617if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100618" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100619 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100620 if &ft != "netrw"
621 return ""
622 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200623 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
624 " popup error window is still showing
625 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
626 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
627 " text under mouse hasn't changed; only close window when it changes
628 call popup_close(s:popuperr_id)
629 unlet s:popuperr_text
630 else
631 let s:popuperr_text= v:beval_text
632 endif
633 let mesg= ""
634 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 +0100635 let mesg= ""
636 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
637 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
638 elseif getline(v:beval_lnum) =~ '^"\s*/'
639 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
640 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100641 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100642 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
643 let mesg = "S: edit sorting sequence"
644 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
645 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
646 elseif v:beval_text == "Quick" || v:beval_text == "Help"
647 let mesg = "Help: press <F1>"
648 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
649 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
650 else
651 let mesg= ""
652 endif
653 return mesg
654 endfun
655"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100656" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
657" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
658" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
659" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
660" 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 +0200661endif
662
Bram Moolenaar071d4272004-06-13 20:20:40 +0000663" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200664" netrw#Explore: launch the local browser in the directory of the current file {{{2
665" indx: == -1: Nexplore
666" == -2: Pexplore
667" == +: this is overloaded:
668" * If Nexplore/Pexplore is in use, then this refers to the
669" indx'th item in the w:netrw_explore_list[] of items which
670" matched the */pattern **/pattern *//pattern **//pattern
671" * If Hexplore or Vexplore, then this will override
672" g:netrw_winsize to specify the qty of rows or columns the
673" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100674" 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 +0200675" dosplit==1: the window will be split before running the local browser
676" style == 0: Explore style == 1: Explore!
677" == 2: Hexplore style == 3: Hexplore!
678" == 4: Vexplore style == 5: Vexplore!
679" == 6: Texplore
680fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100681" 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 +0100682" 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 +0200683 if !exists("b:netrw_curdir")
684 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100685" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200686 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100687
688 " record current file for Rexplore's benefit
689 if &ft != "netrw"
690 let w:netrw_rexfile= expand("%:p")
691 endif
692
693 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200694 let curdir = simplify(b:netrw_curdir)
695 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200696 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200697 let curdir= substitute(curdir,'\','/','g')
698 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100699" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100700
701 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
702 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
703 " try Explore again.
704 if a:0 > 0
705" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100706 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
707 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
708 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
709 \ '~'.expand("<slnum>"))
710 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200711 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
712 if a1 != a:1
713 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
714 return
715 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100716 endif
717 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200718
719 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200720 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100721" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100722 sil! let keepregstar = @*
723 sil! let keepregplus = @+
724 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200725 sil! let keepregslash= @/
726
Bram Moolenaar8d043172014-01-23 14:24:41 +0100727 " if dosplit
728 " -or- file has been modified AND file not hidden when abandoned
729 " -or- Texplore used
730 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaarff034192013-04-24 18:51:19 +0200731 call s:SaveWinVars()
732 let winsz= g:netrw_winsize
733 if a:indx > 0
734 let winsz= a:indx
735 endif
736
737 if a:style == 0 " Explore, Sexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200738 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200739 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200740 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200741
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200742 elseif a:style == 1 " Explore!, Sexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200743 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200744 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200745 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200746
747 elseif a:style == 2 " Hexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200748 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200749 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200750 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200751
752 elseif a:style == 3 " Hexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200753 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200754 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200755 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200756
757 elseif a:style == 4 " Vexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200758 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200759 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200760 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200761
762 elseif a:style == 5 " Vexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200763 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200764 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200765 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200766
767 elseif a:style == 6 " Texplore
768 call s:SaveBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200769 exe "keepalt tabnew ".fnameescape(curdir)
770 call s:RestoreBufVars()
771 endif
772 call s:RestoreWinVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200773 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100774 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200775
776 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100777" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200778 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100779" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200780 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100781" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200782 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100783" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200784 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
785 if dirname !~ '/$'
786 let dirname= dirname."/"
787 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100788" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200789 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100790" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200791 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100792" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200793 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100794" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200795 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100796" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200797 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100798" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200799 let dirname= a:1
800 endif
801 else
802 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100803" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200804 call s:NetrwClearExplore()
805" call Dret("netrw#Explore : cleared list")
806 return
807 endif
808
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100809" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200810 if dirname =~ '\.\./\=$'
811 let dirname= simplify(fnamemodify(dirname,':p:h'))
812 elseif dirname =~ '\.\.' || dirname == '.'
813 let dirname= simplify(fnamemodify(dirname,':p'))
814 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100815" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200816
817 if dirname =~ '^\*//'
818 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100819" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200820 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
821 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100822" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200823 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
824
825 elseif dirname =~ '^\*\*//'
826 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100827" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200828 let pattern= substitute(dirname,'^\*\*//','','')
829 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100830" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200831
832 elseif dirname =~ '/\*\*/'
833 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100834" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200835 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200836 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200837 let b:netrw_curdir = prefixdir
838 else
839 let b:netrw_curdir= getcwd().'/'.prefixdir
840 endif
841 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
842 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100843" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
844" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200845
846 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200847 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200848 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100849" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200850
851 elseif dirname=~ '^\*\*/'
852 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
853 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100854" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200855
856 else
857 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100858" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200859 endif
860
861 if starpat == 0 && a:indx >= 0
862 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100863" 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 +0200864 if dirname == ""
865 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100866" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200867 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200868 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200869 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200870 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200871 if dirname == ""
872 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200873 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100874 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100875 " depending on whether backslashes have been converted to forward slashes by earlier code).
876 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200877 let dirname= b:netrw_curdir."/".dirname
878 endif
879 elseif dirname !~ '^/'
880 let dirname= b:netrw_curdir."/".dirname
881 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100882" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200883 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100884" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
885" 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 +0200886 endif
887 if exists("w:netrw_bannercnt")
888 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
889 " If one wants to return the same place in the netrw window, use :Rex instead.
890 exe w:netrw_bannercnt
891 endif
892
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100893" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200894 " ---------------------------------------------------------------------
895 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
896" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100897" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200898" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100899" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200900" endif
901 " ---------------------------------------------------------------------
902
903 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
904 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
905 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
906 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
907 elseif a:indx <= 0
908 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100909" 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 +0200910 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100911" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200912 let s:didstarstar= 1
913 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
914 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
915 endif
916
917 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100918" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200919 if !exists("w:netrw_explore_indx")
920 let w:netrw_explore_indx= 0
921 endif
922
923 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100924" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200925
926 if indx == -1
927 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100928" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200929 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100930 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 +0200931 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100932" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100933 if @* != keepregstar | sil! let @* = keepregstar | endif
934 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100935 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200936 sil! let @/ = keepregslash
937" call Dret("netrw#Explore")
938 return
939 endif
940 let indx= w:netrw_explore_indx
941 if indx < 0 | let indx= 0 | endif
942 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
943 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100944" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200945 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
946 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100947" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200948 endwhile
949 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100950" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200951
952 elseif indx == -2
953 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100954" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200955 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100956 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 +0200957 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100958" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100959 if @* != keepregstar | sil! let @* = keepregstar | endif
960 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100961 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200962 sil! let @/ = keepregslash
963" call Dret("netrw#Explore")
964 return
965 endif
966 let indx= w:netrw_explore_indx
967 if indx < 0 | let indx= 0 | endif
968 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
969 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100970" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200971 while indx >= 0 && curfile == w:netrw_explore_list[indx]
972 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100973" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200974 endwhile
975 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100976" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200977
978 else
979 " Explore -- initialize
980 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100981" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100982 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200983 let w:netrw_explore_indx= 0
984 if !exists("b:netrw_curdir")
985 let b:netrw_curdir= getcwd()
986 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100987" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200988
989 " switch on starpat to build the w:netrw_explore_list of files
990 if starpat == 1
991 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100992" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
993" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200994 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100995 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200996 catch /^Vim\%((\a\+)\)\=:E480/
997 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
998" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
999 return
1000 endtry
1001 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1002 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1003
1004 elseif starpat == 2
1005 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001006" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1007" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001008 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001009 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001010 catch /^Vim\%((\a\+)\)\=:E480/
1011 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1012 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001013 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001014" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001015 if @* != keepregstar | sil! let @* = keepregstar | endif
1016 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001017 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001018 sil! let @/ = keepregslash
1019" call Dret("netrw#Explore : no files matched pattern")
1020 return
1021 endtry
1022 let s:netrw_curdir = b:netrw_curdir
1023 let w:netrw_explore_list = getqflist()
1024 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1025 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1026
1027 elseif starpat == 3
1028 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001029" 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 +02001030 let filepat= substitute(dirname,'^\*/','','')
1031 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001032" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1033" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001034 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1035 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1036
1037 elseif starpat == 4
1038 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001039" 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 +02001040 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1041 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1042 endif " switch on starpat to build w:netrw_explore_list
1043
1044 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001045" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1046" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001047
1048 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001049 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001050 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001051" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001052 if @* != keepregstar | sil! let @* = keepregstar | endif
1053 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001054 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001055 sil! let @/ = keepregslash
1056" call Dret("netrw#Explore : no files matched")
1057 return
1058 endif
1059 endif " if indx ... endif
1060
1061 " NetrwStatusLine support - for exploring support
1062 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001063" 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 +02001064
1065 " wrap the indx around, but issue a note
1066 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001067" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001068 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1069 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001070 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001071 endif
1072
1073 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001074" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001075 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001076" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001077
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001078" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001079 call netrw#LocalBrowseCheck(newdir)
1080 if !exists("w:netrw_liststyle")
1081 let w:netrw_liststyle= g:netrw_liststyle
1082 endif
1083 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001084 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001085 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001086 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001087 endif
1088 let w:netrw_explore_mtchcnt = indx + 1
1089 let w:netrw_explore_bufnr = bufnr("%")
1090 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001091 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001092" 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 +02001093
1094 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001095" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001096 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001097 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 +02001098 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001099 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001100" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001101 if @* != keepregstar | sil! let @* = keepregstar | endif
1102 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001103 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001104 sil! let @/ = keepregslash
1105" call Dret("netrw#Explore : missing +path_extra")
1106 return
1107 endif
1108
1109 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001110" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001111 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1112 sil! unlet w:netrw_treedict
1113 sil! unlet w:netrw_treetop
1114 endif
1115 let newdir= dirname
1116 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001117 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001118 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001119 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001120 endif
1121 endif
1122
1123 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001124" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1125" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001126 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001127" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001128 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001129 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001130" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001131 let s:explore_prvdir = b:netrw_curdir
1132 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001133 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001134 if b:netrw_curdir !~ '/$'
1135 let dirlen= dirlen + 1
1136 endif
1137 let prvfname= ""
1138 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001139" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001140 if fname =~ '^'.b:netrw_curdir
1141 if s:explore_match == ""
1142 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1143 else
1144 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1145 endif
1146 elseif fname !~ '^/' && fname != prvfname
1147 if s:explore_match == ""
1148 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1149 else
1150 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1151 endif
1152 endif
1153 let prvfname= fname
1154 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001155" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001156 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1157 exe "2match netrwMarkFile /".s:explore_match."/"
1158 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001159 endif
1160 echo "<s-up>==Pexplore <s-down>==Nexplore"
1161 else
1162 2match none
1163 if exists("s:explore_match") | unlet s:explore_match | endif
1164 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001165" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001166 endif
1167
Bram Moolenaara6878372014-03-22 21:02:50 +01001168 " since Explore may be used to initialize netrw's browser,
1169 " there's no danger of a late FocusGained event on initialization.
1170 " Consequently, set s:netrw_events to 2.
1171 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001172 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001173" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001174 if @* != keepregstar | sil! let @* = keepregstar | endif
1175 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001176 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001177 sil! let @/ = keepregslash
1178" call Dret("netrw#Explore : @/<".@/.">")
1179endfun
1180
1181" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001182" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001183" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1184" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1185" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1186" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1187" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001188fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001189" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001190 let curwin= winnr()
1191
Bram Moolenaara6878372014-03-22 21:02:50 +01001192 if a:0 > 0 && a:1 != ""
1193 " if a netrw window is already on the left-side of the tab
1194 " and a directory has been specified, explore with that
1195 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001196" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001197 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001198" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001199 exe "1wincmd w"
1200 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001201" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001202 exe "Explore ".fnameescape(a1)
1203 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001204 let s:lexplore_win= curwin
1205 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001206 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001207" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001208 unlet t:netrw_lexposn
1209 endif
1210" call Dret("netrw#Lexplore")
1211 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001212 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001213 exe curwin."wincmd w"
1214 else
1215 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001216" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001217 endif
1218
Bram Moolenaar8d043172014-01-23 14:24:41 +01001219 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001220 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001221 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001222" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001223 else
1224 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001225" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001226 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001227" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001228
1229 if lexwinnr > 0
1230 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001231" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001232 exe lexwinnr."wincmd w"
1233 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001234 let t:netrw_lexposn = winsaveview()
1235" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001236" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001237 close
1238 if lexwinnr < curwin
1239 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001240 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001241 if lexwinnr != curwin
1242 exe curwin."wincmd w"
1243 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001244 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001245" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001246
1247 else
1248 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001249" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001250 exe "1wincmd w"
1251 let keep_altv = g:netrw_altv
1252 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001253 if a:count != 0
1254 let netrw_winsize = g:netrw_winsize
1255 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001256 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001257 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001258" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001259 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 +02001260" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001261 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001262" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001263 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001264 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001265 elseif curfile =~ '^\a\{3,}://'
1266" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001267 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001268 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001269" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001270 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001271 endif
1272 if a:count != 0
1273 let g:netrw_winsize = netrw_winsize
1274 endif
1275 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001276 let g:netrw_altv = keep_altv
1277 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001278 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1279 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001280 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001281 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001282" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1283" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001284 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001285" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001286" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1287 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001288 unlet t:netrw_lexposn
1289 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001290 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001291
1292 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001293 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001294 if a:rightside
1295 let g:netrw_chgwin= 1
1296 else
1297 let g:netrw_chgwin= 2
1298 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001299" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001300 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001301
Bram Moolenaar8d043172014-01-23 14:24:41 +01001302" call Dret("netrw#Lexplore")
1303endfun
1304
1305" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001306" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001307" supports :NetrwClean -- remove netrw from first directory on runtimepath
1308" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001309fun! netrw#Clean(sys)
1310" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001311
1312 if a:sys
1313 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1314 else
1315 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1316 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001317" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001318 let diddel= 0
1319 let diddir= ""
1320
1321 if choice == 1
1322 for dir in split(&rtp,',')
1323 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001324" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001325 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1326 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1327 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1328 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1329 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1330 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 +00001331 let diddir= dir
1332 let diddel= diddel + 1
1333 if !a:sys|break|endif
1334 endif
1335 endfor
1336 endif
1337
1338 echohl WarningMsg
1339 if diddel == 0
1340 echomsg "netrw is either not installed or not removable"
1341 elseif diddel == 1
1342 echomsg "removed one copy of netrw from <".diddir.">"
1343 else
1344 echomsg "removed ".diddel." copies of netrw"
1345 endif
1346 echohl None
1347
Bram Moolenaara6878372014-03-22 21:02:50 +01001348" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001349endfun
1350
Bram Moolenaar5c736222010-01-06 20:54:52 +01001351" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001352" netrw#MakeTgt: make a target out of the directory name provided {{{2
1353fun! netrw#MakeTgt(dname)
1354" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1355 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001356 let svpos = winsaveview()
1357" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001358 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1359" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001360 if s:netrwmftgt_islocal
1361 let netrwmftgt= simplify(a:dname)
1362 else
1363 let netrwmftgt= a:dname
1364 endif
1365 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1366 " re-selected target, so just clear it
1367 unlet s:netrwmftgt s:netrwmftgt_islocal
1368 else
1369 let s:netrwmftgt= netrwmftgt
1370 endif
1371 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001372 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001373 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001374" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1375 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001376" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001377endfun
1378
Bram Moolenaara6878372014-03-22 21:02:50 +01001379" ---------------------------------------------------------------------
1380" netrw#Obtain: {{{2
1381" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001382" islocal=0 obtain from remote source
1383" =1 obtain from local source
1384" fname : a filename or a list of filenames
1385" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001386fun! netrw#Obtain(islocal,fname,...)
1387" 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 +02001388 " NetrwStatusLine support - for obtaining support
1389
1390 if type(a:fname) == 1
1391 let fnamelist= [ a:fname ]
1392 elseif type(a:fname) == 3
1393 let fnamelist= a:fname
1394 else
1395 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 +01001396" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001397 return
1398 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001399" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001400 if a:0 > 0
1401 let tgtdir= a:1
1402 else
1403 let tgtdir= getcwd()
1404 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001405" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001406
1407 if exists("b:netrw_islocal") && b:netrw_islocal
1408 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001409" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001410 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1411 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001412 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001413 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001414" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001415 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001416" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001417 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001418 if v:shell_error != 0
1419 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 +01001420" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001421 return
1422 endif
1423 endfor
1424 else
1425 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001426" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1427 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1428" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001429 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001430 if v:shell_error != 0
1431 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 +01001432" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001433 return
1434 endif
1435 endif
1436 elseif !exists("b:netrw_curdir")
1437 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1438 else
1439 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1440 endif
1441
1442 else
1443 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001444" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001445 if type(a:fname) == 1
1446 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1447 endif
1448 call s:NetrwMethod(b:netrw_curdir)
1449
1450 if b:netrw_method == 4
1451 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001452" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001453 if exists("g:netrw_port") && g:netrw_port != ""
1454 let useport= " ".g:netrw_scpport." ".g:netrw_port
1455 else
1456 let useport= ""
1457 endif
1458 if b:netrw_fname =~ '/'
1459 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1460 else
1461 let path= ""
1462 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001463 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001464 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 +02001465
1466 elseif b:netrw_method == 2
1467 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001468" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001469 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001470 let tmpbufnr= bufnr("%")
1471 setl ff=unix
1472 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001473 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001474" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001475 endif
1476
1477 if exists("b:netrw_fname") && b:netrw_fname != ""
1478 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001479" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001480 endif
1481
1482 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001483 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001484" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001485 endif
1486 for fname in fnamelist
1487 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001488" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001489 endfor
1490 if exists("g:netrw_port") && g:netrw_port != ""
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)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001492 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001493 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001494 endif
1495 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1496 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1497 let debugkeep= &debug
1498 setl debug=msg
1499 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1500 let &debug= debugkeep
1501 endif
1502
1503 elseif b:netrw_method == 3
1504 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001505" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001506 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001507 let tmpbufnr= bufnr("%")
1508 setl ff=unix
1509
1510 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001511 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001512" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001513 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001514 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001515" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001516 endif
1517
1518 if exists("g:netrw_uid") && g:netrw_uid != ""
1519 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001520 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001521" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001522 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001523 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001524 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001525" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001526 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001527 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001528" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001529 endif
1530 endif
1531
1532 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001533 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001534" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001535 endif
1536
1537 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001538 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001539" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001540 endif
1541
1542 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001543 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001544" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001545 endif
1546
1547 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001548 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001549" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001550 endif
1551 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001552 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001553 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001554" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001555
1556 " perform ftp:
1557 " -i : turns off interactive prompting from ftp
1558 " -n unix : DON'T use <.netrc>, even though it exists
1559 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001560 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1561 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001562 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001563 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1564 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001565" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001566 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001567 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001568 endif
1569 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001570
1571 elseif b:netrw_method == 9
1572 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001573" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001574 if a:fname =~ '/'
1575 let localfile= substitute(a:fname,'^.*/','','')
1576 else
1577 let localfile= a:fname
1578 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001579 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 +02001580
Bram Moolenaarff034192013-04-24 18:51:19 +02001581 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001582 " probably a badly formed url; protocol not recognized
1583" call Dret("netrw#Obtain : unsupported method")
1584 return
1585
1586 else
1587 " protocol recognized but not supported for Obtain (yet?)
1588 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001589 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001590 endif
1591" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001592 return
1593 endif
1594
1595 " restore status line
1596 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001597 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001598 endif
1599
1600 endif
1601
1602 " cleanup
1603 if exists("tmpbufnr")
1604 if bufnr("%") != tmpbufnr
1605 exe tmpbufnr."bw!"
1606 else
1607 q!
1608 endif
1609 endif
1610
Bram Moolenaara6878372014-03-22 21:02:50 +01001611" call Dret("netrw#Obtain")
1612endfun
1613
1614" ---------------------------------------------------------------------
1615" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1616fun! netrw#Nread(mode,fname)
1617" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001618 let svpos= winsaveview()
1619" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001620 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001621" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1622 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001623
1624 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1625 if exists("w:netrw_bannercnt")
1626 " start with cursor just after the banner
1627 exe w:netrw_bannercnt
1628 endif
1629 endif
1630" call Dret("netrw#Nread")
1631endfun
1632
1633" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001634" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1635" Options get restored by s:NetrwOptionsRestore()
1636"
1637" Option handling:
1638" * save user's options (s:NetrwOptionsSave)
1639" * set netrw-safe options (s:NetrwOptionsSafe)
1640" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1641" * restore user's options (s:netrwOPtionsRestore)
1642" - restore a user option when != safe option (s:NetrwRestoreSetting)
1643" vt: (variable type) normally its either "w:" or "s:"
1644fun! s:NetrwOptionsSave(vt)
1645" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1646" 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 +02001647" 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>"))
1648" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001649
1650 if !exists("{a:vt}netrw_optionsave")
1651 let {a:vt}netrw_optionsave= 1
1652 else
1653" call Dret("s:NetrwOptionsSave : options already saved")
1654 return
1655 endif
1656" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1657
1658 " Save current settings and current directory
1659" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1660 let s:yykeep = @@
1661 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1662 let {a:vt}netrw_aikeep = &l:ai
1663 let {a:vt}netrw_awkeep = &l:aw
1664 let {a:vt}netrw_bhkeep = &l:bh
1665 let {a:vt}netrw_blkeep = &l:bl
1666 let {a:vt}netrw_btkeep = &l:bt
1667 let {a:vt}netrw_bombkeep = &l:bomb
1668 let {a:vt}netrw_cedit = &cedit
1669 let {a:vt}netrw_cikeep = &l:ci
1670 let {a:vt}netrw_cinkeep = &l:cin
1671 let {a:vt}netrw_cinokeep = &l:cino
1672 let {a:vt}netrw_comkeep = &l:com
1673 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001674 let {a:vt}netrw_cuckeep = &l:cuc
1675 let {a:vt}netrw_culkeep = &l:cul
1676" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001677 let {a:vt}netrw_diffkeep = &l:diff
1678 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001679 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1680 let {a:vt}netrw_ffkeep = &l:ff
1681 endif
1682 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1683 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001684 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001685 let {a:vt}netrw_hidkeep = &l:hidden
1686 let {a:vt}netrw_imkeep = &l:im
1687 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001688 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001689 let {a:vt}netrw_lskeep = &l:ls
1690 let {a:vt}netrw_makeep = &l:ma
1691 let {a:vt}netrw_magickeep = &l:magic
1692 let {a:vt}netrw_modkeep = &l:mod
1693 let {a:vt}netrw_nukeep = &l:nu
1694 let {a:vt}netrw_rnukeep = &l:rnu
1695 let {a:vt}netrw_repkeep = &l:report
1696 let {a:vt}netrw_rokeep = &l:ro
1697 let {a:vt}netrw_selkeep = &l:sel
1698 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001699 if !g:netrw_use_noswf
1700 let {a:vt}netrw_swfkeep = &l:swf
1701 endif
1702 let {a:vt}netrw_tskeep = &l:ts
1703 let {a:vt}netrw_twkeep = &l:tw " textwidth
1704 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1705 let {a:vt}netrw_wrapkeep = &l:wrap
1706 let {a:vt}netrw_writekeep = &l:write
1707
1708 " save a few selected netrw-related variables
1709" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1710 if g:netrw_keepdir
1711 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001712" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001713 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001714 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001715 sil! let {a:vt}netrw_starkeep = @*
1716 sil! let {a:vt}netrw_pluskeep = @+
1717 endif
1718 sil! let {a:vt}netrw_slashkeep= @/
1719
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001720" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001721" 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>"))
1722" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1723endfun
1724
1725" ---------------------------------------------------------------------
1726" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1727" Use s:NetrwSaveOptions() to save user settings
1728" Use s:NetrwOptionsRestore() to restore user settings
1729fun! s:NetrwOptionsSafe(islocal)
1730" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1731" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1732" 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>"))
1733 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1734 call s:NetrwSetSafeSetting("&l:ai",0)
1735 call s:NetrwSetSafeSetting("&l:aw",0)
1736 call s:NetrwSetSafeSetting("&l:bl",0)
1737 call s:NetrwSetSafeSetting("&l:bomb",0)
1738 if a:islocal
1739 call s:NetrwSetSafeSetting("&l:bt","nofile")
1740 else
1741 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1742 endif
1743 call s:NetrwSetSafeSetting("&l:ci",0)
1744 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001745 if g:netrw_fastbrowse > a:islocal
1746 call s:NetrwSetSafeSetting("&l:bh","hide")
1747 else
1748 call s:NetrwSetSafeSetting("&l:bh","delete")
1749 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001750 call s:NetrwSetSafeSetting("&l:cino","")
1751 call s:NetrwSetSafeSetting("&l:com","")
1752 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1753 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1754 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001755 if &go =~ 'a' | set go-=a | endif
1756 if &go =~ 'A' | set go-=A | endif
1757 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001758 call s:NetrwSetSafeSetting("&l:hid",0)
1759 call s:NetrwSetSafeSetting("&l:im",0)
1760 setl isk+=@ isk+=* isk+=/
1761 call s:NetrwSetSafeSetting("&l:magic",1)
1762 if g:netrw_use_noswf
1763 call s:NetrwSetSafeSetting("swf",0)
1764 endif
1765 call s:NetrwSetSafeSetting("&l:report",10000)
1766 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1767 call s:NetrwSetSafeSetting("&l:spell",0)
1768 call s:NetrwSetSafeSetting("&l:tw",0)
1769 call s:NetrwSetSafeSetting("&l:wig","")
1770 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001771
1772 " set up cuc and cul based on g:netrw_cursor and listing style
1773 " COMBAK -- cuc cul related
1774 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001775
1776 " allow the user to override safe options
1777" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1778 if &ft == "netrw"
1779" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1780 keepalt NetrwKeepj doau FileType netrw
1781 endif
1782
1783" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1784" 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>"))
1785" call Dret("s:NetrwOptionsSafe")
1786endfun
1787
1788" ---------------------------------------------------------------------
1789" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1790fun! s:NetrwOptionsRestore(vt)
1791" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001792" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001793" 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 +01001794 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001795" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Christian Brabandt08d24012024-04-03 22:44:27 +02001796
1797 " filereadable() returns zero for remote files (e.g. scp://localhost//etc/fstab)
1798 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+/'
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001799" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001800 filetype detect
1801" 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>"))
1802 else
1803 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001804 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001805" 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 +02001806" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001807 return
1808 endif
1809 unlet {a:vt}netrw_optionsave
1810
1811 if exists("+acd")
1812 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001813" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001814 let curdir = getcwd()
1815 let &l:acd = {a:vt}netrw_acdkeep
1816 unlet {a:vt}netrw_acdkeep
1817 if &l:acd
1818 call s:NetrwLcd(curdir)
1819 endif
1820 endif
1821 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001822" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001823 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1824 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1825 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1826 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1827 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001828" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001829 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1830 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1831 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1832 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1833 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001834" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001835 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1836 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1837 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1838 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1839 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001840 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001841" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1842 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1843 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001844 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001845 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1846" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1847 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1848 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1849" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1850 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1851" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1852 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1853 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001854 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001855 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1856 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1857" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1858 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1859 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1860 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1861 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1862" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001863 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001864 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1865 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1866 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001867 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001868" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001869 call s:NetrwRestoreSetting("s:yykeep","@@")
1870 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1871 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1872 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1873 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1874
Bram Moolenaara6878372014-03-22 21:02:50 +01001875 if exists("{a:vt}netrw_swfkeep")
1876 if &directory == ""
1877 " user hasn't specified a swapfile directory;
1878 " netrw will temporarily set the swapfile directory
1879 " to the current directory as returned by getcwd().
1880 let &l:directory= getcwd()
1881 sil! let &l:swf = {a:vt}netrw_swfkeep
1882 setl directory=
1883 unlet {a:vt}netrw_swfkeep
1884 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001885 if !g:netrw_use_noswf
1886 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1887 sil! let &l:swf= {a:vt}netrw_swfkeep
1888 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001889 unlet {a:vt}netrw_swfkeep
1890 endif
1891 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001892 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001893 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1894 if exists("{a:vt}netrw_dirkeep")
1895 call s:NetrwLcd(dirkeep)
1896 unlet {a:vt}netrw_dirkeep
1897 endif
1898 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001899 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001900" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001901 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1902 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001903 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001904 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001905
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001906" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1907" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1908" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1909" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1910" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001911 " Moved the filetype detect here from NetrwGetFile() because remote files
1912 " were having their filetype detect-generated settings overwritten by
1913 " NetrwOptionRestore.
1914 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001915" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1916 filetype detect
1917" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001918 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001919" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001920" 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 +02001921" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001922endfun
1923
1924" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001925" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1926" but only when the options' value and the safe setting differ
1927" Doing this means that netrw will not come up as having changed a
1928" setting last when it really didn't actually change it.
1929"
1930" Called from s:NetrwOptionsSafe
1931" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1932fun! s:NetrwSetSafeSetting(setting,safesetting)
1933" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001934
Bram Moolenaar85850f32019-07-19 22:05:51 +02001935 if a:setting =~ '^&'
1936" call Decho("fyi: a:setting starts with &")
1937 exe "let settingval= ".a:setting
1938" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001939
Bram Moolenaar85850f32019-07-19 22:05:51 +02001940 if settingval != a:safesetting
1941" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1942 if type(a:safesetting) == 0
1943 exe "let ".a:setting."=".a:safesetting
1944 elseif type(a:safesetting) == 1
1945 exe "let ".a:setting."= '".a:safesetting."'"
1946 else
1947 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1948 endif
1949 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001950 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001951
Bram Moolenaar85850f32019-07-19 22:05:51 +02001952" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001953endfun
1954
1955" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001956" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1957" but only if the setting value differs from the associated keepvar.
1958" Doing this means that netrw will not come up as having changed a
1959" setting last when it really didn't actually change it.
1960"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001961" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001962" keepvars are set up by s:NetrwOptionsSave
1963fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001964""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001965
Bram Moolenaar85850f32019-07-19 22:05:51 +02001966 " typically called from s:NetrwOptionsRestore
1967 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1968 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001969 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001970 if exists(a:keepvar)
1971 exe "let keepvarval= ".a:keepvar
1972 exe "let setting= ".a:setting
1973
1974"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1975"" call Decho("fyi: keepvarval=".keepvarval)
1976"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1977
1978 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001979"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001980 if type(a:setting) == 0
1981 exe "let ".a:setting."= ".keepvarval
1982 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001983 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001984 else
1985 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1986 endif
1987 endif
1988
1989 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001990 endif
1991
Bram Moolenaar85850f32019-07-19 22:05:51 +02001992"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001993endfun
1994
1995" ---------------------------------------------------------------------
1996" NetrwStatusLine: {{{2
1997fun! NetrwStatusLine()
1998
1999" vvv NetrwStatusLine() debugging vvv
2000" let g:stlmsg=""
2001" if !exists("w:netrw_explore_bufnr")
2002" let g:stlmsg="!X<explore_bufnr>"
2003" elseif w:netrw_explore_bufnr != bufnr("%")
2004" let g:stlmsg="explore_bufnr!=".bufnr("%")
2005" endif
2006" if !exists("w:netrw_explore_line")
2007" let g:stlmsg=" !X<explore_line>"
2008" elseif w:netrw_explore_line != line(".")
2009" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2010" endif
2011" if !exists("w:netrw_explore_list")
2012" let g:stlmsg=" !X<explore_list>"
2013" endif
2014" ^^^ NetrwStatusLine() debugging ^^^
2015
2016 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")
2017 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09002018 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02002019 let &laststatus = s:netrw_users_ls
2020 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2021 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2022 return ""
2023 else
2024 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2025 endif
2026endfun
2027
Bram Moolenaar85850f32019-07-19 22:05:51 +02002028" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002029" Netrw Transfer Functions: {{{1
2030" ===============================
2031
Bram Moolenaar071d4272004-06-13 20:20:40 +00002032" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002033" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002034" mode: =0 read remote file and insert before current line
2035" =1 read remote file and insert after current line
2036" =2 replace with remote file
2037" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002038fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002039" 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 +00002040
Bram Moolenaar5c736222010-01-06 20:54:52 +01002041 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002042 call s:NetrwOptionsSave("w:")
2043 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002044 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002045 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2046 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2047 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002048" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002049
Bram Moolenaar5c736222010-01-06 20:54:52 +01002050 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002051 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002052 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002053 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002054 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002055 elseif a:mode == 2 " replace with remote file
2056 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002057 elseif a:mode == 3 " skip read of file (leave as temporary)
2058 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002059 else
2060 exe a:mode
2061 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002062 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002063 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002064" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002065
Bram Moolenaar5c736222010-01-06 20:54:52 +01002066 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002067 let tmpfile= s:GetTempfile("")
2068 if tmpfile == ""
2069" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002070 return
2071 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002072
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002073 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002074
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002075 " attempt to repeat with previous host-file-etc
2076 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002077" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002078 let choice = b:netrw_lastfile
2079 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002080
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002081 else
2082 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002083" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002084
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002085 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002086 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002087 echomsg 'NetRead Usage:'
2088 echomsg ':Nread machine:path uses rcp'
2089 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2090 echomsg ':Nread "machine id password path" uses ftp'
2091 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2092 echomsg ':Nread fetch://machine/path uses fetch'
2093 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2094 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002095 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002096 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002097 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2098 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2099 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2100 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002101 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002102 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002103
Bram Moolenaar9964e462007-05-05 17:54:07 +00002104 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002105 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002106" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002107 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002108 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002109 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002110 else
2111 " case "... ... ..."
2112 let choice = strpart(choice,1,strlen(choice)-1)
2113 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002114
Bram Moolenaar9964e462007-05-05 17:54:07 +00002115 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002116 let wholechoice = wholechoice . " " . choice
2117 let ichoice = ichoice + 1
2118 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002119 if !exists("g:netrw_quiet")
2120 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2121 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002122" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002123 return
2124 endif
2125 let choice= a:{ichoice}
2126 endwhile
2127 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2128 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002129 endif
2130 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002131
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002132" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002133 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002134
Bram Moolenaar5c736222010-01-06 20:54:52 +01002135 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002136 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002137 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002138" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002139 return
2140 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002141 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002142
Bram Moolenaar8d043172014-01-23 14:24:41 +01002143 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002144" 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 +02002145 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002146" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002147 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002148" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002149 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002150 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002151
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002152 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002153 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002154 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002155 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2156 echo "(netrw) Processing your read request..."
2157 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002158
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002159 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002160 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002161 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002162" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002163 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002164 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002165 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002166 " ER: the tmpfile is full path: rcp sees C:\... as host C
2167 if s:netrw_has_nt_rcp == 1
2168 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2169 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2170 else
2171 " Any way needed it machine contains a '.'
2172 let uid_machine = g:netrw_machine .'.'. $USERNAME
2173 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002174 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002175 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2176 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2177 else
2178 let uid_machine = g:netrw_machine
2179 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002180 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002181 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 +00002182 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002183 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002184
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002185 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002186 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002187 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002188" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002189 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002190 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002191 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002192 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002193 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002194" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002195 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002196 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002197" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002198 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002199 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002200" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002201 if exists("g:netrw_port") && g:netrw_port != ""
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)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002203 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002204 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002205 endif
2206 " 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 +00002207 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002208 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002209 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002210 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002211 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002212 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002213 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002214 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002215 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2216 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002217 q!
2218 endif
2219 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002220 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002221 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002222
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002223 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002224 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002225 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2226 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002227" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002228 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002229 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002230 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002231 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002232 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002233 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002234" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002235 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002236 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002237" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002238 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002239
Bram Moolenaar97d62492012-11-15 21:28:22 +01002240 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002241 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002242 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002243" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002244 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002245 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002246 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002247" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002248 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002249 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002250" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002251 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002252 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002253
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002254 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002255 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002256" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002257 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002258 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002259 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002260" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002261 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002262 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002263" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002264
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002265 " perform ftp:
2266 " -i : turns off interactive prompting from ftp
2267 " -n unix : DON'T use <.netrc>, even though it exists
2268 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002269 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002270 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002271 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2272 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002273" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002274 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002275 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002276 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002277 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002278 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002279 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002280 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002281
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002282 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002283 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002284 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002285" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002286 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002287 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002288 else
2289 let useport= ""
2290 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002291 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2292 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002293 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002294 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2295 else
2296 let tmpfile_get = tmpfile
2297 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002298 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 +00002299 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002300 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002301
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002302 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002303 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002304 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002305" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002306 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002307 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002308 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002309 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002310" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002311 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002312 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002313
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002314 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2315 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002316" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002317 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002318 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 +00002319 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002320 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 +00002321 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002322 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002323
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002324 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002325 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002326" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002327 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2328 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002329" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2330" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2331 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 +00002332 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002333" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002334 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002335 endif
2336 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002337" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002338 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002339
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002340 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002341 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002342 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002343" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002344
Bram Moolenaar5c736222010-01-06 20:54:52 +01002345 if !executable(g:netrw_dav_cmd)
2346 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2347" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2348 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002349 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002350 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002351 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 +01002352 else
2353 " Construct execution string (four lines) which will be passed through filter
2354 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2355 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002356 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002357 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002358 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002359 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002360 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002361 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002362 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002363 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002364 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002365 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2366 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002367
Bram Moolenaar5c736222010-01-06 20:54:52 +01002368 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002369 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002370 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002371 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002372 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002373 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002374 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002375
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002376 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002377 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002378 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002379" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002380 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 +00002381 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002382 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002383
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002384 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002385 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002386 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002387 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002388" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002389 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002390 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002391 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002392 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002393" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002394 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002395 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002396 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002397 let netrw_option= "http"
2398 else
2399 let netrw_option= "ftp"
2400 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002401" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002402
Bram Moolenaar446cb832008-06-24 21:56:24 +00002403 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
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_uid.':'.s:netrw_passwd.'@'.g:netrw_machine."/".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002405 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002406 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 +00002407 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002408
Bram Moolenaar446cb832008-06-24 21:56:24 +00002409 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002410 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002411" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002412 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002413
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002414 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002415 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002416 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002417" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2418 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 +00002419 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002420 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002421
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002422 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002423 " NetRead: (file) NetRead Method #10 {{{3
2424 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002425" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2426 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002427 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2428 let b:netrw_lastfile = choice
2429
2430 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002431 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002432 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002433 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002434 endif
2435 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002436
Bram Moolenaar5c736222010-01-06 20:54:52 +01002437 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002438 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002439" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002440 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002441 unlet b:netrw_fname
2442 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002443 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 +01002444" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002445 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002446 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002447 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002448
Bram Moolenaar9964e462007-05-05 17:54:07 +00002449" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002450endfun
2451
2452" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002453" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002454fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002455" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002456
Bram Moolenaar5c736222010-01-06 20:54:52 +01002457 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002458 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002459 call s:NetrwOptionsSave("w:")
2460 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002461
Bram Moolenaar5c736222010-01-06 20:54:52 +01002462 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002463 let tmpfile= s:GetTempfile("")
2464 if tmpfile == ""
2465" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002466 return
2467 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002468
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002469 if a:0 == 0
2470 let ichoice = 0
2471 else
2472 let ichoice = 1
2473 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002474
Bram Moolenaar9964e462007-05-05 17:54:07 +00002475 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002476" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002477 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002478 " For binary writes, always write entire file.
2479 " (line numbers don't really make sense for that).
2480 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002481" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002482 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002483 elseif g:netrw_cygwin
2484 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002485 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002486" 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 +01002487 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002488 else
2489 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002490" 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 +01002491 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002492 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002493
Bram Moolenaar9964e462007-05-05 17:54:07 +00002494 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002495 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002496 " on the temporary file's name. Deletion of the temporary file during
2497 " cleanup then causes an error message.
2498 0file!
2499 endif
2500
Bram Moolenaar5c736222010-01-06 20:54:52 +01002501 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002502 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002503
Bram Moolenaar9964e462007-05-05 17:54:07 +00002504 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002505 " attempt to repeat with previous host-file-etc
2506 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002507" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002508 let choice = b:netrw_lastfile
2509 let ichoice= ichoice + 1
2510 else
2511 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002512
Bram Moolenaar8d043172014-01-23 14:24:41 +01002513 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002514 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002515 echomsg 'NetWrite Usage:"'
2516 echomsg ':Nwrite machine:path uses rcp'
2517 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2518 echomsg ':Nwrite "machine id password path" uses ftp'
2519 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2520 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2521 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2522 echomsg ':Nwrite rcp://machine/path uses rcp'
2523 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2524 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2525 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002526 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002527 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002528
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002529 elseif match(choice,"^\"") != -1
2530 if match(choice,"\"$") != -1
2531 " case "..."
2532 let choice=strpart(choice,1,strlen(choice)-2)
2533 else
2534 " case "... ... ..."
2535 let choice = strpart(choice,1,strlen(choice)-1)
2536 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002537
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002538 while match(choice,"\"$") == -1
2539 let wholechoice= wholechoice . " " . choice
2540 let ichoice = ichoice + 1
2541 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002542 if !exists("g:netrw_quiet")
2543 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2544 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002545" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002546 return
2547 endif
2548 let choice= a:{ichoice}
2549 endwhile
2550 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2551 endif
2552 endif
2553 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002554 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002555" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002556
Bram Moolenaar9964e462007-05-05 17:54:07 +00002557 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002558 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002559 if !exists("b:netrw_method") || b:netrw_method < 0
2560" call Dfunc("netrw#NetWrite : unsupported method")
2561 return
2562 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002563
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002564 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002565 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002566 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002567 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2568 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002569" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002570 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002571
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002572 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002573 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002574 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002575" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002576 if s:netrw_has_nt_rcp == 1
2577 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2578 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2579 else
2580 let uid_machine = g:netrw_machine .'.'. $USERNAME
2581 endif
2582 else
2583 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2584 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2585 else
2586 let uid_machine = g:netrw_machine
2587 endif
2588 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002589 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 +00002590 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002591
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002592 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002593 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002594 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002595" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002596 let netrw_fname = b:netrw_fname
2597
2598 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2599 let bhkeep = &l:bh
2600 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002601 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002602 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002603
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002604" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002605 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002606 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002607" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002608 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002609 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002610" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002611 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002612 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002613" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002614 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002615 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 +00002616 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002617" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2618 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002619 endif
2620 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2621 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002622 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002623 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002624 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002625 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002627
2628 " remove enew buffer (quietly)
2629 let filtbuf= bufnr("%")
2630 exe curbuf."b!"
2631 let &l:bh = bhkeep
2632 exe filtbuf."bw!"
2633
Bram Moolenaar071d4272004-06-13 20:20:40 +00002634 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002635
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002636 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002637 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002638 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002639 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002640" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002641 let netrw_fname = b:netrw_fname
2642 let bhkeep = &l:bh
2643
2644 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2645 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002646 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002647 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002648 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002649
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002650 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002651 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002652" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002653 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002654 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002655" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002656 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002657 if exists("g:netrw_uid") && g:netrw_uid != ""
2658 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002659 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002660" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002661 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002662 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002663 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002664" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002665 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002666 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002667" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002668 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002669 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002670 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002671" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002672 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002673 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002674" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002675 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002676 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002677" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002678 " save choice/id/password for future use
2679 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002680
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002681 " perform ftp:
2682 " -i : turns off interactive prompting from ftp
2683 " -n unix : DON'T use <.netrc>, even though it exists
2684 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002685 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002686 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002687 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2688 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002689 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002690 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002691 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002692 let mod=1
2693 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002694
2695 " remove enew buffer (quietly)
2696 let filtbuf= bufnr("%")
2697 exe curbuf."b!"
2698 let &l:bh= bhkeep
2699 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002700
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002701 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002702 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002703 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002704" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002705 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002706 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002707 else
2708 let useport= ""
2709 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002710 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 +00002711 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002712
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002713 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002714 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002715 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002716" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002717 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2718 if executable(curl)
2719 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002720 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 +01002721 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002722 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002723 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002724
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002725 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002726 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002727 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002728" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002729
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002730 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002731 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2732 let bhkeep = &l:bh
2733
2734 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2735 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002736 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002737 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002738
Bram Moolenaarff034192013-04-24 18:51:19 +02002739 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002740 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002741 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002742 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002743 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002744 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002745 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002746 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002747 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002748 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002749
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002750 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002751 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002752 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002753
2754 " remove enew buffer (quietly)
2755 let filtbuf= bufnr("%")
2756 exe curbuf."b!"
2757 let &l:bh = bhkeep
2758 exe filtbuf."bw!"
2759
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002760 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002761
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002762 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002763 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002764 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002765" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002766 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 +00002767 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002768
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002769 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002770 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002771 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002772" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002773 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002774 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2775 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2776 else
2777 let uid_machine = g:netrw_machine
2778 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002779
2780 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2781 let bhkeep = &l:bh
2782 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002783 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002784 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002785
Bram Moolenaarff034192013-04-24 18:51:19 +02002786 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002787 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002788" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002789 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002790 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002791 let filtbuf= bufnr("%")
2792 exe curbuf."b!"
2793 let &l:bh = bhkeep
2794 exe filtbuf."bw!"
2795 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002796
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002797 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002798 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002799 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002800 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002801 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002803 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002804
Bram Moolenaar5c736222010-01-06 20:54:52 +01002805 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002806" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002807 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002808" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002809 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002810 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002811 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002812
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002813 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002814 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002815 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002816" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02002817 elseif !exists("leavemod")
2818 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002819" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002820 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002821" 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 +00002822 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002823
Bram Moolenaar9964e462007-05-05 17:54:07 +00002824" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002825endfun
2826
2827" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002828" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002829" uses NetRead to get a copy of the file into a temporarily file,
2830" then sources that file,
2831" then removes that file.
2832fun! netrw#NetSource(...)
2833" call Dfunc("netrw#NetSource() a:0=".a:0)
2834 if a:0 > 0 && a:1 == '?'
2835 " give help
2836 echomsg 'NetSource Usage:'
2837 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2838 echomsg ':Nsource fetch://machine/path uses fetch'
2839 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002840 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002841 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2842 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2843 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2844 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2845 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002846 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002847 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002848 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002849 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002850" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002851 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002852" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002853 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002854" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002855 if delete(s:netrw_tmpfile)
2856 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2857 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002858 unlet s:netrw_tmpfile
2859 else
2860 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2861 endif
2862 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002863 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002864 endif
2865" call Dret("netrw#NetSource")
2866endfun
2867
Bram Moolenaar8d043172014-01-23 14:24:41 +01002868" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002869" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2870" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002871fun! netrw#SetTreetop(iscmd,...)
2872" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2873" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002874
Bram Moolenaar85850f32019-07-19 22:05:51 +02002875 " iscmd==0: netrw#SetTreetop called using gn mapping
2876 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2877" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002878 " clear out the current tree
2879 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002880" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002881 let inittreetop= w:netrw_treetop
2882 unlet w:netrw_treetop
2883 endif
2884 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002885" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002886 unlet w:netrw_treedict
2887 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002888" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002889
Bram Moolenaar85850f32019-07-19 22:05:51 +02002890 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002891 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002892" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002893 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002894 if isdirectory(s:NetrwFile(a:1))
2895" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002896 let treedir = a:1
2897 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002898 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002899 let treedir = b:netrw_curdir."/".a:1
2900 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002901" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002902 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002903 " normally the cursor is left in the message window.
2904 " However, here this results in the directory being listed in the message window, which is not wanted.
2905 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002906 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002907 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002908 let treedir = "."
2909 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002910 endif
2911 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002912" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002913
2914 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002915 let islocal= expand("%") !~ '^\a\{3,}://'
2916" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002917
2918 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002919 if islocal
2920 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2921 else
2922 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2923 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002924
Bram Moolenaara6878372014-03-22 21:02:50 +01002925" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002926endfun
2927
Bram Moolenaar9964e462007-05-05 17:54:07 +00002928" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002929" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002930" readcmd == %r : replace buffer with newly read file
2931" == 0r : read file at top of buffer
2932" == r : read file after current line
2933" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002934fun! s:NetrwGetFile(readcmd, tfile, method)
2935" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002936
2937 " readcmd=='t': simply do nothing
2938 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002939" 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 +01002940" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002941 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002942 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002943
Bram Moolenaar9964e462007-05-05 17:54:07 +00002944 " get name of remote filename (ie. url and all)
2945 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002946" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002947
Bram Moolenaar9964e462007-05-05 17:54:07 +00002948 if exists("*NetReadFixup")
2949 " for the use of NetReadFixup (not otherwise used internally)
2950 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002951 endif
2952
Bram Moolenaar9964e462007-05-05 17:54:07 +00002953 if a:readcmd[0] == '%'
2954 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002955" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002956
2957 " rename the current buffer to the temp file (ie. tfile)
2958 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002959 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002960 else
2961 let tfile= a:tfile
2962 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002963 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002964
2965 " edit temporary file (ie. read the temporary file in)
2966 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002967" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002968 call zip#Browse(tfile)
2969 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002970" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002971 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002972 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002973" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002974 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002975 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002976" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002977 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002978 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002979" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002980 call tar#Browse(tfile)
2981 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002982" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002983 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002984 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002985" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002986 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002987 endif
2988
2989 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002990 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002991
Bram Moolenaar71badf92023-04-22 22:40:14 +01002992 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002993 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002994 " Note that isk must not include a "/" for scripts.vim
2995 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002996" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2997" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002998" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002999" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
3000 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01003001 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01003002 filetype detect
3003" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09003004 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003005" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003006 let line1 = 1
3007 let line2 = line("$")
3008
Bram Moolenaar8d043172014-01-23 14:24:41 +01003009 elseif !&ma
3010 " 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 +01003011 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003012" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003013 return
3014
Bram Moolenaar9964e462007-05-05 17:54:07 +00003015 elseif s:FileReadable(a:tfile)
3016 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003017" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003018 let curline = line(".")
3019 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003020" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003021 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003022 let line1= curline + 1
3023 let line2= line("$") - lastline + 1
3024
3025 else
3026 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003027" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3028" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003029 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003030" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003031 return
3032 endif
3033
3034 " User-provided (ie. optional) fix-it-up command
3035 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003036" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003037 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003038" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003039" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003040 endif
3041
Bram Moolenaaradc21822011-04-01 18:03:16 +02003042 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003043 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003044 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003045 endif
3046
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003047" 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 +00003048
3049 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003050" redraw!
3051
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003052" 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 +00003053" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003054endfun
3055
Bram Moolenaar9964e462007-05-05 17:54:07 +00003056" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003057" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003058" Input:
3059" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3060" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003061" b:netrw_method= 1: rcp
3062" 2: ftp + <.netrc>
3063" 3: ftp + machine, id, password, and [path]filename
3064" 4: scp
3065" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003066" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003067" 7: rsync
3068" 8: fetch
3069" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003070" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003071" g:netrw_machine= hostname
3072" b:netrw_fname = filename
3073" g:netrw_port = optional port number (for ftp)
3074" g:netrw_choice = copy of input url (choice)
3075fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003076" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003077
Bram Moolenaar251e1912011-06-19 05:09:16 +02003078 " sanity check: choice should have at least three slashes in it
3079 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3080 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3081 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003082" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003083 return
3084 endif
3085
Bram Moolenaar5c736222010-01-06 20:54:52 +01003086 " record current g:netrw_machine, if any
3087 " curmachine used if protocol == ftp and no .netrc
3088 if exists("g:netrw_machine")
3089 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003090" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003091 else
3092 let curmachine= "N O T A HOST"
3093 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003094 if exists("g:netrw_port")
3095 let netrw_port= g:netrw_port
3096 endif
3097
3098 " insure that netrw_ftp_cmd starts off every method determination
3099 " with the current g:netrw_ftp_cmd
3100 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003101
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003102 " initialization
3103 let b:netrw_method = 0
3104 let g:netrw_machine = ""
3105 let b:netrw_fname = ""
3106 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003107 let g:netrw_choice = a:choice
3108
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003109 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003110 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003111 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3112 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003113 " rcpurm : rcp://[user@]host/filename Use rcp
3114 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003115 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003116 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003117 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003118 " rsyncurm : rsync://host[:port]/path Use rsync
3119 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3120 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003121 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003122 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3123 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003124 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3125 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003126 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003127 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003128 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003129 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003130 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003131 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003132 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003133 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003134
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003135" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003136 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003137 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003138 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003139" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003140 let b:netrw_method = 1
3141 let userid = substitute(a:choice,rcpurm,'\1',"")
3142 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3143 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003144 if userid != ""
3145 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003147
Bram Moolenaaradc21822011-04-01 18:03:16 +02003148 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003149 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003150" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003151 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003152 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3153 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3154 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003155
Bram Moolenaar15146672011-10-20 22:22:38 +02003156 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003157 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003158" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003159 let b:netrw_method = 5
3160 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3161 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003162 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003163
Bram Moolenaaradc21822011-04-01 18:03:16 +02003164 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003165 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003166" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003167 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003168 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003169 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3170 else
3171 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3172 endif
3173 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003174
Bram Moolenaaradc21822011-04-01 18:03:16 +02003175 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003176 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003177" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003178 let b:netrw_method = 7
3179 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3180 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003181
Bram Moolenaaradc21822011-04-01 18:03:16 +02003182 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003183 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003184" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003185 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003186 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3187 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3188 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003189" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003190 if userid != ""
3191 let g:netrw_uid= userid
3192 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003193
Bram Moolenaaradc21822011-04-01 18:03:16 +02003194 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003195 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003196 call NetUserPass("ftp:".g:netrw_machine)
3197 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003198 " if there's a change in hostname, require password re-entry
3199 unlet s:netrw_passwd
3200 endif
3201 if exists("netrw_port")
3202 unlet netrw_port
3203 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003204 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003205
Bram Moolenaar446cb832008-06-24 21:56:24 +00003206 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003207 let b:netrw_method = 3
3208 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003209 let host= substitute(g:netrw_machine,'\..*$','','')
3210 if exists("s:netrw_hup[host]")
3211 call NetUserPass("ftp:".host)
3212
Nir Lichtman1e34b952024-05-08 19:19:34 +02003213 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003214" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3215" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003216 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003217 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003218" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003219 endif
3220 let b:netrw_method= 2
3221 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003222" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003223 let b:netrw_method= 2
3224 else
3225 if !exists("g:netrw_uid") || g:netrw_uid == ""
3226 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003227 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003228 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003229 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003230 endif
3231 let b:netrw_method= 3
3232 endif
3233 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003234
Bram Moolenaaradc21822011-04-01 18:03:16 +02003235 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003236 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003237" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003238 let b:netrw_method = 8
3239 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3240 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3241 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3242 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003243
Bram Moolenaaradc21822011-04-01 18:03:16 +02003244 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003245 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003246" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003247 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003248 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3249 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003250 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003251 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003252 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003253
Bram Moolenaaradc21822011-04-01 18:03:16 +02003254 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003255 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003256" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003257 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003258 let b:netrw_method = 3
3259 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3260 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003261
Bram Moolenaar9964e462007-05-05 17:54:07 +00003262 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003263 let b:netrw_method = 2
3264 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3265 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3266 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003267
Bram Moolenaaradc21822011-04-01 18:03:16 +02003268 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003269 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003270" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003271 let b:netrw_method = 9
3272 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3273 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003274
Bram Moolenaaradc21822011-04-01 18:03:16 +02003275 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003276 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003277" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003278 let b:netrw_method = 1
3279 let userid = substitute(a:choice,rcphf,'\2',"")
3280 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3281 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003282" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3283" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3284" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3285" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003286 if userid != ""
3287 let g:netrw_uid= userid
3288 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003289
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003290 " Method#10: file://user@hostname/...path-to-file {{{3
3291 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003292" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003293 let b:netrw_method = 10
3294 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003295" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003296
Bram Moolenaaradc21822011-04-01 18:03:16 +02003297 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003298 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003299 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003300 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003301 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003302 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003303 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003304 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003305
Bram Moolenaar81695252004-12-29 20:58:21 +00003306 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003307 " remove any leading [:#] from port number
3308 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3309 elseif exists("netrw_port")
3310 " retain port number as implicit for subsequent ftp operations
3311 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003312 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003313
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003314" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3315" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3316" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3317" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003318" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003319" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003320" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003321" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003322" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003323" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003324" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003325" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003327
Bram Moolenaar9964e462007-05-05 17:54:07 +00003328" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003329" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003330" Usage: :call NetUserPass() -- will prompt for userid and password
3331" :call NetUserPass("uid") -- will prompt for password
3332" :call NetUserPass("uid","password") -- sets global userid and password
3333" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3334" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003335fun! NetUserPass(...)
3336
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003337" call Dfunc("NetUserPass() a:0=".a:0)
3338
3339 if !exists('s:netrw_hup')
3340 let s:netrw_hup= {}
3341 endif
3342
Bram Moolenaar071d4272004-06-13 20:20:40 +00003343 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003344 " case: no input arguments
3345
3346 " change host and username if not previously entered; get new password
3347 if !exists("g:netrw_machine")
3348 let g:netrw_machine= input('Enter hostname: ')
3349 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003350 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003351 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003352 let g:netrw_uid= input('Enter username: ')
3353 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003354 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003355 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003356
3357 " set up hup database
3358 let host = substitute(g:netrw_machine,'\..*$','','')
3359 if !exists('s:netrw_hup[host]')
3360 let s:netrw_hup[host]= {}
3361 endif
3362 let s:netrw_hup[host].uid = g:netrw_uid
3363 let s:netrw_hup[host].passwd = s:netrw_passwd
3364
3365 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003366 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003367
3368 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003369 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003370 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003371" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003372 let host = substitute(a:1,'^ftp:','','')
3373 let host = substitute(host,'\..*','','')
3374 if exists("s:netrw_hup[host]")
3375 let g:netrw_uid = s:netrw_hup[host].uid
3376 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003377" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3378" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003379 else
3380 let g:netrw_uid = input("Enter UserId: ")
3381 let s:netrw_passwd = inputsecret("Enter Password: ")
3382 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003383
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003384 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003385 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003386" 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 +02003387 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003388 if g:netrw_machine =~ '[0-9.]\+'
3389 let host= g:netrw_machine
3390 else
3391 let host= substitute(g:netrw_machine,'\..*$','','')
3392 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003393 else
3394 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003395 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003396 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003397" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003398 if exists("g:netrw_passwd")
3399 " ask for password if one not previously entered
3400 let s:netrw_passwd= g:netrw_passwd
3401 else
3402 let s:netrw_passwd = inputsecret("Enter Password: ")
3403 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003404 endif
3405
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003406" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003407 if exists("host")
3408 if !exists('s:netrw_hup[host]')
3409 let s:netrw_hup[host]= {}
3410 endif
3411 let s:netrw_hup[host].uid = g:netrw_uid
3412 let s:netrw_hup[host].passwd = s:netrw_passwd
3413 endif
3414
3415 elseif a:0 == 2
3416 let g:netrw_uid = a:1
3417 let s:netrw_passwd = a:2
3418
3419 elseif a:0 == 3
3420 " enter hostname, user-id, and password into the hup dictionary
3421 let host = substitute(a:1,'^\a\+:','','')
3422 let host = substitute(host,'\..*$','','')
3423 if !exists('s:netrw_hup[host]')
3424 let s:netrw_hup[host]= {}
3425 endif
3426 let s:netrw_hup[host].uid = a:2
3427 let s:netrw_hup[host].passwd = a:3
3428 let g:netrw_uid = s:netrw_hup[host].uid
3429 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003430" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3431" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003432 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003433
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003434" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003435endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003436
Bram Moolenaar85850f32019-07-19 22:05:51 +02003437" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003438" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003439" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003441" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003442" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3443fun! s:ExplorePatHls(pattern)
3444" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3445 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003446" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003447 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003448" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003449 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3450" call Dret("s:ExplorePatHls repat<".repat.">")
3451 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003452endfun
3453
3454" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003455" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003456" 0: (user: <mb>) bookmark current directory
3457" 1: (user: <gb>) change to the bookmarked directory
3458" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003459" 3: (browsing) records current directory history
3460" 4: (user: <u>) go up (previous) directory, using history
3461" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003462" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003463fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003464" 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 +02003465 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3466" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3467 return
3468 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003469
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003470 let ykeep = @@
3471 let curbufnr = bufnr("%")
3472
Bram Moolenaar9964e462007-05-05 17:54:07 +00003473 if a:chg == 0
3474 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003475" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003476 if exists("s:netrwmarkfilelist_{curbufnr}")
3477 call s:NetrwBookmark(0)
3478 echo "bookmarked marked files"
3479 else
3480 call s:MakeBookmark(a:curdir)
3481 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003482 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003483
KSR-Yasudaf4498252023-10-06 03:34:17 +09003484 try
3485 call s:NetrwBookHistSave()
3486 catch
3487 endtry
3488
Bram Moolenaar9964e462007-05-05 17:54:07 +00003489 elseif a:chg == 1
3490 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003491" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003492 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003493" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003494 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003495 else
3496 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3497 endif
3498
3499 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003500" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003501 let didwork= 0
3502 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003503" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003504 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003505" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003506 let cnt= 1
3507 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003508" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003509 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003510 let didwork = 1
3511 let cnt = cnt + 1
3512 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003513 endif
3514
3515 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003516 " Note: history is saved only when PerformListing is done;
3517 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3518 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003519 let first = 1
3520 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003521 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003522 while ( first || cnt != g:netrw_dirhistcnt )
3523" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003524 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003525" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003526 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003527 let didwork= 1
3528 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003529 let histcnt = histcnt + 1
3530 let first = 0
3531 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003532 if cnt < 0
3533 let cnt= cnt + g:netrw_dirhistmax
3534 endif
3535 endwhile
3536 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003537 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003538 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003539 if didwork
3540 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3541 endif
3542
3543 elseif a:chg == 3
3544 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003545" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003546 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 +02003547 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003548 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3549 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003550 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003551" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003552 endif
3553
3554 elseif a:chg == 4
3555 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003556" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003557 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003558 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3559 if g:netrw_dirhistcnt < 0
3560 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003561 endif
3562 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003563 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003564 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003565 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3566" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003567 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003568 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003569" call Decho("setl ma noro",'~'.expand("<slnum>"))
3570 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003571 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003572" call Decho("setl nomod",'~'.expand("<slnum>"))
3573" 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 +00003574 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003575" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3576 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003577 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003578 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003579 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003580 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003581 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003582 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003583 echo "Sorry, no predecessor directory exists yet"
3584 endif
3585
3586 elseif a:chg == 5
3587 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003588" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003589 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003590 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3591 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3592" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003593 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003594" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003595 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003596 sil! NetrwKeepj %d _
3597" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3598" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003599 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003600" 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 +02003601 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003602" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3603 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003604 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003605 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3606 if g:netrw_dirhistcnt < 0
3607 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003608 endif
3609 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003610 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003611 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003612 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003613 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003614 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003615
3616 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003617" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003618 if exists("s:netrwmarkfilelist_{curbufnr}")
3619 call s:NetrwBookmark(1)
3620 echo "removed marked files from bookmarks"
3621 else
3622 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003623 let iremove = v:count
3624 let dremove = g:netrw_bookmarklist[iremove - 1]
3625" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003626 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003627" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3628 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3629 echo "removed ".dremove." from g:netrw_bookmarklist"
3630" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003631 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003632" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003633
3634 try
3635 call s:NetrwBookHistSave()
3636 catch
3637 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003638 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003639 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003640 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003641 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003642" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003643endfun
3644
3645" ---------------------------------------------------------------------
3646" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003647" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003648" Sister function: s:NetrwBookHistSave()
3649fun! s:NetrwBookHistRead()
3650" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003651 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003652" 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 +02003653 return
3654 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003655 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003656
3657 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003658 if !exists("s:netrw_initbookhist")
3659 let home = s:NetrwHome()
3660 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003661 if filereadable(s:NetrwFile(savefile))
3662" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003663 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003664 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003665
3666 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003667 if g:netrw_dirhistmax > 0
3668 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003669 if filereadable(s:NetrwFile(savefile))
3670" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003671 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003672 endif
3673 let s:netrw_initbookhist= 1
3674 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003675 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003676 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003677
Bram Moolenaar97d62492012-11-15 21:28:22 +01003678 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003679" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3680" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003681" call Dret("s:NetrwBookHistRead")
3682endfun
3683
3684" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003685" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003686" Sister function: s:NetrwBookHistRead()
3687" I used to do this via viminfo but that appears to
3688" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003689" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3690" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003691" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003692fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003693" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003694 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003695" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003696 return
3697 endif
3698
Bram Moolenaar5c736222010-01-06 20:54:52 +01003699 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003700" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003701 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003702
3703 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003704 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003705" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003706 if g:netrw_use_noswf
3707 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3708 else
3709 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3710 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003711 setl nocin noai noci magic nospell nohid wig= noaw
3712 setl ma noro write
3713 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003714 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003715
Bram Moolenaar85850f32019-07-19 22:05:51 +02003716 " rename enew'd file: .netrwhist -- no attempt to merge
3717 " record dirhistmax and current dirhistcnt
3718 " save history
3719" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003720 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003721 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003722 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3723 if g:netrw_dirhistmax > 0
3724 let lastline = line("$")
3725 let cnt = g:netrw_dirhistcnt
3726 let first = 1
3727 while ( first || cnt != g:netrw_dirhistcnt )
3728 let lastline= lastline + 1
3729 if exists("g:netrw_dirhist_{cnt}")
3730 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3731" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3732 endif
3733 let first = 0
3734 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3735 if cnt < 0
3736 let cnt= cnt + g:netrw_dirhistmax
3737 endif
3738 endwhile
3739 exe "sil! w! ".savefile
3740" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3741 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003742
Bram Moolenaar85850f32019-07-19 22:05:51 +02003743 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003744 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003745 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003746" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003747 " merge and write .netrwbook
3748 let savefile= s:NetrwHome()."/.netrwbook"
3749
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003750 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003751 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003752 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003753 for bdm in booklist
3754 if index(g:netrw_bookmarklist,bdm) == -1
3755 call add(g:netrw_bookmarklist,bdm)
3756 endif
3757 endfor
3758 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003759 endif
3760
3761 " construct and save .netrwbook
3762 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003763 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003764" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003765 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003766
3767 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003768 let bgone= bufnr("%")
3769 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003770 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003771
3772" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003773endfun
3774
3775" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003776" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3777" list of the contents of a local or remote directory. It is assumed that the
3778" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3779" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003780" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003781fun! s:NetrwBrowse(islocal,dirname)
3782 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003783" 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 +02003784" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3785" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3786" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003787
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003788 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3789 " This is useful when one edits a local file, then :e ., then :Rex
3790 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3791 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003792" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003793 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003794
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003795 " s:NetrwBrowse : initialize history {{{3
3796 if !exists("s:netrw_initbookhist")
3797 NetrwKeepj call s:NetrwBookHistRead()
3798 endif
3799
3800 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003801 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003802 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003803" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003804 else
3805 let dirname= a:dirname
3806 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003807
Bram Moolenaar85850f32019-07-19 22:05:51 +02003808 " repoint t:netrw_lexbufnr if appropriate
3809 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3810" call Decho("set repointlexbufnr to true!")
3811 let repointlexbufnr= 1
3812 endif
3813
3814 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003815 if exists("s:netrw_skipbrowse")
3816 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003817" 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 +01003818" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003819 return
3820 endif
3821 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003822 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003823" call Dret("s:NetrwBrowse : missing shellescape()")
3824 return
3825 endif
3826 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003827 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003828" call Dret("s:NetrwBrowse : missing fnameescape()")
3829 return
3830 endif
3831
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003832 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003833 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003834
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003835 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003836 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3837 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3838" call Decho("clearing marked files",'~'.expand("<slnum>"))
3839 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3840 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003841 endif
3842
3843 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003844 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003845" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3846" 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 +02003847 if s:NetrwLcd(dirname)
3848" call Dret("s:NetrwBrowse : lcd failure")
3849 return
3850 endif
3851 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003852" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003853
Bram Moolenaar5c736222010-01-06 20:54:52 +01003854 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003855 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003856" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003857 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003858" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003859 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003860 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003861 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003862" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003863
3864 " remove any filetype indicator from end of dirname, except for the
3865 " "this is a directory" indicator (/).
3866 " There shouldn't be one of those here, anyway.
3867 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003868" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003869 call s:RemotePathAnalysis(dirname)
3870
3871 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3872 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003873 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003874 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003875" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003876 let b:netrw_curdir = dirname
3877 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003878 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003879 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3880 sil call netrw#NetRead(2,url)
3881 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003882" call Decho("url<".url.">",'~'.expand("<slnum>"))
3883" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3884" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003885 if s:path =~ '.bz2'
3886 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3887 elseif s:path =~ '.gz'
3888 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3889 elseif s:path =~ '.gz'
3890 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3891 else
3892 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3893 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003894 endif
3895
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003896 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003897 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003898 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003899" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003900 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003901" 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 +00003902
Bram Moolenaar446cb832008-06-24 21:56:24 +00003903" call Dret("s:NetrwBrowse : file<".s:fname.">")
3904 return
3905 endif
3906
Bram Moolenaaradc21822011-04-01 18:03:16 +02003907 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003908 call s:UseBufWinVars()
3909
3910 " set up some variables {{{3
3911 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003912 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003913 let s:last_sort_by = g:netrw_sort_by
3914
3915 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003916 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003917
Bram Moolenaar97d62492012-11-15 21:28:22 +01003918 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003919" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003920 let svpos = winsaveview()
3921" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003922 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003923
Bram Moolenaar446cb832008-06-24 21:56:24 +00003924 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003925 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3926 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3927" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3928" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3929 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3930 else
3931" " call Decho("2match none",'~'.expand("<slnum>"))
3932 2match none
3933 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003934 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003935 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003936 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003937" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003938 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003939" 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 +01003940" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003941 return
3942 endif
3943
3944 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003945" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003946 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003947 if b:netrw_curdir =~ '[/\\]$'
3948 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3949 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003950 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003951 let b:netrw_curdir= b:netrw_curdir."/"
3952 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003953 if b:netrw_curdir == ''
3954 if has("amiga")
3955 " On the Amiga, the empty string connotes the current directory
3956 let b:netrw_curdir= getcwd()
3957 else
3958 " under unix, when the root directory is encountered, the result
3959 " from the preceding substitute is an empty string.
3960 let b:netrw_curdir= '/'
3961 endif
3962 endif
3963 if !a:islocal && b:netrw_curdir !~ '/$'
3964 let b:netrw_curdir= b:netrw_curdir.'/'
3965 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003966" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003967
3968 " ------------
3969 " (local only) {{{3
3970 " ------------
3971 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003972" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003973
3974 " Set up ShellCmdPost handling. Append current buffer to browselist
3975 call s:LocalFastBrowser()
3976
3977 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3978 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003979" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3980" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003981 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003982 if s:NetrwLcd(b:netrw_curdir)
3983" call Dret("s:NetrwBrowse : lcd failure")
3984 return
3985 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003986 endif
3987 endif
3988
3989 " --------------------------------
3990 " remote handling: {{{3
3991 " --------------------------------
3992 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003993" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003994
Bram Moolenaar97d62492012-11-15 21:28:22 +01003995 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003996" 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 +02003997 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003998 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003999" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004000 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
4001 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4002 if dirname !~ '/$'
4003 let dirname= dirname.'/'
4004 endif
4005 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004006" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004007 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004008 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004009" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004010 endif
4011
4012 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4013 if dirname !~ dirpat
4014 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004015 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004016 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004017 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004018" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004019 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004020" 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 +00004021" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4022 return
4023 endif
4024 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004025" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004026 endif " (additional remote handling)
4027
Bram Moolenaar85850f32019-07-19 22:05:51 +02004028 " -------------------------------
4029 " Perform Directory Listing: {{{3
4030 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004031 NetrwKeepj call s:NetrwMaps(a:islocal)
4032 NetrwKeepj call s:NetrwCommands(a:islocal)
4033 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004034
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004035 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004036 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004037" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4038
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004039 " If there is a rexposn: restore position with rexposn
4040 " Otherwise : set rexposn
4041 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004042" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4043 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4044 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4045 NetrwKeepj exe w:netrw_bannercnt
4046 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004047 else
4048 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4049 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004050 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004051 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004052" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004053 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004054 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004055
Bram Moolenaar85850f32019-07-19 22:05:51 +02004056 " repoint t:netrw_lexbufnr if appropriate
4057 if exists("repointlexbufnr")
4058 let t:netrw_lexbufnr= bufnr("%")
4059" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4060 endif
4061
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004062 " restore position
4063 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004064" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4065 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004066 endif
4067
Bram Moolenaara6878372014-03-22 21:02:50 +01004068 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004069 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4070 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004071" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4072" 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 +02004073" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004074 return
4075endfun
4076
4077" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004078" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4079" may not apply correctly; ie. netrw's idea of the current directory may
4080" differ from vim's. This function insures that netrw's idea of the current
4081" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004082" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004083fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004084" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4085" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4086" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4087" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4088" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004089
4090 " clean up any leading treedepthstring
4091 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4092 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004093" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004094 else
4095 let fname= a:fname
4096 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004097
4098 if g:netrw_keepdir
4099 " vim's idea of the current directory possibly may differ from netrw's
4100 if !exists("b:netrw_curdir")
4101 let b:netrw_curdir= getcwd()
4102 endif
4103
Nir Lichtman1e34b952024-05-08 19:19:34 +02004104 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004105 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004106 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004107 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004108" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004109 else
4110 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004111 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004112" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004113 endif
4114
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004115 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004116 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004117 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004118" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004119 else
4120 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004121 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004122" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004123 endif
4124 else
4125 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004126 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004127" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4128" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4129" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004130 endif
4131
Bram Moolenaar85850f32019-07-19 22:05:51 +02004132" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004133 return ret
4134endfun
4135
4136" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004137" s:NetrwFileInfo: supports qf (query for file information) {{{2
4138fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004139" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004140 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004141 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004142 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004143 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004144 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004145 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004146 let lsopt= "-lsadh --si"
4147 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004148" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004149 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004150
4151 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004152 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004153" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004154
Bram Moolenaara6878372014-03-22 21:02:50 +01004155 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004156 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004157" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004158
4159 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004160 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004161" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004162
Bram Moolenaar446cb832008-06-24 21:56:24 +00004163 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004164" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004165 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004166" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004167 endif
4168 else
4169 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004170" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4171 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004172 let fname= substitute(a:fname,".$","","")
4173 else
4174 let fname= a:fname
4175 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004176 let t = getftime(s:NetrwFile(fname))
4177 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004178 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004179 let sz= s:NetrwHumanReadable(sz)
4180 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004181 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4182" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004183 endif
4184 else
4185 echo "sorry, \"qf\" not supported yet for remote files"
4186 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004187 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004188" call Dret("s:NetrwFileInfo")
4189endfun
4190
4191" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004192" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4193fun! s:NetrwFullPath(filename)
4194" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4195 let filename= a:filename
4196 if filename !~ '^/'
4197 let filename= resolve(getcwd().'/'.filename)
4198 endif
4199 if filename != "/" && filename =~ '/$'
4200 let filename= substitute(filename,'/$','','')
4201 endif
4202" " call Dret("s:NetrwFullPath <".filename.">")
4203 return filename
4204endfun
4205
4206" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004207" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004208" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004209" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004210" 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 +00004211fun! s:NetrwGetBuffer(islocal,dirname)
4212" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004213" 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 +02004214" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4215" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004216 let dirname= a:dirname
4217
4218 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004219" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004220 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004221" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004222 let s:netrwbuf= {}
4223 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004224" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4225" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4226
4227 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4228 let bufnum = -1
4229
4230 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4231 if has_key(s:netrwbuf,"NetrwTreeListing")
4232 let bufnum= s:netrwbuf["NetrwTreeListing"]
4233 else
4234 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4235 endif
4236" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4237 if !bufexists(bufnum)
Peter Aronoffbe551da2024-09-22 11:29:40 +02004238 call remove(s:netrwbuf,"NetrwTreeListing")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004239 let bufnum= -1
4240 endif
4241 elseif bufnr("NetrwTreeListing") != -1
4242 let bufnum= bufnr("NetrwTreeListing")
4243" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4244 else
4245" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4246 let bufnum= -1
4247 endif
4248
4249 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004250 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004251" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004252 if !bufexists(bufnum)
4253 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4254 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004255 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004256
Bram Moolenaar446cb832008-06-24 21:56:24 +00004257 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004258" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004259 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004260 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004261" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4262
Bram Moolenaar71badf92023-04-22 22:40:14 +01004263 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004264 " IF the buffer already has the desired name
4265 " AND it is empty
4266 let curbuf = bufname("%")
4267 if curbuf == '.'
4268 let curbuf = getcwd()
4269 endif
4270" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004271" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004272" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4273" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4274" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4275" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4276 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004277" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4278 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004279 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004280" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004281 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004282 " 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 +00004283
4284 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004285 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004286" 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 +00004287 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004288" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004289 " name the buffer
4290 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4291 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004292" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004293 let w:netrw_treebufnr = bufnr("%")
4294 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004295 if g:netrw_use_noswf
4296 setl nobl bt=nofile noswf
4297 else
4298 setl nobl bt=nofile
4299 endif
4300 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4301 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4302 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4303 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004304" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004305 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004306 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004307 " enter the new buffer into the s:netrwbuf dictionary
4308 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4309" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4310" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004311 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004312" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004313
4314 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004315" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004316 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004317 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004318 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004319
4320 if &ft == "netrw"
4321" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4322 exe "sil! NetrwKeepj noswapfile b ".bufnum
4323" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004324 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004325" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4326 call s:NetrwEditBuf(bufnum)
4327" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004328 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004329" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004330 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004331 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004332 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004333
4334 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004335 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004336
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004337 if line("$") <= 1 && getline(1) == ""
4338 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004339 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004340" 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>"))
4341" 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 +01004342" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4343 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004344
Bram Moolenaar97d62492012-11-15 21:28:22 +01004345 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004346" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004347 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004348 sil NetrwKeepj %d _
4349" 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>"))
4350" 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 +01004351" 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 +00004352 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004353
Bram Moolenaar446cb832008-06-24 21:56:24 +00004354 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004355" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4356" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004357 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004358 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004359 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004360" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4361" 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 +01004362" 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 +00004363 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004364
Bram Moolenaar446cb832008-06-24 21:56:24 +00004365 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004366" 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>"))
4367" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4368" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004369 return 1
4370 endif
4371 endif
4372
4373 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4374 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4375 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4376 " med 1 D H
4377 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004378" 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 +00004379 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004380 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004381 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004382
4383 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004384" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4385" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4386 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004387
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004388" 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>"))
4389" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4390" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004391 return 0
4392endfun
4393
4394" ---------------------------------------------------------------------
4395" s:NetrwGetcwd: get the current directory. {{{2
4396" Change backslashes to forward slashes, if any.
4397" If doesc is true, escape certain troublesome characters
4398fun! s:NetrwGetcwd(doesc)
4399" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4400 let curdir= substitute(getcwd(),'\\','/','ge')
4401 if curdir !~ '[\/]$'
4402 let curdir= curdir.'/'
4403 endif
4404 if a:doesc
4405 let curdir= fnameescape(curdir)
4406 endif
4407" call Dret("NetrwGetcwd <".curdir.">")
4408 return curdir
4409endfun
4410
4411" ---------------------------------------------------------------------
4412" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4413fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004414" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4415" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4416 let keepsol= &l:sol
4417 setl nosol
4418
Bram Moolenaar446cb832008-06-24 21:56:24 +00004419 call s:UseBufWinVars()
4420
4421 " insure that w:netrw_liststyle is set up
4422 if !exists("w:netrw_liststyle")
4423 if exists("g:netrw_liststyle")
4424 let w:netrw_liststyle= g:netrw_liststyle
4425 else
4426 let w:netrw_liststyle= s:THINLIST
4427 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004428" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004429 endif
4430
4431 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4432 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004433" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004434 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004435 let dirname= "./"
4436 let curline= getline('.')
4437
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004438 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004439 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004440 let s:netrw_skipbrowse= 1
4441 echo 'Pressing "s" also works'
4442
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004443 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004444 let s:netrw_skipbrowse= 1
4445 echo 'Press "S" to edit sorting sequence'
4446
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004447 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004448 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004449 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004450
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004451 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004452 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004453 let s:netrw_skipbrowse= 1
4454 echo 'Pressing "a" also works'
4455
4456 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004457 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004458 endif
4459
4460 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004461" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004462 NetrwKeepj norm! 0
4463 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004464
4465 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004466" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004467 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004468 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4469
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004470 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004471" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004472 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004473 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004474
4475 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004476" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004477 let dirname= getline('.')
4478
4479 if !exists("b:netrw_cpf")
4480 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004481 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 +01004482 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004483" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004484 endif
4485
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004486" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004487 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004488" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4489" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004490 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004491 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004492 else
4493 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004494 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004495 endif
Enno3146d632024-07-04 19:44:42 +02004496
4497 let dict={}
4498 " save the unnamed register and register 0-9 and a
4499 let dict.a=[getreg('a'), getregtype('a')]
4500 for i in range(0, 9)
4501 let dict[i] = [getreg(i), getregtype(i)]
4502 endfor
4503 let dict.unnamed = [getreg(''), getregtype('')]
4504
Bram Moolenaarc236c162008-07-13 17:41:49 +00004505 let eofname= filestart + b:netrw_cpf + 1
4506 if eofname <= col("$")
4507 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004508 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004509 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004510 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004511 endif
Enno3146d632024-07-04 19:44:42 +02004512
Bram Moolenaar446cb832008-06-24 21:56:24 +00004513 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004514 call s:RestoreRegister(dict)
4515
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004516" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004517 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004518" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004519 endif
4520
4521 " symlinks are indicated by a trailing "@". Remove it before further processing.
4522 let dirname= substitute(dirname,"@$","","")
4523
4524 " executables are indicated by a trailing "*". Remove it before further processing.
4525 let dirname= substitute(dirname,"\*$","","")
4526
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004527 let &l:sol= keepsol
4528
Bram Moolenaar446cb832008-06-24 21:56:24 +00004529" call Dret("s:NetrwGetWord <".dirname.">")
4530 return dirname
4531endfun
4532
4533" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004534" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4535" g:netrw_bufsettings will be used after the listing is produced.
4536" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004537fun! s:NetrwListSettings(islocal)
4538" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004539" 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 +00004540 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004541" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4542 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4543 setl bt=nofile nobl ma nonu nowrap noro nornu
4544 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004545 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004546 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004547 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004548" call Dredir("ls!","s:NetrwListSettings")
4549" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004550 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004551 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004552 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004553 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004554 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004555 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004556 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004557" 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 +00004558" call Dret("s:NetrwListSettings")
4559endfun
4560
4561" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004562" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004563" islocal=0: remote browsing
4564" =1: local browsing
4565fun! s:NetrwListStyle(islocal)
4566" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004567
Bram Moolenaar97d62492012-11-15 21:28:22 +01004568 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004569 let fname = s:NetrwGetWord()
4570 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004571 let svpos = winsaveview()
4572" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004573 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004574" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4575" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4576" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004577
Bram Moolenaar85850f32019-07-19 22:05:51 +02004578 " repoint t:netrw_lexbufnr if appropriate
4579 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4580" call Decho("set repointlexbufnr to true!")
4581 let repointlexbufnr= 1
4582 endif
4583
Bram Moolenaar446cb832008-06-24 21:56:24 +00004584 if w:netrw_liststyle == s:THINLIST
4585 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004586" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004587 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4588
4589 elseif w:netrw_liststyle == s:LONGLIST
4590 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004591" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004592 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4593
4594 elseif w:netrw_liststyle == s:WIDELIST
4595 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004596" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004597 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4598
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004599 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004600" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004601 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4602
4603 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004604 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004605 let g:netrw_liststyle = s:THINLIST
4606 let w:netrw_liststyle = g:netrw_liststyle
4607 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4608 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004609 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004610" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004611
4612 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004613" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4614 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004615 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004616" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004617 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004618" 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 +00004619
4620 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004621" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004622 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004623 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004624
Bram Moolenaar85850f32019-07-19 22:05:51 +02004625 " repoint t:netrw_lexbufnr if appropriate
4626 if exists("repointlexbufnr")
4627 let t:netrw_lexbufnr= bufnr("%")
4628" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4629 endif
4630
Bram Moolenaar13600302014-05-22 18:26:40 +02004631 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004632" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4633 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004634 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004635
4636" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4637endfun
4638
4639" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004640" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4641fun! s:NetrwBannerCtrl(islocal)
4642" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4643
Bram Moolenaar97d62492012-11-15 21:28:22 +01004644 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004645 " toggle the banner (enable/suppress)
4646 let g:netrw_banner= !g:netrw_banner
4647
4648 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004649 let svpos= winsaveview()
4650" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004651 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4652
4653 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004654 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4655 let fname= s:NetrwGetWord()
4656 sil NetrwKeepj $
4657 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4658" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4659 if result <= 0 && exists("w:netrw_bannercnt")
4660 exe "NetrwKeepj ".w:netrw_bannercnt
4661 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004662 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004663 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004664" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4665endfun
4666
4667" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004668" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4669"
4670" No bang: enters files/directories into Netrw's bookmark system
4671" No argument and in netrw buffer:
4672" if there are marked files: bookmark marked files
4673" otherwise : bookmark file/directory under cursor
4674" No argument and not in netrw buffer: bookmarks current open file
4675" Has arguments: globs them individually and bookmarks them
4676"
4677" With bang: deletes files/directories from Netrw's bookmark system
4678fun! s:NetrwBookmark(del,...)
4679" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4680 if a:0 == 0
4681 if &ft == "netrw"
4682 let curbufnr = bufnr("%")
4683
4684 if exists("s:netrwmarkfilelist_{curbufnr}")
4685 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004686" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004687 let svpos = winsaveview()
4688" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004689 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004690 for fname in s:netrwmarkfilelist_{curbufnr}
4691 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4692 endfor
4693 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4694 call s:NetrwUnmarkList(curbufnr,curdir)
4695 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004696" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4697 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004698 else
4699 let fname= s:NetrwGetWord()
4700 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4701 endif
4702
4703 else
4704 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004705" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004706 let fname= expand("%")
4707 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4708 endif
4709
4710 else
4711 " bookmark specified files
4712 " attempts to infer if working remote or local
4713 " by deciding if the current file begins with an url
4714 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004715 let islocal= expand("%") !~ '^\a\{3,}://'
4716" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004717 let i = 1
4718 while i <= a:0
4719 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004720 if v:version > 704 || (v:version == 704 && has("patch656"))
4721 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004722 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004723 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004724 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004725 else
4726 let mbfiles= [a:{i}]
4727 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004728" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004729 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004730" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004731 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4732 endfor
4733 let i= i + 1
4734 endwhile
4735 endif
4736
4737 " update the menu
4738 call s:NetrwBookmarkMenu()
4739
4740" call Dret("s:NetrwBookmark")
4741endfun
4742
4743" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004744" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4745" .2.[cnt] for bookmarks, and
4746" .3.[cnt] for history
4747" (see s:NetrwMenu())
4748fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004749 if !exists("s:netrw_menucnt")
4750 return
4751 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004752" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004753
4754 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004755 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004756 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004757" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004758 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4759 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004760 endif
4761 if !exists("s:netrw_initbookhist")
4762 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004763 endif
4764
4765 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004766 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004767 let cnt= 1
4768 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004769" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004770 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004771
4772 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004773 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004774
4775 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004776 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 +01004777 let cnt= cnt + 1
4778 endfor
4779
4780 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004781
4782 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004783 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004784 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004785 let first = 1
4786 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004787 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004788 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004789 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004790 if exists("g:netrw_dirhist_{cnt}")
4791 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004792" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004793 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4794 endif
4795 let first = 0
4796 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4797 if cnt < 0
4798 let cnt= cnt + g:netrw_dirhistmax
4799 endif
4800 endwhile
4801 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004802
Bram Moolenaar9964e462007-05-05 17:54:07 +00004803 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004804" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004805endfun
4806
4807" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004808" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4809" directory and a new directory name. Also, if the
4810" "new directory name" is actually a file,
4811" NetrwBrowseChgDir() edits the file.
4812fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004813" 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 +01004814" 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 +00004815
Bram Moolenaar97d62492012-11-15 21:28:22 +01004816 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004817 if !exists("b:netrw_curdir")
4818 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4819 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004820 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004821" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4822" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004823" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004824" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004825 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004826 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004827" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004828
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004829 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004830" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004831 call s:SavePosn(s:netrw_posn)
4832 NetrwKeepj call s:NetrwOptionsSave("s:")
4833 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004834 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004835 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004836 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004837 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004838 endif
4839 let newdir = a:newdir
4840 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004841 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004842" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004843" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004844" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004845
4846 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004847" 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 +01004848 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004849" 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 +01004850 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004851 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004852" 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 +01004853 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004854" 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 +02004855 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004856 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004857 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004858 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004859" 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 +01004860 endif
4861 endif
4862" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004863" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004864 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004865
Bram Moolenaar446cb832008-06-24 21:56:24 +00004866 " set up o/s-dependent directory recognition pattern
4867 if has("amiga")
4868 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004869 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004870 let dirpat= '[\/]$'
4871 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004872" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004873
4874 if dirname !~ dirpat
4875 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004876 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004877 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004878" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004879 endif
4880
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004881" 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 +01004882 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004883 " ------------------------------
4884 " NetrwBrowseChgDir: edit a file {{{3
4885 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004886" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004887
Bram Moolenaar97d62492012-11-15 21:28:22 +01004888 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004889 let s:rexposn_{bufnr("%")}= winsaveview()
4890" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004891" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4892" 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 +01004893
Bram Moolenaar446cb832008-06-24 21:56:24 +00004894 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004895" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4896" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004897" let newdir = s:NetrwTreePath(s:netrw_treetop)
4898" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004899 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004900 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4901" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4902 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004903 if dirname =~ '/$'
4904 let dirname= dirname.newdir
4905 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004906 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004907 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004908" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4909" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004910 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004911" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004912 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004913 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004914 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004915 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004916" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004917 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004918 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004919" 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 +02004920 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004921 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004922 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004923" " 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 +01004924 if type(g:netrw_browse_split) == 3
4925 " open file in server
4926 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004927" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004928 call s:NetrwServerEdit(a:islocal,dirname)
4929" call Dret("s:NetrwBrowseChgDir")
4930 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004931
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004932 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004933 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004934" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004935 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4936 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004937 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004938 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004939 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004940 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004941
Bram Moolenaar446cb832008-06-24 21:56:24 +00004942 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004943 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004944" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004945 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4946 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004947 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004948 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004949 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004950 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004951
Bram Moolenaar446cb832008-06-24 21:56:24 +00004952 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004953 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004954" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004955 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004956 if !exists("b:netrw_curdir")
4957 let b:netrw_curdir= getcwd()
4958 endif
4959 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004960
Bram Moolenaar446cb832008-06-24 21:56:24 +00004961 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004962 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004963" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004964 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004965 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004966" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004967 return
4968 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004969 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004970
Bram Moolenaar9964e462007-05-05 17:54:07 +00004971 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004972 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004973" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004974 call s:NetrwMenu(0)
4975 " optional change to window
4976 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004977" 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 +02004978 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004979 " if g:netrw_chgwin is set to one more than the last window, then
4980 " vertically split the last window to make that window available.
4981 let curwin= winnr()
4982 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4983 vs
4984 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004985 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004986 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004987 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004988 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004989 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004990
Bram Moolenaar9964e462007-05-05 17:54:07 +00004991 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004992
Bram Moolenaar446cb832008-06-24 21:56:24 +00004993 " the point where netrw actually edits the (local) file
4994 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004995 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004996 if !&mod
4997 " if e the new file would fail due to &mod, then don't change any of the flags
4998 let dolockout= 1
4999 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005000 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005001" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005002 " some like c-^ to return to the last edited file
5003 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005004 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
5005 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01005006 call s:NetrwEditFile("e","",dirname)
5007" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005008 " COMBAK -- cuc cul related
5009 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005010 if &hidden || &bufhidden == "hide"
5011 " file came from vim's hidden storage. Don't "restore" options with it.
5012 let dorestore= 0
5013 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005014 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005015" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005016 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005017
5018 " handle g:Netrw_funcref -- call external-to-netrw functions
5019 " This code will handle g:Netrw_funcref as an individual function reference
5020 " or as a list of function references. It will ignore anything that's not
5021 " a function reference. See :help Funcref for information about function references.
5022 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005023" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005024 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005025" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005026 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005027 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005028" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005029 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005030 if type(Fncref) == 2
5031 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005032 endif
5033 endfor
5034 endif
5035 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005036 endif
5037
5038 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005039 " ----------------------------------------------------
5040 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5041 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005042" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005043 let dirname = newdir
5044 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005045 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005046 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005047
5048 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005049 " ---------------------------------------------
5050 " NetrwBrowseChgDir: refresh the directory list {{{3
5051 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005052" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005053 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005054 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005055
5056 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005057 " --------------------------------------
5058 " NetrwBrowseChgDir: go up one directory {{{3
5059 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005060" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005061
5062 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5063 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005064" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5065" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005066 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005067 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005068 endif
5069
5070 if has("amiga")
5071 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005072" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005073 if a:islocal
5074 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5075 let dirname= substitute(dirname,'/$','','')
5076 else
5077 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5078 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005079" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005080
Nir Lichtman1e34b952024-05-08 19:19:34 +02005081 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005082 " windows
5083 if a:islocal
5084 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5085 if dirname == ""
5086 let dirname= '/'
5087 endif
5088 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005089 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005090 endif
5091 if dirname =~ '^\a:$'
5092 let dirname= dirname.'/'
5093 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005094" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005095
Bram Moolenaar446cb832008-06-24 21:56:24 +00005096 else
5097 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005098" 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 +00005099 if a:islocal
5100 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5101 if dirname == ""
5102 let dirname= '/'
5103 endif
5104 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005105 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005106 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005107" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005108 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005109 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005110 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005111
5112 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005113 " --------------------------------------
5114 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5115 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005116" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005117 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5118" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005119 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005120 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005121" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5122 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005123 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005124 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005125" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005126 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005127 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005128" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005129
5130 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005131" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005132 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005133" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005134 let haskey= 1
5135 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005136" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005137 endif
5138
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005139 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005140" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005141 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005142 if has_key(w:netrw_treedict,treedir."/")
5143 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005144" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005145 let haskey = 1
5146 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005147" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005148 endif
5149 endif
5150
5151 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005152" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005153 if !haskey && treedir =~ '/$'
5154 let treedir= substitute(treedir,'/$','','')
5155 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005156" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005157 let haskey = 1
5158 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005159" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005160 endif
5161 endif
5162
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005163" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005164 if haskey
5165 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005166" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005167 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005168" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5169" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005170 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005171 else
5172 " go down one directory
5173 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005174" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5175" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005176 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005177 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005178" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005179 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005180
5181 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005182 " ----------------------------------------
5183 " NetrwBrowseChgDir: Go down one directory {{{3
5184 " ----------------------------------------
5185 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005186" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005187 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005188 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005189 endif
5190
Bram Moolenaar97d62492012-11-15 21:28:22 +01005191 " --------------------------------------
5192 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5193 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005194 if dorestore
5195 " dorestore is zero'd when a local file was hidden or bufhidden;
5196 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005197" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005198 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005199" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005200" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005201 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005202 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005203" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005204 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005205" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5206" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005207 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005208" 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 +02005209 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005210" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5211" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005212 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005213" 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 +02005214 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005215 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005216 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005217 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005218
Bram Moolenaar446cb832008-06-24 21:56:24 +00005219" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5220 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005221endfun
5222
5223" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005224" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5225" for thin, long, and wide: cursor placed just after banner
5226" for tree, keeps cursor on current filename
5227fun! s:NetrwBrowseUpDir(islocal)
5228" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005229 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5230 " this test needed because occasionally this function seems to be incorrectly called
5231 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005232 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005233 " directories.
5234" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5235 return
5236 endif
5237
Bram Moolenaara6878372014-03-22 21:02:50 +01005238 norm! 0
5239 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005240" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005241 let curline= getline(".")
5242 let swwline= winline() - 1
5243 if exists("w:netrw_treetop")
5244 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005245 elseif exists("b:netrw_curdir")
5246 let w:netrw_treetop= b:netrw_curdir
5247 else
5248 let w:netrw_treetop= getcwd()
5249 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005250 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005251 let curfile = getline(".")
5252 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005253 if a:islocal
5254 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5255 else
5256 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5257 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005258" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5259" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5260 if w:netrw_treetop == '/'
5261 keepj call search('^\M'.curfile,"w")
5262 elseif curfile == '../'
5263 keepj call search('^\M'.curfile,"wb")
5264 else
5265" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5266 while 1
5267 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5268 let treepath= s:NetrwTreePath(w:netrw_treetop)
5269" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5270 if treepath == curpath
5271 break
5272 endif
5273 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005274 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005275
Bram Moolenaara6878372014-03-22 21:02:50 +01005276 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005277" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005278 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005279 if exists("b:netrw_curdir")
5280 let curdir= b:netrw_curdir
5281 else
5282 let curdir= expand(getcwd())
5283 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005284 if a:islocal
5285 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5286 else
5287 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5288 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005289 call s:RestorePosn(s:netrw_posn)
5290 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005291 let curdir= '\<'. escape(curdir, '~'). '/'
5292 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005293 endif
5294" call Dret("s:NetrwBrowseUpDir")
5295endfun
5296
5297" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005298" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005299" given filename; typically this means given their extension.
5300" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005301fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005302 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005303" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005304
Bram Moolenaar91359012019-11-30 17:57:03 +01005305 if a:remote == 0 && isdirectory(a:fname)
5306 " if its really just a local directory, then do a "gf" instead
5307" 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 +01005308" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5309 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005310" call Dret("netrw#BrowseX")
5311 return
5312 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5313 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5314" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5315" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5316" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5317" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5318 norm! gf
5319" call Dret("netrw#BrowseX")
5320 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005321 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005322" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005323
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005324 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5325 let remote = a:remote
5326 else
5327 let remote = 0
5328 endif
5329
Bram Moolenaar97d62492012-11-15 21:28:22 +01005330 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005331 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005332" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005333
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005334 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5335 let awkeep = &aw
5336 set noaw
5337
Bram Moolenaar5c736222010-01-06 20:54:52 +01005338 " special core dump handler
5339 if a:fname =~ '/core\(\.\d\+\)\=$'
5340 if exists("g:Netrw_corehandler")
5341 if type(g:Netrw_corehandler) == 2
5342 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005343" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005344 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005345 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005346 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005347" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005348 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005349 if type(Fncref) == 2
5350 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005351 endif
5352 endfor
5353 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005354" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005355 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005356 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005357 let &aw= awkeep
5358" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005359 return
5360 endif
5361 endif
5362
Bram Moolenaar446cb832008-06-24 21:56:24 +00005363 " set up the filename
5364 " (lower case the extension, make a local copy of a remote file)
5365 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005366 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005367 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005368 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005369 if exten =~ "[\\/]"
5370 let exten= ""
5371 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005372" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005373
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005374 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005375 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005376" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005377 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005378 call netrw#NetRead(3,a:fname)
5379 " attempt to rename tempfile
5380 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005381 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005382" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5383" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005384 if s:netrw_tmpfile != newname && newname != ""
5385 if rename(s:netrw_tmpfile,newname) == 0
5386 " renaming succeeded
5387" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5388 let fname= newname
5389 else
5390 " renaming failed
5391" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5392 let fname= s:netrw_tmpfile
5393 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005394 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005395 let fname= s:netrw_tmpfile
5396 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005397 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005398" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005399 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005400 " special ~ handler for local
5401 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005402" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5403 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005404 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005405 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005406" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5407" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005408
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005409 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005410 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005411" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005412 if g:netrw_browsex_viewer =~ '\s'
5413 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5414 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5415 let oviewer = ''
5416 let cnt = 1
5417 while !executable(viewer) && viewer != oviewer
5418 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5419 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5420 let cnt = cnt + 1
5421 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005422" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005423 endwhile
5424 else
5425 let viewer = g:netrw_browsex_viewer
5426 let viewopt = ""
5427 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005428" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005429 endif
5430
Luca Saccarolaa7d45612024-10-21 21:27:03 +02005431 if exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005432" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Konfekt3d7e5672024-10-27 22:16:49 +01005433 exe 'Launch' viewer viewopt shellescape(fname, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005434 else
Konfekt3d7e5672024-10-27 22:16:49 +01005435 " though shellescape(..., 1) is used in Open, it's insufficient
5436 exe 'Open' escape(fname, '#%')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005437 endif
5438
Bram Moolenaar446cb832008-06-24 21:56:24 +00005439 " cleanup: remove temporary file,
5440 " delete current buffer if success with handler,
5441 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005442 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005443 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005444" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005445"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005446" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005447" endif
5448
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005449 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005450 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005451 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005452 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005453 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005454 if use_ctrlo
5455 exe "sil! NetrwKeepj norm! \<c-o>"
5456 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005457 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005458" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005459 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005460 let @@ = ykeep
5461 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005462
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005463" call Dret("netrw#BrowseX")
5464endfun
5465
5466" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005467" netrw#GX: gets word under cursor for gx support {{{2
5468" See also: netrw#BrowseXVis
5469" netrw#BrowseX
5470fun! netrw#GX()
5471" call Dfunc("netrw#GX()")
5472 if &ft == "netrw"
5473 let fname= s:NetrwGetWord()
5474 else
Konfekt3d7e5672024-10-27 22:16:49 +01005475 let fname= exists("g:netrw_gx")? expand(g:netrw_gx) : s:GetURL()
Bram Moolenaar85850f32019-07-19 22:05:51 +02005476 endif
5477" call Dret("netrw#GX <".fname.">")
5478 return fname
5479endfun
5480
Konfekt3d7e5672024-10-27 22:16:49 +01005481fun! s:GetURL() abort
5482 let URL = ''
5483 if exists('*Netrw_get_URL_' .. &filetype)
5484 let URL = call('Netrw_get_URL_' .. &filetype, [])
5485 endif
5486 if !empty(URL) | return URL | endif
5487 " URLs end in letter, digit or forward slash
5488 let URL = matchstr(expand("<cWORD>"), '\<' .. g:netrw_regex_url .. '\ze[^A-Za-z0-9/]*$')
5489 if !empty(URL) | return URL | endif
5490
5491 " Is it a file in the current work dir ...
5492 let file = expand("<cfile>")
5493 if filereadable(file) | return file | endif
5494 " ... or in that of the current buffer?
5495 let path = fnamemodify(expand('%'), ':p')
5496 if isdirectory(path)
5497 let dir = path
5498 elseif filereadable(path)
5499 let dir = fnamemodify(path, ':h')
5500 endif
5501 if exists('dir') && filereadable(dir..'/'..file) | return dir..'/'..file | endif
5502
5503 return ''
5504endf
5505
Bram Moolenaar85850f32019-07-19 22:05:51 +02005506" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005507" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5508fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005509 let dict={}
5510 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005511 norm! gv"ay
5512 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005513 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005514 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005515endfun
5516
5517" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005518" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5519" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5520" to become an unlisted buffer, so in that case don't bwipe it.
5521fun! s:NetrwBufRename(newname)
5522" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5523" call Dredir("ls!","s:NetrwBufRename (before rename)")
5524 let oldbufname= bufname(bufnr("%"))
5525" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5526
5527 if oldbufname != a:newname
5528" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5529 let b:junk= 1
5530" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5531 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005532" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005533 let oldbufnr= bufnr(oldbufname)
5534" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5535" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5536 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5537" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5538 exe "bwipe! ".oldbufnr
5539" else " Decho
5540" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005541" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5542" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5543" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005544 endif
5545" call Dredir("ls!","s:NetrwBufRename (after rename)")
5546" else " Decho
5547" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5548 endif
5549
5550" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5551endfun
5552
5553" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005554" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005555fun! netrw#CheckIfRemote(...)
5556" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5557 if a:0 > 0
5558 let curfile= a:1
5559 else
5560 let curfile= expand("%")
5561 endif
5562" call Decho("curfile<".curfile.">")
5563 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005564" call Dret("netrw#CheckIfRemote 1")
5565 return 1
5566 else
5567" call Dret("netrw#CheckIfRemote 0")
5568 return 0
5569 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005570endfun
5571
5572" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005573" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5574fun! s:NetrwChgPerm(islocal,curdir)
5575" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005576 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005577 call inputsave()
5578 let newperm= input("Enter new permission: ")
5579 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005580 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5581 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5582" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005583 call system(chgperm)
5584 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005585 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005586 endif
5587 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005588 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005589 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005590 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005591" call Dret("s:NetrwChgPerm")
5592endfun
5593
5594" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005595" s:CheckIfKde: checks if kdeinit is running {{{2
5596" Returns 0: kdeinit not running
5597" 1: kdeinit is running
5598fun! s:CheckIfKde()
5599" call Dfunc("s:CheckIfKde()")
5600 " seems kde systems often have gnome-open due to dependencies, even though
5601 " gnome-open's subsidiary display tools are largely absent. Kde systems
5602 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5603 if !exists("s:haskdeinit")
5604 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005605 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005606 if v:shell_error
5607 let s:haskdeinit = 0
5608 endif
5609 else
5610 let s:haskdeinit= 0
5611 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005612" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005613 endif
5614
5615" call Dret("s:CheckIfKde ".s:haskdeinit)
5616 return s:haskdeinit
5617endfun
5618
5619" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005620" s:NetrwClearExplore: clear explore variables (if any) {{{2
5621fun! s:NetrwClearExplore()
5622" call Dfunc("s:NetrwClearExplore()")
5623 2match none
5624 if exists("s:explore_match") |unlet s:explore_match |endif
5625 if exists("s:explore_indx") |unlet s:explore_indx |endif
5626 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5627 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5628 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5629 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5630 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5631 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5632 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5633" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005634" call Dret("s:NetrwClearExplore")
5635endfun
5636
5637" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005638" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5639fun! s:NetrwEditBuf(bufnum)
5640" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5641 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5642" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5643 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5644 else
5645" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005646 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005647 endif
5648" call Dret("s:NetrwEditBuf")
5649endfun
5650
5651" ---------------------------------------------------------------------
5652" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5653" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5654fun! s:NetrwEditFile(cmd,opt,fname)
5655" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5656 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5657" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5658 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5659 else
5660" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005661 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5662 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5663 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005664 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5665 endif
5666" call Dret("s:NetrwEditFile")
5667endfun
5668
5669" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005670" s:NetrwExploreListUniq: {{{2
5671fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005672" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005673
5674 " this assumes that the list is already sorted
5675 let newexplist= []
5676 for member in a:explist
5677 if !exists("uniqmember") || member != uniqmember
5678 let uniqmember = member
5679 let newexplist = newexplist + [ member ]
5680 endif
5681 endfor
5682
Bram Moolenaar15146672011-10-20 22:22:38 +02005683" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005684 return newexplist
5685endfun
5686
5687" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005688" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5689fun! s:NetrwForceChgDir(islocal,newdir)
5690" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005691 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005692 if a:newdir !~ '/$'
5693 " ok, looks like force is needed to get directory-style treatment
5694 if a:newdir =~ '@$'
5695 let newdir= substitute(a:newdir,'@$','/','')
5696 elseif a:newdir =~ '[*=|\\]$'
5697 let newdir= substitute(a:newdir,'.$','/','')
5698 else
5699 let newdir= a:newdir.'/'
5700 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005701" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005702 else
5703 " should already be getting treatment as a directory
5704 let newdir= a:newdir
5705 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005706 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005707 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005708 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005709" call Dret("s:NetrwForceChgDir")
5710endfun
5711
5712" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005713" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005714" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5715" expr : this is the expression to follow the directory. Will use s:ComposePath()
5716" pare =1: remove the current directory from the resulting glob() filelist
5717" =0: leave the current directory in the resulting glob() filelist
5718fun! s:NetrwGlob(direntry,expr,pare)
5719" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005720 if netrw#CheckIfRemote()
5721 keepalt 1sp
5722 keepalt enew
5723 let keep_liststyle = w:netrw_liststyle
5724 let w:netrw_liststyle = s:THINLIST
5725 if s:NetrwRemoteListing() == 0
5726 keepj keepalt %s@/@@
5727 let filelist= getline(1,$)
5728 q!
5729 else
5730 " remote listing error -- leave treedict unchanged
5731 let filelist= w:netrw_treedict[a:direntry]
5732 endif
5733 let w:netrw_liststyle= keep_liststyle
5734 else
Christian Brabandt14879472024-06-13 21:25:35 +02005735 let path= s:ComposePath(fnameescape(a:direntry),a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005736 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005737 " escape [ so it is not detected as wildcard character, see :h wildcard
5738 let path= substitute(path, '[', '[[]', 'g')
5739 endif
5740 if v:version > 704 || (v:version == 704 && has("patch656"))
5741 let filelist= glob(path,0,1,1)
5742 else
5743 let filelist= glob(path,0,1)
5744 endif
5745 if a:pare
5746 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5747 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005748 endif
5749" call Dret("s:NetrwGlob ".string(filelist))
5750 return filelist
5751endfun
5752
5753" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005754" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5755fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005756" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005757 if a:newfile =~ '[/@*=|\\]$'
5758 let newfile= substitute(a:newfile,'.$','','')
5759 else
5760 let newfile= a:newfile
5761 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005762 if a:islocal
5763 call s:NetrwBrowseChgDir(a:islocal,newfile)
5764 else
5765 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5766 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005767" call Dret("s:NetrwForceFile")
5768endfun
5769
5770" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005771" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5772" and switches the hiding mode. The actual hiding is done by
5773" s:NetrwListHide().
5774" g:netrw_hide= 0: show all
5775" 1: show not-hidden files
5776" 2: show hidden files only
5777fun! s:NetrwHide(islocal)
5778" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005779 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005780 let svpos= winsaveview()
5781" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005782
5783 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005784" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5785" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005786
5787 " hide the files in the markfile list
5788 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005789" call Decho("match(g:netrw_list_hide<".g:netrw_list_hide.'> fname<\<'.fname.'\>>)='.match(g:netrw_list_hide,'\<'.fname.'\>')." l:isk=".&l:isk,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005790 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5791 " remove fname from hiding list
5792 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5793 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5794 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005795" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005796 else
5797 " append fname to hiding list
5798 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5799 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5800 else
5801 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5802 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005803" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005804 endif
5805 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005806 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005807 let g:netrw_hide= 1
5808
5809 else
5810
5811 " switch between show-all/show-not-hidden/show-hidden
5812 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005813 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005814 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005815 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005816 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005817" call Dret("NetrwHide")
5818 return
5819 endif
5820 endif
5821
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005822 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005823" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5824 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005825 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005826" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005827endfun
5828
5829" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005830" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5831fun! s:NetrwHideEdit(islocal)
5832" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5833
5834 let ykeep= @@
5835 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005836 let svpos= winsaveview()
5837" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005838
5839 " get new hiding list from user
5840 call inputsave()
5841 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5842 call inputrestore()
5843 let g:netrw_list_hide= newhide
5844" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5845
5846 " refresh the listing
5847 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5848
5849 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005850" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5851 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005852 let @@= ykeep
5853
5854" call Dret("NetrwHideEdit")
5855endfun
5856
5857" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005858" s:NetrwHidden: invoked by "gh" {{{2
5859fun! s:NetrwHidden(islocal)
5860" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005861 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005862 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005863 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005864" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005865
5866 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005867 " remove .file pattern from hiding list
5868" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005869 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005870 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005871" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005872 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5873 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005874" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005875 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5876 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005877 if g:netrw_list_hide =~ '^,'
5878 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5879 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005880
5881 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005882 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005883" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5884 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005885 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005886" call Dret("s:NetrwHidden")
5887endfun
5888
5889" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005890" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5891fun! s:NetrwHome()
5892 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005893 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005894 else
5895 " go to vim plugin home
5896 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005897 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005898 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005899 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005900 let home= basehome."/.vim"
5901 break
5902 endif
5903 endfor
5904 if home == ""
5905 " just pick the first directory
5906 let home= substitute(&rtp,',.*$','','')
5907 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005908 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005909 let home= substitute(home,'/','\\','g')
5910 endif
5911 endif
5912 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005913 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005914" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005915 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005916" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005917 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005918 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005919" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005920 call mkdir(home)
5921 endif
5922 endif
5923 let g:netrw_home= home
5924 return home
5925endfun
5926
5927" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005928" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5929fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005930 if exists("s:netrwdrag")
5931 return
5932 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005933 if &ft != "netrw"
5934 return
5935 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005936" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005937
Bram Moolenaar97d62492012-11-15 21:28:22 +01005938 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005939 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005940 while getchar(0) != 0
5941 "clear the input stream
5942 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005943 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005944 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005945 let mouse_lnum = v:mouse_lnum
5946 let wlastline = line('w$')
5947 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005948" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
5949" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005950 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5951 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005952 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005953" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
5954 return
5955 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005956 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005957 " Windows are separated by vertical separator bars - but the mouse seems to be doing what it should when dragging that bar
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005958 " without this test when its disabled.
5959 " May 26, 2014: edit file, :Lex, resize window -- causes refresh. Reinstated a modified test. See if problems develop.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005960" call Decho("v:mouse_col=".v:mouse_col." col#".col('.')." virtcol#".virtcol('.')." col($)#".col("$")." virtcol($)#".virtcol("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005961 if v:mouse_col > virtcol('.')
5962 let @@= ykeep
5963" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
5964 return
5965 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005966
Bram Moolenaar446cb832008-06-24 21:56:24 +00005967 if a:islocal
5968 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005969 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005970 endif
5971 else
5972 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005973 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005974 endif
5975 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005976 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005977" call Dret("s:NetrwLeftmouse")
5978endfun
5979
5980" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005981" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
5982fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005983 if &ft != "netrw"
5984 return
5985 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005986" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
5987 call s:NetrwMarkFileTgt(a:islocal)
5988" call Dret("s:NetrwCLeftmouse")
5989endfun
5990
5991" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005992" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
5993" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02005994" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005995" a:islocal=2 : <c-r> used, remote
5996" a:islocal=3 : <c-r> used, local
5997fun! s:NetrwServerEdit(islocal,fname)
5998" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
5999 let islocal = a:islocal%2 " =0: remote =1: local
6000 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006001" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006002
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006003 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006004 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006005 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006006" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006007 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006008 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006009 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6010 unlet s:netrw_browse_split_{winnr()}
6011 endif
6012 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6013" call Dret("s:NetrwServerEdit")
6014 return
6015 endif
6016
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006017" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006018 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006019" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006020
6021 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006022" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006023 let srvrname = g:netrw_browse_split[0]
6024 let tabnum = g:netrw_browse_split[1]
6025 let winnum = g:netrw_browse_split[2]
6026
6027 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006028" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006029
6030 if !ctrlr
6031 " user must have closed the server window and the user did not use <c-r>, but
6032 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006033" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006034 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006035 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006036 endif
6037 let g:netrw_browse_split= 0
6038 if exists("s:netrw_browse_split_".winnr())
6039 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6040 endif
6041 call s:NetrwBrowseChgDir(islocal,a:fname)
6042" call Dret("s:NetrwServerEdit")
6043 return
6044
6045 elseif has("win32") && executable("start")
6046 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006047" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006048 call system("start gvim --servername ".srvrname)
6049
6050 else
6051 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006052" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006053 call system("gvim --servername ".srvrname)
6054 endif
6055 endif
6056
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006057" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006058 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6059 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006060 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006061
6062 else
6063
6064 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6065
6066 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006067" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006068 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006069 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006070 endif
6071 let g:netrw_browse_split= 0
6072 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6073" call Dret("s:NetrwServerEdit")
6074 return
6075
6076 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006077" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006078 if has("win32") && executable("start")
6079 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006080" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006081 call system("start gvim --servername ".g:netrw_servername)
6082 else
6083 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006084" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006085 call system("gvim --servername ".g:netrw_servername)
6086 endif
6087 endif
6088 endif
6089
6090 while 1
6091 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006092" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6093 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006094 break
6095 catch /^Vim\%((\a\+)\)\=:E241/
6096 sleep 200m
6097 endtry
6098 endwhile
6099
6100 if exists("g:netrw_browse_split")
6101 if type(g:netrw_browse_split) != 3
6102 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6103 endif
6104 unlet g:netrw_browse_split
6105 endif
6106 let g:netrw_browse_split= [g:netrw_servername,1,1]
6107 endif
6108
6109 else
6110 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6111 endif
6112
6113" call Dret("s:NetrwServerEdit")
6114endfun
6115
6116" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006117" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6118fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006119 if &ft != "netrw"
6120 return
6121 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006122" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006123
Bram Moolenaar8d043172014-01-23 14:24:41 +01006124 let s:ngw= s:NetrwGetWord()
6125 call s:NetrwMarkFile(a:islocal,s:ngw)
6126
6127" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006128endfun
6129
6130" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006131" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6132" Used to mark multiple files.
6133fun! s:NetrwSLeftdrag(islocal)
6134" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6135 if !exists("s:netrwdrag")
6136 let s:netrwdrag = winnr()
6137 if a:islocal
6138 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006139 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006140 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006141 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006142 endif
6143 let ngw = s:NetrwGetWord()
6144 if !exists("s:ngw") || s:ngw != ngw
6145 call s:NetrwMarkFile(a:islocal,ngw)
6146 endif
6147 let s:ngw= ngw
6148" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6149endfun
6150
6151" ---------------------------------------------------------------------
6152" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6153fun! s:NetrwSLeftrelease(islocal)
6154" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6155 if exists("s:netrwdrag")
6156 nunmap <s-leftrelease>
6157 let ngw = s:NetrwGetWord()
6158 if !exists("s:ngw") || s:ngw != ngw
6159 call s:NetrwMarkFile(a:islocal,ngw)
6160 endif
6161 if exists("s:ngw")
6162 unlet s:ngw
6163 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006164 unlet s:netrwdrag
6165 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006166" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006167endfun
6168
6169" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006170" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6171" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006172fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006173" call Dfunc("s:NetrwListHide() g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02006174" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006175 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006176
6177 " find a character not in the "hide" string to use as a separator for :g and :v commands
Bram Moolenaar85850f32019-07-19 22:05:51 +02006178 " How-it-works: take the hiding command, convert it into a range.
6179 " Duplicate characters don't matter.
6180 " Remove all such characters from the '/~@#...890' string.
6181 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006182" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006183 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006184 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006185" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006186
6187 while listhide != ""
6188 if listhide =~ ','
6189 let hide = substitute(listhide,',.*$','','e')
6190 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6191 else
6192 let hide = listhide
6193 let listhide = ""
6194 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006195" call Decho("..extracted pattern from listhide: hide<".hide."> g:netrw_sort_by<".g:netrw_sort_by.'>','~'.expand("<slnum>"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006196 if g:netrw_sort_by =~ '^[ts]'
6197 if hide =~ '^\^'
6198" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6199 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6200 elseif hide =~ '^\\(\^'
6201 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6202 endif
6203" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6204 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006205
6206 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006207" call Decho("..prune the list by hiding any files which ".((g:netrw_hide == 1)? "" : "don't")."match hide<".hide.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006208 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006209" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006210 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006211 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006212" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006213 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006214 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006215" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006216 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006217
Bram Moolenaar446cb832008-06-24 21:56:24 +00006218 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006219 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006220" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006221 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006222" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006223 endif
6224
Bram Moolenaaradc21822011-04-01 18:03:16 +02006225 " remove any blank lines that have somehow remained.
6226 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006227 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006228
Bram Moolenaar97d62492012-11-15 21:28:22 +01006229 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006230" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006231endfun
6232
6233" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006234" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006235" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006236fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006237" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006238
Bram Moolenaar97d62492012-11-15 21:28:22 +01006239 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006240 " get name of new directory from user. A bare <CR> will skip.
6241 " if its currently a directory, also request will be skipped, but with
6242 " a message.
6243 call inputsave()
6244 let newdirname= input("Please give directory name: ")
6245 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006246" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006247
6248 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006249 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006250" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006251 return
6252 endif
6253
6254 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006255" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006256
6257 " Local mkdir:
6258 " sanity checks
6259 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006260" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6261 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006262 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006263 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006264 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006265 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006266" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006267 return
6268 endif
6269 if s:FileReadable(fullnewdir)
6270 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006271 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006272 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006273 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006274" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006275 return
6276 endif
6277
6278 " requested new local directory is neither a pre-existing file or
6279 " directory, so make it!
6280 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006281 if has("unix")
6282 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6283 else
6284 call mkdir(fullnewdir,"p")
6285 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006286 else
6287 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006288 if s:NetrwLcd(b:netrw_curdir)
6289" call Dret("s:NetrwMakeDir : lcd failure")
6290 return
6291 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006292" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006293 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006294 if v:shell_error != 0
6295 let @@= ykeep
6296 call netrw#ErrorMsg(s:ERROR,"consider setting g:netrw_localmkdir<".g:netrw_localmkdir."> to something that works",80)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006297" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006298 return
6299 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006300 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006301" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006302 if s:NetrwLcd(netrw_origdir)
6303" call Dret("s:NetrwBrowse : lcd failure")
6304 return
6305 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006306 endif
6307 endif
6308
6309 if v:shell_error == 0
6310 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006311" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006312 let svpos= winsaveview()
6313" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006314 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006315" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6316 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006317 elseif !exists("g:netrw_quiet")
6318 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6319 endif
6320" redraw!
6321
6322 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006323 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006324" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006325 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6326 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006327 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006328 if v:shell_error == 0
6329 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006330 let svpos= winsaveview()
6331" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006332 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006333" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6334 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006335 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006336 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006337 endif
6338" redraw!
6339
6340 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006341 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006342 let svpos= winsaveview()
6343" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006344" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006345 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006346" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006347 let remotepath= b:netrw_fname
6348 else
6349 let remotepath= ""
6350 endif
6351 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006352 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006353" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6354 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006355
Bram Moolenaar446cb832008-06-24 21:56:24 +00006356 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006357 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006358 let svpos= winsaveview()
6359" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006360" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006361 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006362" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006363 let remotepath= b:netrw_fname
6364 else
6365 let remotepath= ""
6366 endif
6367 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006368 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006369" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6370 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006371 endif
6372
Bram Moolenaar97d62492012-11-15 21:28:22 +01006373 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006374" call Dret("s:NetrwMakeDir")
6375endfun
6376
6377" ---------------------------------------------------------------------
6378" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6379fun! s:TreeSqueezeDir(islocal)
6380" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6381 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6382 " its a tree-listing style
6383 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006384 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006385 let depth = strchars(substitute(curdepth,' ','','g'))
6386 let srch = -1
6387" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6388" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006389" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006390" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6391 if depth >= 2
6392 NetrwKeepj norm! 0
6393 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6394 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6395" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6396" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6397 elseif depth == 1
6398 NetrwKeepj norm! 0
6399 let treedepthchr= substitute(s:treedepthstring,' ','','')
6400 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6401" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6402 endif
6403 if srch > 0
6404" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6405 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6406 exe srch
6407 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006408 endif
6409" call Dret("s:TreeSqueezeDir")
6410endfun
6411
6412" ---------------------------------------------------------------------
6413" s:NetrwMaps: {{{2
6414fun! s:NetrwMaps(islocal)
6415" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6416
Bram Moolenaar85850f32019-07-19 22:05:51 +02006417 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006418 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006419" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006420 if !hasmapto("<Plug>NetrwReturn")
6421 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006422" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006423 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6424 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006425" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006426 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6427 endif
6428 endif
6429 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006430" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006431 endif
6432
Bram Moolenaar85850f32019-07-19 22:05:51 +02006433 " generate default <Plug> maps {{{3
6434 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006435 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006436 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6437 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6438 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6439 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6440 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6441 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6442 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6443 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6444 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6445 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6446" ---------------------------------------------------------------------
6447" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6448" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6449" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6450" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6451" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6452" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6453" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6454" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6455" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6456" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6457" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6458" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6459" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6460" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6461" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6462" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6463" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6464" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6465" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6466" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6467" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6468" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6469" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6470" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6471" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6472" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6473" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6474" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6475" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6476" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6477" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6478" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6479" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6480" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6481" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6482" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6483" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6484" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6485" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6486" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6487" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6488" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6489" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6490" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6491" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6492" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6493" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6494
Bram Moolenaara6878372014-03-22 21:02:50 +01006495 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006496" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006497 " local normal-mode maps {{{3
6498 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6499 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6500 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6501 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6502 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6503 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6504 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6505 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6506 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6507 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6508 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6509" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006510 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6511 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6512 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006513 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006514 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006515 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6516 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6517 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6518 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006519 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6520 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6521 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6522 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6523 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6524 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6525 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6526 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6527 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6528 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6529 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6530 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6531 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006532 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006533 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006534 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6535 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6536 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6537 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6538 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006539 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006540 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006541 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6542 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006543 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6544 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6545 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006546 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006547 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006548 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6549 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006550 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006551 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006552 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6553 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6554 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006555 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6556 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006557
6558 nnoremap <buffer> <silent> <nowait> r :<c-u>let g:netrw_sort_direction= (g:netrw_sort_direction =~# 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,'./'))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006559 if !hasmapto('<Plug>NetrwHideEdit')
6560 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006561 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006562 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006563 if !hasmapto('<Plug>NetrwRefresh')
6564 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006565 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006566 nnoremap <buffer> <silent> <Plug>NetrwRefresh <c-l>:call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,(exists("w:netrw_liststyle") && exists("w:netrw_treetop") && w:netrw_liststyle == 3)? w:netrw_treetop : './'))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006567 if s:didstarstar || !mapcheck("<s-down>","n")
6568 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006569 endif
6570 if s:didstarstar || !mapcheck("<s-up>","n")
6571 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006572 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006573 if !hasmapto('<Plug>NetrwTreeSqueeze')
6574 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006575 endif
6576 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006577 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6578 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006579 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6580 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6581 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6582 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6583 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6584 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6585 imap <buffer> <leftmouse> <Plug>ILeftmouse
6586 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006587 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6588 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6589 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6590 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6591 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006592 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006593 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6594 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006595 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006596 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6597 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6598 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6599 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6600 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6601 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6602 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006603 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6604
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006605 " support user-specified maps
6606 call netrw#UserMaps(1)
6607
Bram Moolenaar85850f32019-07-19 22:05:51 +02006608 else
6609 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006610" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006611 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006612 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6613 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6614 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6615 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6616 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6617 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6618 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6619 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6620 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6621 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6622 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6623" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006624 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6625 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6626 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6627 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6628 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6629 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6630 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6631 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006632 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006633 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006634 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6635 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6636 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6637 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6638 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6639 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6640 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6641 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6642 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6643 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6644 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006645 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006646 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006647 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6648 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6649 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6650 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6651 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006652 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6653 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6654 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6655 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006656 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006657 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6658 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006659 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006660 nnoremap <buffer> <silent> <nowait> r :<c-u>let g:netrw_sort_direction= (g:netrw_sort_direction =~# 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006661 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6662 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6663 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6664 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6665 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6666 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6667 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6668 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6669 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Konfekt3d7e5672024-10-27 22:16:49 +01006670 nmap <buffer> <nowait> gx x
Bram Moolenaara6878372014-03-22 21:02:50 +01006671 if !hasmapto('<Plug>NetrwHideEdit')
6672 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006673 endif
6674 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6675 if !hasmapto('<Plug>NetrwRefresh')
6676 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006677 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006678 if !hasmapto('<Plug>NetrwTreeSqueeze')
6679 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006680 endif
6681 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006682
6683 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006684 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006685
6686 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6687 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006688 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006689 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006690 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006691 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006692 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006693 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006694 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006695 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006696 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006697 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006698 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6699 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6700 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006701 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006702 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006703 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6704 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006705 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006706 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6707 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6708 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6709 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6710 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6711 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6712 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006713 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006714
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006715 " support user-specified maps
6716 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006717 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006718
6719" call Dret("s:NetrwMaps")
6720endfun
6721
6722" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006723" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006724" If -buffer, the command is only available from within netrw buffers
6725" Otherwise, the command is available from any window, so long as netrw
6726" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006727fun! s:NetrwCommands(islocal)
6728" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6729
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006730 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6731 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006732 com! Rexplore if exists("w:netrw_rexlocal")|call s:NetrwRexplore(w:netrw_rexlocal,exists("w:netrw_rexdir")? w:netrw_rexdir : ".")|else|call netrw#ErrorMsg(s:WARNING,"win#".winnr()." not a former netrw window",79)|endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006733 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006734 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006735 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006736 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006737 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006738 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006739
6740" call Dret("s:NetrwCommands")
6741endfun
6742
6743" ---------------------------------------------------------------------
6744" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6745" glob()ing only works with local files
6746fun! s:NetrwMarkFiles(islocal,...)
6747" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006748 let curdir = s:NetrwGetCurdir(a:islocal)
6749 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006750 while i <= a:0
6751 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006752 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006753 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006754 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006755 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006756 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006757 else
6758 let mffiles= [a:{i}]
6759 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006760" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006761 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006762" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006763 call s:NetrwMarkFile(a:islocal,mffile)
6764 endfor
6765 let i= i + 1
6766 endwhile
6767" call Dret("s:NetrwMarkFiles")
6768endfun
6769
6770" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006771" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006772fun! s:NetrwMarkTarget(...)
6773" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6774 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006775 let curdir = s:NetrwGetCurdir(1)
6776 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006777 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006778 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6779 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006780 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006781" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006782 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006783 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6784 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006785 let svpos = winsaveview()
6786" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006787 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006788" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6789 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006790" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006791endfun
6792
6793" ---------------------------------------------------------------------
6794" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6795" mark and unmark files. If a markfile list exists,
6796" then the rename and delete functions will use it instead
6797" of whatever may happen to be under the cursor at that
6798" moment. When the mouse and gui are available,
6799" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006800"
6801" Creates two lists
6802" s:netrwmarkfilelist -- holds complete paths to all marked files
6803" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6804"
6805" Creates a marked file match string
6806" s:netrwmarfilemtch_# -- used with 2match to display marked files
6807"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006808" Creates a buffer version of islocal
6809" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006810fun! s:NetrwMarkFile(islocal,fname)
6811" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006812" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006813
6814 " sanity check
6815 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006816" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006817 return
6818 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006819 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006820
Bram Moolenaar97d62492012-11-15 21:28:22 +01006821 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006822 let curbufnr= bufnr("%")
yasudac18a9d52024-09-19 18:09:51 +02006823 let leader= '\%(^\|\s\)\zs'
Bram Moolenaara6878372014-03-22 21:02:50 +01006824 if a:fname =~ '\a$'
6825 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6826 else
6827 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6828 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006829
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006830 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006831 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006832" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6833" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6834" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006835 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006836
6837 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006838 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006839" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006840 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006841 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006842
6843 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006844 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006845" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006846 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6847 if s:netrwmarkfilelist_{curbufnr} == []
6848 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006849" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006850 call s:NetrwUnmarkList(curbufnr,curdir)
6851 else
6852 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006853" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006854 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006855 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006856 for fname in s:netrwmarkfilelist_{curbufnr}
6857 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006858 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006859 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006860 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006861 endif
6862 let first= 0
6863 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006864" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006865 endif
6866 endif
6867
6868 else
6869 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006870" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006871
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006872" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006873 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006874 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6875" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006876
6877 " build initial markfile matching pattern
6878 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006879 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006880 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006881 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006882 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006883" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006884 endif
6885
6886 " handle global markfilelist
6887 if exists("s:netrwmarkfilelist")
6888 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6889 if index(s:netrwmarkfilelist,dname) == -1
6890 " append new filename to global markfilelist
6891 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006892" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006893 else
6894 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006895" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6896" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006897 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006898" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006899 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006900" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006901 unlet s:netrwmarkfilelist
6902 endif
6903 endif
6904 else
6905 " initialize new global-directory markfilelist
6906 let s:netrwmarkfilelist= []
6907 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006908" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006909 endif
6910
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006911 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006912 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6913 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6914" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6915 if exists("g:did_drchip_netrwlist_syntax")
6916 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6917 endif
6918 else
6919" " call Decho("2match none",'~'.expand("<slnum>"))
6920 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006921 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006922 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006923 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006924" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6925" call Dret("s:NetrwMarkFile : s:netrwmarkfilelist_".curbufnr."<".(exists("s:netrwmarkfilelist_{curbufnr}")? string(s:netrwmarkfilelist_{curbufnr}) : " doesn't exist")."> (buf#".curbufnr."list)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006926endfun
6927
6928" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006929" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6930" mA: move the argument list to marked file list (tomflist=1)
6931" Uses the global marked file list
6932fun! s:NetrwMarkFileArgList(islocal,tomflist)
6933" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
6934
6935 let svpos = winsaveview()
6936" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6937 let curdir = s:NetrwGetCurdir(a:islocal)
6938 let curbufnr = bufnr("%")
6939
6940 if a:tomflist
6941 " mA: move argument list to marked file list
6942 while argc()
6943 let fname= argv(0)
6944" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
6945 exe "argdel ".fnameescape(fname)
6946 call s:NetrwMarkFile(a:islocal,fname)
6947 endwhile
6948
6949 else
6950 " ma: move marked file list to argument list
6951 if exists("s:netrwmarkfilelist")
6952
6953 " for every filename in the marked list
6954 for fname in s:netrwmarkfilelist
6955" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
6956 exe "argadd ".fnameescape(fname)
6957 endfor " for every file in the marked list
6958
6959 " unmark list and refresh
6960 call s:NetrwUnmarkList(curbufnr,curdir)
6961 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
6962" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6963 NetrwKeepj call winrestview(svpos)
6964 endif
6965 endif
6966
6967" call Dret("s:NetrwMarkFileArgList")
6968endfun
6969
6970" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006971" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
6972" compress/decompress files using the programs
6973" in g:netrw_compress and g:netrw_uncompress,
6974" using g:netrw_compress_suffix to know which to
6975" do. By default:
6976" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006977" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00006978fun! s:NetrwMarkFileCompress(islocal)
6979" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006980 let svpos = winsaveview()
6981" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006982 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006983 let curbufnr = bufnr("%")
6984
Bram Moolenaarff034192013-04-24 18:51:19 +02006985 " sanity check
6986 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006987 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006988" call Dret("s:NetrwMarkFileCompress")
6989 return
6990 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006991" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006992
Bram Moolenaar446cb832008-06-24 21:56:24 +00006993 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02006994
6995 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00006996 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02006997 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006998" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006999 if exists("g:netrw_decompress['".sfx."']")
7000 " fname has a suffix indicating that its compressed; apply associated decompression routine
7001 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007002" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007003 let exe= netrw#WinPath(exe)
7004 if a:islocal
7005 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007006 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007007 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007008 call system(exe." ".fname)
7009 if v:shell_error
7010 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007011 endif
7012 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007013 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7014 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007015 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007016
Bram Moolenaarff034192013-04-24 18:51:19 +02007017 endif
7018 unlet sfx
7019
Bram Moolenaar446cb832008-06-24 21:56:24 +00007020 if exists("exe")
7021 unlet exe
7022 elseif a:islocal
7023 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007024 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007025 if v:shell_error
7026 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7027 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007028 else
7029 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007030 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007031 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007032 endfor " for every file in the marked list
7033
Bram Moolenaar446cb832008-06-24 21:56:24 +00007034 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007035 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007036" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7037 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007038 endif
7039" call Dret("s:NetrwMarkFileCompress")
7040endfun
7041
7042" ---------------------------------------------------------------------
7043" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7044" If no marked files, then set up directory as the
7045" target. Currently does not support copying entire
7046" directories. Uses the local-buffer marked file list.
7047" Returns 1=success (used by NetrwMarkFileMove())
7048" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007049fun! s:NetrwMarkFileCopy(islocal,...)
7050" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7051
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007052 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007053 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007054 if b:netrw_curdir !~ '/$'
7055 if !exists("b:netrw_curdir")
7056 let b:netrw_curdir= curdir
7057 endif
7058 let b:netrw_curdir= b:netrw_curdir."/"
7059 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007060
Bram Moolenaarff034192013-04-24 18:51:19 +02007061 " sanity check
7062 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007063 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007064" call Dret("s:NetrwMarkFileCopy")
7065 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007066 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007067" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007068
Bram Moolenaar446cb832008-06-24 21:56:24 +00007069 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007070 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007071" call Dret("s:NetrwMarkFileCopy 0")
7072 return 0
7073 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007074" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007075
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007076 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007077 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007078" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007079 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007080 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7081" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7082 return
7083 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007084
7085 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02007086 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007087 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7088 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007089" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007090 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007091 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7092 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007093" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007094 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007095 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007096 let oldname = a:1
7097 else
7098 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007099" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007100 let s:recursive= 1
7101 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7102 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7103 if ret == 0
7104 break
7105 endif
7106 endfor
7107 unlet s:recursive
7108 call s:NetrwUnmarkList(curbufnr,curdir)
7109" call Dret("s:NetrwMarkFileCopy ".ret)
7110 return ret
7111 endif
7112
7113 call inputsave()
7114 let newname= input("Copy ".oldname." to : ",oldname,"file")
7115 call inputrestore()
7116 if newname == ""
7117" call Dret("s:NetrwMarkFileCopy 0")
7118 return 0
7119 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007120 let args= s:ShellEscape(oldname)
7121 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007122 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007123 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7124 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007125 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007126 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007127 let args= substitute(args,'/','\\','g')
7128 let tgt = substitute(tgt, '/','\\','g')
7129 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007130 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7131 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7132 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7133 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7134" call Decho("args <".args.">",'~'.expand("<slnum>"))
7135" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007136 if isdirectory(s:NetrwFile(args))
7137" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007138 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007139" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007140 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007141 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7142 " contents to a target. One must append the source directory name to the target to get xcopy to
7143 " do the right thing.
7144 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007145" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007146 endif
7147 else
7148 let copycmd= g:netrw_localcopycmd
7149 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007150 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007151 let copycmd = substitute(copycmd,'\s.*$','','')
7152 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007153 let copycmd = netrw#WinPath(copycmd).copycmdargs
7154 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007155 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007156 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007157" call Decho("args <".args.">",'~'.expand("<slnum>"))
7158" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7159" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7160" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007161 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007162 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02007163 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007164 call netrw#ErrorMsg(s:ERROR,"copy failed; perhaps due to vim's current directory<".getcwd()."> not matching netrw's (".b:netrw_curdir.") (see :help netrw-cd)",101)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007165 else
7166 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7167 endif
7168" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007169 return 0
7170 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007171
7172 elseif a:islocal && !s:netrwmftgt_islocal
7173 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007174" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007175 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007176
7177 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007178 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007179" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007180 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007181
7182 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007183 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007184" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007185 let curdir = getcwd()
7186 let tmpdir = s:GetTempfile("")
7187 if tmpdir !~ '/'
7188 let tmpdir= curdir."/".tmpdir
7189 endif
7190 if exists("*mkdir")
7191 call mkdir(tmpdir)
7192 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007193 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007194 if v:shell_error != 0
7195 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localmkdir<".g:netrw_localmkdir."> to something that works",80)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007196" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007197 return
7198 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007199 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007200 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007201 if s:NetrwLcd(tmpdir)
7202" call Dret("s:NetrwMarkFileCopy : lcd failure")
7203 return
7204 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007205 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007206 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007207 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007208 if getcwd() == tmpdir
7209 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007210 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007211 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007212 if s:NetrwLcd(curdir)
7213" call Dret("s:NetrwMarkFileCopy : lcd failure")
7214 return
7215 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007216 if delete(tmpdir,"d")
7217 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007218 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007219 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007220 if s:NetrwLcd(curdir)
7221" call Dret("s:NetrwMarkFileCopy : lcd failure")
7222 return
7223 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007224 endif
7225 endif
7226 endif
7227
7228 " -------
7229 " cleanup
7230 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007231" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007232 " remove markings from local buffer
7233 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007234" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7235" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7236" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7237" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7238" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7239" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7240 if exists("s:recursive")
7241" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7242 else
7243" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007244 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007245 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007246 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007247 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007248 else
7249 " refresh local and targets for fast browsing
7250 if !exists("s:recursive")
7251 " remove markings from local buffer
7252" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7253 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7254 endif
7255
7256 " refresh buffers
7257 if s:netrwmftgt_islocal
7258" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7259 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7260 endif
7261 if a:islocal && s:netrwmftgt != curdir
7262" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7263 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7264 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007265 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007266
Bram Moolenaar446cb832008-06-24 21:56:24 +00007267" call Dret("s:NetrwMarkFileCopy 1")
7268 return 1
7269endfun
7270
7271" ---------------------------------------------------------------------
7272" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7273" invoke vim's diff mode on the marked files.
7274" Either two or three files can be so handled.
7275" Uses the global marked file list.
7276fun! s:NetrwMarkFileDiff(islocal)
7277" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7278 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007279
Bram Moolenaarff034192013-04-24 18:51:19 +02007280 " sanity check
7281 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007282 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007283" call Dret("s:NetrwMarkFileDiff")
7284 return
7285 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007286 let curdir= s:NetrwGetCurdir(a:islocal)
7287" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007288
Bram Moolenaara6878372014-03-22 21:02:50 +01007289 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007290 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007291 for fname in s:netrwmarkfilelist
7292 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007293 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007294" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007295 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007296 diffthis
7297 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007298 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007299" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007300 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007301 diffthis
7302 else
7303 break
7304 endif
7305 endfor
7306 call s:NetrwUnmarkList(curbufnr,curdir)
7307 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007308
Bram Moolenaar446cb832008-06-24 21:56:24 +00007309" call Dret("s:NetrwMarkFileDiff")
7310endfun
7311
7312" ---------------------------------------------------------------------
7313" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7314" Uses global markfilelist
7315fun! s:NetrwMarkFileEdit(islocal)
7316" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7317
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007318 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007319 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007320
7321 " sanity check
7322 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007323 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007324" call Dret("s:NetrwMarkFileEdit")
7325 return
7326 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007327" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007328
Bram Moolenaar446cb832008-06-24 21:56:24 +00007329 if exists("s:netrwmarkfilelist_{curbufnr}")
7330 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007331 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007332 " unmark markedfile list
7333" call s:NetrwUnmarkList(curbufnr,curdir)
7334 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007335" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007336 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007337 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007338 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007339
Bram Moolenaar446cb832008-06-24 21:56:24 +00007340" call Dret("s:NetrwMarkFileEdit")
7341endfun
7342
7343" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007344" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007345fun! s:NetrwMarkFileQFEL(islocal,qfel)
7346" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7347 call s:NetrwUnmarkAll()
7348 let curbufnr= bufnr("%")
7349
7350 if !empty(a:qfel)
7351 for entry in a:qfel
7352 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007353" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007354 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007355" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007356 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7357 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7358 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7359 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007360" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007361 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7362 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007363" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007364 endif
7365 endfor
7366 echo "(use me to edit marked files)"
7367 else
7368 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7369 endif
7370
7371" call Dret("s:NetrwMarkFileQFEL")
7372endfun
7373
7374" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007375" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7376" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7377" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7378fun! s:NetrwMarkFileExe(islocal,enbloc)
7379" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007380 let svpos = winsaveview()
7381" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007382 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007383 let curbufnr = bufnr("%")
7384
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007385 if a:enbloc == 0
7386 " individually apply command to files, one at a time
7387 " sanity check
7388 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7389 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7390" call Dret("s:NetrwMarkFileExe")
7391 return
7392 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007393" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007394
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007395 if exists("s:netrwmarkfilelist_{curbufnr}")
7396 " get the command
7397 call inputsave()
7398 let cmd= input("Enter command: ","","file")
7399 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007400" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007401 if cmd == ""
7402" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7403 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007404 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007405
7406 " apply command to marked files, individually. Substitute: filename -> %
7407 " If no %, then append a space and the filename to the command
7408 for fname in s:netrwmarkfilelist_{curbufnr}
7409 if a:islocal
7410 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007411 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007412 endif
7413 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007414 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007415 endif
7416 if cmd =~ '%'
7417 let xcmd= substitute(cmd,'%',fname,'g')
7418 else
7419 let xcmd= cmd.' '.fname
7420 endif
7421 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007422" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007423 let ret= system(xcmd)
7424 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007425" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007426 let ret= s:RemoteSystem(xcmd)
7427 endif
7428 if v:shell_error < 0
7429 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7430 break
7431 else
yasudac75dad02024-08-22 21:06:32 +02007432 if ret !=# ''
7433 echo "\n"
7434 " skip trailing new line
7435 echo ret[0:-2]
7436 else
7437 echo ret
7438 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007439 endif
7440 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007441
7442 " unmark marked file list
7443 call s:NetrwUnmarkList(curbufnr,curdir)
7444
7445 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007446 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007447" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7448 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007449 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007450 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007451 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007452
7453 else " apply command to global list of files, en bloc
7454
7455 call inputsave()
7456 let cmd= input("Enter command: ","","file")
7457 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007458" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007459 if cmd == ""
7460" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7461 return
7462 endif
7463 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007464 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007465 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007466 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007467 endif
7468 if a:islocal
7469 call system(cmd)
7470 if v:shell_error < 0
7471 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7472 endif
7473 else
7474 let ret= s:RemoteSystem(cmd)
7475 endif
7476 call s:NetrwUnmarkAll()
7477
7478 " refresh the listing
7479 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007480" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7481 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007482
7483 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007484
Bram Moolenaar446cb832008-06-24 21:56:24 +00007485" call Dret("s:NetrwMarkFileExe")
7486endfun
7487
7488" ---------------------------------------------------------------------
7489" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7490" as the marked file(s) (toggles suffix presence)
7491" Uses the local marked file list.
7492fun! s:NetrwMarkHideSfx(islocal)
7493" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007494 let svpos = winsaveview()
7495" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007496 let curbufnr = bufnr("%")
7497
7498 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7499 if exists("s:netrwmarkfilelist_{curbufnr}")
7500
7501 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007502" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007503 " construct suffix pattern
7504 if fname =~ '\.'
7505 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7506 else
7507 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7508 endif
7509 " determine if its in the hiding list or not
7510 let inhidelist= 0
7511 if g:netrw_list_hide != ""
7512 let itemnum = 0
7513 let hidelist= split(g:netrw_list_hide,',')
7514 for hidepat in hidelist
7515 if sfxpat == hidepat
7516 let inhidelist= 1
7517 break
7518 endif
7519 let itemnum= itemnum + 1
7520 endfor
7521 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007522" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007523 if inhidelist
7524 " remove sfxpat from list
7525 call remove(hidelist,itemnum)
7526 let g:netrw_list_hide= join(hidelist,",")
7527 elseif g:netrw_list_hide != ""
7528 " append sfxpat to non-empty list
7529 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7530 else
7531 " set hiding list to sfxpat
7532 let g:netrw_list_hide= sfxpat
7533 endif
7534 endfor
7535
7536 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007537 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007538" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7539 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007540 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007541 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007542 endif
7543
7544" call Dret("s:NetrwMarkHideSfx")
7545endfun
7546
7547" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007548" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007549" Uses the local marked-file list.
7550fun! s:NetrwMarkFileVimCmd(islocal)
7551" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007552 let svpos = winsaveview()
7553" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007554 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007555 let curbufnr = bufnr("%")
7556
Bram Moolenaarff034192013-04-24 18:51:19 +02007557 " sanity check
7558 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007559 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007560" call Dret("s:NetrwMarkFileVimCmd")
7561 return
7562 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007563" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007564
Bram Moolenaar15146672011-10-20 22:22:38 +02007565 if exists("s:netrwmarkfilelist_{curbufnr}")
7566 " get the command
7567 call inputsave()
7568 let cmd= input("Enter vim command: ","","file")
7569 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007570" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007571 if cmd == ""
7572" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7573 return
7574 endif
7575
7576 " apply command to marked files. Substitute: filename -> %
7577 " If no %, then append a space and the filename to the command
7578 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007579" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007580 if a:islocal
7581 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007582 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007583" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007584 exe cmd
7585 exe "sil! keepalt wq!"
7586 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007587" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007588 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007589 endif
7590 endfor
7591
7592 " unmark marked file list
7593 call s:NetrwUnmarkList(curbufnr,curdir)
7594
7595 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007596 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007597" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7598 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007599 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007600 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007601 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007602
Bram Moolenaar15146672011-10-20 22:22:38 +02007603" call Dret("s:NetrwMarkFileVimCmd")
7604endfun
7605
7606" ---------------------------------------------------------------------
7607" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7608" as the marked file(s) (toggles suffix presence)
7609" Uses the local marked file list.
7610fun! s:NetrwMarkHideSfx(islocal)
7611" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007612 let svpos = winsaveview()
7613" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007614 let curbufnr = bufnr("%")
7615
7616 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7617 if exists("s:netrwmarkfilelist_{curbufnr}")
7618
7619 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007620" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007621 " construct suffix pattern
7622 if fname =~ '\.'
7623 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7624 else
7625 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7626 endif
7627 " determine if its in the hiding list or not
7628 let inhidelist= 0
7629 if g:netrw_list_hide != ""
7630 let itemnum = 0
7631 let hidelist= split(g:netrw_list_hide,',')
7632 for hidepat in hidelist
7633 if sfxpat == hidepat
7634 let inhidelist= 1
7635 break
7636 endif
7637 let itemnum= itemnum + 1
7638 endfor
7639 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007640" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007641 if inhidelist
7642 " remove sfxpat from list
7643 call remove(hidelist,itemnum)
7644 let g:netrw_list_hide= join(hidelist,",")
7645 elseif g:netrw_list_hide != ""
7646 " append sfxpat to non-empty list
7647 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7648 else
7649 " set hiding list to sfxpat
7650 let g:netrw_list_hide= sfxpat
7651 endif
7652 endfor
7653
7654 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007655 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007656" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7657 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007658 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007659 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007660 endif
7661
7662" call Dret("s:NetrwMarkHideSfx")
7663endfun
7664
7665" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007666" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7667" Uses the global markfilelist
7668fun! s:NetrwMarkFileGrep(islocal)
7669" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007670 let svpos = winsaveview()
7671" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007672 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007673 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007674
7675 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007676" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007677 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007678" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007679 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007680 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007681" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007682 let netrwmarkfilelist= "*"
7683 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007684
Bram Moolenaarff034192013-04-24 18:51:19 +02007685 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007686" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007687 call inputsave()
7688 let pat= input("Enter pattern: ","")
7689 call inputrestore()
7690 let patbang = ""
7691 if pat =~ '^!'
7692 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007693 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007694 endif
7695 if pat =~ '^\i'
7696 let pat = escape(pat,'/')
7697 let pat = '/'.pat.'/'
7698 else
7699 let nonisi = pat[0]
7700 endif
7701
7702 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007703" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007704 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007705 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007706 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007707 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007708" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7709 return
7710 endtry
7711 echo "(use :cn, :cp to navigate, :Rex to return)"
7712
7713 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007714" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7715 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007716
7717 if exists("nonisi")
7718 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007719" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007720 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007721 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007722 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007723 endif
7724
7725" call Dret("s:NetrwMarkFileGrep")
7726endfun
7727
7728" ---------------------------------------------------------------------
7729" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7730" uses the global marked file list
7731" s:netrwmfloc= 0: target directory is remote
7732" = 1: target directory is local
7733fun! s:NetrwMarkFileMove(islocal)
7734" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007735 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007736 let curbufnr = bufnr("%")
7737
7738 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007739 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007740 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007741" call Dret("s:NetrwMarkFileMove")
7742 return
7743 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007744" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007745
Bram Moolenaar446cb832008-06-24 21:56:24 +00007746 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007747 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007748" call Dret("s:NetrwMarkFileCopy 0")
7749 return 0
7750 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007751" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007752
7753 if a:islocal && s:netrwmftgt_islocal
7754 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007755" call Decho("move from local to local",'~'.expand("<slnum>"))
7756" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007757 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007758 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7759" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7760 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007761 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007762 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007763" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007764 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007765 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007766" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007767 if g:netrw_localmovecmd =~ '\s'
7768 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7769 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7770 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007771" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007772 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007773 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007774" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007775 endif
7776 else
7777 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007778" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007779 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007780 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007781 if g:netrw_keepdir
7782 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7783 let fname= b:netrw_curdir."/".fname
7784 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007785 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007786 let fname= substitute(fname,'/','\\','g')
7787 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007788" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007789 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007790 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007791 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007792 call netrw#ErrorMsg(s:ERROR,"move failed; perhaps due to vim's current directory<".getcwd()."> not matching netrw's (".b:netrw_curdir.") (see :help netrw-cd)",100)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007793 else
7794 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7795 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007796 break
7797 endif
7798 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007799
7800 elseif a:islocal && !s:netrwmftgt_islocal
7801 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007802" call Decho("move from local to remote",'~'.expand("<slnum>"))
7803" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007804 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007805 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007806" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007807 for fname in mflist
7808 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7809 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7810 endfor
7811 unlet mflist
7812
7813 elseif !a:islocal && s:netrwmftgt_islocal
7814 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007815" call Decho("move from remote to local",'~'.expand("<slnum>"))
7816" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007817 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007818 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007819" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007820 for fname in mflist
7821 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7822 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7823 endfor
7824 unlet mflist
7825
7826 elseif !a:islocal && !s:netrwmftgt_islocal
7827 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007828" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7829" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007830 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007831 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007832" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007833 for fname in mflist
7834 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7835 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7836 endfor
7837 unlet mflist
7838 endif
7839
7840 " -------
7841 " cleanup
7842 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007843" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007844
7845 " remove markings from local buffer
7846 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7847
7848 " refresh buffers
7849 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007850" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007851 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007852 endif
7853 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007854" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007855 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007856 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007857 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007858" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007859 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007860 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007861
Bram Moolenaar446cb832008-06-24 21:56:24 +00007862" call Dret("s:NetrwMarkFileMove")
7863endfun
7864
7865" ---------------------------------------------------------------------
7866" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7867" using the hardcopy command. Local marked-file list only.
7868fun! s:NetrwMarkFilePrint(islocal)
7869" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7870 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007871
7872 " sanity check
7873 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007874 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007875" call Dret("s:NetrwMarkFilePrint")
7876 return
7877 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007878" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7879 let curdir= s:NetrwGetCurdir(a:islocal)
7880
Bram Moolenaar446cb832008-06-24 21:56:24 +00007881 if exists("s:netrwmarkfilelist_{curbufnr}")
7882 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007883 call s:NetrwUnmarkList(curbufnr,curdir)
7884 for fname in netrwmarkfilelist
7885 if a:islocal
7886 if g:netrw_keepdir
7887 let fname= s:ComposePath(curdir,fname)
7888 endif
7889 else
7890 let fname= curdir.fname
7891 endif
7892 1split
7893 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007894" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007895 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007896" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007897 hardcopy
7898 q
7899 endfor
7900 2match none
7901 endif
7902" call Dret("s:NetrwMarkFilePrint")
7903endfun
7904
7905" ---------------------------------------------------------------------
7906" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7907" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007908" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007909fun! s:NetrwMarkFileRegexp(islocal)
7910" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7911
7912 " get the regular expression
7913 call inputsave()
7914 let regexp= input("Enter regexp: ","","file")
7915 call inputrestore()
7916
7917 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007918 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007919" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007920 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007921" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007922 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007923 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007924 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007925 else
7926 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007927 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007928 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007929" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007930
7931 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007932 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007933 if fname =~ '^'.fnameescape(curdir)
7934" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7935 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7936 else
7937" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7938 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7939 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007940 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007941
7942 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007943" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007944
7945 " convert displayed listing into a filelist
7946 let eikeep = &ei
7947 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007948 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007949 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007950" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007951 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007952 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02007953 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007954 sil NetrwKeepj norm! "ap
7955 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007956 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007957 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007958 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007959 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007960 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007961 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007962 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007963 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007964 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007965 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007966 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7967 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007968 call histdel("/",-1)
7969 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007970 endif
7971 " convert regexp into the more usual glob-style format
7972 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007973" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007974 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01007975 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007976 let filelist= getline(1,line("$"))
7977 q!
7978 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007979 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007980 endfor
7981 unlet filelist
7982 let @a = areg
7983 let &ei = eikeep
7984 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007985 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007986
7987" call Dret("s:NetrwMarkFileRegexp")
7988endfun
7989
7990" ---------------------------------------------------------------------
7991" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
7992" Uses the local marked file list.
7993fun! s:NetrwMarkFileSource(islocal)
7994" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
7995 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007996
7997 " sanity check
7998 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007999 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008000" call Dret("s:NetrwMarkFileSource")
8001 return
8002 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008003" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8004 let curdir= s:NetrwGetCurdir(a:islocal)
8005
Bram Moolenaar446cb832008-06-24 21:56:24 +00008006 if exists("s:netrwmarkfilelist_{curbufnr}")
8007 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008008 call s:NetrwUnmarkList(curbufnr,curdir)
8009 for fname in netrwmarkfilelist
8010 if a:islocal
8011 if g:netrw_keepdir
8012 let fname= s:ComposePath(curdir,fname)
8013 endif
8014 else
8015 let fname= curdir.fname
8016 endif
8017 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008018" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008019 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008020 endfor
8021 2match none
8022 endif
8023" call Dret("s:NetrwMarkFileSource")
8024endfun
8025
8026" ---------------------------------------------------------------------
8027" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8028" Uses the global markfilelist
8029fun! s:NetrwMarkFileTag(islocal)
8030" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008031 let svpos = winsaveview()
8032" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008033 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008034 let curbufnr = bufnr("%")
8035
Bram Moolenaarff034192013-04-24 18:51:19 +02008036 " sanity check
8037 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008038 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008039" call Dret("s:NetrwMarkFileTag")
8040 return
8041 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008042" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008043
Bram Moolenaar446cb832008-06-24 21:56:24 +00008044 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008045" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8046 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008047 call s:NetrwUnmarkAll()
8048
8049 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008050
8051" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8052 call system(g:netrw_ctags." ".netrwmarkfilelist)
8053 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008054 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8055 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008056
Bram Moolenaar446cb832008-06-24 21:56:24 +00008057 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008058 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008059 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008060 let curdir= b:netrw_curdir
8061 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008062 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008063 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008064" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008065 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008066 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008067 wq!
8068 endif
8069 2match none
8070 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008071" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8072 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008073 endif
8074
8075" call Dret("s:NetrwMarkFileTag")
8076endfun
8077
8078" ---------------------------------------------------------------------
8079" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008080" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008081" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008082" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008083" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008084fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008085" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8086 let svpos = winsaveview()
8087" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008088 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008089 let hadtgt = exists("s:netrwmftgt")
8090 if !exists("w:netrw_bannercnt")
8091 let w:netrw_bannercnt= b:netrw_bannercnt
8092 endif
8093
8094 " set up target
8095 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008096" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008097 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8098 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008099" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008100 unlet s:netrwmftgt s:netrwmftgt_islocal
8101 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008102 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008103 endif
8104 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008105" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8106 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008107" call Dret("s:NetrwMarkFileTgt : removed target")
8108 return
8109 else
8110 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008111" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008112 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008113
8114 else
8115 " get word under cursor.
8116 " * If directory, use it for the target.
8117 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008118" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008119 let curword= s:NetrwGetWord()
8120 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008121 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008122 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008123" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008124 elseif !a:islocal && tgtdir =~ '/$'
8125 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008126" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008127 else
8128 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008129" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008130 endif
8131 endif
8132 if a:islocal
8133 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8134 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008135" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008136 endif
8137 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008138 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008139 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8140 endif
8141 let s:netrwmftgt_islocal= a:islocal
8142
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008143 " need to do refresh so that the banner will be updated
8144 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008145 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008146" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008147 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008148 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008149" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008150 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008151 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8152 else
8153 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8154 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008155" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8156 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008157 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008158 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008159 endif
8160
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008161" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8162" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008163" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8164endfun
8165
8166" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008167" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8168fun! s:NetrwGetCurdir(islocal)
8169" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8170
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008171 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008172 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8173" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8174 elseif !exists("b:netrw_curdir")
8175 let b:netrw_curdir= getcwd()
8176" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8177 endif
8178
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008179" call Decho("b:netrw_curdir<".b:netrw_curdir."> ".((b:netrw_curdir !~ '\<\a\{3,}://')? "does not match" : "matches")." url pattern",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008180 if b:netrw_curdir !~ '\<\a\{3,}://'
8181 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008182" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008183 if g:netrw_keepdir == 0
8184 call s:NetrwLcd(curdir)
8185 endif
8186 endif
8187
8188" call Dret("s:NetrwGetCurdir <".curdir.">")
8189 return b:netrw_curdir
8190endfun
8191
8192" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008193" s:NetrwOpenFile: query user for a filename and open it {{{2
8194fun! s:NetrwOpenFile(islocal)
8195" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008196 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008197 call inputsave()
8198 let fname= input("Enter filename: ")
8199 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008200" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8201
8202 " determine if Lexplore is in use
8203 if exists("t:netrw_lexbufnr")
8204 " check if t:netrw_lexbufnr refers to a netrw window
8205" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8206 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8207 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8208" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8209 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8210 exe "NetrwKeepj e ".fnameescape(fname)
8211 let @@= ykeep
8212" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8213 endif
8214 endif
8215
8216 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008217 if fname !~ '[/\\]'
8218 if exists("b:netrw_curdir")
8219 if exists("g:netrw_quiet")
8220 let netrw_quiet_keep = g:netrw_quiet
8221 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008222 let g:netrw_quiet = 1
8223 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008224 let s:rexposn_{bufnr("%")}= winsaveview()
8225" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008226 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008227 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008228 else
8229 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8230 endif
8231 if exists("netrw_quiet_keep")
8232 let g:netrw_quiet= netrw_quiet_keep
8233 else
8234 unlet g:netrw_quiet
8235 endif
8236 endif
8237 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008238 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008239 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008240 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008241" call Dret("s:NetrwOpenFile")
8242endfun
8243
8244" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008245" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8246" For the mapping to this function be made via
8247" netrwPlugin, you'll need to have had
8248" g:netrw_usetab set to non-zero.
8249fun! netrw#Shrink()
8250" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8251 let curwin = winnr()
8252 let wiwkeep = &wiw
8253 set wiw=1
8254
8255 if &ft == "netrw"
8256 if winwidth(0) > g:netrw_wiw
8257 let t:netrw_winwidth= winwidth(0)
8258 exe "vert resize ".g:netrw_wiw
8259 wincmd l
8260 if winnr() == curwin
8261 wincmd h
8262 endif
8263" call Decho("vert resize 0",'~'.expand("<slnum>"))
8264 else
8265 exe "vert resize ".t:netrw_winwidth
8266" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8267 endif
8268
8269 elseif exists("t:netrw_lexbufnr")
8270 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8271 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8272 let t:netrw_winwidth= winwidth(0)
8273 exe "vert resize ".g:netrw_wiw
8274 wincmd l
8275 if winnr() == curwin
8276 wincmd h
8277 endif
8278" call Decho("vert resize 0",'~'.expand("<slnum>"))
8279 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8280 exe "vert resize ".t:netrw_winwidth
8281" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8282 else
8283 call netrw#Lexplore(0,0)
8284 endif
8285
8286 else
8287 call netrw#Lexplore(0,0)
8288 endif
8289 let wiw= wiwkeep
8290
8291" call Dret("netrw#Shrink")
8292endfun
8293
8294" ---------------------------------------------------------------------
8295" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8296fun! s:NetSortSequence(islocal)
8297" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8298
8299 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008300 let svpos= winsaveview()
8301" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008302 call inputsave()
8303 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8304 call inputrestore()
8305
8306 " refresh the listing
8307 let g:netrw_sort_sequence= newsortseq
8308 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008309" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8310 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008311 let @@= ykeep
8312
8313" call Dret("NetSortSequence")
8314endfun
8315
8316" ---------------------------------------------------------------------
8317" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8318" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008319" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008320fun! s:NetrwUnmarkList(curbufnr,curdir)
8321" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8322
8323 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008324 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008325 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8326 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8327 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8328 call remove(s:netrwmarkfilelist,idx) " remove from global list
8329 endfor
8330 if s:netrwmarkfilelist == []
8331 unlet s:netrwmarkfilelist
8332 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008333
Bram Moolenaar446cb832008-06-24 21:56:24 +00008334 " getting rid of the local marked-file lists is easy
8335 unlet s:netrwmarkfilelist_{a:curbufnr}
8336 endif
8337 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8338 unlet s:netrwmarkfilemtch_{a:curbufnr}
8339 endif
8340 2match none
8341" call Dret("s:NetrwUnmarkList")
8342endfun
8343
8344" ---------------------------------------------------------------------
8345" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8346fun! s:NetrwUnmarkAll()
8347" call Dfunc("s:NetrwUnmarkAll()")
8348 if exists("s:netrwmarkfilelist")
8349 unlet s:netrwmarkfilelist
8350 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008351 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008352 2match none
8353" call Dret("s:NetrwUnmarkAll")
8354endfun
8355
8356" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008357" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008358fun! s:NetrwUnmarkAll2()
8359" call Dfunc("s:NetrwUnmarkAll2()")
8360 redir => netrwmarkfilelist_let
8361 let
8362 redir END
8363 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008364 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008365 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8366 for flist in netrwmarkfilelist_list
8367 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8368 unlet s:netrwmarkfilelist_{curbufnr}
8369 unlet s:netrwmarkfilemtch_{curbufnr}
8370 endfor
8371" call Dret("s:NetrwUnmarkAll2")
8372endfun
8373
8374" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008375" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8376"
8377" Marked files are in two types of lists:
8378" s:netrwmarkfilelist -- holds complete paths to all marked files
8379" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8380"
8381" Marked files suitable for use with 2match are in:
8382" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008383fun! s:NetrwUnMarkFile(islocal)
8384" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008385 let svpos = winsaveview()
8386" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008387 let curbufnr = bufnr("%")
8388
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008389 " unmark marked file list
8390 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8391 if exists("s:netrwmarkfilelist")
8392" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008393 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008394 endif
8395
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008396 let ibuf= 1
8397 while ibuf < bufnr("$")
8398 if exists("s:netrwmarkfilelist_".ibuf)
8399 unlet s:netrwmarkfilelist_{ibuf}
8400 unlet s:netrwmarkfilemtch_{ibuf}
8401 endif
8402 let ibuf = ibuf + 1
8403 endwhile
8404 2match none
8405
Bram Moolenaar446cb832008-06-24 21:56:24 +00008406" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008407"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8408call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008409" call Dret("s:NetrwUnMarkFile")
8410endfun
8411
8412" ---------------------------------------------------------------------
8413" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8414fun! s:NetrwMenu(domenu)
8415
8416 if !exists("g:NetrwMenuPriority")
8417 let g:NetrwMenuPriority= 80
8418 endif
8419
Bram Moolenaaradc21822011-04-01 18:03:16 +02008420 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008421" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8422
8423 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008424" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008425 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008426 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8427 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8428 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8429 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8430 if g:netrw_dirhistmax > 0
8431 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8432 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8433 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8434 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8435 else
8436 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8437 endif
8438 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8439 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8440 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8441 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8442 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8443 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8444 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8445 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8446 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8447 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8448 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8449 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8450 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8451 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8452 exe 'sil! menu '.g:NetrwMenuPriority.'.11.4 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Window<tab>o o'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008453 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Tab<tab>t t'
Bram Moolenaarff034192013-04-24 18:51:19 +02008454 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8455 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8456 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8457 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8458 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8459 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8460 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8461 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8462 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8463 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8464 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8465 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8466 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8467 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8468 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8469 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8470 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8471 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8472 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8473 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8474 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8475 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8476 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8477 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8478 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8479 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8480 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8481 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8482 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8483 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.1 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Show\ All<tab>a :let g:netrw_hide=0<cr><c-L>'
8484 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.3 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Normal<tab>a :let g:netrw_hide=1<cr><c-L>'
8485 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.2 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Hidden\ Only<tab>a :let g:netrw_hide=2<cr><c-L>'
8486 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8487 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.1 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Name<tab>s :let g:netrw_sort_by="name"<cr><c-L>'
8488 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.2 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Time<tab>s :let g:netrw_sort_by="time"<cr><c-L>'
8489 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.3 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Size<tab>s :let g:netrw_sort_by="size"<cr><c-L>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008490 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.3 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Exten<tab>s :let g:netrw_sort_by="exten"<cr><c-L>'
Bram Moolenaarff034192013-04-24 18:51:19 +02008491 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8492 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008493 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008494 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8495 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008496
8497 elseif !a:domenu
8498 let s:netrwcnt = 0
8499 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008500 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008501 exe curwin."wincmd w"
8502
8503 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008504" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008505 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008506" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008507 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008508 endif
8509 endif
8510" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008511 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008512 endif
8513
8514endfun
8515
8516" ---------------------------------------------------------------------
8517" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8518" Used by the O maps (as <SID>NetrwObtain())
8519fun! s:NetrwObtain(islocal)
8520" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8521
Bram Moolenaar97d62492012-11-15 21:28:22 +01008522 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008523 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008524 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008525 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008526 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8527 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008528 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008529 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008530 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008531
8532" call Dret("NetrwObtain")
8533endfun
8534
8535" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008536" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8537" If there's only one window, then the window will first be split.
8538" Returns:
8539" choice = 0 : didn't have to choose
8540" choice = 1 : saved modified file in window first
8541" choice = 2 : didn't save modified file, opened window
8542" choice = 3 : cancel open
8543fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008544" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008545
Bram Moolenaar97d62492012-11-15 21:28:22 +01008546 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008547 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008548 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008549" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008550
8551 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008552 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008553 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008554" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8555" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8556 let curword = s:NetrwGetWord()
8557 let choice = 0
8558 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8559" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008560 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008561" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008562 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008563" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008564" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008565" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008566
Bram Moolenaar8d043172014-01-23 14:24:41 +01008567 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008568 if lastwinnr == 1
8569 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008570" call Decho("only one window, so open a new one (g:netrw_alto=".g:netrw_alto.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008571 " g:netrw_preview=0: preview window shown in a horizontally split window
8572 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008573 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008574 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008575 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008576" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008577 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008578 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008579 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008580 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008581" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008582 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008583 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008584 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008585" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008586
8587 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008588" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008589 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008590" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008591 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008592" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008593 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008594" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008595 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008596" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008597" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008598" call Decho("COMBAK#12: mod=".&mod)
8599
8600 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8601 " whoops -- user trying to open file in the Lexplore window.
8602 " Use Lexplore's opening-file window instead.
8603" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8604" exe g:netrw_chgwin."wincmd w"
8605 wincmd p
8606 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8607 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008608
8609 " prevwinnr: the window number of the "prev" window
8610 " prevbufnr: the buffer number of the buffer in the "prev" window
8611 " bnrcnt : the qty of windows open on the "prev" buffer
8612 let prevwinnr = winnr()
8613 let prevbufnr = bufnr("%")
8614 let prevbufname = bufname("%")
8615 let prevmod = &mod
8616 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008617" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008618 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008619" call Decho("after wincmd p: win#".winnr()." win($)#".winnr("$")." origwin#".origwin." &mod=".&mod." bufname(%)<".bufname("%")."> prevbufnr=".prevbufnr,'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008620" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008621
8622 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008623 " and it doesn't appear in any other extant window, then ask the
8624 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008625 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008626" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008627 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008628" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008629 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008630" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008631
8632 if bnrcnt == 1 && &hidden == 0
8633 " only one copy of the modified buffer in a window, and
8634 " hidden not set, so overwriting will lose the modified file. Ask first...
8635 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008636" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008637 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008638" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008639
8640 if choice == 1
8641 " Yes -- write file & then browse
8642 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008643 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008644 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008645 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008646 exe origwin."wincmd w"
8647 let &ei = eikeep
8648 let @@ = ykeep
8649" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008650 return choice
8651 endif
8652
8653 elseif choice == 2
8654 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008655" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008656 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008657
8658 else
8659 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008660" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008661 exe origwin."wincmd w"
8662 let &ei= eikeep
8663 let @@ = ykeep
8664" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008665 return choice
8666 endif
8667 endif
8668 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008669 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008670 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008671" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008672
8673 " restore b:netrw_curdir (window split/enew may have lost it)
8674 let b:netrw_curdir= curdir
8675 if a:islocal < 2
8676 if a:islocal
8677 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8678 else
8679 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8680 endif
8681 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008682 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008683" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008684 return choice
8685endfun
8686
8687" ---------------------------------------------------------------------
8688" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8689" Always assumed to be local -> remote
8690" call s:NetrwUpload(filename, target)
8691" call s:NetrwUpload(filename, target, fromdirectory)
8692fun! s:NetrwUpload(fname,tgt,...)
8693" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8694
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008695 if a:tgt =~ '^\a\{3,}://'
8696 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008697 else
8698 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8699 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008700" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008701
8702 if a:0 > 0
8703 let fromdir= a:1
8704 else
8705 let fromdir= getcwd()
8706 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008707" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008708
8709 if type(a:fname) == 1
8710 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008711" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008712 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008713" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8714 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8715" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008716 if a:tgt =~ '/$'
8717 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008718" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008719 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008720 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008721" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008722 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008723" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008724 endif
8725 q!
8726
8727 elseif type(a:fname) == 3
8728 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008729" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008730 let curdir= getcwd()
8731 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008732 if s:NetrwLcd(fromdir)
8733" call Dret("s:NetrwUpload : lcd failure")
8734 return
8735 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008736 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008737 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008738 if exists("g:netrw_port") && g:netrw_port != ""
8739 let useport= " ".g:netrw_scpport." ".g:netrw_port
8740 else
8741 let useport= ""
8742 endif
8743 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8744 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008745 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.s:ShellEscape(useport,1)." ".args." ".s:ShellEscape(machine.":".tgt,1))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008746 if s:NetrwLcd(curdir)
8747" call Dret("s:NetrwUpload : lcd failure")
8748 return
8749 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008750
8751 elseif a:tgt =~ '^ftp:'
8752 call s:NetrwMethod(a:tgt)
8753
8754 if b:netrw_method == 2
8755 " handle uploading a list of files via ftp+.netrc
8756 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008757 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008758" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008759
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008760 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008761" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008762
8763 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008764 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008765" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008766 endif
8767
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008768 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008769" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008770
Bram Moolenaaradc21822011-04-01 18:03:16 +02008771 if tgtdir == ""
8772 let tgtdir= '/'
8773 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008774 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008775" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008776
8777 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008778 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8779" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008780 endfor
8781
8782 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008783 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008784 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008785" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8786 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008787 endif
8788 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008789 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008790 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008791 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8792 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8793 else
8794 bw!|q
8795 endif
8796
8797 elseif b:netrw_method == 3
8798 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8799 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008800 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008801 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008802 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008803
8804 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008805 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008806" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008807 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008808 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008809" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008810 endif
8811
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008812 if exists("g:netrw_uid") && g:netrw_uid != ""
8813 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008814 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008815" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008816 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008817 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008818 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008819" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008820 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008821 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008822" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008823 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008824 endif
8825
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008826 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008827" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008828
8829 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008830 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008831" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008832 endif
8833
8834 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008835 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008836" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008837 endif
8838
8839 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008840 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008841" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008842 endfor
8843
8844 " perform ftp:
8845 " -i : turns off interactive prompting from ftp
8846 " -n unix : DON'T use <.netrc>, even though it exists
8847 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008848 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008849 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008850 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008851 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008852 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008853 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8854 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008855 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008856 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8857 let &debug = debugkeep
8858 let mod = 1
8859 else
8860 bw!|q
8861 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008862 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008863" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008864 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008865 endif
8866 else
8867 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8868 endif
8869 endif
8870
8871" call Dret("s:NetrwUpload")
8872endfun
8873
8874" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008875" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008876fun! s:NetrwPreview(path) range
8877" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008878" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8879" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008880 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008881 NetrwKeepj call s:NetrwOptionsSave("s:")
8882 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8883 NetrwKeepj call s:NetrwOptionsSafe(1)
8884 else
8885 NetrwKeepj call s:NetrwOptionsSafe(0)
8886 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008887 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008888" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008889 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008890" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8891 if g:netrw_preview
8892 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008893 let pvhkeep = &pvh
8894 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8895 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008896" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8897 else
8898 " horizontal split
8899 let pvhkeep = &pvh
8900 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8901 let &pvh = winheight(0) - winsz
8902" call Decho("!g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008903 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008904 " g:netrw_preview g:netrw_alto
8905 " 1 : vert 1: top -- preview window is vertically split off and on the left
8906 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8907 " 0 : 1: top -- preview window is horizontally split off and on the top
8908 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8909 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008910 " Note that the file being previewed is already known to not be a directory, hence we can avoid doing a LocalBrowseCheck() check via
Bram Moolenaar85850f32019-07-19 22:05:51 +02008911 " the BufEnter event set up in netrwPlugin.vim
8912" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8913 let eikeep = &ei
8914 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008915 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008916 let &ei= eikeep
8917" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008918 if exists("pvhkeep")
8919 let &pvh= pvhkeep
8920 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008921 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008922 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008923 endif
8924 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008925 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, to preview your vim needs the quickfix feature compiled in",39)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008926 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008927 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008928 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008929" call Dret("NetrwPreview")
8930endfun
8931
8932" ---------------------------------------------------------------------
8933" s:NetrwRefresh: {{{2
8934fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008935" call Dfunc("s:NetrwRefresh(islocal<".a:islocal.">,dirname=".a:dirname.") g:netrw_hide=".g:netrw_hide." g:netrw_sort_direction=".g:netrw_sort_direction)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008936 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008937 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008938" call Decho("setl ma noro",'~'.expand("<slnum>"))
8939" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008940 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008941 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8942 if !exists("w:netrw_treetop")
8943 if exists("b:netrw_curdir")
8944 let w:netrw_treetop= b:netrw_curdir
8945 else
8946 let w:netrw_treetop= getcwd()
8947 endif
8948 endif
8949 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
8950 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008951
8952 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008953 let screenposn = winsaveview()
8954" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008955
8956" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
8957" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
8958 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008959 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008960 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008961 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008962 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008963 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008964
8965 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008966" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
8967 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008968
8969 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02008970 if has("syntax") && exists("g:syntax_on") && g:syntax_on
8971 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8972" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
8973 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8974 else
8975" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
8976 2match none
8977 endif
8978 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008979
Bram Moolenaar97d62492012-11-15 21:28:22 +01008980" restore
8981 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008982" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008983endfun
8984
8985" ---------------------------------------------------------------------
8986" s:NetrwRefreshDir: refreshes a directory by name {{{2
8987" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008988" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008989fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008990" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008991 if g:netrw_fastbrowse == 0
8992 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008993" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008994 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008995" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008996
8997 if tgtwin > 0
8998 " tgtwin is being displayed, so refresh it
8999 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009000" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009001 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009002 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009003 exe curwin."wincmd w"
9004
9005 elseif bufnr(a:dirname) > 0
9006 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009007" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9008 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009009 endif
9010
9011 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009012" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009013 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009014 endif
9015" call Dret("s:NetrwRefreshDir")
9016endfun
9017
9018" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009019" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9020" window number to do its editing in.
9021" Supports [count]C where the count, if present, is used to specify
9022" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009023fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009024" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009025 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009026" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009027 if a:1 == "" " :NetrwC win#
9028 let g:netrw_chgwin= winnr()
9029 else " :NetrwC
9030 let g:netrw_chgwin= a:1
9031 endif
9032 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009033 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009034 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009035 let g:netrw_chgwin= winnr()
9036 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009037 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009038" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009039endfun
9040
9041" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009042" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9043" What this function does is to compute a priority for the patterns
9044" in the g:netrw_sort_sequence. It applies a substitute to any
9045" "files" that satisfy each pattern, putting the priority / in
9046" front. An "*" pattern handles the default priority.
9047fun! s:NetrwSetSort()
9048" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009049 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009050 if w:netrw_liststyle == s:LONGLIST
9051 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9052 else
9053 let seqlist = g:netrw_sort_sequence
9054 endif
9055 " sanity check -- insure that * appears somewhere
9056 if seqlist == ""
9057 let seqlist= '*'
9058 elseif seqlist !~ '\*'
9059 let seqlist= seqlist.',*'
9060 endif
9061 let priority = 1
9062 while seqlist != ""
9063 if seqlist =~ ','
9064 let seq = substitute(seqlist,',.*$','','e')
9065 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9066 else
9067 let seq = seqlist
9068 let seqlist = ""
9069 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009070 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009071 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009072 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009073 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009074 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009075 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009076 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009077" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009078
9079 " sanity check
9080 if w:netrw_bannercnt > line("$")
9081 " apparently no files were left after a Hiding pattern was used
9082" call Dret("SetSort : no files left after hiding")
9083 return
9084 endif
9085 if seq == '*'
9086 let starpriority= spriority
9087 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009088 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009089 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009090 " sometimes multiple sorting patterns will match the same file or directory.
9091 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009092 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9093 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009094 endif
9095 let priority = priority + 1
9096 endwhile
9097 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009098 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9099 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009100 endif
9101
9102 " Following line associated with priority -- items that satisfy a priority
9103 " pattern get prefixed by ###/ which permits easy sorting by priority.
9104 " Sometimes files can satisfy multiple priority patterns -- only the latest
9105 " priority pattern needs to be retained. So, at this point, these excess
9106 " priority prefixes need to be removed, but not directories that happen to
9107 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009108 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9109 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009110 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009111
9112" call Dret("SetSort")
9113endfun
9114
Bram Moolenaarff034192013-04-24 18:51:19 +02009115" ---------------------------------------------------------------------
9116" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9117" Implements [count]Tb (bookhist<b>)
9118" [count]Th (bookhist<h>)
9119" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009120fun! s:NetrwSetTgt(islocal,bookhist,choice)
9121" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009122
9123 if a:bookhist == 'b'
9124 " supports choosing a bookmark as a target using a qb-generated list
9125 let choice= a:choice - 1
9126 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009127 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009128 else
9129 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9130 endif
9131
9132 elseif a:bookhist == 'h'
9133 " supports choosing a history stack entry as a target using a qb-generated list
9134 let choice= (a:choice % g:netrw_dirhistmax) + 1
9135 if exists("g:netrw_dirhist_".choice)
9136 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009137 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009138 else
9139 echomsg "Sorry, history#".a:choice." not available!"
9140 endif
9141 endif
9142
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009143 " refresh the display
9144 if !exists("b:netrw_curdir")
9145 let b:netrw_curdir= getcwd()
9146 endif
9147 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9148
Bram Moolenaarff034192013-04-24 18:51:19 +02009149" call Dret("s:NetrwSetTgt")
9150endfun
9151
Bram Moolenaar446cb832008-06-24 21:56:24 +00009152" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009153" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009154fun! s:NetrwSortStyle(islocal)
9155" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009156 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009157 let svpos= winsaveview()
9158" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009159
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009160 let g:netrw_sort_by= (g:netrw_sort_by =~# '^n')? 'time' : (g:netrw_sort_by =~# '^t')? 'size' : (g:netrw_sort_by =~# '^siz')? 'exten' : 'name'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009161 NetrwKeepj norm! 0
9162 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009163" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9164 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009165
9166" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9167endfun
9168
9169" ---------------------------------------------------------------------
9170" s:NetrwSplit: mode {{{2
9171" =0 : net and o
9172" =1 : net and t
9173" =2 : net and v
9174" =3 : local and o
9175" =4 : local and t
9176" =5 : local and v
9177fun! s:NetrwSplit(mode)
9178" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9179
Bram Moolenaar97d62492012-11-15 21:28:22 +01009180 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009181 call s:SaveWinVars()
9182
9183 if a:mode == 0
9184 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009185 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009186 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009187" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009188 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009189 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009190 NetrwKeepj call s:RestoreWinVars()
9191 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009192 unlet s:didsplit
9193
9194 elseif a:mode == 1
9195 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009196 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009197" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009198 tabnew
9199 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009200 NetrwKeepj call s:RestoreWinVars()
9201 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009202 unlet s:didsplit
9203
9204 elseif a:mode == 2
9205 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009206 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009207 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009208" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009209 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009210 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009211 NetrwKeepj call s:RestoreWinVars()
9212 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009213 unlet s:didsplit
9214
9215 elseif a:mode == 3
9216 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009217 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009218 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009219" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009220 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009221 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009222 NetrwKeepj call s:RestoreWinVars()
9223 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009224 unlet s:didsplit
9225
9226 elseif a:mode == 4
9227 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009228 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009229 let eikeep = &ei
9230 let netrw_winnr = winnr()
9231 let netrw_line = line(".")
9232 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009233 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009234 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009235 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009236 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9237 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009238 let &ei = eikeep
9239 let netrw_curdir = s:NetrwTreeDir(0)
9240" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009241 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009242 let b:netrw_curdir = netrw_curdir
9243 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009244 NetrwKeepj call s:RestoreWinVars()
9245 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009246 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009247 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009248 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9249 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009250 let &ei= eikeep
9251 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009252 unlet s:didsplit
9253
9254 elseif a:mode == 5
9255 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009256 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009257 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009258" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009259 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009260 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009261 NetrwKeepj call s:RestoreWinVars()
9262 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009263 unlet s:didsplit
9264
9265 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009266 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009267 endif
9268
Bram Moolenaar97d62492012-11-15 21:28:22 +01009269 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009270" call Dret("s:NetrwSplit")
9271endfun
9272
9273" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009274" s:NetrwTgtMenu: {{{2
9275fun! s:NetrwTgtMenu()
9276 if !exists("s:netrw_menucnt")
9277 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009278 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009279" call Dfunc("s:NetrwTgtMenu()")
9280
9281 " the following test assures that gvim is running, has menus available, and has menus enabled.
9282 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9283 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009284" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009285 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9286 endif
9287 if !exists("s:netrw_initbookhist")
9288 call s:NetrwBookHistRead()
9289 endif
9290
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009291 " try to cull duplicate entries
9292 let tgtdict={}
9293
Bram Moolenaarff034192013-04-24 18:51:19 +02009294 " target bookmarked places
9295 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009296" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009297 let cnt= 1
9298 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009299 if has_key(tgtdict,bmd)
9300 let cnt= cnt + 1
9301 continue
9302 endif
9303 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009304 let ebmd= escape(bmd,g:netrw_menu_escape)
9305 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009306" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009307 exe 'sil! menu <silent> '.g:NetrwMenuPriority.".19.1.".cnt." ".g:NetrwTopLvlMenu.'Targets.'.ebmd." :call netrw#MakeTgt('".bmd."')\<cr>"
Bram Moolenaarff034192013-04-24 18:51:19 +02009308 let cnt= cnt + 1
9309 endfor
9310 endif
9311
9312 " target directory browsing history
9313 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009314" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009315 let histcnt = 1
9316 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009317 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009318 if exists("g:netrw_dirhist_{histcnt}")
9319 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009320 if has_key(tgtdict,histentry)
9321 let histcnt = histcnt + 1
9322 continue
9323 endif
9324 let tgtdict[histentry] = histcnt
9325 let ehistentry = escape(histentry,g:netrw_menu_escape)
9326" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009327 exe 'sil! menu <silent> '.g:NetrwMenuPriority.".19.2.".priority." ".g:NetrwTopLvlMenu.'Targets.'.ehistentry." :call netrw#MakeTgt('".histentry."')\<cr>"
Bram Moolenaarff034192013-04-24 18:51:19 +02009328 endif
9329 let histcnt = histcnt + 1
9330 endwhile
9331 endif
9332 endif
9333" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009334endfun
9335
9336" ---------------------------------------------------------------------
9337" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9338" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009339fun! s:NetrwTreeDir(islocal)
9340" call Dfunc("s:NetrwTreeDir(islocal=".a:islocal.") getline(".line(".").")"."<".getline('.')."> b:netrw_curdir<".b:netrw_curdir."> tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009341" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009342" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9343" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9344" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009345" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009346
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009347 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009348 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009349" call Decho('s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early')
Bram Moolenaar8d043172014-01-23 14:24:41 +01009350 let treedir= s:treedir
9351 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009352 unlet s:prevwinopen
9353" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009354 return treedir
9355 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009356 if exists("s:prevwinopen")
9357 unlet s:prevwinopen
9358 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009359" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009360
Bram Moolenaar8d043172014-01-23 14:24:41 +01009361 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9362 let b:netrw_curdir= getcwd()
9363 endif
9364 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009365" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009366" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009367
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009368 let s:treecurpos= winsaveview()
9369" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009370" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009371
9372 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009373" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9374" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009375" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009376
9377 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009378 let curline= substitute(getline('.'),"\t -->.*$",'','')
9379 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009380" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009381 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009382" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9383 elseif curline =~ '@$'
9384" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009385 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009386" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009387 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009388" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009389 let treedir= ""
9390 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009391" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009392
9393 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009394" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9395" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009396" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009397 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009398" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009399 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009400" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9401 sil! NetrwKeepj %d _
9402" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009403 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009404" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009405" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009406 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009407" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009408
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009409" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009410" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009411" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009412
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009413 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9414" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9415" let newdir = w:netrw_treetop.'/'.potentialdir
9416" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9417" let treedir = s:NetrwTreePath(newdir)
9418" let w:netrw_treetop = newdir
9419" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9420" else
9421" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009422 if a:islocal && curline =~ '@$'
9423 if isdirectory(s:NetrwFile(potentialdir))
9424 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9425 let w:netrw_treetop = treedir
9426 endif
9427 else
9428 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9429 let treedir = s:NetrwTreePath(w:netrw_treetop)
9430 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009431 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009432" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009433
9434 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009435 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009436" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009437" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009438
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009439" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009440 return treedir
9441endfun
9442
9443" ---------------------------------------------------------------------
9444" s:NetrwTreeDisplay: recursive tree display {{{2
9445fun! s:NetrwTreeDisplay(dir,depth)
9446" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9447
9448 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009449 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009450
9451 " install ../ and shortdir
9452 if a:depth == ""
9453 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009454" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009455 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009456 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009457 if a:dir == w:netrw_treetop
9458 let shortdir= a:dir
9459 else
9460 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9461 endif
9462 call setline(line("$")+1,a:depth.shortdir)
9463 else
9464 let shortdir= substitute(a:dir,'^.*/','','e')
9465 call setline(line("$")+1,a:depth.shortdir.'/')
9466 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009467" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009468 " append a / to dir if its missing one
9469 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009470
9471 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009472 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009473" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009474
Bram Moolenaar85850f32019-07-19 22:05:51 +02009475 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9476 if g:netrw_hide == 1
9477 " hide given patterns
9478 let listhide= split(g:netrw_list_hide,',')
9479" call Decho("listhide=".string(listhide))
9480 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009481 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009482 endfor
9483
9484 elseif g:netrw_hide == 2
9485 " show given patterns (only)
9486 let listhide= split(g:netrw_list_hide,',')
9487" call Decho("listhide=".string(listhide))
9488 let entries=[]
9489 for entry in w:netrw_treedict[dir]
9490 for pat in listhide
9491 if entry =~ pat
9492 call add(entries,entry)
9493 break
9494 endif
9495 endfor
9496 endfor
9497 let w:netrw_treedict[dir]= entries
9498 endif
9499 if depth != ""
9500 " always remove "." and ".." entries when there's depth
9501 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9502 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9503 endif
9504
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009505" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009506 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009507 if dir =~ '/$'
9508 let direntry= substitute(dir.entry,'[@/]$','','e')
9509 else
9510 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9511 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009512" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009513 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009514" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009515 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009516 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009517" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9518 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9519 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9520" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009521 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009522 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009523" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009524 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009525 endif
9526 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009527" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009528
Bram Moolenaar446cb832008-06-24 21:56:24 +00009529" call Dret("NetrwTreeDisplay")
9530endfun
9531
9532" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009533" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9534fun! s:NetrwRefreshTreeDict(dir)
9535" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009536 if !exists("w:netrw_treedict")
9537" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9538 return
9539 endif
9540
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009541 for entry in w:netrw_treedict[a:dir]
9542 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9543" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9544
9545 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9546" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9547 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009548 let liststar = s:NetrwGlob(direntry,'*',1)
9549 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009550 let w:netrw_treedict[direntry] = liststar + listdotstar
9551" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9552
9553 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9554" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9555 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009556 let liststar = s:NetrwGlob(direntry.'/','*',1)
9557 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009558 let w:netrw_treedict[direntry]= liststar + listdotstar
9559" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9560
9561 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9562" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9563 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009564 let liststar = s:NetrwGlob(direntry.'/','*',1)
9565 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009566" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9567
9568 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009569" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009570 endif
9571 endfor
9572" call Dret("s:NetrwRefreshTreeDict")
9573endfun
9574
9575" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009576" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009577" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009578fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009579 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009580" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009581" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9582" 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>"))
9583" 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 +00009584
9585 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009586 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009587" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009588 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009589 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009590" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009591 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 +02009592" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009593 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009594 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009595" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009596 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009597 if exists("w:netrw_treetop")
9598 let s:netrw_treetop= w:netrw_treetop
9599 else
9600 let w:netrw_treetop= getcwd()
9601 let s:netrw_treetop= w:netrw_treetop
9602 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009603
Bram Moolenaar446cb832008-06-24 21:56:24 +00009604 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009605 " insure that we have a treedict, albeit empty
9606" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009607 let w:netrw_treedict= {}
9608 endif
9609
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009610 " update the dictionary for the current directory
9611" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009612" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009613 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009614 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009615" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009616 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009617
9618 " if past banner, record word
9619 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9620 let fname= expand("<cword>")
9621 else
9622 let fname= ""
9623 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009624" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9625" 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 +00009626
9627 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009628" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009629 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009630" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009631
9632 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9633 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009634" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009635 1d
9636 endwhile
9637
Bram Moolenaar13600302014-05-22 18:26:40 +02009638 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009639
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009640" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009641 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009642 endif
9643endfun
9644
9645" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009646" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009647" Normally, treetop is w:netrw_treetop, but a
9648" user of the function ( netrw#SetTreetop() )
9649" wipes that out prior to calling this function
9650fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009651" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9652 if line(".") < w:netrw_bannercnt + 2
9653 let treedir= a:treetop
9654 if treedir !~ '/$'
9655 let treedir= treedir.'/'
9656 endif
9657" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9658 return treedir
9659 endif
9660
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009661 let svpos = winsaveview()
9662" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009663 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009664" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009665 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009666" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9667 let curline= getline('.')
9668" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9669 if curline =~ '/$'
9670" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9671 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9672" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9673 elseif curline =~ '@\s\+-->'
9674" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9675 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9676 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9677" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009678 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009679" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009680 let treedir= ""
9681 endif
9682 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009683" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9684" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009685 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9686 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9687 let treedir= dirname.treedir
9688 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009689" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009690 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009691" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009692 if a:treetop =~ '/$'
9693 let treedir= a:treetop.treedir
9694 else
9695 let treedir= a:treetop.'/'.treedir
9696 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009697" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009698 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009699" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009700" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9701 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009702" call Dret("s:NetrwTreePath <".treedir.">")
9703 return treedir
9704endfun
9705
9706" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009707" s:NetrwWideListing: {{{2
9708fun! s:NetrwWideListing()
9709
9710 if w:netrw_liststyle == s:WIDELIST
9711" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9712 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009713 " cpf: characters per filename
9714 " fpl: filenames per line
9715 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009716 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009717 let dict={}
9718 " save the unnamed register and register 0-9 and a
9719 let dict.a=[getreg('a'), getregtype('a')]
9720 for i in range(0, 9)
9721 let dict[i] = [getreg(i), getregtype(i)]
9722 endfor
9723 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009724" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009725 let b:netrw_cpf= 0
9726 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009727 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009728 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9729 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009730 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009731 " restore stored registers
9732 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009733" call Dret("NetrwWideListing")
9734 return
9735 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009736 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009737 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009738" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009739
9740 " determine qty files per line (fpl)
9741 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9742 if w:netrw_fpl <= 0
9743 let w:netrw_fpl= 1
9744 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009745" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009746
9747 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009748 " fpc: files per column of wide listing
9749 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009750 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009751 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9752 let newcolstart = w:netrw_bannercnt + fpc
9753 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009754" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009755 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009756" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009757 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009758 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009759 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009760 while line("$") >= newcolstart
9761 if newcolend > line("$") | let newcolend= line("$") | endif
9762 let newcolqty= newcolend - newcolstart
9763 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009764 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009765 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009766 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009767 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009768 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009769 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009770 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009771 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009772 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009773 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009774" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009775 if @* != keepregstar | sil! let @* = keepregstar | endif
9776 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009777 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009778 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9779 NetrwKeepj call histdel("/",-1)
9780 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9781 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009782" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009783 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009784 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009785" 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 +00009786" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009787 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009788 else
9789 if hasmapto("w","n")
9790 sil! nunmap <buffer> w
9791 endif
9792 if hasmapto("b","n")
9793 sil! nunmap <buffer> b
9794 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009795 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009796endfun
9797
9798" ---------------------------------------------------------------------
9799" s:PerformListing: {{{2
9800fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009801" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9802" 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 +02009803" 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>"))
9804 sil! NetrwKeepj %d _
9805" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009806
Bram Moolenaar15146672011-10-20 22:22:38 +02009807 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009808" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009809 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009810
Bram Moolenaar85850f32019-07-19 22:05:51 +02009811 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009812 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009813" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009814
9815" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009816" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009817" endif " Decho
9818
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009819" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009820 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9821 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009822" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9823 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009824 endif
9825
9826 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009827 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009828
9829 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009830 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009831" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009832 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009833 if exists("g:netrw_pchk")
9834 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9835 " failure detections.
9836 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009837 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009838 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9839 endif
9840 if exists("g:netrw_pchk")
9841 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9842 else
9843 let curdir= b:netrw_curdir
9844 endif
9845 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9846 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9847 else
9848 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009849 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009850 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009851 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009852 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009853" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009854 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009855 let w:netrw_bannercnt= 1
9856 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009857" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9858" 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 +00009859
Bram Moolenaar85850f32019-07-19 22:05:51 +02009860 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009861 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009862 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009863 let sortby= sortby." reversed"
9864 endif
9865
9866 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009867 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009868" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009869 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009870" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009871 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009872 NetrwKeepj put ='\" Sorted by '.sortby
9873 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009874 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9875 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009876" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009877 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009878 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009879 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9880 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009881 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009882" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009883" 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 +00009884 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009885
Bram Moolenaar85850f32019-07-19 22:05:51 +02009886 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009887 if g:netrw_banner
9888 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009889" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009890 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009891 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009892 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009893 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009894 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009895 endif
9896 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009897 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009898" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009899 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009900 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009901 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009902
9903 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009904 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009905" 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 +01009906 if g:netrw_list_hide != "" && g:netrw_hide
9907 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009908 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009909 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009910 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009911 endif
9912 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009913 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009914 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009915
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009916" 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 +01009917 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009918" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009919 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009920" 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 +01009921 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009922 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009923" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009924" 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 +00009925 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009926
9927 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009928 if g:netrw_banner
9929 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009930 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009931" 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 +01009932" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009933" 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 +01009934 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009935
Bram Moolenaar446cb832008-06-24 21:56:24 +00009936 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009937" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009938 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009939 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009940 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009941 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009942 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009943" 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 +01009944" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9945 return
9946 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009947 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009948
9949 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009950 if !exists("w:netrw_bannercnt")
9951 let w:netrw_bannercnt= 0
9952 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009953" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
9954" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
9955" 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 +01009956
Bram Moolenaar5c736222010-01-06 20:54:52 +01009957 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009958" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009959" 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 +00009960 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009961 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009962 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009963 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009964" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009965
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009966 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009967 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +02009968" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009969 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009970
Bram Moolenaar5c736222010-01-06 20:54:52 +01009971 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009972" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009973 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +02009974 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009975 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009976 else
9977 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009978 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009979 endif
9980 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009981
Bram Moolenaar446cb832008-06-24 21:56:24 +00009982 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009983" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009984 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
9985 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009986
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009987 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +02009988 " exten: sort by extension
9989 " The histdel(...,-1) calls remove the last search from the search history
9990" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009991 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
9992 NetrwKeepj call histdel("/",-1)
9993 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
9994 NetrwKeepj call histdel("/",-1)
9995 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
9996 NetrwKeepj call histdel("/",-1)
9997 if !g:netrw_banner || w:netrw_bannercnt < line("$")
9998" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009999 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010000 " normal direction sorting
10001 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10002 else
10003 " reverse direction sorting
10004 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10005 endif
10006 endif
10007 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10008 NetrwKeepj call histdel("/",-1)
10009
Bram Moolenaar446cb832008-06-24 21:56:24 +000010010 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010011 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010012" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010013 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010014" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010015 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010016 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010017" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010018 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010019 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010020" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010021 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10022 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010023 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010024 endif
10025
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010026 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010027" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010028 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010029 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010030 call histdel("/",-1)
10031 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010032 endif
10033 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010034" 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 +000010035
10036 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010037" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10038" 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 +010010039 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010040" 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 +010010041 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010042" 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 +000010043
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010044 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010045 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010046" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010047 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010048 endif
10049
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010050 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010051 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010052" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10053 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010054 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010055" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10056 else
10057" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10058" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10059" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10060" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010061 endif
10062
10063 " record previous current directory
10064 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010065" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010066
10067 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010068" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10069" 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 +010010070 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010071" 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 +020010072 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010073" 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 +000010074
10075 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010076" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010077 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010078" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#7)",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010079 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010080" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010081 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10082 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010083" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010084" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010085
Bram Moolenaar8d043172014-01-23 14:24:41 +010010086 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010087" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10088" 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 +010010089" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10090 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010091 unlet s:treecurpos
10092 endif
10093
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010094" 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>"))
10095" 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 +000010096" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10097endfun
10098
10099" ---------------------------------------------------------------------
10100" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010101fun! s:SetupNetrwStatusLine(statline)
10102" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10103
10104 if !exists("s:netrw_setup_statline")
10105 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010106" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010107
10108 if !exists("s:netrw_users_stl")
10109 let s:netrw_users_stl= &stl
10110 endif
10111 if !exists("s:netrw_users_ls")
10112 let s:netrw_users_ls= &laststatus
10113 endif
10114
10115 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +020010116 let dict={}
10117 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +000010118 redir @a
10119 try
10120 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010121 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010122 if &bg == "dark"
10123 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10124 else
10125 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10126 endif
10127 endtry
10128 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +020010129 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010130 endif
10131
10132 " set up status line (may use User9 highlighting)
10133 " insure that windows have a statusline
10134 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010135 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010136 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010137" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010138 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010139
10140" call Dret("SetupNetrwStatusLine : stl=".&stl)
10141endfun
10142
Bram Moolenaar85850f32019-07-19 22:05:51 +020010143" =========================================
10144" Remote Directory Browsing Support: {{{1
10145" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010146
10147" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010148" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10149" This function assumes that a long listing will be received. Size, time,
10150" and reverse sorts will be requested of the server but not otherwise
10151" enforced here.
10152fun! s:NetrwRemoteFtpCmd(path,listcmd)
10153" 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 +010010154" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010155 " sanity check: {{{3
10156 if !exists("w:netrw_method")
10157 if exists("b:netrw_method")
10158 let w:netrw_method= b:netrw_method
10159 else
10160 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10161" call Dret("NetrwRemoteFtpCmd")
10162 return
10163 endif
10164 endif
10165
10166 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10167 let ffkeep= &ff
10168 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010169" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010170
10171 " clear off any older non-banner lines " {{{3
10172 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010173" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10174 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010175
10176 ".........................................
10177 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10178 " ftp + <.netrc>: Method #2
10179 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010180 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010181 endif
10182 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010183 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010184" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010185 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010186 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010187" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010188 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010189" 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>"))
10190 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 +010010191 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010192" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10193 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 +010010194 endif
10195
10196 ".........................................
10197 elseif w:netrw_method == 3 " {{{3
10198 " ftp + machine,id,passwd,filename: Method #3
10199 setl ff=unix
10200 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010201 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010202 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010203 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010204 endif
10205
10206 " handle userid and password
10207 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010208" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010209 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10210 call NetUserPass("ftp:".host)
10211 endif
10212 if exists("g:netrw_uid") && g:netrw_uid != ""
10213 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010214 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010215 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010216 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010217 endif
10218 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010219 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010220 endif
10221 endif
10222
10223 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010224 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010225 endif
10226 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010227 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010228" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010229 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010230 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010231
10232 " perform ftp:
10233 " -i : turns off interactive prompting from ftp
10234 " -n unix : DON'T use <.netrc>, even though it exists
10235 " -n win32: quit being obnoxious about password
10236 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010237" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010238 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010239" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010240" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10241" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010242 endif
10243
10244 ".........................................
10245 elseif w:netrw_method == 9 " {{{3
10246 " sftp username@machine: Method #9
10247 " s:netrw_sftp_cmd
10248 setl ff=unix
10249
10250 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010251 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010252" call Dret("NetrwRemoteFtpCmd")
10253 return
10254
10255 ".........................................
10256 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010257 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010258 endif
10259
10260 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010261 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010262 sil! NetrwKeepj %s/\r$//e
10263 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010264 endif
10265 if a:listcmd == "dir"
10266 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010267 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10268 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10269 NetrwKeepj call histdel("/",-1)
10270 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010271 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 +010010272 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10273 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010274 endif
10275 endif
10276
10277 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10278 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010279 exe 'NetrwKeepj '.w:netrw_bannercnt
10280 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010281 endif
10282 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010283 exe 'NetrwKeepj '.w:netrw_bannercnt
10284 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010285 endif
10286
10287 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010288 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010289" call Dret("NetrwRemoteFtpCmd")
10290endfun
10291
10292" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010293" s:NetrwRemoteListing: {{{2
10294fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010295" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010296
Bram Moolenaara6878372014-03-22 21:02:50 +010010297 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10298 let w:netrw_bannercnt= s:bannercnt
10299 endif
10300 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010301 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010302 endif
10303
Bram Moolenaar446cb832008-06-24 21:56:24 +000010304 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010305
Bram Moolenaar446cb832008-06-24 21:56:24 +000010306 " sanity check:
10307 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010308" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010309 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010310" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010311 if !exists("g:netrw_quiet")
10312 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10313 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010314 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010315" call Dret("s:NetrwRemoteListing -1")
10316 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010317 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010318
Bram Moolenaar8d043172014-01-23 14:24:41 +010010319 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010320" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010321 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010322 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010323 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 +000010324 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010325 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 +000010326 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010327 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010328
Bram Moolenaar85850f32019-07-19 22:05:51 +020010329 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010330" call Dret("s:NetrwRemoteListing -1")
10331 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010332 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010333" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010334
Bram Moolenaar446cb832008-06-24 21:56:24 +000010335 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010336" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010337 let w:netrw_method= b:netrw_method
10338 endif
10339
Bram Moolenaar13600302014-05-22 18:26:40 +020010340 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010341 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010342" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010343 let s:method = "ftp"
10344 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010345 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010346 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010347 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010348 let listcmd= g:netrw_ftp_sizelist_cmd
10349 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010350" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010351 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010352" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010353
Bram Moolenaara6878372014-03-22 21:02:50 +010010354 " report on missing file or directory messages
10355 if search('[Nn]o such file or directory\|Failed to change directory')
10356 let mesg= getline(".")
10357 if exists("w:netrw_bannercnt")
10358 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010359 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010360 setl noma
10361 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010362 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010363 call netrw#ErrorMsg(s:WARNING,mesg,96)
10364" call Dret("s:NetrwRemoteListing : -1")
10365 return -1
10366 endif
10367
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010368 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 +000010369 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010370" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010371 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010372
10373 " cleanup
10374 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010375 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10376 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010377 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010378 sil! NetrwKeepj %s/\r$//e
10379 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010380
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010381 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010382 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010383 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010384 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010385" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010386 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010387" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010388 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010389 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010390 exe "sil! NetrwKeepj ".line1
10391 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010392
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010393" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010394 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010395" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010396 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10397 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010398 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010399" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010400 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10401 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10402 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10403 NetrwKeepj call histdel("/",-1)
10404 NetrwKeepj call histdel("/",-1)
10405 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010406 endif
10407 endif
10408
Bram Moolenaar13600302014-05-22 18:26:40 +020010409 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010410 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010411" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010412 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010413" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010414 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010415" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10416 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010417 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010418 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10419 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10420 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10421 NetrwKeepj call histdel("/",-1)
10422 NetrwKeepj call histdel("/",-1)
10423 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010424 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010425 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10426 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010427 endif
10428 else
10429 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010430" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010431 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010432 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010433" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10434 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10435" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010436 endif
10437 endif
10438
10439 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010440 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010441" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010442 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10443 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010444 endif
10445 endif
10446
10447 if w:netrw_liststyle == s:LONGLIST
10448 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010449" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010450
10451 if s:method == "ftp"
10452 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010453 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010454 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010455 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010456 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010457 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010458 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010459 sil! NetrwKeepj 1
10460 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010461 let line2= line(".")
10462 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010463 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010464 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010465 endif
10466 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010467 exe "sil! NetrwKeepj ".line1
10468 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010469 endif
10470
10471 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010472" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010473 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 +000010474 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010475" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010476 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010477 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010478 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10479 NetrwKeepj call histdel("/",-1)
10480 NetrwKeepj call histdel("/",-1)
10481 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010482 endif
10483 endif
10484
10485" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010486" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010487" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010488
10489" call Dret("s:NetrwRemoteListing 0")
10490 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010491endfun
10492
Bram Moolenaar446cb832008-06-24 21:56:24 +000010493" ---------------------------------------------------------------------
10494" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10495fun! s:NetrwRemoteRm(usrhost,path) range
10496" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010497" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010498 let svpos= winsaveview()
10499" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010500
10501 let all= 0
10502 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10503 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010504" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010505 for fname in s:netrwmarkfilelist_{bufnr("%")}
10506 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010507 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010508 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010509 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010510 let all= 1
10511 endif
10512 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010513 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010514
10515 else
10516 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010517" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010518
10519 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010520 let keepsol = &l:sol
10521 setl nosol
10522 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010523
10524 " remove multiple files and directories
10525 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010526 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010527 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010528 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010529 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010530 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010531 let all= 1
10532 endif
10533 let ctr= ctr + 1
10534 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010535 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010536 endif
10537
10538 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010539" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010540 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010541" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10542 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010543
10544" call Dret("s:NetrwRemoteRm")
10545endfun
10546
10547" ---------------------------------------------------------------------
10548" s:NetrwRemoteRmFile: {{{2
10549fun! s:NetrwRemoteRmFile(path,rmfile,all)
10550" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10551
10552 let all= a:all
10553 let ok = ""
10554
10555 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10556 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010557" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010558 if !all
10559 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010560" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010561 call inputsave()
10562 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10563 call inputrestore()
10564 echohl NONE
10565 if ok == ""
10566 let ok="no"
10567 endif
10568 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010569 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010570 let all= 1
10571 endif
10572 endif
10573
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010574 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010575" 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 +000010576 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010577" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010578 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010579 if path =~ '^\a\{3,}://'
10580 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010581 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010582 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010583 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10584 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010585" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010586 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010587" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010588 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010589 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010590 let ok="q"
10591 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010592 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010593" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10594" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10595" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010596 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010597 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010598 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010599 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010600 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010601" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010602 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010603 if v:shell_error != 0
10604 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010605 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 +010010606 else
10607 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10608 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010609 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010610 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010611 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010612" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010613 endif
10614 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010615 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010616" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010617 endif
10618
10619 else
10620 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010621" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010622 if !all
10623 call inputsave()
10624 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10625 call inputrestore()
10626 if ok == ""
10627 let ok="no"
10628 endif
10629 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010630 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010631 let all= 1
10632 endif
10633 endif
10634
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010635 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010636 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010637 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010638 else
10639 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010640 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10641" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010642 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010643" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010644
10645 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010646" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10647 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10648" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010649 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010650" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010651
10652 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010653 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010654 endif
10655 endif
10656 endif
10657
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010658 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010659" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010660 endif
10661 endif
10662
10663" call Dret("s:NetrwRemoteRmFile ".ok)
10664 return ok
10665endfun
10666
10667" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010668" s:NetrwRemoteRename: rename a remote file or directory {{{2
10669fun! s:NetrwRemoteRename(usrhost,path) range
10670" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10671
10672 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010673 let svpos = winsaveview()
10674" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010675 let ctr = a:firstline
10676 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10677
10678 " rename files given by the markfilelist
10679 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10680 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010681" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010682 if exists("subfrom")
10683 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010684" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010685 else
10686 call inputsave()
10687 let newname= input("Moving ".oldname." to : ",oldname)
10688 call inputrestore()
10689 if newname =~ '^s/'
10690 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10691 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10692 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010693" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010694 endif
10695 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010696
Bram Moolenaar446cb832008-06-24 21:56:24 +000010697 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010698 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010699 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010700 let oldname= s:ShellEscape(a:path.oldname)
10701 let newname= s:ShellEscape(a:path.newname)
10702" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010703 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010704 endif
10705
10706 endfor
10707 call s:NetrwUnMarkFile(1)
10708
10709 else
10710
10711 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010712 let keepsol= &l:sol
10713 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010714 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010715 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010716
10717 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010718" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010719
10720 call inputsave()
10721 let newname= input("Moving ".oldname." to : ",oldname)
10722 call inputrestore()
10723
10724 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10725 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10726 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010727 let oldname= s:ShellEscape(a:path.oldname)
10728 let newname= s:ShellEscape(a:path.newname)
10729" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010730 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010731 endif
10732
10733 let ctr= ctr + 1
10734 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010735 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010736 endif
10737
10738 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010739 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010740" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10741 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010742
10743" call Dret("NetrwRemoteRename")
10744endfun
10745
Bram Moolenaar85850f32019-07-19 22:05:51 +020010746" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010747" Local Directory Browsing Support: {{{1
10748" ==========================================
10749
10750" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010751" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010752" Should accept: file://localhost/etc/fstab
10753" file:///etc/fstab
10754" file:///c:/WINDOWS/clock.avi
10755" file:///c|/WINDOWS/clock.avi
10756" file://localhost/c:/WINDOWS/clock.avi
10757" file://localhost/c|/WINDOWS/clock.avi
10758" file://c:/foo.txt
10759" file:///c:/foo.txt
10760" 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 +020010761fun! netrw#FileUrlEdit(fname)
10762" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010763 let fname = a:fname
10764 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010765" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010766 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010767" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010768 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010769 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010770 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010771" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010772 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010773" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010774 endif
10775 endif
10776 let fname2396 = netrw#RFC2396(fname)
10777 let fname2396e= fnameescape(fname2396)
10778 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010779 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010780" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010781 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010782" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010783 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10784 endif
10785 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010786
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010787" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10788" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010789 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010790 exe 'NetrwKeepj keepalt edit '.plainfname
10791 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10792
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010793" 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 +020010794" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010795 exe "sil doau BufReadPost ".fname2396e
10796endfun
10797
10798" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010799" netrw#LocalBrowseCheck: {{{2
10800fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010801 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010802 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10803 "
10804 " unfortunate interaction -- split window debugging can't be used here, must use
10805 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10806 " another call to LocalBrowseCheck() when attempts to write
10807 " to the DBG buffer are made.
10808 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010809 " The &ft == "netrw" test was installed because the BufEnter event
10810 " would hit when re-entering netrw windows, creating unexpected
10811 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010812" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010813" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010814" 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 +010010815 " getting E930: Cannot use :redir inside execute
10816"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010817" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10818" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010819
Bram Moolenaar97d62492012-11-15 21:28:22 +010010820 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010821 if isdirectory(s:NetrwFile(a:dirname))
10822" 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 +010010823
Bram Moolenaar97d62492012-11-15 21:28:22 +010010824 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010825" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10826" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010827 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010828
Bram Moolenaar446cb832008-06-24 21:56:24 +000010829 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010830" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010831 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010832
Bram Moolenaar5c736222010-01-06 20:54:52 +010010833 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010834" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010835 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010836 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010837 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010838" 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 +010010839" call Dret("netrw#LocalBrowseCheck")
10840 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010841 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010842
Bram Moolenaar85850f32019-07-19 22:05:51 +020010843 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010844 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10845 " AND IF the listing style is not a tree listing
10846 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010847" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010848 let ibuf = 1
10849 let buflast = bufnr("$")
10850 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010851 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10852 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010853 endif
10854 let ibuf= ibuf + 1
10855 endwhile
10856 endif
10857 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010858" 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>"))
10859" 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 +000010860 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010861" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010862endfun
10863
10864" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010865" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010866" performed any shell command. The idea is to cause all local-browsing
10867" buffers to be refreshed after a user has executed some shell command,
10868" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010869fun! s:LocalBrowseRefresh()
10870" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010871" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10872" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010873
Bram Moolenaar446cb832008-06-24 21:56:24 +000010874 " determine which buffers currently reside in a tab
10875 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010876" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010877 return
10878 endif
10879 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010880" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010881 return
10882 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010883 if !empty(getcmdwintype())
10884 " cannot move away from cmdline window, see :h E11
10885 return
10886 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010887 if exists("s:netrw_events") && s:netrw_events == 1
10888 " s:LocalFastBrowser gets called (indirectly) from a
10889 let s:netrw_events= 2
10890" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10891 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010892 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010893 let itab = 1
10894 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010895 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010896 while itab <= tabpagenr("$")
10897 let buftablist = buftablist + tabpagebuflist()
10898 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010899 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010900 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010901" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10902" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010903 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10904 " | refresh any netrw window
10905 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010906 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010907 let ibl = 0
10908 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010909" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010910 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10911 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010912 " (ibuf not shown in a current window AND
10913 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010914" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10915 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010916 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010917" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010918 continue
10919 elseif index(tabpagebuflist(),ibuf) != -1
10920 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010921" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010922 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010923 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010924 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10925 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10926 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10927 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010928" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010929 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10930 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10931 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010932 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010933 endif
10934 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010935" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010936 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010937" call Decho("restore window: win_gotoid(".curwinid.")")
10938 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010939 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010940
Bram Moolenaara6878372014-03-22 21:02:50 +010010941" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010942endfun
10943
10944" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010945" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10946"
10947" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010948" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010949" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10950" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010951" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010952"
10953" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
10954" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010010955" (re-using a buffer may not be as accurate)
10956"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010957" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010010958" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
10959" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
10960" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
10961" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010962fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020010963" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
10964" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
10965" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
10966" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010967
10968 " initialize browselist, a list of buffer numbers that the local browser has used
10969 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010970" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010971 let s:netrw_browselist= []
10972 endif
10973
10974 " append current buffer to fastbrowse list
10975 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010976" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010977 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010978" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010979 endif
10980
10981 " enable autocmd events to handle refreshing/removing local browser buffers
10982 " If local browse buffer is currently showing: refresh it
10983 " If local browse buffer is currently hidden : wipe it
10984 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
10985 " =1 : medium speed, re-use directory listing for remote only
10986 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010010987 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
10988 let s:netrw_events= 1
10989 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010990 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020010991 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010992" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010993 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010994 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010995" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010996 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010997 endif
10998 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010010999
11000 " user must have changed fastbrowse to its fast setting, so remove
11001 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011002 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011003" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011004 unlet s:netrw_events
11005 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011006 au!
11007 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011008 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011009 endif
11010
Bram Moolenaar85850f32019-07-19 22:05:51 +020011011" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011012endfun
11013
11014" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011015" s:LocalListing: does the job of "ls" for local directories {{{2
11016fun! s:LocalListing()
11017" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011018" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11019" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11020" 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 +010011021
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011022" 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
11023" 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
11024" 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 +010011025
11026 " get the list of files contained in the current directory
11027 let dirname = b:netrw_curdir
11028 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011029 let filelist = s:NetrwGlob(dirname,"*",0)
11030 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011031" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011032
Nir Lichtman1e34b952024-05-08 19:19:34 +020011033 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011034" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011035 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11036 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011037" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011038 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011039" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011040 endif
11041
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011042" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011043" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011044" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011045
11046 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11047 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11048 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011049" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11050" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011051 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011052" 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 +010011053
11054 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011055" call Decho(" ",'~'.expand("<slnum>"))
11056" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011057
11058 if getftype(filename) == "link"
11059 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011060" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011061 let pfile= filename."@"
11062
11063 elseif getftype(filename) == "socket"
11064 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011065" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011066 let pfile= filename."="
11067
11068 elseif getftype(filename) == "fifo"
11069 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011070" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011071 let pfile= filename."|"
11072
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011073 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011074 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011075" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011076 let pfile= filename."/"
11077
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011078 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011079 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011080 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11081 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011082" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011083 let pfile= filename."*"
11084 else
11085 " normal file
11086 let pfile= filename
11087 endif
11088 elseif executable(filename)
11089 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011090" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011091 let pfile= filename."*"
11092 else
11093 " normal file
11094 let pfile= filename
11095 endif
11096
11097 else
11098 " normal file
11099 let pfile= filename
11100 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011101" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011102
11103 if pfile =~ '//$'
11104 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011105" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011106 endif
11107 let pfile= strpart(pfile,dirnamelen)
11108 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011109" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11110" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011111
11112 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011113 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11114 let sz = getfsize(filename)
11115 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11116 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011117
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011118 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011119 let sz= s:NetrwHumanReadable(sz)
11120 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011121 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011122 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011123" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011124 endif
11125
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011126 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011127 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011128 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011129" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011130" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011131 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011132 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011133" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011134 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011135 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011136
11137 elseif g:netrw_sort_by =~ "^s"
11138 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011139" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011140" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011141 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011142 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011143" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011144 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011145 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011146
11147 else
11148 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011149" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011150" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011151 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011152 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011153" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011154 endfor
11155
11156 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011157 sil! NetrwKeepj g/^$/d
11158 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011159 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011160" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011161 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11162
11163" call Dret("s:LocalListing")
11164endfun
11165
11166" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011167" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11168fun! s:NetrwLocalExecute(cmd)
11169" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11170 let ykeep= @@
11171 " sanity check
11172 if !executable(a:cmd)
11173 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11174 let @@= ykeep
11175" call Dret("s:NetrwLocalExecute")
11176 return
11177 endif
11178
11179 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011180" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011181 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011182" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011183
11184 " strip any ansi escape sequences off
11185 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11186
11187 " show user the result(s)
11188 echomsg result
11189 let @@= ykeep
11190
11191" call Dret("s:NetrwLocalExecute")
11192endfun
11193
11194" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011195" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011196fun! s:NetrwLocalRename(path) range
11197" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11198
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011199 if !exists("w:netrw_bannercnt")
11200 let w:netrw_bannercnt= b:netrw_bannercnt
11201 endif
11202
Bram Moolenaar97d62492012-11-15 21:28:22 +010011203 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011204 let ykeep = @@
11205 let ctr = a:firstline
11206 let svpos = winsaveview()
11207 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011208" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011209
11210 " rename files given by the markfilelist
11211 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11212 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011213" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011214 if exists("subfrom")
11215 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011216" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011217 else
11218 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011219 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011220 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011221 if newname =~ ''
11222 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11223 let newname = substitute(newname,'^.*','','')
11224 elseif newname =~ ''
11225 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11226 let newname = substitute(newname,'[^/]*','','')
11227 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011228 if newname =~ '^s/'
11229 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11230 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011231" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011232 let newname = substitute(oldname,subfrom,subto,'')
11233 endif
11234 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011235 if !all && filereadable(newname)
11236 call inputsave()
11237 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11238 call inputrestore()
11239 if response == "all"
11240 let all= 1
11241 elseif response != "y" && response != "yes"
11242 " refresh the directory
11243" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11244 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11245" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11246 NetrwKeepj call winrestview(svpos)
11247 let @@= ykeep
11248" call Dret("NetrwLocalRename")
11249 return
11250 endif
11251 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011252 call rename(oldname,newname)
11253 endfor
11254 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011255
Bram Moolenaar97d62492012-11-15 21:28:22 +010011256 else
11257
11258 " attempt to rename files/directories
11259 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011260 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011261
11262 " sanity checks
11263 if line(".") < w:netrw_bannercnt
11264 let ctr= ctr + 1
11265 continue
11266 endif
11267 let curword= s:NetrwGetWord()
11268 if curword == "./" || curword == "../"
11269 let ctr= ctr + 1
11270 continue
11271 endif
11272
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011273 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011274 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011275" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011276
11277 call inputsave()
11278 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11279 call inputrestore()
11280
11281 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011282" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011283
11284 let ctr= ctr + 1
11285 endwhile
11286 endif
11287
11288 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011289" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011290 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011291" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11292 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011293 let @@= ykeep
11294
11295" call Dret("NetrwLocalRename")
11296endfun
11297
11298" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011299" s:NetrwLocalRm: {{{2
11300fun! s:NetrwLocalRm(path) range
11301" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011302" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011303
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011304 if !exists("w:netrw_bannercnt")
11305 let w:netrw_bannercnt= b:netrw_bannercnt
11306 endif
11307
Bram Moolenaar446cb832008-06-24 21:56:24 +000011308 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011309 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011310 let ret = 0
11311 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011312 let svpos = winsaveview()
11313" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011314
11315 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11316 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011317" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011318 for fname in s:netrwmarkfilelist_{bufnr("%")}
11319 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011320 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011321 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011322 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011323 let all= 1
11324 endif
11325 endfor
11326 call s:NetrwUnMarkFile(1)
11327
11328 else
11329 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011330" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011331
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011332 let keepsol= &l:sol
11333 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011334 let ctr = a:firstline
11335 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011336 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011337
11338 " sanity checks
11339 if line(".") < w:netrw_bannercnt
11340 let ctr= ctr + 1
11341 continue
11342 endif
11343 let curword= s:NetrwGetWord()
11344 if curword == "./" || curword == "../"
11345 let ctr= ctr + 1
11346 continue
11347 endif
11348 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011349 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011350 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011351 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011352 let all= 1
11353 endif
11354 let ctr= ctr + 1
11355 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011356 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011357 endif
11358
11359 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011360" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011361 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011362 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011363" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11364 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011365 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011366 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011367
11368" call Dret("s:NetrwLocalRm")
11369endfun
11370
11371" ---------------------------------------------------------------------
11372" s:NetrwLocalRmFile: remove file fname given the path {{{2
11373" Give confirmation prompt unless all==1
11374fun! s:NetrwLocalRmFile(path,fname,all)
11375" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011376
Bram Moolenaar446cb832008-06-24 21:56:24 +000011377 let all= a:all
11378 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011379 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020011380 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011381" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011382
11383 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11384 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011385" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011386 if !all
11387 echohl Statement
11388 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011389 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011390 call inputrestore()
11391 echohl NONE
11392 if ok == ""
11393 let ok="no"
11394 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011395" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011396 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011397" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011398 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011399 let all= 1
11400 endif
11401 endif
11402
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011403 if all || ok =~# '^y\%[es]$' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011404 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011405" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011406 endif
11407
11408 else
11409 " attempt to remove directory
11410 if !all
11411 echohl Statement
11412 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011413 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011414 call inputrestore()
11415 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11416 if ok == ""
11417 let ok="no"
11418 endif
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011419 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011420 let all= 1
11421 endif
11422 endif
11423 let rmfile= substitute(rmfile,'[\/]$','','e')
11424
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011425 if all || ok =~# '^y\%[es]$' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011426 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011427 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011428 endif
11429 endif
11430 endif
11431
11432" call Dret("s:NetrwLocalRmFile ".ok)
11433 return ok
11434endfun
11435
Bram Moolenaar85850f32019-07-19 22:05:51 +020011436" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011437" Support Functions: {{{1
11438
Bram Moolenaar488c6512005-08-11 20:09:58 +000011439" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011440" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11441" 0: marked file list of current buffer
11442" 1: marked file target
11443fun! netrw#Access(ilist)
11444 if a:ilist == 0
11445 if exists("s:netrwmarkfilelist_".bufnr('%'))
11446 return s:netrwmarkfilelist_{bufnr('%')}
11447 else
11448 return "no-list-buf#".bufnr('%')
11449 endif
11450 elseif a:ilist == 1
11451 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011452 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011453endfun
11454
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011455" ---------------------------------------------------------------------
11456" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11457fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011458 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011459endfun
11460
Bram Moolenaara6878372014-03-22 21:02:50 +010011461" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011462" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11463" I expect this function to be used in
11464" :PChkAssert netrw#Expose("netrwmarkfilelist")
11465" for example.
11466fun! netrw#Expose(varname)
11467" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011468 if exists("s:".a:varname)
11469 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011470" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011471 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011472" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011473 if type(retval) == 3
11474 let retval = copy(retval)
11475 let i = 0
11476 while i < len(retval)
11477 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11478 let i = i + 1
11479 endwhile
11480 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011481" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011482 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011483 else
11484" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011485 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011486 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011487" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011488 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011489 endif
11490
11491" call Dret("netrw#Expose ".string(retval))
11492 return retval
11493endfun
11494
11495" ---------------------------------------------------------------------
11496" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11497fun! netrw#Modify(varname,newvalue)
11498" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11499 exe "let s:".a:varname."= ".string(a:newvalue)
11500" call Dret("netrw#Modify")
11501endfun
11502
11503" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011504" netrw#RFC2396: converts %xx into characters {{{2
11505fun! netrw#RFC2396(fname)
11506" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011507 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011508" call Dret("netrw#RFC2396 ".fname)
11509 return fname
11510endfun
11511
11512" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011513" netrw#UserMaps: supports user-specified maps {{{2
11514" see :help function()
11515"
11516" g:Netrw_UserMaps is a List with members such as:
11517" [[keymap sequence, function reference],...]
11518"
11519" The referenced function may return a string,
11520" refresh : refresh the display
11521" -other- : this string will be executed
11522" or it may return a List of strings.
11523"
11524" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011525" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011526" Related functions:
11527" netrw#Expose(varname) -- see s:varname variables
11528" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11529" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11530fun! netrw#UserMaps(islocal)
11531" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11532" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11533
11534 " set up usermaplist
11535 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11536" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11537 for umap in g:Netrw_UserMaps
11538" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11539" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11540 " if umap[0] is a string and umap[1] is a string holding a function name
11541 if type(umap[0]) == 1 && type(umap[1]) == 1
11542" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11543 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11544 else
11545 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11546 endif
11547 endfor
11548 endif
11549" call Dret("netrw#UserMaps")
11550endfun
11551
11552" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011553" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11554fun! netrw#WinPath(path)
11555" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011556 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011557 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011558 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011559 " remove trailing slash (Win95)
11560 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11561 " remove escaped spaces
11562 let path = substitute(path, '\ ', ' ', 'g')
11563 " convert slashes to backslashes
11564 let path = substitute(path, '/', '\', 'g')
11565 else
11566 let path= a:path
11567 endif
11568" call Dret("netrw#WinPath <".path.">")
11569 return path
11570endfun
11571
11572" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020011573" s:StripTrailingSlash: removes trailing slashes from a path {{{2
11574fun! s:StripTrailingSlash(path)
11575 " remove trailing slash
11576 return substitute(a:path, '[/\\]$', '', 'g')
11577endfun
11578
Travis Sheltone34d0e32024-07-30 21:08:56 +020011579" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011580" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11581" cb : bl2mf=0 add marked files to buffer list
11582" cB : bl2mf=1 use bufferlist to mark files
11583" (mnemonic: cb = copy (marked files) to buffer list)
11584fun! s:NetrwBadd(islocal,bl2mf)
11585" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11586 if a:bl2mf
11587 " cB: add buffer list to marked files
11588 redir => bufl
11589 ls
11590 redir END
11591 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11592 for fname in bufl
11593 call s:NetrwMarkFile(a:islocal,fname)
11594 endfor
11595 else
11596 " cb: add marked files to buffer list
11597 for fname in s:netrwmarkfilelist_{bufnr("%")}
11598" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11599 exe "badd ".fnameescape(fname)
11600 endfor
11601 let curbufnr = bufnr("%")
11602 let curdir = s:NetrwGetCurdir(a:islocal)
11603 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11604 endif
11605" call Dret("s:NetrwBadd")
11606endfun
11607
11608" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011609" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11610fun! s:ComposePath(base,subdir)
11611" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11612
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011613 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011614" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011615 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011616 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011617 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011618 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011619 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011620 endif
11621
Bram Moolenaar85850f32019-07-19 22:05:51 +020011622 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011623 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011624" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011625 let ret= a:subdir
11626
Nir Lichtman1e34b952024-05-08 19:19:34 +020011627 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011628" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011629 if a:base =~ '[/\\]$'
11630 let ret= a:base.a:subdir
11631 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011632 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011633 endif
11634
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011635 elseif a:base =~ '^\a\{3,}://'
11636" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011637 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11638 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11639 if a:subdir == '../'
11640 if curpath =~ '[^/]/[^/]\+/$'
11641 let curpath= substitute(curpath,'[^/]\+/$','','')
11642 else
11643 let curpath=""
11644 endif
11645 let ret= urlbase.curpath
11646 else
11647 let ret= urlbase.curpath.a:subdir
11648 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011649" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11650" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11651" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011652
11653 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011654" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011655 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11656 if a:base =~ '^//'
11657 " keeping initial '//' for the benefit of network share listing support
11658 let ret= '/'.ret
11659 endif
11660 let ret= simplify(ret)
11661 endif
11662
11663" call Dret("s:ComposePath ".ret)
11664 return ret
11665endfun
11666
11667" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011668" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11669" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11670fun! s:DeleteBookmark(fname)
11671" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11672 call s:MergeBookmarks()
11673
11674 if exists("g:netrw_bookmarklist")
11675 let indx= index(g:netrw_bookmarklist,a:fname)
11676 if indx == -1
11677 let indx= 0
11678 while indx < len(g:netrw_bookmarklist)
11679 if g:netrw_bookmarklist[indx] =~ a:fname
11680 call remove(g:netrw_bookmarklist,indx)
11681 let indx= indx - 1
11682 endif
11683 let indx= indx + 1
11684 endwhile
11685 else
11686 " remove exact match
11687 call remove(g:netrw_bookmarklist,indx)
11688 endif
11689 endif
11690
11691" call Dret("s:DeleteBookmark")
11692endfun
11693
11694" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011695" s:FileReadable: o/s independent filereadable {{{2
11696fun! s:FileReadable(fname)
11697" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11698
11699 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011700 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011701 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011702 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011703 endif
11704
11705" call Dret("s:FileReadable ".ret)
11706 return ret
11707endfun
11708
11709" ---------------------------------------------------------------------
11710" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11711" Places correct suffix on end of temporary filename,
11712" using the suffix provided with fname
11713fun! s:GetTempfile(fname)
11714" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11715
11716 if !exists("b:netrw_tmpfile")
11717 " get a brand new temporary filename
11718 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011719" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011720
Bram Moolenaarc236c162008-07-13 17:41:49 +000011721 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011722" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011723
Bram Moolenaar9964e462007-05-05 17:54:07 +000011724 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011725 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11726" 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 +010011727 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011728" call Dret("s:GetTempfile getcwd<".getcwd().">")
11729 return ""
11730 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011731
Bram Moolenaar9964e462007-05-05 17:54:07 +000011732 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011733 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011734" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011735
Bram Moolenaar9964e462007-05-05 17:54:07 +000011736 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011737 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011738 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011739 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011740 if !exists("+shellslash") || !&ssl
11741 let tmpfile = substitute(tmpfile,'/','\','g')
11742 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011743 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011744 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011745 endif
11746 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011747" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011748 else
11749 " re-use temporary filename
11750 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011751" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011752 endif
11753
11754 " use fname's suffix for the temporary file
11755 if a:fname != ""
11756 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011757" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011758 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011759 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011760 elseif a:fname =~ '.txz$'
11761 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011762 else
11763 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11764 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011765" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011766 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011767" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011768 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011769" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011770 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11771 endif
11772 endif
11773
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011774" 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 +000011775" call Dret("s:GetTempfile <".tmpfile.">")
11776 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011777endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011778
11779" ---------------------------------------------------------------------
11780" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011781" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011782fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011783" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011784 if s:user == ""
11785 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11786 else
11787 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11788 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011789 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011790 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011791 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011792 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011793 else
11794 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11795 endif
11796" call Dret("s:MakeSshCmd <".sshcmd.">")
11797 return sshcmd
11798endfun
11799
11800" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011801" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11802fun! s:MakeBookmark(fname)
11803" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11804
11805 if !exists("g:netrw_bookmarklist")
11806 let g:netrw_bookmarklist= []
11807 endif
11808
11809 if index(g:netrw_bookmarklist,a:fname) == -1
11810 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011811 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011812 call add(g:netrw_bookmarklist,a:fname.'/')
11813 elseif a:fname !~ '/'
11814 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11815 else
11816 call add(g:netrw_bookmarklist,a:fname)
11817 endif
11818 call sort(g:netrw_bookmarklist)
11819 endif
11820
11821" call Dret("s:MakeBookmark")
11822endfun
11823
11824" ---------------------------------------------------------------------
11825" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11826fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011827" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011828 " get bookmarks from .netrwbook file
11829 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011830 if filereadable(s:NetrwFile(savefile))
11831" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011832 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011833" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011834 NetrwKeepj call delete(savefile)
11835 endif
11836" call Dret("s:MergeBookmarks")
11837endfun
11838
11839" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011840" s:NetrwBMShow: {{{2
11841fun! s:NetrwBMShow()
11842" call Dfunc("s:NetrwBMShow()")
11843 redir => bmshowraw
11844 menu
11845 redir END
11846 let bmshowlist = split(bmshowraw,'\n')
11847 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011848 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011849 if bmshowfuncs != []
11850 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011851 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011852 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011853 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011854 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011855 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011856" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11857endfun
11858
11859" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011860" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011861fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011862 if !exists("w:netrw_liststyle")
11863 let w:netrw_liststyle= g:netrw_liststyle
11864 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011865" 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 +020011866
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011867" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11868
Bram Moolenaaradc21822011-04-01 18:03:16 +020011869 if &ft != "netrw"
11870 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11871 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011872" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011873
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011874 elseif g:netrw_cursor == 8
11875 if w:netrw_liststyle == s:WIDELIST
11876 setl cursorline
11877 setl cursorcolumn
11878 else
11879 setl cursorline
11880 endif
11881 elseif g:netrw_cursor == 7
11882 setl cursorline
11883 elseif g:netrw_cursor == 6
11884 if w:netrw_liststyle == s:WIDELIST
11885 setl cursorline
11886 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011887 elseif g:netrw_cursor == 4
11888 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011889" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011890 setl cursorline
11891 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011892
11893 elseif g:netrw_cursor == 3
11894 " thin-long-tree: cursorline, user's cursorcolumn
11895 " wide : cursorline, cursorcolumn
11896 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011897" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011898 setl cursorline
11899 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011900 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011901" 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 +020011902 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011903 endif
11904
11905 elseif g:netrw_cursor == 2
11906 " thin-long-tree: cursorline, user's cursorcolumn
11907 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011908" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011909 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011910
11911 elseif g:netrw_cursor == 1
11912 " thin-long-tree: user's cursorline, user's cursorcolumn
11913 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011914 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011915" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011916 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011917 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011918" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011919 endif
11920
11921 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011922 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011923" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011924 let &l:cursorline = s:netrw_usercul
11925 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011926 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011927
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011928" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011929" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011930endfun
11931
11932" ---------------------------------------------------------------------
11933" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11934fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011935" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011936 if exists("s:netrw_usercul")
11937 let &l:cursorline = s:netrw_usercul
11938 endif
11939 if exists("s:netrw_usercuc")
11940 let &l:cursorcolumn = s:netrw_usercuc
11941 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011942" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011943" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11944endfun
11945
Christian Brabandt62f7b552024-06-23 20:23:40 +020011946" s:RestoreRegister: restores all registers given in the dict {{{2
11947fun! s:RestoreRegister(dict)
11948 for [key, val] in items(a:dict)
11949 if key == 'unnamed'
11950 let key = ''
11951 endif
11952 call setreg(key, val[0], val[1])
11953 endfor
11954endfun
11955
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011956" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011957" s:NetrwDelete: Deletes a file. {{{2
11958" Uses Steve Hall's idea to insure that Windows paths stay
11959" acceptable. No effect on Unix paths.
11960" Examples of use: let result= s:NetrwDelete(path)
11961fun! s:NetrwDelete(path)
11962" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11963
Bram Moolenaar5c736222010-01-06 20:54:52 +010011964 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011965 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000011966 if exists("+shellslash")
11967 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011968 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011969 let result = delete(path)
11970 let &shellslash = sskeep
11971 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011972" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011973 let result= delete(path)
11974 endif
11975 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011976" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011977 let result= delete(path)
11978 endif
11979 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011980 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011981 endif
11982
11983" call Dret("s:NetrwDelete ".result)
11984 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000011985endfun
11986
11987" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011988" s:NetrwBufRemover: removes a buffer that: {{{2s
11989" has buffer-id > 1
11990" is unlisted
11991" is unnamed
11992" does not appear in any window
11993fun! s:NetrwBufRemover(bufid)
11994" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
11995" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
11996" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
11997" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
11998" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
11999
yasuda4dbb2662023-10-04 20:50:35 +020012000 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012001" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012002 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012003 endif
12004
12005" call Dret("s:NetrwBufRemover")
12006endfun
12007
12008" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012009" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012010fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012011" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012012" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012013
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012014 " Clean out the last buffer:
12015 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12016 " If so, delete it.
12017 call s:NetrwBufRemover(bufnr("$"))
12018
Bram Moolenaar446cb832008-06-24 21:56:24 +000012019 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012020" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012021 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12022 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12023 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12024 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12025 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12026 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12027 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12028 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12029 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12030 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12031 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12032 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12033 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12034 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12035 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12036 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12037
Bram Moolenaar85850f32019-07-19 22:05:51 +020012038 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012039" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012040 " when tree listing uses file TreeListing... a new buffer is made.
12041 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012042 " COMBAK: this causes a problem, see P43
12043" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012044 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012045 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012046 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012047" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012048 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012049
Bram Moolenaar446cb832008-06-24 21:56:24 +000012050 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012051" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012052 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12053 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12054 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12055 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12056 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12057 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12058 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12059 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12060 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12061 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12062 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12063 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12064 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12065 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12066 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12067 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12068
Bram Moolenaar5c736222010-01-06 20:54:52 +010012069 if a:0 > 0
12070 let b:netrw_curdir= a:1
12071 if b:netrw_curdir =~ '/$'
12072 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012073 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012074 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012075 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012076 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12077 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012078 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012079 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012080 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012081 endif
12082 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012083 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12084 let &l:bexpr = "netrw#BalloonHelp()"
12085 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012086
Bram Moolenaar8d043172014-01-23 14:24:41 +010012087" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012088endfun
12089
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012090" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012091" s:NetrwExe: executes a string using "!" {{{2
12092fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012093" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Konfekt3d7e5672024-10-27 22:16:49 +010012094 if has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012095" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012096 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12097 set shell& shellcmdflag& shellxquote& shellxescape&
12098 set shellquote& shellpipe& shellredir& shellslash&
Konfekt3d7e5672024-10-27 22:16:49 +010012099 try
12100 exe a:cmd
12101 finally
12102 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12103 endtry
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012104 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012105" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012106 exe a:cmd
12107 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012108 if v:shell_error
12109 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12110 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012111" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012112endfun
12113
12114" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012115" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12116fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012117 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012118" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012119 let curbuf = bufnr("%")
12120 let curwin = winnr()
12121 let iwin = 1
12122 while iwin <= winnr("$")
12123 exe iwin."wincmd w"
12124 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12125 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12126 let winvars= w:
12127 break
12128 endif
12129 let iwin= iwin + 1
12130 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012131 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012132 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012133" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012134 for k in keys(winvars)
12135 let w:{k}= winvars[k]
12136 endfor
12137 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012138" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012139 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012140endfun
12141
Bram Moolenaara6878372014-03-22 21:02:50 +010012142" ---------------------------------------------------------------------
12143" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012144" Returns: 0=success
12145" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012146fun! s:NetrwLcd(newdir)
12147" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012148" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012149
Bram Moolenaar85850f32019-07-19 22:05:51 +020012150 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012151 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012152 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012153 catch /^Vim\%((\a\+)\)\=:E344/
12154 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12155 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012156 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012157 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12158 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012159 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012160 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12161 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012162 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012163 endif
12164 endif
12165 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012166 let err472= 1
12167 endtry
12168
12169 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012170 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12171 if exists("w:netrw_prvdir")
12172 let a:newdir= w:netrw_prvdir
12173 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012174 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012175" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012176 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012177" 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 +010012178 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012179 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012180" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12181 return -1
12182 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012183
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012184" call Decho("getcwd <".getcwd().">")
12185" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012186" call Dret("s:NetrwLcd 0")
12187 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012188endfun
12189
Bram Moolenaar9964e462007-05-05 17:54:07 +000012190" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012191" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12192" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12193fun! s:NetrwSaveWordPosn()
12194" call Dfunc("NetrwSaveWordPosn()")
12195 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12196" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12197endfun
12198
12199" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012200" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12201" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12202fun! s:NetrwHumanReadable(sz)
12203" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12204
12205 if g:netrw_sizestyle == 'h'
12206 if a:sz >= 1000000000
12207 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12208 elseif a:sz >= 10000000
12209 let sz = printf("%d",a:sz/1000000)."m"
12210 elseif a:sz >= 1000000
12211 let sz = printf("%.1f",a:sz/1000000.0)."m"
12212 elseif a:sz >= 10000
12213 let sz = printf("%d",a:sz/1000)."k"
12214 elseif a:sz >= 1000
12215 let sz = printf("%.1f",a:sz/1000.0)."k"
12216 else
12217 let sz= a:sz
12218 endif
12219
12220 elseif g:netrw_sizestyle == 'H'
12221 if a:sz >= 1073741824
12222 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12223 elseif a:sz >= 10485760
12224 let sz = printf("%d",a:sz/1048576)."M"
12225 elseif a:sz >= 1048576
12226 let sz = printf("%.1f",a:sz/1048576.0)."M"
12227 elseif a:sz >= 10240
12228 let sz = printf("%d",a:sz/1024)."K"
12229 elseif a:sz >= 1024
12230 let sz = printf("%.1f",a:sz/1024.0)."K"
12231 else
12232 let sz= a:sz
12233 endif
12234
12235 else
12236 let sz= a:sz
12237 endif
12238
12239" call Dret("s:NetrwHumanReadable ".sz)
12240 return sz
12241endfun
12242
12243" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012244" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12245" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12246fun! s:NetrwRestoreWordPosn()
12247" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012248 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012249" call Dret("NetrwRestoreWordPosn")
12250endfun
12251
12252" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012253" s:RestoreBufVars: {{{2
12254fun! s:RestoreBufVars()
12255" call Dfunc("s:RestoreBufVars()")
12256
12257 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12258 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12259 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12260 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12261 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12262 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12263
12264" call Dret("s:RestoreBufVars")
12265endfun
12266
12267" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012268" s:RemotePathAnalysis: {{{2
12269fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012270" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012271
Bram Moolenaara6878372014-03-22 21:02:50 +010012272 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012273 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012274 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012275 let s:user = substitute(a:dirname,dirpat,'\3','')
12276 let s:machine = substitute(a:dirname,dirpat,'\4','')
12277 let s:port = substitute(a:dirname,dirpat,'\5','')
12278 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012279 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012280 if s:machine =~ '@'
12281 let dirpat = '^\(.*\)@\(.\{-}\)$'
12282 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12283 let s:machine = substitute(s:machine,dirpat,'\2','')
12284 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012285
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012286" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12287" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12288" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12289" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12290" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12291" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012292
12293" call Dret("s:RemotePathAnalysis")
12294endfun
12295
12296" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012297" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12298" Returns status
12299" Runs system() on
12300" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012301" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012302fun! s:RemoteSystem(cmd)
12303" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12304 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012305 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 +000012306 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012307 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012308 else
12309 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12310 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12311 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012312 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012313 else
12314 let cmd= cmd.' '
12315 endif
12316 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012317" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012318 let ret= system(cmd)
12319 endif
12320" call Dret("s:RemoteSystem ".ret)
12321 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012322endfun
12323
12324" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012325" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012326fun! s:RestoreWinVars()
12327" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012328 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012329 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12330 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12331 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12332 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12333 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12334 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12335 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12336 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12337 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12338 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12339 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12340 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012341 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12342 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012343 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12344 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12345 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12346" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012347endfun
12348
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012349" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012350" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12351"
12352" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12353" is true) and a command, :Rexplore, which call this function.
12354"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012355" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012356"
12357" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012358fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012359 if exists("s:netrwdrag")
12360 return
12361 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012362" 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 +010012363" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12364" 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 +010012365
12366 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012367 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012368" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012369 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012370 unlet w:netrw_rexfile
12371" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012372 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012373" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012374" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12375" 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 +020012376 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012377
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012378 " ---------------------------
12379 " :Rex issued while in a file
12380 " ---------------------------
12381
Bram Moolenaara6878372014-03-22 21:02:50 +010012382 " record current file so :Rex can return to it from netrw
12383 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012384" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012385
12386 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012387" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012388 return
12389 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012390" 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 +020012391 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012392 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012393 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012394 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012395 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012396 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012397 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012398 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012399 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012400" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12401 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012402" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12403 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012404 if exists("s:rexposn_".bufnr('%'))
12405 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012406 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012407 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012408" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012409 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012410
Bram Moolenaar85850f32019-07-19 22:05:51 +020012411 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12412 if exists("s:explore_match")
12413 exe "2match netrwMarkFile /".s:explore_match."/"
12414 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012415 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012416
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012417" 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 +010012418" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012419endfun
12420
12421" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012422" s:SaveBufVars: save selected b: variables to s: variables {{{2
12423" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012424fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012425" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012426
12427 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12428 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12429 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12430 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12431 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12432 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12433
12434" call Dret("s:SaveBufVars")
12435endfun
12436
12437" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012438" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12439fun! s:SavePosn(posndict)
12440" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12441
Bram Moolenaar85850f32019-07-19 22:05:51 +020012442 if !exists("a:posndict[bufnr('%')]")
12443 let a:posndict[bufnr("%")]= []
12444 endif
12445" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12446 call add(a:posndict[bufnr("%")],winsaveview())
12447" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012448
12449" call Dret("s:SavePosn posndict")
12450 return a:posndict
12451endfun
12452
12453" ---------------------------------------------------------------------
12454" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12455fun! s:RestorePosn(posndict)
12456" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012457 if exists("a:posndict")
12458 if has_key(a:posndict,bufnr("%"))
12459" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12460 let posnlen= len(a:posndict[bufnr("%")])
12461 if posnlen > 0
12462 let posnlen= posnlen - 1
12463" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12464 call winrestview(a:posndict[bufnr("%")][posnlen])
12465 call remove(a:posndict[bufnr("%")],posnlen)
12466" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12467 endif
12468 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012469 endif
12470" call Dret("s:RestorePosn")
12471endfun
12472
12473" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012474" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012475fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012476" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012477 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12478 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12479 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12480 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12481 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12482 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12483 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12484 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12485 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12486 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12487 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12488 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12489 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12490 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12491 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12492 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12493 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12494 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12495" call Dret("s:SaveWinVars")
12496endfun
12497
12498" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012499" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012500" To allow separate windows to have their own activities, such as
12501" Explore **/pattern, several variables have been made window-oriented.
12502" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012503" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012504" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012505fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012506" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012507 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12508 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12509 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12510 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12511 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12512 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12513 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12514 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12515 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12516 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12517" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012518endfun
12519
12520" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012521" s:SetRexDir: set directory for :Rexplore {{{2
12522fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012523" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012524 let w:netrw_rexdir = a:dirname
12525 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012526 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012527" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12528" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012529" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012530" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012531" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012532endfun
12533
12534" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012535" s:ShowLink: used to modify thin and tree listings to show links {{{2
12536fun! s:ShowLink()
12537" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012538" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12539" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012540 if exists("b:netrw_curdir")
12541 norm! $?\a
12542 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12543 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012544" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12545" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12546" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12547 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012548 let dirlen = strlen(b:netrw_curdir)
12549 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012550" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012551 endif
12552 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012553" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12554" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012555 setl noro ma
12556 call setline(".",modline)
12557 setl ro noma nomod
12558 endif
12559" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12560endfun
12561
12562" ---------------------------------------------------------------------
12563" s:ShowStyle: {{{2
12564fun! s:ShowStyle()
12565 if !exists("w:netrw_liststyle")
12566 let liststyle= g:netrw_liststyle
12567 else
12568 let liststyle= w:netrw_liststyle
12569 endif
12570 if liststyle == s:THINLIST
12571 return s:THINLIST.":thin"
12572 elseif liststyle == s:LONGLIST
12573 return s:LONGLIST.":long"
12574 elseif liststyle == s:WIDELIST
12575 return s:WIDELIST.":wide"
12576 elseif liststyle == s:TREELIST
12577 return s:TREELIST.":tree"
12578 else
12579 return 'n/a'
12580 endif
12581endfun
12582
12583" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012584" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12585" Solution from Nicolai Weibull, vim docs (:help strlen()),
12586" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012587fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012588" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12589
12590 if v:version >= 703 && exists("*strdisplaywidth")
12591 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012592
Bram Moolenaar8d043172014-01-23 14:24:41 +010012593 elseif type(g:Align_xstrlen) == 1
12594 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12595 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012596
Bram Moolenaar8d043172014-01-23 14:24:41 +010012597 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012598 " number of codepoints (Latin a + combining circumflex is two codepoints)
12599 " (comment from TM, solution from NW)
12600 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012601
Bram Moolenaar8d043172014-01-23 14:24:41 +010012602 elseif g:Align_xstrlen == 2
12603 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012604 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12605 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012606 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012607
Bram Moolenaar8d043172014-01-23 14:24:41 +010012608 elseif g:Align_xstrlen == 3
12609 " virtual length (counting, for instance, tabs as anything between 1 and
12610 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012611 " preceded by lam, one otherwise, etc.)
12612 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012613 let modkeep= &l:mod
12614 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012615 call setline(line("."),a:x)
12616 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012617 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012618 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012619 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012620
Bram Moolenaar446cb832008-06-24 21:56:24 +000012621 else
12622 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012623 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012624 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012625" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012626 return ret
12627endfun
12628
12629" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012630" s:ShellEscape: shellescape(), or special windows handling {{{2
12631fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012632 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012633 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12634 endif
12635 let f = a:0 > 0 ? a:1 : 0
12636 return shellescape(a:s, f)
12637endfun
12638
12639" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012640" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012641fun! s:TreeListMove(dir)
12642" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012643 let curline = getline('.')
12644 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12645 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12646 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12647 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12648 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12649 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12650" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12651" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12652" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12653" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12654" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12655 " COMBAK : need to handle when on a directory
12656 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012657 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012658 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012659 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012660 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012661" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012662 elseif a:dir == '[]' && nxtline != ''
12663 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012664" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012665 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12666 if nl != 0
12667 NetrwKeepj norm! k
12668 else
12669 NetrwKeepj norm! G
12670 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012671" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012672 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012673 endif
12674
12675" call Dret("s:TreeListMove")
12676endfun
12677
12678" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012679" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12680" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12681" can't be called except via emenu. But due to locale, that menu line may not be called
12682" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12683fun! s:UpdateBuffersMenu()
12684" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012685 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012686 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012687 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012688 catch /^Vim\%((\a\+)\)\=:E/
12689 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012690 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012691 endtry
12692 endif
12693" call Dret("s:UpdateBuffersMenu")
12694endfun
12695
12696" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012697" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012698" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012699fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012700" call Dfunc("s:UseBufWinVars()")
12701 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012702 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12703 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12704 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12705 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12706 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12707 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12708 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12709 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12710 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 +000012711" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012712endfun
12713
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012714" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012715" s:UserMaps: supports user-defined UserMaps {{{2
12716" * calls a user-supplied funcref(islocal,curdir)
12717" * interprets result
12718" See netrw#UserMaps()
12719fun! s:UserMaps(islocal,funcname)
12720" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12721
12722 if !exists("b:netrw_curdir")
12723 let b:netrw_curdir= getcwd()
12724 endif
12725 let Funcref = function(a:funcname)
12726 let result = Funcref(a:islocal)
12727
12728 if type(result) == 1
12729 " if result from user's funcref is a string...
12730" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12731 if result == "refresh"
12732" call Decho("refreshing display",'~'.expand("<slnum>"))
12733 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12734 elseif result != ""
12735" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12736 exe result
12737 endif
12738
12739 elseif type(result) == 3
12740 " if result from user's funcref is a List...
12741" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12742 for action in result
12743 if action == "refresh"
12744" call Decho("refreshing display",'~'.expand("<slnum>"))
12745 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12746 elseif action != ""
12747" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12748 exe action
12749 endif
12750 endfor
12751 endif
12752
12753" call Dret("s:UserMaps")
12754endfun
12755
Bram Moolenaar85850f32019-07-19 22:05:51 +020012756" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012757" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012758" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012759let &cpo= s:keepcpo
12760unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012761
Bram Moolenaar85850f32019-07-19 22:05:51 +020012762" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012763" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012764" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012765" vim:ts=8 fdm=marker