blob: 04a556980f0f896196efbf9c8eb74404a4163f1a [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" netrw.vim: Handles file transfer and remote directory listing across
2" AUTOLOAD SECTION
Christian Brabandtf9ca1392024-02-19 20:37:11 +01003" Maintainer: This runtime file is looking for a new maintainer.
4" Date: May 03, 2023
Christian Brabandtcb0c1132023-11-21 18:48:16 +00005" Version: 173a
Travis Sheltone34d0e32024-07-30 21:08:56 +02006" Last Change: {{{1
Luca Saccarolaa7d45612024-10-21 21:27:03 +02007" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
8" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
Christian Brabandt8fad5d52024-02-29 18:12:30 +01009" 2024 Feb 19 by Vim Project: (announce adoption)
10" 2024 Feb 29 by Vim Project: handle symlinks in tree mode correctly
Christian Brabandt08d24012024-04-03 22:44:27 +020011" 2024 Apr 03 by Vim Project: detect filetypes for remote edited files
Nir Lichtman1e34b952024-05-08 19:19:34 +020012" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
Nir Lichtmance2ad9f2024-05-09 20:20:36 +020013" 2024 May 09 by Vim Project: remove hard-coded private.ppk
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020014" 2024 May 10 by Vim Project: recursively delete directories by default
Christian Brabandt43f2edc2024-05-13 20:56:43 +020015" 2024 May 13 by Vim Project: prefer scp over pscp
Christian Brabandt98b73eb2024-06-04 18:15:57 +020016" 2024 Jun 04 by Vim Project: set bufhidden if buffer changed, nohidden is set and buffer shall be switched (#14915)
Christian Brabandt14879472024-06-13 21:25:35 +020017" 2024 Jun 13 by Vim Project: glob() on Windows fails when a directory name contains [] (#14952)
Enno3146d632024-07-04 19:44:42 +020018" 2024 Jun 23 by Vim Project: save ad restore registers when liststyle = WIDELIST (#15077, #15114)
Damien9d57ea52024-07-22 20:23:48 +020019" 2024 Jul 22 by Vim Project: avoid endless recursion (#15318)
Christian Brabandt581d4a72024-07-23 21:14:06 +020020" 2024 Jul 23 by Vim Project: escape filename before trying to delete it (#15330)
Travis Sheltone34d0e32024-07-30 21:08:56 +020021" 2024 Jul 30 by Vim Project: handle mark-copy to same target directory (#12112)
Ivan Shapovalovc527d902024-08-02 19:43:12 +020022" 2024 Aug 02 by Vim Project: honor g:netrw_alt{o,v} for :{S,H,V}explore (#15417)
Damien7c754112024-08-15 21:58:57 +020023" 2024 Aug 15 by Vim Project: style changes, prevent E121 (#15501)
yasuda38cfa2b2024-08-22 20:54:47 +020024" 2024 Aug 22 by Vim Project: fix mf-selection highlight (#15551)
yasudac75dad02024-08-22 21:06:32 +020025" 2024 Aug 22 by Vim Project: adjust echo output of mx command (#15550)
Christian Brabandt0f5effb2024-09-15 19:17:23 +020026" 2024 Sep 15 by Vim Project: more strict confirmation dialog (#15680)
yasudac18a9d52024-09-19 18:09:51 +020027" 2024 Sep 19 by Vim Project: mf-selection highlight uses wrong pattern (#15700)
Peter Aronoffbe551da2024-09-22 11:29:40 +020028" 2024 Sep 21 by Vim Project: remove extraneous closing bracket (#15718)
Luca Saccarolaa7d45612024-10-21 21:27:03 +020029" 2024 Oct 21 by Vim Project: remove netrwFileHandlers (#15895)
Konfekt3d7e5672024-10-27 22:16:49 +010030" 2024 Oct 27 by Vim Project: clean up gx mapping (#15721)
Christian Brabandtaa2ce6f2024-10-30 18:27:03 +010031" 2024 Oct 30 by Vim Project: fix filetype detection for remote files (#15961)
Christian Brabandt9f320692024-10-30 18:36:20 +010032" 2024 Oct 30 by Vim Project: fix x mapping on cygwin (#13687)
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010033" 2024 Oct 31 by Vim Project: add netrw#Launch() and netrw#Open() (#15962)
Travis Sheltone34d0e32024-07-30 21:08:56 +020034" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010035" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000036" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010037" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000038" Permission is hereby granted to use and distribute this code,
39" with or without modifications, provided that this copyright
40" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000041" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000042" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000043" expressed or implied. By using this plugin, you agree that
44" in no event will the copyright holder be liable for any damages
45" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010046"
47" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
48" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
49"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020050"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000051"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000052" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000053" (James 1:22 RSV)
54" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000055" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000056if &cp || exists("g:loaded_netrw")
57 finish
58endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020059
60" Check that vim has patches that netrw requires.
61" Patches needed for v7.4: 1557, and 213.
62" (netrw will benefit from vim's having patch#656, too)
63let s:needspatches=[1557,213]
64if exists("s:needspatches")
65 for ptch in s:needspatches
66 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
67 if !exists("s:needpatch{ptch}")
68 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
69 endif
70 let s:needpatch{ptch}= 1
71 finish
72 endif
73 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020074endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020075
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010076let g:loaded_netrw = "v173"
Bram Moolenaar446cb832008-06-24 21:56:24 +000077
Bram Moolenaar1afcace2005-11-25 19:54:28 +000078let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010079setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020080"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010081"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010082"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000083
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000084" ======================
85" Netrw Variables: {{{1
86" ======================
87
Bram Moolenaar071d4272004-06-13 20:20:40 +000088" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020089" netrw#ErrorMsg: {{{2
90" 0=note = s:NOTE
91" 1=warning = s:WARNING
92" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010093" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
94" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
95" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010096" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020097fun! netrw#ErrorMsg(level,msg,errnum)
98" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
99
100 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200101" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200102 return
103 endif
104
105 if a:level == 1
106 let level= "**warning** (netrw) "
107 elseif a:level == 2
108 let level= "**error** (netrw) "
109 else
110 let level= "**note** (netrw) "
111 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100112" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200113
Damienb4d11642024-08-15 22:00:45 +0200114 if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200115 " use popup window
116 if type(a:msg) == 3
117 let msg = [level]+a:msg
118 else
119 let msg= level.a:msg
120 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200121 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200122 let s:popuperr_text= ""
123 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200124 " (default) netrw creates a one-line window to show error/warning
125 " messages (reliably displayed)
126
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100127 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200128 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100129" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200130
131 " getting messages out reliably is just plain difficult!
132 " This attempt splits the current window, creating a one line window.
133 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100134" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200135 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100136" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200137 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100138 if type(a:msg) == 3
139 for msg in a:msg
140 NetrwKeepj call setline(line("$")+1,level.msg)
141 endfor
142 else
143 NetrwKeepj call setline(line("$")+1,level.a:msg)
144 endif
145 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200146 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100147" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200148 bo 1split
149 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200150 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200151 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100152 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100153" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200154 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100155 if type(a:msg) == 3
156 for msg in a:msg
157 NetrwKeepj call setline(line("$")+1,level.msg)
158 endfor
159 else
160 NetrwKeepj call setline(line("$"),level.a:msg)
161 endif
162 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200163 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100164" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200165 if &fo !~ '[ta]'
166 syn clear
167 syn match netrwMesgNote "^\*\*note\*\*"
168 syn match netrwMesgWarning "^\*\*warning\*\*"
169 syn match netrwMesgError "^\*\*error\*\*"
170 hi link netrwMesgWarning WarningMsg
171 hi link netrwMesgError Error
172 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100173" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200174 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200175
176 else
177 " (optional) netrw will show messages using echomsg. Even if the
178 " message doesn't appear, at least it'll be recallable via :messages
179" redraw!
180 if a:level == s:WARNING
181 echohl WarningMsg
182 elseif a:level == s:ERROR
183 echohl Error
184 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100185
186 if type(a:msg) == 3
187 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100188 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100189 endfor
190 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100191 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100192 endif
193
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100194" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200195 echohl None
196 endif
197
198" call Dret("netrw#ErrorMsg")
199endfun
200
201" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100202" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100203" Loosely, varname = value.
204fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100205" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100206 if !exists(a:varname)
207 if type(a:value) == 0
208 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200209 elseif type(a:value) == 1 && a:value =~ '^[{[]'
210 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100211 elseif type(a:value) == 1
212 exe "let ".a:varname."="."'".a:value."'"
213 else
214 exe "let ".a:varname."=".a:value
215 endif
216 endif
217endfun
218
219" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000220" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200221call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000222if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100223 call s:NetrwInit("s:THINLIST",0)
224 call s:NetrwInit("s:LONGLIST",1)
225 call s:NetrwInit("s:WIDELIST",2)
226 call s:NetrwInit("s:TREELIST",3)
227 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000228endif
229
Damien7c754112024-08-15 21:58:57 +0200230let s:NOTE = 0
231let s:WARNING = 1
232let s:ERROR = 2
233call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
234
Bram Moolenaar9964e462007-05-05 17:54:07 +0000235" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200236" Default option values: {{{2
237let g:netrw_localcopycmdopt = ""
238let g:netrw_localcopydircmdopt = ""
239let g:netrw_localmkdiropt = ""
240let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200241
242" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000243" Default values for netrw's global protocol variables {{{2
Damienb4d11642024-08-15 22:00:45 +0200244if exists("*popup_atcursor")
245\ && has("syntax")
246\ && exists("g:syntax_on")
247\ && has("mouse")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200248 call s:NetrwInit("g:netrw_use_errorwindow",2)
249else
250 call s:NetrwInit("g:netrw_use_errorwindow",1)
251endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200252
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000253if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100254 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000255 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100256 elseif executable("curl")
257 let g:netrw_dav_cmd = "curl"
258 else
259 let g:netrw_dav_cmd = ""
260 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000261endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000262if !exists("g:netrw_fetch_cmd")
263 if executable("fetch")
264 let g:netrw_fetch_cmd = "fetch -o"
265 else
266 let g:netrw_fetch_cmd = ""
267 endif
268endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100269if !exists("g:netrw_file_cmd")
270 if executable("elinks")
271 call s:NetrwInit("g:netrw_file_cmd","elinks")
272 elseif executable("links")
273 call s:NetrwInit("g:netrw_file_cmd","links")
274 endif
275endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000276if !exists("g:netrw_ftp_cmd")
277 let g:netrw_ftp_cmd = "ftp"
278endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200279let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200280if !exists("g:netrw_ftp_options")
281 let g:netrw_ftp_options= "-i -n"
282endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000283if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100284 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100285 let g:netrw_http_cmd = "wget"
286 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100287 elseif executable("curl")
288 let g:netrw_http_cmd = "curl"
289 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200290 elseif executable("elinks")
291 let g:netrw_http_cmd = "elinks"
292 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000293 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100294 let g:netrw_http_cmd = "fetch"
295 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200296 elseif executable("links")
297 let g:netrw_http_cmd = "links"
298 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000299 else
300 let g:netrw_http_cmd = ""
301 endif
302endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100303call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100304call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100305call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
306call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200307call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200308if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200309 if executable("scp")
310 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
311 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200312 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200313 else
314 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
315 endif
316endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100317call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
318call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000319
Nir Lichtman1e34b952024-05-08 19:19:34 +0200320if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000321 \ && exists("g:netrw_use_nt_rcp")
322 \ && g:netrw_use_nt_rcp
323 \ && executable( $SystemRoot .'/system32/rcp.exe')
324 let s:netrw_has_nt_rcp = 1
325 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000326else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000327 let s:netrw_has_nt_rcp = 0
328 let s:netrw_rcpmode = ''
329endif
330
331" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000332" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000333" Cygwin Detection ------- {{{3
334if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200335 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
336 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000337 else
338 let g:netrw_cygwin= 0
339 endif
340endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000341" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100342call s:NetrwInit("g:netrw_alto" , &sb)
343call s:NetrwInit("g:netrw_altv" , &spr)
344call s:NetrwInit("g:netrw_banner" , 1)
345call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200346call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100347call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200348call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100349call s:NetrwInit("g:netrw_compress" , "gzip")
350call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200351if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
352 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
353 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000354endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200355call s:NetrwInit("g:netrw_cursor" , 2)
356let s:netrw_usercul = &cursorline
357let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200358"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100359call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000360" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200361call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200362call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200363call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100364call s:NetrwInit("g:netrw_dirhistmax" , 10)
365call s:NetrwInit("g:netrw_fastbrowse" , 1)
366call 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 +0000367if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000368 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
369 let g:netrw_ftp_list_cmd = "ls -lF"
370 let g:netrw_ftp_timelist_cmd = "ls -tlF"
371 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000372 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000373 let g:netrw_ftp_list_cmd = "dir"
374 let g:netrw_ftp_timelist_cmd = "dir"
375 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000376 endif
377endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100378call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000379" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100380call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000381if !exists("g:netrw_ignorenetrc")
382 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
383 let g:netrw_ignorenetrc= 1
384 else
385 let g:netrw_ignorenetrc= 0
386 endif
387endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100388call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000389if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000390 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100391 if exists("g:netrw_list_cmd_options")
392 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
393 else
394 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
395 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000396 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200397 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100398 if exists("g:netrw_list_cmd_options")
399 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
400 else
401 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
402 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000403 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100404" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000405 let g:netrw_list_cmd= ""
406 endif
407endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100408call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000409" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200410if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200411 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200412 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
413endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100414if !exists("g:netrw_localcmdshell")
415 let g:netrw_localcmdshell= ""
416endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000417if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200418 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000419 if g:netrw_cygwin
420 let g:netrw_localcopycmd= "cp"
421 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000422 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200423 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000424 endif
425 elseif has("unix") || has("macunix")
426 let g:netrw_localcopycmd= "cp"
427 else
428 let g:netrw_localcopycmd= ""
429 endif
430endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100431if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200432 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100433 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200434 let g:netrw_localcopydircmd = "cp"
435 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100436 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000437 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200438 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100439 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200440 elseif has("unix")
441 let g:netrw_localcopydircmd = "cp"
442 let g:netrw_localcopydircmdopt= " -R"
443 elseif has("macunix")
444 let g:netrw_localcopydircmd = "cp"
445 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100446 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200447 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100448 endif
449endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200450if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100451 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200452 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
453endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200454if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200455 if g:netrw_cygwin
456 call s:NetrwInit("g:netrw_localmkdir","mkdir")
457 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000458 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200459 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200460 endif
461else
462 call s:NetrwInit("g:netrw_localmkdir","mkdir")
463endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200464call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200465if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200466 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200467 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
468endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000469if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200470 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000471 if g:netrw_cygwin
472 let g:netrw_localmovecmd= "mv"
473 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000474 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200475 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000476 endif
477 elseif has("unix") || has("macunix")
478 let g:netrw_localmovecmd= "mv"
479 else
480 let g:netrw_localmovecmd= ""
481 endif
482endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100483" following serves as an example for how to insert a version&patch specific test
484"if v:version < 704 || (v:version == 704 && !has("patch1107"))
485"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100486call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
487" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000488if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000489 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000490endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000491if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000492 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
493endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000494" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100495call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
496call s:NetrwInit("g:netrw_maxfilenamelen", 32)
497call s:NetrwInit("g:netrw_menu" , 1)
498call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200499call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100500call s:NetrwInit("g:netrw_retmap" , 0)
501if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
502 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200503elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100504 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
505else
506 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000507endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100508call s:NetrwInit("g:netrw_preview" , 0)
509call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100510call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100511call s:NetrwInit("g:netrw_sshport" , "-p")
512call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
513call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
514call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100515call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
516" Default values - q-s ---------- {{{3
517call s:NetrwInit("g:netrw_quickhelp",0)
518let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100519 \ "(create new) %:file d:directory",
520 \ "(windows split&open) o:horz v:vert p:preview",
521 \ "i:style qf:file info O:obtain r:reverse",
522 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
523 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
524 \ "(history) qb:list u:go up U:go down",
525 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100526" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
527call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100528if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
529 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
530else
531 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
532endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100533call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
534call s:NetrwInit("g:netrw_sort_options" , "")
535call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000536if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100537 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200538 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100539 else
540 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000541 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000542endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100543call s:NetrwInit("g:netrw_special_syntax" , 0)
544call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaara6878372014-03-22 21:02:50 +0100545call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100546call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000547" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100548call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200549if !exists("g:netrw_xstrlen")
550 if exists("g:Align_xstrlen")
551 let g:netrw_xstrlen= g:Align_xstrlen
552 elseif exists("g:drawit_xstrlen")
553 let g:netrw_xstrlen= g:drawit_xstrlen
554 elseif &enc == "latin1" || !has("multi_byte")
555 let g:netrw_xstrlen= 0
556 else
557 let g:netrw_xstrlen= 1
558 endif
559endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100560call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200561call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100562call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200563if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000564" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000565" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100566call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200567if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200568 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200569else
Bram Moolenaarff034192013-04-24 18:51:19 +0200570 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200571endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200572call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100573call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
574call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100575if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100576 let s:treedepthstring= "│ "
577else
578 let s:treedepthstring= "| "
579endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200580call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000581
582" BufEnter event ignored by decho when following variable is true
583" Has a side effect that doau BufReadPost doesn't work, so
584" files read by network transfer aren't appropriately highlighted.
585"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586
Bram Moolenaaradc21822011-04-01 18:03:16 +0200587" ======================
588" Netrw Initialization: {{{1
589" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200590if 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 +0100591" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100592 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200593" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100594 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100595 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
596 au VimEnter * let s:initbeval= &beval
597"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100598" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
599" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
600" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
601" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
602" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
603" 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 +0200604endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200605au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200606
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200607if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100608 com! -nargs=* NetrwKeepj keepj <args>
609else
610 let g:netrw_keepj= ""
611 com! -nargs=* NetrwKeepj <args>
612endif
613
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000614" ==============================
615" Netrw Utility Functions: {{{1
616" ==============================
617
Bram Moolenaaradc21822011-04-01 18:03:16 +0200618" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100619" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100620if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100621" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100622 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100623 if &ft != "netrw"
624 return ""
625 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200626 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
627 " popup error window is still showing
628 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
629 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
630 " text under mouse hasn't changed; only close window when it changes
631 call popup_close(s:popuperr_id)
632 unlet s:popuperr_text
633 else
634 let s:popuperr_text= v:beval_text
635 endif
636 let mesg= ""
637 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 +0100638 let mesg= ""
639 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
640 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
641 elseif getline(v:beval_lnum) =~ '^"\s*/'
642 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
643 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100644 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100645 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
646 let mesg = "S: edit sorting sequence"
647 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
648 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
649 elseif v:beval_text == "Quick" || v:beval_text == "Help"
650 let mesg = "Help: press <F1>"
651 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
652 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
653 else
654 let mesg= ""
655 endif
656 return mesg
657 endfun
658"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100659" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
660" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
661" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
662" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
663" 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 +0200664endif
665
Bram Moolenaar071d4272004-06-13 20:20:40 +0000666" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200667" netrw#Explore: launch the local browser in the directory of the current file {{{2
668" indx: == -1: Nexplore
669" == -2: Pexplore
670" == +: this is overloaded:
671" * If Nexplore/Pexplore is in use, then this refers to the
672" indx'th item in the w:netrw_explore_list[] of items which
673" matched the */pattern **/pattern *//pattern **//pattern
674" * If Hexplore or Vexplore, then this will override
675" g:netrw_winsize to specify the qty of rows or columns the
676" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100677" 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 +0200678" dosplit==1: the window will be split before running the local browser
679" style == 0: Explore style == 1: Explore!
680" == 2: Hexplore style == 3: Hexplore!
681" == 4: Vexplore style == 5: Vexplore!
682" == 6: Texplore
683fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100684" 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 +0100685" 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 +0200686 if !exists("b:netrw_curdir")
687 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100688" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200689 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100690
691 " record current file for Rexplore's benefit
692 if &ft != "netrw"
693 let w:netrw_rexfile= expand("%:p")
694 endif
695
696 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200697 let curdir = simplify(b:netrw_curdir)
698 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200699 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200700 let curdir= substitute(curdir,'\','/','g')
701 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100702" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100703
704 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
705 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
706 " try Explore again.
707 if a:0 > 0
708" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100709 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
710 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
711 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
712 \ '~'.expand("<slnum>"))
713 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200714 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
715 if a1 != a:1
716 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
717 return
718 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100719 endif
720 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200721
722 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200723 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100724" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100725 sil! let keepregstar = @*
726 sil! let keepregplus = @+
727 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200728 sil! let keepregslash= @/
729
Bram Moolenaar8d043172014-01-23 14:24:41 +0100730 " if dosplit
731 " -or- file has been modified AND file not hidden when abandoned
732 " -or- Texplore used
733 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaarff034192013-04-24 18:51:19 +0200734 call s:SaveWinVars()
735 let winsz= g:netrw_winsize
736 if a:indx > 0
737 let winsz= a:indx
738 endif
739
740 if a:style == 0 " Explore, Sexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200741 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200742 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200743 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200744
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200745 elseif a:style == 1 " Explore!, Sexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200746 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200747 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200748 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200749
750 elseif a:style == 2 " Hexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200751 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200752 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200753 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200754
755 elseif a:style == 3 " Hexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200756 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200757 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200758 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200759
760 elseif a:style == 4 " Vexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200761 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200762 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200763 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200764
765 elseif a:style == 5 " Vexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200766 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200767 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200768 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200769
770 elseif a:style == 6 " Texplore
771 call s:SaveBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200772 exe "keepalt tabnew ".fnameescape(curdir)
773 call s:RestoreBufVars()
774 endif
775 call s:RestoreWinVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200776 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100777 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200778
779 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100780" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200781 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100782" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200783 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100784" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200785 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100786" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200787 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
788 if dirname !~ '/$'
789 let dirname= dirname."/"
790 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100791" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200792 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100793" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200794 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100795" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200796 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100797" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200798 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100799" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200800 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100801" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200802 let dirname= a:1
803 endif
804 else
805 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100806" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200807 call s:NetrwClearExplore()
808" call Dret("netrw#Explore : cleared list")
809 return
810 endif
811
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100812" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200813 if dirname =~ '\.\./\=$'
814 let dirname= simplify(fnamemodify(dirname,':p:h'))
815 elseif dirname =~ '\.\.' || dirname == '.'
816 let dirname= simplify(fnamemodify(dirname,':p'))
817 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100818" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200819
820 if dirname =~ '^\*//'
821 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100822" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200823 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
824 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100825" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200826 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
827
828 elseif dirname =~ '^\*\*//'
829 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100830" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200831 let pattern= substitute(dirname,'^\*\*//','','')
832 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100833" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200834
835 elseif dirname =~ '/\*\*/'
836 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100837" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200838 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200839 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200840 let b:netrw_curdir = prefixdir
841 else
842 let b:netrw_curdir= getcwd().'/'.prefixdir
843 endif
844 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
845 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100846" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
847" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200848
849 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200850 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200851 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100852" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200853
854 elseif dirname=~ '^\*\*/'
855 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
856 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100857" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200858
859 else
860 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100861" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200862 endif
863
864 if starpat == 0 && a:indx >= 0
865 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100866" 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 +0200867 if dirname == ""
868 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100869" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200870 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200871 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200872 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200873 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200874 if dirname == ""
875 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200876 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100877 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100878 " depending on whether backslashes have been converted to forward slashes by earlier code).
879 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200880 let dirname= b:netrw_curdir."/".dirname
881 endif
882 elseif dirname !~ '^/'
883 let dirname= b:netrw_curdir."/".dirname
884 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100885" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200886 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100887" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
888" 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 +0200889 endif
890 if exists("w:netrw_bannercnt")
891 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
892 " If one wants to return the same place in the netrw window, use :Rex instead.
893 exe w:netrw_bannercnt
894 endif
895
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100896" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200897 " ---------------------------------------------------------------------
898 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
899" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100900" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200901" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100902" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200903" endif
904 " ---------------------------------------------------------------------
905
906 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
907 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
908 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
909 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
910 elseif a:indx <= 0
911 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100912" 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 +0200913 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100914" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200915 let s:didstarstar= 1
916 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
917 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
918 endif
919
920 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100921" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200922 if !exists("w:netrw_explore_indx")
923 let w:netrw_explore_indx= 0
924 endif
925
926 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100927" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200928
929 if indx == -1
930 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100931" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200932 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100933 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 +0200934 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100935" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100936 if @* != keepregstar | sil! let @* = keepregstar | endif
937 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100938 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200939 sil! let @/ = keepregslash
940" call Dret("netrw#Explore")
941 return
942 endif
943 let indx= w:netrw_explore_indx
944 if indx < 0 | let indx= 0 | endif
945 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
946 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100947" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200948 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
949 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100950" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200951 endwhile
952 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100953" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200954
955 elseif indx == -2
956 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100957" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200958 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100959 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 +0200960 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100961" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100962 if @* != keepregstar | sil! let @* = keepregstar | endif
963 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100964 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200965 sil! let @/ = keepregslash
966" call Dret("netrw#Explore")
967 return
968 endif
969 let indx= w:netrw_explore_indx
970 if indx < 0 | let indx= 0 | endif
971 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
972 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100973" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200974 while indx >= 0 && curfile == w:netrw_explore_list[indx]
975 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100976" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200977 endwhile
978 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100979" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200980
981 else
982 " Explore -- initialize
983 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100984" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100985 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200986 let w:netrw_explore_indx= 0
987 if !exists("b:netrw_curdir")
988 let b:netrw_curdir= getcwd()
989 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100990" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200991
992 " switch on starpat to build the w:netrw_explore_list of files
993 if starpat == 1
994 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100995" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
996" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200997 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100998 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200999 catch /^Vim\%((\a\+)\)\=:E480/
1000 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
1001" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
1002 return
1003 endtry
1004 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1005 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1006
1007 elseif starpat == 2
1008 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001009" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1010" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001011 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001012 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001013 catch /^Vim\%((\a\+)\)\=:E480/
1014 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1015 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001016 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001017" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001018 if @* != keepregstar | sil! let @* = keepregstar | endif
1019 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001020 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001021 sil! let @/ = keepregslash
1022" call Dret("netrw#Explore : no files matched pattern")
1023 return
1024 endtry
1025 let s:netrw_curdir = b:netrw_curdir
1026 let w:netrw_explore_list = getqflist()
1027 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1028 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1029
1030 elseif starpat == 3
1031 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001032" 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 +02001033 let filepat= substitute(dirname,'^\*/','','')
1034 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001035" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1036" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001037 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1038 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1039
1040 elseif starpat == 4
1041 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001042" 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 +02001043 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1044 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1045 endif " switch on starpat to build w:netrw_explore_list
1046
1047 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001048" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1049" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001050
1051 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001052 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001053 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001054" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001055 if @* != keepregstar | sil! let @* = keepregstar | endif
1056 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001057 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001058 sil! let @/ = keepregslash
1059" call Dret("netrw#Explore : no files matched")
1060 return
1061 endif
1062 endif " if indx ... endif
1063
1064 " NetrwStatusLine support - for exploring support
1065 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001066" 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 +02001067
1068 " wrap the indx around, but issue a note
1069 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001070" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001071 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1072 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001073 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001074 endif
1075
1076 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001077" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001078 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001079" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001080
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001081" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001082 call netrw#LocalBrowseCheck(newdir)
1083 if !exists("w:netrw_liststyle")
1084 let w:netrw_liststyle= g:netrw_liststyle
1085 endif
1086 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001087 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001088 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001089 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001090 endif
1091 let w:netrw_explore_mtchcnt = indx + 1
1092 let w:netrw_explore_bufnr = bufnr("%")
1093 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001094 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001095" 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 +02001096
1097 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001098" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001099 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001100 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 +02001101 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001102 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001103" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001104 if @* != keepregstar | sil! let @* = keepregstar | endif
1105 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001106 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001107 sil! let @/ = keepregslash
1108" call Dret("netrw#Explore : missing +path_extra")
1109 return
1110 endif
1111
1112 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001113" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001114 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1115 sil! unlet w:netrw_treedict
1116 sil! unlet w:netrw_treetop
1117 endif
1118 let newdir= dirname
1119 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001120 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001121 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001122 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001123 endif
1124 endif
1125
1126 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001127" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1128" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001129 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001130" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001131 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001132 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001133" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001134 let s:explore_prvdir = b:netrw_curdir
1135 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001136 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001137 if b:netrw_curdir !~ '/$'
1138 let dirlen= dirlen + 1
1139 endif
1140 let prvfname= ""
1141 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001142" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001143 if fname =~ '^'.b:netrw_curdir
1144 if s:explore_match == ""
1145 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1146 else
1147 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1148 endif
1149 elseif fname !~ '^/' && fname != prvfname
1150 if s:explore_match == ""
1151 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1152 else
1153 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1154 endif
1155 endif
1156 let prvfname= fname
1157 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001158" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001159 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1160 exe "2match netrwMarkFile /".s:explore_match."/"
1161 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001162 endif
1163 echo "<s-up>==Pexplore <s-down>==Nexplore"
1164 else
1165 2match none
1166 if exists("s:explore_match") | unlet s:explore_match | endif
1167 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001168" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001169 endif
1170
Bram Moolenaara6878372014-03-22 21:02:50 +01001171 " since Explore may be used to initialize netrw's browser,
1172 " there's no danger of a late FocusGained event on initialization.
1173 " Consequently, set s:netrw_events to 2.
1174 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001175 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001176" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001177 if @* != keepregstar | sil! let @* = keepregstar | endif
1178 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001179 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001180 sil! let @/ = keepregslash
1181" call Dret("netrw#Explore : @/<".@/.">")
1182endfun
1183
1184" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001185" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001186" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1187" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1188" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1189" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1190" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001191fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001192" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001193 let curwin= winnr()
1194
Bram Moolenaara6878372014-03-22 21:02:50 +01001195 if a:0 > 0 && a:1 != ""
1196 " if a netrw window is already on the left-side of the tab
1197 " and a directory has been specified, explore with that
1198 " directory.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001199 let a1 = expand(a:1)
Bram Moolenaara6878372014-03-22 21:02:50 +01001200 exe "1wincmd w"
1201 if &ft == "netrw"
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 Moolenaar8feef4f2015-01-07 16:57:10 +01001207 unlet t:netrw_lexposn
1208 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001209 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001210 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001211 exe curwin."wincmd w"
1212 else
1213 let a1= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01001214 endif
1215
Bram Moolenaar8d043172014-01-23 14:24:41 +01001216 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001217 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001218 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001219 else
1220 let lexwinnr= 0
1221 endif
1222
1223 if lexwinnr > 0
1224 " close down netrw explorer window
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001225 exe lexwinnr."wincmd w"
1226 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001227 let t:netrw_lexposn = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001228 close
1229 if lexwinnr < curwin
1230 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001231 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001232 if lexwinnr != curwin
1233 exe curwin."wincmd w"
1234 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001235 unlet t:netrw_lexbufnr
1236
1237 else
1238 " open netrw explorer window
1239 exe "1wincmd w"
1240 let keep_altv = g:netrw_altv
1241 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001242 if a:count != 0
1243 let netrw_winsize = g:netrw_winsize
1244 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001245 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001246 let curfile= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001247 exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
1248 if a:0 > 0 && a1 != ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001249 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001250 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001251 elseif curfile =~ '^\a\{3,}://'
Bram Moolenaar85850f32019-07-19 22:05:51 +02001252 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001253 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02001254 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001255 endif
1256 if a:count != 0
1257 let g:netrw_winsize = netrw_winsize
1258 endif
1259 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001260 let g:netrw_altv = keep_altv
1261 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001262 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1263 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001264 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001265 set bh=wipe
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001266 if exists("t:netrw_lexposn")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001267 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001268 unlet t:netrw_lexposn
1269 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001270 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001271
1272 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001273 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001274 if a:rightside
1275 let g:netrw_chgwin= 1
1276 else
1277 let g:netrw_chgwin= 2
1278 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001279 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001280
Bram Moolenaar8d043172014-01-23 14:24:41 +01001281endfun
1282
1283" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001284" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001285" supports :NetrwClean -- remove netrw from first directory on runtimepath
1286" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001287fun! netrw#Clean(sys)
1288" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001289
1290 if a:sys
1291 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1292 else
1293 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1294 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001295" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001296 let diddel= 0
1297 let diddir= ""
1298
1299 if choice == 1
1300 for dir in split(&rtp,',')
1301 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001302" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001303 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1304 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1305 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1306 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1307 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1308 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 +00001309 let diddir= dir
1310 let diddel= diddel + 1
1311 if !a:sys|break|endif
1312 endif
1313 endfor
1314 endif
1315
1316 echohl WarningMsg
1317 if diddel == 0
1318 echomsg "netrw is either not installed or not removable"
1319 elseif diddel == 1
1320 echomsg "removed one copy of netrw from <".diddir.">"
1321 else
1322 echomsg "removed ".diddel." copies of netrw"
1323 endif
1324 echohl None
1325
Bram Moolenaara6878372014-03-22 21:02:50 +01001326" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001327endfun
1328
Bram Moolenaar5c736222010-01-06 20:54:52 +01001329" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001330" netrw#MakeTgt: make a target out of the directory name provided {{{2
1331fun! netrw#MakeTgt(dname)
1332" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1333 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001334 let svpos = winsaveview()
1335" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001336 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1337" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001338 if s:netrwmftgt_islocal
1339 let netrwmftgt= simplify(a:dname)
1340 else
1341 let netrwmftgt= a:dname
1342 endif
1343 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1344 " re-selected target, so just clear it
1345 unlet s:netrwmftgt s:netrwmftgt_islocal
1346 else
1347 let s:netrwmftgt= netrwmftgt
1348 endif
1349 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001350 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001351 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001352" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1353 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001354" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001355endfun
1356
Bram Moolenaara6878372014-03-22 21:02:50 +01001357" ---------------------------------------------------------------------
1358" netrw#Obtain: {{{2
1359" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001360" islocal=0 obtain from remote source
1361" =1 obtain from local source
1362" fname : a filename or a list of filenames
1363" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001364fun! netrw#Obtain(islocal,fname,...)
1365" 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 +02001366 " NetrwStatusLine support - for obtaining support
1367
1368 if type(a:fname) == 1
1369 let fnamelist= [ a:fname ]
1370 elseif type(a:fname) == 3
1371 let fnamelist= a:fname
1372 else
1373 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 +01001374" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001375 return
1376 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001377" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001378 if a:0 > 0
1379 let tgtdir= a:1
1380 else
1381 let tgtdir= getcwd()
1382 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001383" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001384
1385 if exists("b:netrw_islocal") && b:netrw_islocal
1386 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001387" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001388 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1389 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001390 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001391 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001392" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001393 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001394" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001395 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001396 if v:shell_error != 0
1397 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 +01001398" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001399 return
1400 endif
1401 endfor
1402 else
1403 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001404" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1405 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1406" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001407 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001408 if v:shell_error != 0
1409 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 +01001410" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001411 return
1412 endif
1413 endif
1414 elseif !exists("b:netrw_curdir")
1415 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1416 else
1417 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1418 endif
1419
1420 else
1421 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001422" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001423 if type(a:fname) == 1
1424 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1425 endif
1426 call s:NetrwMethod(b:netrw_curdir)
1427
1428 if b:netrw_method == 4
1429 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001430" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001431 if exists("g:netrw_port") && g:netrw_port != ""
1432 let useport= " ".g:netrw_scpport." ".g:netrw_port
1433 else
1434 let useport= ""
1435 endif
1436 if b:netrw_fname =~ '/'
1437 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1438 else
1439 let path= ""
1440 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001441 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001442 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 +02001443
1444 elseif b:netrw_method == 2
1445 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001446" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001447 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001448 let tmpbufnr= bufnr("%")
1449 setl ff=unix
1450 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001451 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001452" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001453 endif
1454
1455 if exists("b:netrw_fname") && b:netrw_fname != ""
1456 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001457" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001458 endif
1459
1460 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001461 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001462" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001463 endif
1464 for fname in fnamelist
1465 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001466" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001467 endfor
1468 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001469 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 +02001470 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001471 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001472 endif
1473 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1474 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1475 let debugkeep= &debug
1476 setl debug=msg
1477 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1478 let &debug= debugkeep
1479 endif
1480
1481 elseif b:netrw_method == 3
1482 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001483" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001484 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001485 let tmpbufnr= bufnr("%")
1486 setl ff=unix
1487
1488 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001489 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001490" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001491 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001492 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001493" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001494 endif
1495
1496 if exists("g:netrw_uid") && g:netrw_uid != ""
1497 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001498 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001499" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001500 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001501 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001502 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001503" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001504 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001505 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001506" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001507 endif
1508 endif
1509
1510 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001511 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001512" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001513 endif
1514
1515 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001516 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001517" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001518 endif
1519
1520 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001521 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001522" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001523 endif
1524
1525 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001526 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001527" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001528 endif
1529 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001530 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001531 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001532" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001533
1534 " perform ftp:
1535 " -i : turns off interactive prompting from ftp
1536 " -n unix : DON'T use <.netrc>, even though it exists
1537 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001538 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1539 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001540 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001541 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1542 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001543" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001544 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001545 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001546 endif
1547 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001548
1549 elseif b:netrw_method == 9
1550 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001551" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001552 if a:fname =~ '/'
1553 let localfile= substitute(a:fname,'^.*/','','')
1554 else
1555 let localfile= a:fname
1556 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001557 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 +02001558
Bram Moolenaarff034192013-04-24 18:51:19 +02001559 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001560 " probably a badly formed url; protocol not recognized
1561" call Dret("netrw#Obtain : unsupported method")
1562 return
1563
1564 else
1565 " protocol recognized but not supported for Obtain (yet?)
1566 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001567 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001568 endif
1569" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001570 return
1571 endif
1572
1573 " restore status line
1574 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001575 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001576 endif
1577
1578 endif
1579
1580 " cleanup
1581 if exists("tmpbufnr")
1582 if bufnr("%") != tmpbufnr
1583 exe tmpbufnr."bw!"
1584 else
1585 q!
1586 endif
1587 endif
1588
Bram Moolenaara6878372014-03-22 21:02:50 +01001589" call Dret("netrw#Obtain")
1590endfun
1591
1592" ---------------------------------------------------------------------
1593" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1594fun! netrw#Nread(mode,fname)
1595" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001596 let svpos= winsaveview()
1597" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001598 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001599" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1600 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001601
1602 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1603 if exists("w:netrw_bannercnt")
1604 " start with cursor just after the banner
1605 exe w:netrw_bannercnt
1606 endif
1607 endif
1608" call Dret("netrw#Nread")
1609endfun
1610
1611" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001612" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1613" Options get restored by s:NetrwOptionsRestore()
1614"
1615" Option handling:
1616" * save user's options (s:NetrwOptionsSave)
1617" * set netrw-safe options (s:NetrwOptionsSafe)
1618" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1619" * restore user's options (s:netrwOPtionsRestore)
1620" - restore a user option when != safe option (s:NetrwRestoreSetting)
1621" vt: (variable type) normally its either "w:" or "s:"
1622fun! s:NetrwOptionsSave(vt)
1623" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1624" 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 +02001625" 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>"))
1626" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001627
1628 if !exists("{a:vt}netrw_optionsave")
1629 let {a:vt}netrw_optionsave= 1
1630 else
1631" call Dret("s:NetrwOptionsSave : options already saved")
1632 return
1633 endif
1634" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1635
1636 " Save current settings and current directory
1637" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1638 let s:yykeep = @@
1639 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1640 let {a:vt}netrw_aikeep = &l:ai
1641 let {a:vt}netrw_awkeep = &l:aw
1642 let {a:vt}netrw_bhkeep = &l:bh
1643 let {a:vt}netrw_blkeep = &l:bl
1644 let {a:vt}netrw_btkeep = &l:bt
1645 let {a:vt}netrw_bombkeep = &l:bomb
1646 let {a:vt}netrw_cedit = &cedit
1647 let {a:vt}netrw_cikeep = &l:ci
1648 let {a:vt}netrw_cinkeep = &l:cin
1649 let {a:vt}netrw_cinokeep = &l:cino
1650 let {a:vt}netrw_comkeep = &l:com
1651 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001652 let {a:vt}netrw_cuckeep = &l:cuc
1653 let {a:vt}netrw_culkeep = &l:cul
1654" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001655 let {a:vt}netrw_diffkeep = &l:diff
1656 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001657 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1658 let {a:vt}netrw_ffkeep = &l:ff
1659 endif
1660 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1661 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001662 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001663 let {a:vt}netrw_hidkeep = &l:hidden
1664 let {a:vt}netrw_imkeep = &l:im
1665 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001666 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001667 let {a:vt}netrw_lskeep = &l:ls
1668 let {a:vt}netrw_makeep = &l:ma
1669 let {a:vt}netrw_magickeep = &l:magic
1670 let {a:vt}netrw_modkeep = &l:mod
1671 let {a:vt}netrw_nukeep = &l:nu
1672 let {a:vt}netrw_rnukeep = &l:rnu
1673 let {a:vt}netrw_repkeep = &l:report
1674 let {a:vt}netrw_rokeep = &l:ro
1675 let {a:vt}netrw_selkeep = &l:sel
1676 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001677 if !g:netrw_use_noswf
1678 let {a:vt}netrw_swfkeep = &l:swf
1679 endif
1680 let {a:vt}netrw_tskeep = &l:ts
1681 let {a:vt}netrw_twkeep = &l:tw " textwidth
1682 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1683 let {a:vt}netrw_wrapkeep = &l:wrap
1684 let {a:vt}netrw_writekeep = &l:write
1685
1686 " save a few selected netrw-related variables
1687" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1688 if g:netrw_keepdir
1689 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001690" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001691 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001692 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001693 sil! let {a:vt}netrw_starkeep = @*
1694 sil! let {a:vt}netrw_pluskeep = @+
1695 endif
1696 sil! let {a:vt}netrw_slashkeep= @/
1697
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001698" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001699" 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>"))
1700" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1701endfun
1702
1703" ---------------------------------------------------------------------
1704" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1705" Use s:NetrwSaveOptions() to save user settings
1706" Use s:NetrwOptionsRestore() to restore user settings
1707fun! s:NetrwOptionsSafe(islocal)
1708" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1709" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1710" 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>"))
1711 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1712 call s:NetrwSetSafeSetting("&l:ai",0)
1713 call s:NetrwSetSafeSetting("&l:aw",0)
1714 call s:NetrwSetSafeSetting("&l:bl",0)
1715 call s:NetrwSetSafeSetting("&l:bomb",0)
1716 if a:islocal
1717 call s:NetrwSetSafeSetting("&l:bt","nofile")
1718 else
1719 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1720 endif
1721 call s:NetrwSetSafeSetting("&l:ci",0)
1722 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001723 if g:netrw_fastbrowse > a:islocal
1724 call s:NetrwSetSafeSetting("&l:bh","hide")
1725 else
1726 call s:NetrwSetSafeSetting("&l:bh","delete")
1727 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001728 call s:NetrwSetSafeSetting("&l:cino","")
1729 call s:NetrwSetSafeSetting("&l:com","")
1730 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1731 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1732 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001733 if &go =~ 'a' | set go-=a | endif
1734 if &go =~ 'A' | set go-=A | endif
1735 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001736 call s:NetrwSetSafeSetting("&l:hid",0)
1737 call s:NetrwSetSafeSetting("&l:im",0)
1738 setl isk+=@ isk+=* isk+=/
1739 call s:NetrwSetSafeSetting("&l:magic",1)
1740 if g:netrw_use_noswf
1741 call s:NetrwSetSafeSetting("swf",0)
1742 endif
1743 call s:NetrwSetSafeSetting("&l:report",10000)
1744 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1745 call s:NetrwSetSafeSetting("&l:spell",0)
1746 call s:NetrwSetSafeSetting("&l:tw",0)
1747 call s:NetrwSetSafeSetting("&l:wig","")
1748 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001749
1750 " set up cuc and cul based on g:netrw_cursor and listing style
1751 " COMBAK -- cuc cul related
1752 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001753
1754 " allow the user to override safe options
1755" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1756 if &ft == "netrw"
1757" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1758 keepalt NetrwKeepj doau FileType netrw
1759 endif
1760
1761" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1762" 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>"))
1763" call Dret("s:NetrwOptionsSafe")
1764endfun
1765
1766" ---------------------------------------------------------------------
1767" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1768fun! s:NetrwOptionsRestore(vt)
Bram Moolenaara6878372014-03-22 21:02:50 +01001769 if !exists("{a:vt}netrw_optionsave")
Christian Brabandtaa2ce6f2024-10-30 18:27:03 +01001770 " filereadable() returns zero for remote files (e.g. scp://user@localhost//etc/fstab)
1771 " Note: @ may not be in 'isfname', so '^\w\+://\f\+/' may not match
1772 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+'
Bram Moolenaar71badf92023-04-22 22:40:14 +01001773 filetype detect
Bram Moolenaar71badf92023-04-22 22:40:14 +01001774 else
1775 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001776 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001777 return
1778 endif
1779 unlet {a:vt}netrw_optionsave
1780
1781 if exists("+acd")
1782 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara6878372014-03-22 21:02:50 +01001783 let curdir = getcwd()
1784 let &l:acd = {a:vt}netrw_acdkeep
1785 unlet {a:vt}netrw_acdkeep
1786 if &l:acd
1787 call s:NetrwLcd(curdir)
1788 endif
1789 endif
1790 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001791 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1792 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1793 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1794 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1795 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
1796 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1797 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1798 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1799 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1800 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
1801 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1802 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1803 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1804 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1805 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001806 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001807 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1808 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001809 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001810 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001811 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1812 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001813 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001814 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1815 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001816 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001817 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1818 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001819 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1820 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1821 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1822 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001823 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001824 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1825 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1826 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001827 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
1828 call s:NetrwRestoreSetting("s:yykeep","@@")
1829 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1830 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1831 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1832 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1833
Bram Moolenaara6878372014-03-22 21:02:50 +01001834 if exists("{a:vt}netrw_swfkeep")
1835 if &directory == ""
1836 " user hasn't specified a swapfile directory;
1837 " netrw will temporarily set the swapfile directory
1838 " to the current directory as returned by getcwd().
1839 let &l:directory= getcwd()
1840 sil! let &l:swf = {a:vt}netrw_swfkeep
1841 setl directory=
1842 unlet {a:vt}netrw_swfkeep
1843 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001844 if !g:netrw_use_noswf
1845 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1846 sil! let &l:swf= {a:vt}netrw_swfkeep
1847 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001848 unlet {a:vt}netrw_swfkeep
1849 endif
1850 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001851 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001852 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1853 if exists("{a:vt}netrw_dirkeep")
1854 call s:NetrwLcd(dirkeep)
1855 unlet {a:vt}netrw_dirkeep
1856 endif
1857 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001858 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001859 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1860 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001861 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001862 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001863
Bram Moolenaara6878372014-03-22 21:02:50 +01001864 " Moved the filetype detect here from NetrwGetFile() because remote files
1865 " were having their filetype detect-generated settings overwritten by
1866 " NetrwOptionRestore.
1867 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001868 filetype detect
Bram Moolenaara6878372014-03-22 21:02:50 +01001869 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001870endfun
1871
1872" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001873" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1874" but only when the options' value and the safe setting differ
1875" Doing this means that netrw will not come up as having changed a
1876" setting last when it really didn't actually change it.
1877"
1878" Called from s:NetrwOptionsSafe
1879" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1880fun! s:NetrwSetSafeSetting(setting,safesetting)
1881" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001882
Bram Moolenaar85850f32019-07-19 22:05:51 +02001883 if a:setting =~ '^&'
1884" call Decho("fyi: a:setting starts with &")
1885 exe "let settingval= ".a:setting
1886" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001887
Bram Moolenaar85850f32019-07-19 22:05:51 +02001888 if settingval != a:safesetting
1889" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1890 if type(a:safesetting) == 0
1891 exe "let ".a:setting."=".a:safesetting
1892 elseif type(a:safesetting) == 1
1893 exe "let ".a:setting."= '".a:safesetting."'"
1894 else
1895 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1896 endif
1897 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001898 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001899
Bram Moolenaar85850f32019-07-19 22:05:51 +02001900" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001901endfun
1902
1903" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001904" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1905" but only if the setting value differs from the associated keepvar.
1906" Doing this means that netrw will not come up as having changed a
1907" setting last when it really didn't actually change it.
1908"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001909" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001910" keepvars are set up by s:NetrwOptionsSave
1911fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001912""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001913
Bram Moolenaar85850f32019-07-19 22:05:51 +02001914 " typically called from s:NetrwOptionsRestore
1915 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1916 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001917 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001918 if exists(a:keepvar)
1919 exe "let keepvarval= ".a:keepvar
1920 exe "let setting= ".a:setting
1921
1922"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1923"" call Decho("fyi: keepvarval=".keepvarval)
1924"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1925
1926 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001927"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001928 if type(a:setting) == 0
1929 exe "let ".a:setting."= ".keepvarval
1930 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001931 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001932 else
1933 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1934 endif
1935 endif
1936
1937 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001938 endif
1939
Bram Moolenaar85850f32019-07-19 22:05:51 +02001940"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001941endfun
1942
1943" ---------------------------------------------------------------------
1944" NetrwStatusLine: {{{2
1945fun! NetrwStatusLine()
1946
1947" vvv NetrwStatusLine() debugging vvv
1948" let g:stlmsg=""
1949" if !exists("w:netrw_explore_bufnr")
1950" let g:stlmsg="!X<explore_bufnr>"
1951" elseif w:netrw_explore_bufnr != bufnr("%")
1952" let g:stlmsg="explore_bufnr!=".bufnr("%")
1953" endif
1954" if !exists("w:netrw_explore_line")
1955" let g:stlmsg=" !X<explore_line>"
1956" elseif w:netrw_explore_line != line(".")
1957" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
1958" endif
1959" if !exists("w:netrw_explore_list")
1960" let g:stlmsg=" !X<explore_list>"
1961" endif
1962" ^^^ NetrwStatusLine() debugging ^^^
1963
1964 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")
1965 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09001966 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02001967 let &laststatus = s:netrw_users_ls
1968 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
1969 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
1970 return ""
1971 else
1972 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
1973 endif
1974endfun
1975
Bram Moolenaar85850f32019-07-19 22:05:51 +02001976" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001977" Netrw Transfer Functions: {{{1
1978" ===============================
1979
Bram Moolenaar071d4272004-06-13 20:20:40 +00001980" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001981" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001982" mode: =0 read remote file and insert before current line
1983" =1 read remote file and insert after current line
1984" =2 replace with remote file
1985" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001986fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02001987" 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 +00001988
Bram Moolenaar5c736222010-01-06 20:54:52 +01001989 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02001990 call s:NetrwOptionsSave("w:")
1991 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001992 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001993 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
1994 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
1995 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02001996" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001997
Bram Moolenaar5c736222010-01-06 20:54:52 +01001998 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001999 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002000 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002001 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002002 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002003 elseif a:mode == 2 " replace with remote file
2004 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002005 elseif a:mode == 3 " skip read of file (leave as temporary)
2006 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002007 else
2008 exe a:mode
2009 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002010 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002011 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002012" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002013
Bram Moolenaar5c736222010-01-06 20:54:52 +01002014 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002015 let tmpfile= s:GetTempfile("")
2016 if tmpfile == ""
2017" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002018 return
2019 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002020
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002021 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002022
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002023 " attempt to repeat with previous host-file-etc
2024 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002025" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002026 let choice = b:netrw_lastfile
2027 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002028
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002029 else
2030 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002031" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002032
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002033 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002034 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002035 echomsg 'NetRead Usage:'
2036 echomsg ':Nread machine:path uses rcp'
2037 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2038 echomsg ':Nread "machine id password path" uses ftp'
2039 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2040 echomsg ':Nread fetch://machine/path uses fetch'
2041 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2042 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002043 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002044 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002045 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2046 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2047 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2048 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002049 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002050 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002051
Bram Moolenaar9964e462007-05-05 17:54:07 +00002052 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002053 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002054" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002055 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002056 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002057 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002058 else
2059 " case "... ... ..."
2060 let choice = strpart(choice,1,strlen(choice)-1)
2061 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002062
Bram Moolenaar9964e462007-05-05 17:54:07 +00002063 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002064 let wholechoice = wholechoice . " " . choice
2065 let ichoice = ichoice + 1
2066 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002067 if !exists("g:netrw_quiet")
2068 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2069 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002070" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002071 return
2072 endif
2073 let choice= a:{ichoice}
2074 endwhile
2075 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2076 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002077 endif
2078 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002079
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002080" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002081 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002082
Bram Moolenaar5c736222010-01-06 20:54:52 +01002083 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002084 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002085 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002086" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002087 return
2088 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002089 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002090
Bram Moolenaar8d043172014-01-23 14:24:41 +01002091 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002092" 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 +02002093 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002094" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002095 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002096" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002097 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002098 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002099
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002100 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002101 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002102 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002103 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2104 echo "(netrw) Processing your read request..."
2105 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002106
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002107 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002108 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002109 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002110" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002111 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002112 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002113 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002114 " ER: the tmpfile is full path: rcp sees C:\... as host C
2115 if s:netrw_has_nt_rcp == 1
2116 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2117 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2118 else
2119 " Any way needed it machine contains a '.'
2120 let uid_machine = g:netrw_machine .'.'. $USERNAME
2121 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002122 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002123 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2124 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2125 else
2126 let uid_machine = g:netrw_machine
2127 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002128 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002129 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 +00002130 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002131 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002132
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002133 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002134 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002135 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002136" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002137 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002138 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002139 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002140 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002141 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002142" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002143 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002144 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002145" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002146 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002147 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002148" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002149 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002150 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 +00002151 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002152 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002153 endif
2154 " 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 +00002155 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002156 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002157 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002158 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002159 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002160 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002161 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002162 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002163 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2164 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002165 q!
2166 endif
2167 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002168 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002169 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002170
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002171 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002172 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002173 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2174 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002175" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002176 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002177 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002178 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002179 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002180 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002181 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002182" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002183 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002184 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002185" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002186 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002187
Bram Moolenaar97d62492012-11-15 21:28:22 +01002188 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002189 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002190 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002191" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002192 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002193 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002194 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002195" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002196 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002197 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002198" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002199 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002200 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002201
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002202 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002203 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002204" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002205 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002206 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002207 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002208" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002209 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002210 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002211" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002212
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002213 " perform ftp:
2214 " -i : turns off interactive prompting from ftp
2215 " -n unix : DON'T use <.netrc>, even though it exists
2216 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002217 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002218 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002219 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2220 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002221" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002222 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002223 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002224 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002225 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002226 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002227 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002228 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002229
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002230 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002231 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002232 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002233" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002234 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002235 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002236 else
2237 let useport= ""
2238 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002239 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2240 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002241 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002242 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2243 else
2244 let tmpfile_get = tmpfile
2245 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002246 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 +00002247 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002248 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002249
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002250 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002251 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002252 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002253" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002254 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002255 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002256 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002257 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002258" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002259 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002260 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002261
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002262 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2263 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002264" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002265 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002266 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 +00002267 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002268 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 +00002269 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002270 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002271
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002272 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002273 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002274" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002275 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2276 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002277" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2278" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2279 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 +00002280 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002281" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002282 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002283 endif
2284 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002285" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002286 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002287
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002288 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002289 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002290 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002291" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002292
Bram Moolenaar5c736222010-01-06 20:54:52 +01002293 if !executable(g:netrw_dav_cmd)
2294 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2295" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2296 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002297 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002298 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002299 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 +01002300 else
2301 " Construct execution string (four lines) which will be passed through filter
2302 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2303 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002304 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002305 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002306 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002307 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002308 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002309 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002310 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002311 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002312 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002313 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2314 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002315
Bram Moolenaar5c736222010-01-06 20:54:52 +01002316 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002317 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002318 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002319 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002320 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002321 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002322 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002323
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002324 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002325 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002326 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002327" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002328 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 +00002329 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002330 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002331
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002332 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002333 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002334 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002335 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002336" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002337 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002338 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002339 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002340 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002341" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002342 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002343 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002344 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002345 let netrw_option= "http"
2346 else
2347 let netrw_option= "ftp"
2348 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002349" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002350
Bram Moolenaar446cb832008-06-24 21:56:24 +00002351 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002352 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 +00002353 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002354 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 +00002355 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002356
Bram Moolenaar446cb832008-06-24 21:56:24 +00002357 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002358 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002359" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002360 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002361
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002362 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002363 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002364 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002365" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2366 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 +00002367 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002368 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002369
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002370 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002371 " NetRead: (file) NetRead Method #10 {{{3
2372 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002373" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2374 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002375 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2376 let b:netrw_lastfile = choice
2377
2378 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002379 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002380 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002381 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002382 endif
2383 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002384
Bram Moolenaar5c736222010-01-06 20:54:52 +01002385 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002386 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002387" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002388 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002389 unlet b:netrw_fname
2390 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002391 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 +01002392" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002393 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002394 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002395 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002396
Bram Moolenaar9964e462007-05-05 17:54:07 +00002397" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002398endfun
2399
2400" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002401" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002402fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002403" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002404
Bram Moolenaar5c736222010-01-06 20:54:52 +01002405 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002406 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002407 call s:NetrwOptionsSave("w:")
2408 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002409
Bram Moolenaar5c736222010-01-06 20:54:52 +01002410 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002411 let tmpfile= s:GetTempfile("")
2412 if tmpfile == ""
2413" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002414 return
2415 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002416
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002417 if a:0 == 0
2418 let ichoice = 0
2419 else
2420 let ichoice = 1
2421 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002422
Bram Moolenaar9964e462007-05-05 17:54:07 +00002423 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002424" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002425 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002426 " For binary writes, always write entire file.
2427 " (line numbers don't really make sense for that).
2428 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002429" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002430 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002431 elseif g:netrw_cygwin
2432 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002433 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002434" 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 +01002435 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002436 else
2437 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002438" 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 +01002439 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002440 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002441
Bram Moolenaar9964e462007-05-05 17:54:07 +00002442 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002443 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002444 " on the temporary file's name. Deletion of the temporary file during
2445 " cleanup then causes an error message.
2446 0file!
2447 endif
2448
Bram Moolenaar5c736222010-01-06 20:54:52 +01002449 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002450 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002451
Bram Moolenaar9964e462007-05-05 17:54:07 +00002452 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002453 " attempt to repeat with previous host-file-etc
2454 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002455" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002456 let choice = b:netrw_lastfile
2457 let ichoice= ichoice + 1
2458 else
2459 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002460
Bram Moolenaar8d043172014-01-23 14:24:41 +01002461 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002462 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002463 echomsg 'NetWrite Usage:"'
2464 echomsg ':Nwrite machine:path uses rcp'
2465 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2466 echomsg ':Nwrite "machine id password path" uses ftp'
2467 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2468 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2469 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2470 echomsg ':Nwrite rcp://machine/path uses rcp'
2471 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2472 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2473 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002474 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002475 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002476
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002477 elseif match(choice,"^\"") != -1
2478 if match(choice,"\"$") != -1
2479 " case "..."
2480 let choice=strpart(choice,1,strlen(choice)-2)
2481 else
2482 " case "... ... ..."
2483 let choice = strpart(choice,1,strlen(choice)-1)
2484 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002485
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002486 while match(choice,"\"$") == -1
2487 let wholechoice= wholechoice . " " . choice
2488 let ichoice = ichoice + 1
2489 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002490 if !exists("g:netrw_quiet")
2491 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2492 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002493" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002494 return
2495 endif
2496 let choice= a:{ichoice}
2497 endwhile
2498 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2499 endif
2500 endif
2501 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002502 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002503" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002504
Bram Moolenaar9964e462007-05-05 17:54:07 +00002505 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002506 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002507 if !exists("b:netrw_method") || b:netrw_method < 0
2508" call Dfunc("netrw#NetWrite : unsupported method")
2509 return
2510 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002511
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002512 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002513 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002514 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002515 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2516 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002517" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002518 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002519
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002520 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002521 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002522 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002523" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002524 if s:netrw_has_nt_rcp == 1
2525 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2526 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2527 else
2528 let uid_machine = g:netrw_machine .'.'. $USERNAME
2529 endif
2530 else
2531 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2532 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2533 else
2534 let uid_machine = g:netrw_machine
2535 endif
2536 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002537 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 +00002538 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002539
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002540 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002541 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002542 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002543" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002544 let netrw_fname = b:netrw_fname
2545
2546 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2547 let bhkeep = &l:bh
2548 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002549 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002550 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002551
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002552" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002553 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002554 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002555" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002556 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002557 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002558" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002559 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002560 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002561" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002562 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002563 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 +00002564 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002565" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2566 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002567 endif
2568 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2569 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002570 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002571 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002572 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002573 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002574 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002575
2576 " remove enew buffer (quietly)
2577 let filtbuf= bufnr("%")
2578 exe curbuf."b!"
2579 let &l:bh = bhkeep
2580 exe filtbuf."bw!"
2581
Bram Moolenaar071d4272004-06-13 20:20:40 +00002582 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002583
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002584 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002585 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002586 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002587 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002588" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002589 let netrw_fname = b:netrw_fname
2590 let bhkeep = &l:bh
2591
2592 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2593 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002594 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002595 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002596 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002597
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002598 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002599 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002600" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002601 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002602 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002603" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002604 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002605 if exists("g:netrw_uid") && g:netrw_uid != ""
2606 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002607 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002608" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002609 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002610 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002611 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002612" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002613 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002614 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002615" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002616 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002617 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002618 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002619" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002620 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002621 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002622" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002623 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002624 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002625" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002626 " save choice/id/password for future use
2627 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002628
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002629 " perform ftp:
2630 " -i : turns off interactive prompting from ftp
2631 " -n unix : DON'T use <.netrc>, even though it exists
2632 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002633 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002634 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002635 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2636 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002637 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002638 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002639 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002640 let mod=1
2641 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002642
2643 " remove enew buffer (quietly)
2644 let filtbuf= bufnr("%")
2645 exe curbuf."b!"
2646 let &l:bh= bhkeep
2647 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002648
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002649 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002650 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002651 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002652" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002653 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002654 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002655 else
2656 let useport= ""
2657 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002658 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 +00002659 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002660
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002661 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002662 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002663 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002664" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002665 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2666 if executable(curl)
2667 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002668 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 +01002669 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002670 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002671 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002672
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002673 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002674 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002675 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002676" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002677
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002678 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002679 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2680 let bhkeep = &l:bh
2681
2682 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2683 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002684 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002685 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002686
Bram Moolenaarff034192013-04-24 18:51:19 +02002687 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002688 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002689 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002690 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002691 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002692 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002693 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002694 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002695 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002696 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002697
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002698 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002699 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002700 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002701
2702 " remove enew buffer (quietly)
2703 let filtbuf= bufnr("%")
2704 exe curbuf."b!"
2705 let &l:bh = bhkeep
2706 exe filtbuf."bw!"
2707
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002708 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002709
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002710 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002711 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002712 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002713" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002714 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 +00002715 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002716
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002717 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002718 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002719 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002720" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002721 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002722 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2723 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2724 else
2725 let uid_machine = g:netrw_machine
2726 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002727
2728 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2729 let bhkeep = &l:bh
2730 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002731 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002732 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002733
Bram Moolenaarff034192013-04-24 18:51:19 +02002734 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002735 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002736" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002737 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002738 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002739 let filtbuf= bufnr("%")
2740 exe curbuf."b!"
2741 let &l:bh = bhkeep
2742 exe filtbuf."bw!"
2743 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002744
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002745 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002746 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002747 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002748 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002749 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002750 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002751 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002752
Bram Moolenaar5c736222010-01-06 20:54:52 +01002753 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002754" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002755 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002756" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002757 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002758 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002759 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002760
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002761 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002762 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002763 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002764" 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 +02002765 elseif !exists("leavemod")
2766 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002767" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002768 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002769" 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 +00002770 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002771
Bram Moolenaar9964e462007-05-05 17:54:07 +00002772" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002773endfun
2774
2775" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002776" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002777" uses NetRead to get a copy of the file into a temporarily file,
2778" then sources that file,
2779" then removes that file.
2780fun! netrw#NetSource(...)
2781" call Dfunc("netrw#NetSource() a:0=".a:0)
2782 if a:0 > 0 && a:1 == '?'
2783 " give help
2784 echomsg 'NetSource Usage:'
2785 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2786 echomsg ':Nsource fetch://machine/path uses fetch'
2787 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002788 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002789 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2790 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2791 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2792 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2793 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002794 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002795 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002796 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002797 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002798" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002799 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002800" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002801 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002802" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002803 if delete(s:netrw_tmpfile)
2804 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2805 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002806 unlet s:netrw_tmpfile
2807 else
2808 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2809 endif
2810 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002811 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002812 endif
2813" call Dret("netrw#NetSource")
2814endfun
2815
Bram Moolenaar8d043172014-01-23 14:24:41 +01002816" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002817" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2818" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002819fun! netrw#SetTreetop(iscmd,...)
2820" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2821" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002822
Bram Moolenaar85850f32019-07-19 22:05:51 +02002823 " iscmd==0: netrw#SetTreetop called using gn mapping
2824 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2825" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002826 " clear out the current tree
2827 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002828" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002829 let inittreetop= w:netrw_treetop
2830 unlet w:netrw_treetop
2831 endif
2832 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002833" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002834 unlet w:netrw_treedict
2835 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002836" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002837
Bram Moolenaar85850f32019-07-19 22:05:51 +02002838 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002839 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002840" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002841 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002842 if isdirectory(s:NetrwFile(a:1))
2843" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002844 let treedir = a:1
2845 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002846 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002847 let treedir = b:netrw_curdir."/".a:1
2848 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002849" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002850 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002851 " normally the cursor is left in the message window.
2852 " However, here this results in the directory being listed in the message window, which is not wanted.
2853 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002854 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002855 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002856 let treedir = "."
2857 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002858 endif
2859 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002860" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002861
2862 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002863 let islocal= expand("%") !~ '^\a\{3,}://'
2864" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002865
2866 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002867 if islocal
2868 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2869 else
2870 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2871 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002872
Bram Moolenaara6878372014-03-22 21:02:50 +01002873" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002874endfun
2875
Bram Moolenaar9964e462007-05-05 17:54:07 +00002876" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002877" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002878" readcmd == %r : replace buffer with newly read file
2879" == 0r : read file at top of buffer
2880" == r : read file after current line
2881" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002882fun! s:NetrwGetFile(readcmd, tfile, method)
2883" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002884
2885 " readcmd=='t': simply do nothing
2886 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002887" 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 +01002888" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002889 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002890 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002891
Bram Moolenaar9964e462007-05-05 17:54:07 +00002892 " get name of remote filename (ie. url and all)
2893 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002894" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002895
Bram Moolenaar9964e462007-05-05 17:54:07 +00002896 if exists("*NetReadFixup")
2897 " for the use of NetReadFixup (not otherwise used internally)
2898 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002899 endif
2900
Bram Moolenaar9964e462007-05-05 17:54:07 +00002901 if a:readcmd[0] == '%'
2902 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002903" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002904
2905 " rename the current buffer to the temp file (ie. tfile)
2906 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002907 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002908 else
2909 let tfile= a:tfile
2910 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002911 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002912
2913 " edit temporary file (ie. read the temporary file in)
2914 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002915" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002916 call zip#Browse(tfile)
2917 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002918" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002919 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002920 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002921" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002922 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002923 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002924" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002925 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002926 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002927" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002928 call tar#Browse(tfile)
2929 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002930" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002931 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002932 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002933" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002934 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002935 endif
2936
2937 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002938 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002939
Bram Moolenaar71badf92023-04-22 22:40:14 +01002940 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002941 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002942 " Note that isk must not include a "/" for scripts.vim
2943 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002944" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2945" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002946" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002947" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
2948 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01002949 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01002950 filetype detect
2951" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09002952 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02002953" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002954 let line1 = 1
2955 let line2 = line("$")
2956
Bram Moolenaar8d043172014-01-23 14:24:41 +01002957 elseif !&ma
2958 " 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 +01002959 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002960" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002961 return
2962
Bram Moolenaar9964e462007-05-05 17:54:07 +00002963 elseif s:FileReadable(a:tfile)
2964 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002965" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002966 let curline = line(".")
2967 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002968" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002969 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002970 let line1= curline + 1
2971 let line2= line("$") - lastline + 1
2972
2973 else
2974 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002975" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
2976" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002977 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002978" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002979 return
2980 endif
2981
2982 " User-provided (ie. optional) fix-it-up command
2983 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002984" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002985 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002986" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002987" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002988 endif
2989
Bram Moolenaaradc21822011-04-01 18:03:16 +02002990 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00002991 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002992 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00002993 endif
2994
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002995" 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 +00002996
2997 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00002998" redraw!
2999
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003000" 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 +00003001" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003002endfun
3003
Bram Moolenaar9964e462007-05-05 17:54:07 +00003004" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003005" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003006" Input:
3007" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3008" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003009" b:netrw_method= 1: rcp
3010" 2: ftp + <.netrc>
3011" 3: ftp + machine, id, password, and [path]filename
3012" 4: scp
3013" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003014" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003015" 7: rsync
3016" 8: fetch
3017" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003018" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003019" g:netrw_machine= hostname
3020" b:netrw_fname = filename
3021" g:netrw_port = optional port number (for ftp)
3022" g:netrw_choice = copy of input url (choice)
3023fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003024" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003025
Bram Moolenaar251e1912011-06-19 05:09:16 +02003026 " sanity check: choice should have at least three slashes in it
3027 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3028 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3029 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003030" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003031 return
3032 endif
3033
Bram Moolenaar5c736222010-01-06 20:54:52 +01003034 " record current g:netrw_machine, if any
3035 " curmachine used if protocol == ftp and no .netrc
3036 if exists("g:netrw_machine")
3037 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003038" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003039 else
3040 let curmachine= "N O T A HOST"
3041 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003042 if exists("g:netrw_port")
3043 let netrw_port= g:netrw_port
3044 endif
3045
3046 " insure that netrw_ftp_cmd starts off every method determination
3047 " with the current g:netrw_ftp_cmd
3048 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003049
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003050 " initialization
3051 let b:netrw_method = 0
3052 let g:netrw_machine = ""
3053 let b:netrw_fname = ""
3054 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003055 let g:netrw_choice = a:choice
3056
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003057 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003058 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003059 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3060 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003061 " rcpurm : rcp://[user@]host/filename Use rcp
3062 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003063 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003064 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003065 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003066 " rsyncurm : rsync://host[:port]/path Use rsync
3067 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3068 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003069 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003070 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3071 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003072 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3073 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003074 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003075 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003076 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003077 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003078 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003079 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003080 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003081 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003082
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003083" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003084 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003085 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003086 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003087" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003088 let b:netrw_method = 1
3089 let userid = substitute(a:choice,rcpurm,'\1',"")
3090 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3091 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003092 if userid != ""
3093 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003094 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003095
Bram Moolenaaradc21822011-04-01 18:03:16 +02003096 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003097 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003098" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003099 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003100 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3101 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3102 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003103
Bram Moolenaar15146672011-10-20 22:22:38 +02003104 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003105 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003106" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003107 let b:netrw_method = 5
3108 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3109 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003110 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003111
Bram Moolenaaradc21822011-04-01 18:03:16 +02003112 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003113 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003114" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003115 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003116 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003117 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3118 else
3119 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3120 endif
3121 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003122
Bram Moolenaaradc21822011-04-01 18:03:16 +02003123 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003124 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003125" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003126 let b:netrw_method = 7
3127 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3128 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003129
Bram Moolenaaradc21822011-04-01 18:03:16 +02003130 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003131 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003132" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003133 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003134 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3135 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3136 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003137" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003138 if userid != ""
3139 let g:netrw_uid= userid
3140 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003141
Bram Moolenaaradc21822011-04-01 18:03:16 +02003142 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003143 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003144 call NetUserPass("ftp:".g:netrw_machine)
3145 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003146 " if there's a change in hostname, require password re-entry
3147 unlet s:netrw_passwd
3148 endif
3149 if exists("netrw_port")
3150 unlet netrw_port
3151 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003152 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003153
Bram Moolenaar446cb832008-06-24 21:56:24 +00003154 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003155 let b:netrw_method = 3
3156 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003157 let host= substitute(g:netrw_machine,'\..*$','','')
3158 if exists("s:netrw_hup[host]")
3159 call NetUserPass("ftp:".host)
3160
Nir Lichtman1e34b952024-05-08 19:19:34 +02003161 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003162" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3163" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003164 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003165 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003166" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003167 endif
3168 let b:netrw_method= 2
3169 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003170" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003171 let b:netrw_method= 2
3172 else
3173 if !exists("g:netrw_uid") || g:netrw_uid == ""
3174 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003175 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003176 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003177 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003178 endif
3179 let b:netrw_method= 3
3180 endif
3181 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003182
Bram Moolenaaradc21822011-04-01 18:03:16 +02003183 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003184 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003185" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003186 let b:netrw_method = 8
3187 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3188 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3189 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3190 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003191
Bram Moolenaaradc21822011-04-01 18:03:16 +02003192 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003193 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003194" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003195 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003196 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3197 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003198 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003199 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003200 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003201
Bram Moolenaaradc21822011-04-01 18:03:16 +02003202 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003203 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003204" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003205 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003206 let b:netrw_method = 3
3207 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3208 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003209
Bram Moolenaar9964e462007-05-05 17:54:07 +00003210 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003211 let b:netrw_method = 2
3212 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3213 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3214 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003215
Bram Moolenaaradc21822011-04-01 18:03:16 +02003216 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003217 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003218" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003219 let b:netrw_method = 9
3220 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3221 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003222
Bram Moolenaaradc21822011-04-01 18:03:16 +02003223 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003224 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003225" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003226 let b:netrw_method = 1
3227 let userid = substitute(a:choice,rcphf,'\2',"")
3228 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3229 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003230" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3231" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3232" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3233" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003234 if userid != ""
3235 let g:netrw_uid= userid
3236 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003237
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003238 " Method#10: file://user@hostname/...path-to-file {{{3
3239 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003240" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003241 let b:netrw_method = 10
3242 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003243" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003244
Bram Moolenaaradc21822011-04-01 18:03:16 +02003245 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003246 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003247 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003248 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003249 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003250 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003251 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003252 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003253
Bram Moolenaar81695252004-12-29 20:58:21 +00003254 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003255 " remove any leading [:#] from port number
3256 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3257 elseif exists("netrw_port")
3258 " retain port number as implicit for subsequent ftp operations
3259 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003260 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003261
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003262" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3263" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3264" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3265" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003266" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003267" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003268" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003269" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003270" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003271" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003272" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003273" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003274endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003275
Bram Moolenaar9964e462007-05-05 17:54:07 +00003276" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003277" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003278" Usage: :call NetUserPass() -- will prompt for userid and password
3279" :call NetUserPass("uid") -- will prompt for password
3280" :call NetUserPass("uid","password") -- sets global userid and password
3281" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3282" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003283fun! NetUserPass(...)
3284
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003285" call Dfunc("NetUserPass() a:0=".a:0)
3286
3287 if !exists('s:netrw_hup')
3288 let s:netrw_hup= {}
3289 endif
3290
Bram Moolenaar071d4272004-06-13 20:20:40 +00003291 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003292 " case: no input arguments
3293
3294 " change host and username if not previously entered; get new password
3295 if !exists("g:netrw_machine")
3296 let g:netrw_machine= input('Enter hostname: ')
3297 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003299 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003300 let g:netrw_uid= input('Enter username: ')
3301 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003302 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003303 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003304
3305 " set up hup database
3306 let host = substitute(g:netrw_machine,'\..*$','','')
3307 if !exists('s:netrw_hup[host]')
3308 let s:netrw_hup[host]= {}
3309 endif
3310 let s:netrw_hup[host].uid = g:netrw_uid
3311 let s:netrw_hup[host].passwd = s:netrw_passwd
3312
3313 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003314 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003315
3316 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003317 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003318 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003319" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003320 let host = substitute(a:1,'^ftp:','','')
3321 let host = substitute(host,'\..*','','')
3322 if exists("s:netrw_hup[host]")
3323 let g:netrw_uid = s:netrw_hup[host].uid
3324 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003325" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3326" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003327 else
3328 let g:netrw_uid = input("Enter UserId: ")
3329 let s:netrw_passwd = inputsecret("Enter Password: ")
3330 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003331
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003332 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003333 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003334" 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 +02003335 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003336 if g:netrw_machine =~ '[0-9.]\+'
3337 let host= g:netrw_machine
3338 else
3339 let host= substitute(g:netrw_machine,'\..*$','','')
3340 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003341 else
3342 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003343 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003344 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003345" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003346 if exists("g:netrw_passwd")
3347 " ask for password if one not previously entered
3348 let s:netrw_passwd= g:netrw_passwd
3349 else
3350 let s:netrw_passwd = inputsecret("Enter Password: ")
3351 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003352 endif
3353
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003354" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003355 if exists("host")
3356 if !exists('s:netrw_hup[host]')
3357 let s:netrw_hup[host]= {}
3358 endif
3359 let s:netrw_hup[host].uid = g:netrw_uid
3360 let s:netrw_hup[host].passwd = s:netrw_passwd
3361 endif
3362
3363 elseif a:0 == 2
3364 let g:netrw_uid = a:1
3365 let s:netrw_passwd = a:2
3366
3367 elseif a:0 == 3
3368 " enter hostname, user-id, and password into the hup dictionary
3369 let host = substitute(a:1,'^\a\+:','','')
3370 let host = substitute(host,'\..*$','','')
3371 if !exists('s:netrw_hup[host]')
3372 let s:netrw_hup[host]= {}
3373 endif
3374 let s:netrw_hup[host].uid = a:2
3375 let s:netrw_hup[host].passwd = a:3
3376 let g:netrw_uid = s:netrw_hup[host].uid
3377 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003378" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3379" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003380 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003381
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003382" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003383endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003384
Bram Moolenaar85850f32019-07-19 22:05:51 +02003385" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003386" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003387" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003388
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003389" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003390" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3391fun! s:ExplorePatHls(pattern)
3392" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3393 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003394" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003395 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003396" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003397 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3398" call Dret("s:ExplorePatHls repat<".repat.">")
3399 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003400endfun
3401
3402" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003403" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003404" 0: (user: <mb>) bookmark current directory
3405" 1: (user: <gb>) change to the bookmarked directory
3406" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003407" 3: (browsing) records current directory history
3408" 4: (user: <u>) go up (previous) directory, using history
3409" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003410" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003411fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003412" 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 +02003413 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3414" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3415 return
3416 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003417
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003418 let ykeep = @@
3419 let curbufnr = bufnr("%")
3420
Bram Moolenaar9964e462007-05-05 17:54:07 +00003421 if a:chg == 0
3422 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003423" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003424 if exists("s:netrwmarkfilelist_{curbufnr}")
3425 call s:NetrwBookmark(0)
3426 echo "bookmarked marked files"
3427 else
3428 call s:MakeBookmark(a:curdir)
3429 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003430 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003431
KSR-Yasudaf4498252023-10-06 03:34:17 +09003432 try
3433 call s:NetrwBookHistSave()
3434 catch
3435 endtry
3436
Bram Moolenaar9964e462007-05-05 17:54:07 +00003437 elseif a:chg == 1
3438 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003439" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003440 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003441" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003442 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003443 else
3444 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3445 endif
3446
3447 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003448" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003449 let didwork= 0
3450 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003451" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003452 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003453" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003454 let cnt= 1
3455 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003456" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003457 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003458 let didwork = 1
3459 let cnt = cnt + 1
3460 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003461 endif
3462
3463 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003464 " Note: history is saved only when PerformListing is done;
3465 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3466 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003467 let first = 1
3468 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003469 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003470 while ( first || cnt != g:netrw_dirhistcnt )
3471" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003472 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003473" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003474 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003475 let didwork= 1
3476 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003477 let histcnt = histcnt + 1
3478 let first = 0
3479 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003480 if cnt < 0
3481 let cnt= cnt + g:netrw_dirhistmax
3482 endif
3483 endwhile
3484 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003485 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003486 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003487 if didwork
3488 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3489 endif
3490
3491 elseif a:chg == 3
3492 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003493" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003494 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 +02003495 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003496 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3497 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003498 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003499" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003500 endif
3501
3502 elseif a:chg == 4
3503 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003504" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003505 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003506 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3507 if g:netrw_dirhistcnt < 0
3508 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003509 endif
3510 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003511 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003512 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003513 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3514" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003515 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003516 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003517" call Decho("setl ma noro",'~'.expand("<slnum>"))
3518 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003519 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003520" call Decho("setl nomod",'~'.expand("<slnum>"))
3521" 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 +00003522 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003523" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3524 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003525 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003526 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003527 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003528 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003529 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003530 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003531 echo "Sorry, no predecessor directory exists yet"
3532 endif
3533
3534 elseif a:chg == 5
3535 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003536" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003537 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003538 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3539 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3540" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003541 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003542" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003543 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003544 sil! NetrwKeepj %d _
3545" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3546" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003547 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003548" 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 +02003549 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003550" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3551 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003552 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003553 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3554 if g:netrw_dirhistcnt < 0
3555 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003556 endif
3557 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003558 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003559 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003560 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003561 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003562 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003563
3564 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003565" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003566 if exists("s:netrwmarkfilelist_{curbufnr}")
3567 call s:NetrwBookmark(1)
3568 echo "removed marked files from bookmarks"
3569 else
3570 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003571 let iremove = v:count
3572 let dremove = g:netrw_bookmarklist[iremove - 1]
3573" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003574 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003575" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3576 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3577 echo "removed ".dremove." from g:netrw_bookmarklist"
3578" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003579 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003580" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003581
3582 try
3583 call s:NetrwBookHistSave()
3584 catch
3585 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003586 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003587 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003588 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003589 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003590" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003591endfun
3592
3593" ---------------------------------------------------------------------
3594" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003595" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003596" Sister function: s:NetrwBookHistSave()
3597fun! s:NetrwBookHistRead()
3598" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003599 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003600" 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 +02003601 return
3602 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003603 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003604
3605 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003606 if !exists("s:netrw_initbookhist")
3607 let home = s:NetrwHome()
3608 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003609 if filereadable(s:NetrwFile(savefile))
3610" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003611 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003612 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003613
3614 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003615 if g:netrw_dirhistmax > 0
3616 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003617 if filereadable(s:NetrwFile(savefile))
3618" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003619 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003620 endif
3621 let s:netrw_initbookhist= 1
3622 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003623 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003624 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003625
Bram Moolenaar97d62492012-11-15 21:28:22 +01003626 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003627" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3628" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003629" call Dret("s:NetrwBookHistRead")
3630endfun
3631
3632" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003633" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003634" Sister function: s:NetrwBookHistRead()
3635" I used to do this via viminfo but that appears to
3636" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003637" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3638" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003639" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003640fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003641" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003642 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003643" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003644 return
3645 endif
3646
Bram Moolenaar5c736222010-01-06 20:54:52 +01003647 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003648" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003649 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003650
3651 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003652 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003653" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003654 if g:netrw_use_noswf
3655 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3656 else
3657 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3658 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003659 setl nocin noai noci magic nospell nohid wig= noaw
3660 setl ma noro write
3661 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003662 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003663
Bram Moolenaar85850f32019-07-19 22:05:51 +02003664 " rename enew'd file: .netrwhist -- no attempt to merge
3665 " record dirhistmax and current dirhistcnt
3666 " save history
3667" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003668 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003669 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003670 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3671 if g:netrw_dirhistmax > 0
3672 let lastline = line("$")
3673 let cnt = g:netrw_dirhistcnt
3674 let first = 1
3675 while ( first || cnt != g:netrw_dirhistcnt )
3676 let lastline= lastline + 1
3677 if exists("g:netrw_dirhist_{cnt}")
3678 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3679" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3680 endif
3681 let first = 0
3682 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3683 if cnt < 0
3684 let cnt= cnt + g:netrw_dirhistmax
3685 endif
3686 endwhile
3687 exe "sil! w! ".savefile
3688" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3689 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003690
Bram Moolenaar85850f32019-07-19 22:05:51 +02003691 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003692 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003693 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003694" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003695 " merge and write .netrwbook
3696 let savefile= s:NetrwHome()."/.netrwbook"
3697
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003698 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003699 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003700 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003701 for bdm in booklist
3702 if index(g:netrw_bookmarklist,bdm) == -1
3703 call add(g:netrw_bookmarklist,bdm)
3704 endif
3705 endfor
3706 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003707 endif
3708
3709 " construct and save .netrwbook
3710 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003711 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003712" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003713 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003714
3715 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003716 let bgone= bufnr("%")
3717 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003718 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003719
3720" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003721endfun
3722
3723" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003724" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3725" list of the contents of a local or remote directory. It is assumed that the
3726" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3727" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003728" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003729fun! s:NetrwBrowse(islocal,dirname)
3730 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003731" 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 +02003732" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3733" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3734" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003735
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003736 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3737 " This is useful when one edits a local file, then :e ., then :Rex
3738 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3739 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003740" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003741 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003742
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003743 " s:NetrwBrowse : initialize history {{{3
3744 if !exists("s:netrw_initbookhist")
3745 NetrwKeepj call s:NetrwBookHistRead()
3746 endif
3747
3748 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003749 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003750 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003751" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003752 else
3753 let dirname= a:dirname
3754 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003755
Bram Moolenaar85850f32019-07-19 22:05:51 +02003756 " repoint t:netrw_lexbufnr if appropriate
3757 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3758" call Decho("set repointlexbufnr to true!")
3759 let repointlexbufnr= 1
3760 endif
3761
3762 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003763 if exists("s:netrw_skipbrowse")
3764 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003765" 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 +01003766" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003767 return
3768 endif
3769 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003770 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003771" call Dret("s:NetrwBrowse : missing shellescape()")
3772 return
3773 endif
3774 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003775 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003776" call Dret("s:NetrwBrowse : missing fnameescape()")
3777 return
3778 endif
3779
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003780 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003781 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003782
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003783 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003784 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3785 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3786" call Decho("clearing marked files",'~'.expand("<slnum>"))
3787 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3788 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003789 endif
3790
3791 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003792 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003793" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3794" 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 +02003795 if s:NetrwLcd(dirname)
3796" call Dret("s:NetrwBrowse : lcd failure")
3797 return
3798 endif
3799 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003800" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003801
Bram Moolenaar5c736222010-01-06 20:54:52 +01003802 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003803 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003804" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003805 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003806" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003807 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003808 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003809 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003810" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003811
3812 " remove any filetype indicator from end of dirname, except for the
3813 " "this is a directory" indicator (/).
3814 " There shouldn't be one of those here, anyway.
3815 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003816" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003817 call s:RemotePathAnalysis(dirname)
3818
3819 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3820 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003821 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003822 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003823" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003824 let b:netrw_curdir = dirname
3825 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003826 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003827 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3828 sil call netrw#NetRead(2,url)
3829 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003830" call Decho("url<".url.">",'~'.expand("<slnum>"))
3831" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3832" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003833 if s:path =~ '.bz2'
3834 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3835 elseif s:path =~ '.gz'
3836 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3837 elseif s:path =~ '.gz'
3838 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3839 else
3840 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3841 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003842 endif
3843
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003844 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003845 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003846 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003847" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003848 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003849" 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 +00003850
Bram Moolenaar446cb832008-06-24 21:56:24 +00003851" call Dret("s:NetrwBrowse : file<".s:fname.">")
3852 return
3853 endif
3854
Bram Moolenaaradc21822011-04-01 18:03:16 +02003855 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003856 call s:UseBufWinVars()
3857
3858 " set up some variables {{{3
3859 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003860 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003861 let s:last_sort_by = g:netrw_sort_by
3862
3863 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003864 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003865
Bram Moolenaar97d62492012-11-15 21:28:22 +01003866 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003867" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003868 let svpos = winsaveview()
3869" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003870 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003871
Bram Moolenaar446cb832008-06-24 21:56:24 +00003872 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003873 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3874 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3875" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3876" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3877 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3878 else
3879" " call Decho("2match none",'~'.expand("<slnum>"))
3880 2match none
3881 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003882 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003883 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003884 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003885" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003886 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003887" 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 +01003888" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003889 return
3890 endif
3891
3892 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003893" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003894 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003895 if b:netrw_curdir =~ '[/\\]$'
3896 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3897 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003898 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003899 let b:netrw_curdir= b:netrw_curdir."/"
3900 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003901 if b:netrw_curdir == ''
3902 if has("amiga")
3903 " On the Amiga, the empty string connotes the current directory
3904 let b:netrw_curdir= getcwd()
3905 else
3906 " under unix, when the root directory is encountered, the result
3907 " from the preceding substitute is an empty string.
3908 let b:netrw_curdir= '/'
3909 endif
3910 endif
3911 if !a:islocal && b:netrw_curdir !~ '/$'
3912 let b:netrw_curdir= b:netrw_curdir.'/'
3913 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003914" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003915
3916 " ------------
3917 " (local only) {{{3
3918 " ------------
3919 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003920" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003921
3922 " Set up ShellCmdPost handling. Append current buffer to browselist
3923 call s:LocalFastBrowser()
3924
3925 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3926 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003927" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3928" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003929 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003930 if s:NetrwLcd(b:netrw_curdir)
3931" call Dret("s:NetrwBrowse : lcd failure")
3932 return
3933 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003934 endif
3935 endif
3936
3937 " --------------------------------
3938 " remote handling: {{{3
3939 " --------------------------------
3940 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003941" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003942
Bram Moolenaar97d62492012-11-15 21:28:22 +01003943 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003944" 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 +02003945 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003946 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003947" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003948 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3949 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3950 if dirname !~ '/$'
3951 let dirname= dirname.'/'
3952 endif
3953 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003954" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003955 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003956 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003957" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003958 endif
3959
3960 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
3961 if dirname !~ dirpat
3962 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003963 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003964 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003965 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003966" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003967 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003968" 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 +00003969" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
3970 return
3971 endif
3972 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003973" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003974 endif " (additional remote handling)
3975
Bram Moolenaar85850f32019-07-19 22:05:51 +02003976 " -------------------------------
3977 " Perform Directory Listing: {{{3
3978 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003979 NetrwKeepj call s:NetrwMaps(a:islocal)
3980 NetrwKeepj call s:NetrwCommands(a:islocal)
3981 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003982
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003983 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003984 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003985" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3986
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003987 " If there is a rexposn: restore position with rexposn
3988 " Otherwise : set rexposn
3989 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003990" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
3991 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
3992 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
3993 NetrwKeepj exe w:netrw_bannercnt
3994 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003995 else
3996 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
3997 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02003998 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01003999 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004000" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004001 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004002 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004003
Bram Moolenaar85850f32019-07-19 22:05:51 +02004004 " repoint t:netrw_lexbufnr if appropriate
4005 if exists("repointlexbufnr")
4006 let t:netrw_lexbufnr= bufnr("%")
4007" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4008 endif
4009
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004010 " restore position
4011 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004012" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4013 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004014 endif
4015
Bram Moolenaara6878372014-03-22 21:02:50 +01004016 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004017 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4018 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004019" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4020" 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 +02004021" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004022 return
4023endfun
4024
4025" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004026" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4027" may not apply correctly; ie. netrw's idea of the current directory may
4028" differ from vim's. This function insures that netrw's idea of the current
4029" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004030" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004031fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004032" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4033" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4034" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4035" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4036" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004037
4038 " clean up any leading treedepthstring
4039 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4040 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004041" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004042 else
4043 let fname= a:fname
4044 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004045
4046 if g:netrw_keepdir
4047 " vim's idea of the current directory possibly may differ from netrw's
4048 if !exists("b:netrw_curdir")
4049 let b:netrw_curdir= getcwd()
4050 endif
4051
Nir Lichtman1e34b952024-05-08 19:19:34 +02004052 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004053 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004054 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004055 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004056" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004057 else
4058 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004059 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004060" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004061 endif
4062
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004063 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004064 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004065 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004066" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004067 else
4068 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004069 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004070" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004071 endif
4072 else
4073 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004074 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004075" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4076" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4077" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004078 endif
4079
Bram Moolenaar85850f32019-07-19 22:05:51 +02004080" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004081 return ret
4082endfun
4083
4084" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004085" s:NetrwFileInfo: supports qf (query for file information) {{{2
4086fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004087" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004088 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004089 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004090 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004091 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004092 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004093 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004094 let lsopt= "-lsadh --si"
4095 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004096" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004097 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004098
4099 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004100 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004101" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004102
Bram Moolenaara6878372014-03-22 21:02:50 +01004103 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004104 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004105" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004106
4107 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004108 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004109" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004110
Bram Moolenaar446cb832008-06-24 21:56:24 +00004111 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004112" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004113 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004114" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004115 endif
4116 else
4117 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004118" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4119 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004120 let fname= substitute(a:fname,".$","","")
4121 else
4122 let fname= a:fname
4123 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004124 let t = getftime(s:NetrwFile(fname))
4125 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004126 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004127 let sz= s:NetrwHumanReadable(sz)
4128 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004129 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4130" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004131 endif
4132 else
4133 echo "sorry, \"qf\" not supported yet for remote files"
4134 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004135 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004136" call Dret("s:NetrwFileInfo")
4137endfun
4138
4139" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004140" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4141fun! s:NetrwFullPath(filename)
4142" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4143 let filename= a:filename
4144 if filename !~ '^/'
4145 let filename= resolve(getcwd().'/'.filename)
4146 endif
4147 if filename != "/" && filename =~ '/$'
4148 let filename= substitute(filename,'/$','','')
4149 endif
4150" " call Dret("s:NetrwFullPath <".filename.">")
4151 return filename
4152endfun
4153
4154" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004155" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004156" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004157" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004158" 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 +00004159fun! s:NetrwGetBuffer(islocal,dirname)
4160" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004161" 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 +02004162" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4163" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004164 let dirname= a:dirname
4165
4166 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004167" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004168 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004169" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004170 let s:netrwbuf= {}
4171 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004172" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4173" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4174
4175 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4176 let bufnum = -1
4177
4178 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4179 if has_key(s:netrwbuf,"NetrwTreeListing")
4180 let bufnum= s:netrwbuf["NetrwTreeListing"]
4181 else
4182 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4183 endif
4184" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4185 if !bufexists(bufnum)
Peter Aronoffbe551da2024-09-22 11:29:40 +02004186 call remove(s:netrwbuf,"NetrwTreeListing")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004187 let bufnum= -1
4188 endif
4189 elseif bufnr("NetrwTreeListing") != -1
4190 let bufnum= bufnr("NetrwTreeListing")
4191" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4192 else
4193" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4194 let bufnum= -1
4195 endif
4196
4197 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004198 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004199" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004200 if !bufexists(bufnum)
4201 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4202 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004203 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004204
Bram Moolenaar446cb832008-06-24 21:56:24 +00004205 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004206" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004207 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004208 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004209" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4210
Bram Moolenaar71badf92023-04-22 22:40:14 +01004211 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004212 " IF the buffer already has the desired name
4213 " AND it is empty
4214 let curbuf = bufname("%")
4215 if curbuf == '.'
4216 let curbuf = getcwd()
4217 endif
4218" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004219" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004220" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4221" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4222" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4223" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4224 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004225" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4226 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004227 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004228" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004229 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004230 " 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 +00004231
4232 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004233 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004234" 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 +00004235 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004236" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004237 " name the buffer
4238 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4239 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004240" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004241 let w:netrw_treebufnr = bufnr("%")
4242 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004243 if g:netrw_use_noswf
4244 setl nobl bt=nofile noswf
4245 else
4246 setl nobl bt=nofile
4247 endif
4248 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4249 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4250 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4251 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004252" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004253 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004254 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004255 " enter the new buffer into the s:netrwbuf dictionary
4256 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4257" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4258" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004259 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004260" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004261
4262 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004263" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004264 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004265 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004266 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004267
4268 if &ft == "netrw"
4269" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4270 exe "sil! NetrwKeepj noswapfile b ".bufnum
4271" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004272 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004273" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4274 call s:NetrwEditBuf(bufnum)
4275" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004276 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004277" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004278 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004279 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004280 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004281
4282 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004283 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004284
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004285 if line("$") <= 1 && getline(1) == ""
4286 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004287 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004288" 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>"))
4289" 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 +01004290" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4291 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004292
Bram Moolenaar97d62492012-11-15 21:28:22 +01004293 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004294" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004295 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004296 sil NetrwKeepj %d _
4297" 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>"))
4298" 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 +01004299" 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 +00004300 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004301
Bram Moolenaar446cb832008-06-24 21:56:24 +00004302 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004303" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4304" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004305 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004306 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004307 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004308" 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>"))
4309" 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 +01004310" 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 +00004311 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004312
Bram Moolenaar446cb832008-06-24 21:56:24 +00004313 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004314" 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>"))
4315" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4316" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004317 return 1
4318 endif
4319 endif
4320
4321 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4322 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4323 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4324 " med 1 D H
4325 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004326" 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 +00004327 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004328 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004329 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004330
4331 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004332" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4333" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4334 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004335
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004336" 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>"))
4337" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4338" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004339 return 0
4340endfun
4341
4342" ---------------------------------------------------------------------
4343" s:NetrwGetcwd: get the current directory. {{{2
4344" Change backslashes to forward slashes, if any.
4345" If doesc is true, escape certain troublesome characters
4346fun! s:NetrwGetcwd(doesc)
4347" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4348 let curdir= substitute(getcwd(),'\\','/','ge')
4349 if curdir !~ '[\/]$'
4350 let curdir= curdir.'/'
4351 endif
4352 if a:doesc
4353 let curdir= fnameescape(curdir)
4354 endif
4355" call Dret("NetrwGetcwd <".curdir.">")
4356 return curdir
4357endfun
4358
4359" ---------------------------------------------------------------------
4360" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4361fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004362" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4363" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4364 let keepsol= &l:sol
4365 setl nosol
4366
Bram Moolenaar446cb832008-06-24 21:56:24 +00004367 call s:UseBufWinVars()
4368
4369 " insure that w:netrw_liststyle is set up
4370 if !exists("w:netrw_liststyle")
4371 if exists("g:netrw_liststyle")
4372 let w:netrw_liststyle= g:netrw_liststyle
4373 else
4374 let w:netrw_liststyle= s:THINLIST
4375 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004376" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004377 endif
4378
4379 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4380 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004381" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004382 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004383 let dirname= "./"
4384 let curline= getline('.')
4385
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004386 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004387 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004388 let s:netrw_skipbrowse= 1
4389 echo 'Pressing "s" also works'
4390
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004391 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004392 let s:netrw_skipbrowse= 1
4393 echo 'Press "S" to edit sorting sequence'
4394
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004395 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004396 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004397 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004398
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004399 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004400 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004401 let s:netrw_skipbrowse= 1
4402 echo 'Pressing "a" also works'
4403
4404 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004405 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004406 endif
4407
4408 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004409" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004410 NetrwKeepj norm! 0
4411 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004412
4413 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004414" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004415 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004416 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4417
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004418 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004419" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004420 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004421 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004422
4423 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004424" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004425 let dirname= getline('.')
4426
4427 if !exists("b:netrw_cpf")
4428 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004429 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 +01004430 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004431" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004432 endif
4433
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004434" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004435 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004436" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4437" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004438 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004439 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004440 else
4441 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004442 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004443 endif
Enno3146d632024-07-04 19:44:42 +02004444
4445 let dict={}
4446 " save the unnamed register and register 0-9 and a
4447 let dict.a=[getreg('a'), getregtype('a')]
4448 for i in range(0, 9)
4449 let dict[i] = [getreg(i), getregtype(i)]
4450 endfor
4451 let dict.unnamed = [getreg(''), getregtype('')]
4452
Bram Moolenaarc236c162008-07-13 17:41:49 +00004453 let eofname= filestart + b:netrw_cpf + 1
4454 if eofname <= col("$")
4455 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004456 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004457 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004458 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004459 endif
Enno3146d632024-07-04 19:44:42 +02004460
Bram Moolenaar446cb832008-06-24 21:56:24 +00004461 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004462 call s:RestoreRegister(dict)
4463
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004464" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004465 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004466" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004467 endif
4468
4469 " symlinks are indicated by a trailing "@". Remove it before further processing.
4470 let dirname= substitute(dirname,"@$","","")
4471
4472 " executables are indicated by a trailing "*". Remove it before further processing.
4473 let dirname= substitute(dirname,"\*$","","")
4474
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004475 let &l:sol= keepsol
4476
Bram Moolenaar446cb832008-06-24 21:56:24 +00004477" call Dret("s:NetrwGetWord <".dirname.">")
4478 return dirname
4479endfun
4480
4481" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004482" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4483" g:netrw_bufsettings will be used after the listing is produced.
4484" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004485fun! s:NetrwListSettings(islocal)
4486" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004487" 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 +00004488 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004489" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4490 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4491 setl bt=nofile nobl ma nonu nowrap noro nornu
4492 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004493 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004494 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004495 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004496" call Dredir("ls!","s:NetrwListSettings")
4497" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004498 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004499 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004500 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004501 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004502 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004503 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004504 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004505" 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 +00004506" call Dret("s:NetrwListSettings")
4507endfun
4508
4509" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004510" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004511" islocal=0: remote browsing
4512" =1: local browsing
4513fun! s:NetrwListStyle(islocal)
4514" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004515
Bram Moolenaar97d62492012-11-15 21:28:22 +01004516 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004517 let fname = s:NetrwGetWord()
4518 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004519 let svpos = winsaveview()
4520" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004521 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004522" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4523" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4524" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004525
Bram Moolenaar85850f32019-07-19 22:05:51 +02004526 " repoint t:netrw_lexbufnr if appropriate
4527 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4528" call Decho("set repointlexbufnr to true!")
4529 let repointlexbufnr= 1
4530 endif
4531
Bram Moolenaar446cb832008-06-24 21:56:24 +00004532 if w:netrw_liststyle == s:THINLIST
4533 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004534" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004535 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4536
4537 elseif w:netrw_liststyle == s:LONGLIST
4538 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004539" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004540 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4541
4542 elseif w:netrw_liststyle == s:WIDELIST
4543 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004544" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004545 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4546
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004547 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004548" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004549 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4550
4551 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004552 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004553 let g:netrw_liststyle = s:THINLIST
4554 let w:netrw_liststyle = g:netrw_liststyle
4555 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4556 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004557 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004558" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004559
4560 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004561" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4562 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004563 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004564" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004565 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004566" 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 +00004567
4568 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004569" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004570 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004571 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004572
Bram Moolenaar85850f32019-07-19 22:05:51 +02004573 " repoint t:netrw_lexbufnr if appropriate
4574 if exists("repointlexbufnr")
4575 let t:netrw_lexbufnr= bufnr("%")
4576" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4577 endif
4578
Bram Moolenaar13600302014-05-22 18:26:40 +02004579 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004580" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4581 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004582 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004583
4584" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4585endfun
4586
4587" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004588" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4589fun! s:NetrwBannerCtrl(islocal)
4590" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4591
Bram Moolenaar97d62492012-11-15 21:28:22 +01004592 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004593 " toggle the banner (enable/suppress)
4594 let g:netrw_banner= !g:netrw_banner
4595
4596 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004597 let svpos= winsaveview()
4598" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004599 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4600
4601 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004602 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4603 let fname= s:NetrwGetWord()
4604 sil NetrwKeepj $
4605 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4606" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4607 if result <= 0 && exists("w:netrw_bannercnt")
4608 exe "NetrwKeepj ".w:netrw_bannercnt
4609 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004610 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004611 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004612" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4613endfun
4614
4615" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004616" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4617"
4618" No bang: enters files/directories into Netrw's bookmark system
4619" No argument and in netrw buffer:
4620" if there are marked files: bookmark marked files
4621" otherwise : bookmark file/directory under cursor
4622" No argument and not in netrw buffer: bookmarks current open file
4623" Has arguments: globs them individually and bookmarks them
4624"
4625" With bang: deletes files/directories from Netrw's bookmark system
4626fun! s:NetrwBookmark(del,...)
4627" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4628 if a:0 == 0
4629 if &ft == "netrw"
4630 let curbufnr = bufnr("%")
4631
4632 if exists("s:netrwmarkfilelist_{curbufnr}")
4633 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004634" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004635 let svpos = winsaveview()
4636" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004637 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004638 for fname in s:netrwmarkfilelist_{curbufnr}
4639 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4640 endfor
4641 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4642 call s:NetrwUnmarkList(curbufnr,curdir)
4643 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004644" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4645 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004646 else
4647 let fname= s:NetrwGetWord()
4648 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4649 endif
4650
4651 else
4652 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004653" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004654 let fname= expand("%")
4655 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4656 endif
4657
4658 else
4659 " bookmark specified files
4660 " attempts to infer if working remote or local
4661 " by deciding if the current file begins with an url
4662 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004663 let islocal= expand("%") !~ '^\a\{3,}://'
4664" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004665 let i = 1
4666 while i <= a:0
4667 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004668 if v:version > 704 || (v:version == 704 && has("patch656"))
4669 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004670 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004671 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004672 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004673 else
4674 let mbfiles= [a:{i}]
4675 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004676" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004677 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004678" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004679 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4680 endfor
4681 let i= i + 1
4682 endwhile
4683 endif
4684
4685 " update the menu
4686 call s:NetrwBookmarkMenu()
4687
4688" call Dret("s:NetrwBookmark")
4689endfun
4690
4691" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004692" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4693" .2.[cnt] for bookmarks, and
4694" .3.[cnt] for history
4695" (see s:NetrwMenu())
4696fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004697 if !exists("s:netrw_menucnt")
4698 return
4699 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004700" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004701
4702 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004703 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004704 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004705" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004706 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4707 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004708 endif
4709 if !exists("s:netrw_initbookhist")
4710 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004711 endif
4712
4713 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004714 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004715 let cnt= 1
4716 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004717" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004718 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004719
4720 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004721 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004722
4723 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004724 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 +01004725 let cnt= cnt + 1
4726 endfor
4727
4728 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004729
4730 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004731 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004732 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004733 let first = 1
4734 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004735 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004736 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004737 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004738 if exists("g:netrw_dirhist_{cnt}")
4739 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004740" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004741 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4742 endif
4743 let first = 0
4744 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4745 if cnt < 0
4746 let cnt= cnt + g:netrw_dirhistmax
4747 endif
4748 endwhile
4749 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004750
Bram Moolenaar9964e462007-05-05 17:54:07 +00004751 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004752" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004753endfun
4754
4755" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004756" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4757" directory and a new directory name. Also, if the
4758" "new directory name" is actually a file,
4759" NetrwBrowseChgDir() edits the file.
4760fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004761" 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 +01004762" 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 +00004763
Bram Moolenaar97d62492012-11-15 21:28:22 +01004764 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004765 if !exists("b:netrw_curdir")
4766 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4767 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004768 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004769" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4770" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004771" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004772" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004773 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004774 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004775" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004776
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004777 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004778" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004779 call s:SavePosn(s:netrw_posn)
4780 NetrwKeepj call s:NetrwOptionsSave("s:")
4781 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004782 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004783 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004784 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004785 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004786 endif
4787 let newdir = a:newdir
4788 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004789 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004790" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004791" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004792" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004793
4794 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004795" 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 +01004796 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004797" 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 +01004798 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004799 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004800" 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 +01004801 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004802" 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 +02004803 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004804 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004805 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004806 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004807" 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 +01004808 endif
4809 endif
4810" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004811" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004812 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004813
Bram Moolenaar446cb832008-06-24 21:56:24 +00004814 " set up o/s-dependent directory recognition pattern
4815 if has("amiga")
4816 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004817 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004818 let dirpat= '[\/]$'
4819 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004820" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004821
4822 if dirname !~ dirpat
4823 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004824 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004825 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004826" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004827 endif
4828
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004829" 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 +01004830 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004831 " ------------------------------
4832 " NetrwBrowseChgDir: edit a file {{{3
4833 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004834" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004835
Bram Moolenaar97d62492012-11-15 21:28:22 +01004836 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004837 let s:rexposn_{bufnr("%")}= winsaveview()
4838" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004839" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4840" 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 +01004841
Bram Moolenaar446cb832008-06-24 21:56:24 +00004842 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004843" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4844" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004845" let newdir = s:NetrwTreePath(s:netrw_treetop)
4846" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004847 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004848 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4849" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4850 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004851 if dirname =~ '/$'
4852 let dirname= dirname.newdir
4853 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004854 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004855 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004856" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4857" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004858 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004859" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004860 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004861 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004862 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004863 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004864" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004865 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004866 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004867" 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 +02004868 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004869 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004870 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004871" " 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 +01004872 if type(g:netrw_browse_split) == 3
4873 " open file in server
4874 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004875" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004876 call s:NetrwServerEdit(a:islocal,dirname)
4877" call Dret("s:NetrwBrowseChgDir")
4878 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004879
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004880 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004881 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004882" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004883 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4884 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004885 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004886 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004887 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004888 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004889
Bram Moolenaar446cb832008-06-24 21:56:24 +00004890 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004891 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004892" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004893 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4894 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004895 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004896 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004897 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004898 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004899
Bram Moolenaar446cb832008-06-24 21:56:24 +00004900 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004901 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004902" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004903 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004904 if !exists("b:netrw_curdir")
4905 let b:netrw_curdir= getcwd()
4906 endif
4907 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004908
Bram Moolenaar446cb832008-06-24 21:56:24 +00004909 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004910 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004911" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004912 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004913 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004914" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004915 return
4916 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004917 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004918
Bram Moolenaar9964e462007-05-05 17:54:07 +00004919 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004920 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004921" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004922 call s:NetrwMenu(0)
4923 " optional change to window
4924 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004925" 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 +02004926 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004927 " if g:netrw_chgwin is set to one more than the last window, then
4928 " vertically split the last window to make that window available.
4929 let curwin= winnr()
4930 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4931 vs
4932 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004933 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004934 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004935 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004936 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004937 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004938
Bram Moolenaar9964e462007-05-05 17:54:07 +00004939 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004940
Bram Moolenaar446cb832008-06-24 21:56:24 +00004941 " the point where netrw actually edits the (local) file
4942 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004943 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004944 if !&mod
4945 " if e the new file would fail due to &mod, then don't change any of the flags
4946 let dolockout= 1
4947 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004948 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004949" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004950 " some like c-^ to return to the last edited file
4951 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004952 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4953 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01004954 call s:NetrwEditFile("e","",dirname)
4955" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004956 " COMBAK -- cuc cul related
4957 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02004958 if &hidden || &bufhidden == "hide"
4959 " file came from vim's hidden storage. Don't "restore" options with it.
4960 let dorestore= 0
4961 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004962 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004963" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00004964 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004965
4966 " handle g:Netrw_funcref -- call external-to-netrw functions
4967 " This code will handle g:Netrw_funcref as an individual function reference
4968 " or as a list of function references. It will ignore anything that's not
4969 " a function reference. See :help Funcref for information about function references.
4970 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004971" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004972 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004973" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004974 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004975 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004976" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004977 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004978 if type(Fncref) == 2
4979 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004980 endif
4981 endfor
4982 endif
4983 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004984 endif
4985
4986 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004987 " ----------------------------------------------------
4988 " NetrwBrowseChgDir: just go to the new directory spec {{{3
4989 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004990" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004991 let dirname = newdir
4992 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004993 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004994 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004995
4996 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004997 " ---------------------------------------------
4998 " NetrwBrowseChgDir: refresh the directory list {{{3
4999 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005000" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005001 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005002 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005003
5004 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005005 " --------------------------------------
5006 " NetrwBrowseChgDir: go up one directory {{{3
5007 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005008" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005009
5010 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5011 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005012" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5013" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005014 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005015 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005016 endif
5017
5018 if has("amiga")
5019 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005020" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005021 if a:islocal
5022 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5023 let dirname= substitute(dirname,'/$','','')
5024 else
5025 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5026 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005027" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005028
Nir Lichtman1e34b952024-05-08 19:19:34 +02005029 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005030 " windows
5031 if a:islocal
5032 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5033 if dirname == ""
5034 let dirname= '/'
5035 endif
5036 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005037 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005038 endif
5039 if dirname =~ '^\a:$'
5040 let dirname= dirname.'/'
5041 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005042" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005043
Bram Moolenaar446cb832008-06-24 21:56:24 +00005044 else
5045 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005046" 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 +00005047 if a:islocal
5048 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5049 if dirname == ""
5050 let dirname= '/'
5051 endif
5052 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005053 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005054 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005055" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005056 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005057 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005058 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005059
5060 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005061 " --------------------------------------
5062 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5063 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005064" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005065 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5066" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005067 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005068 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005069" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5070 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005071 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005072 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005073" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005074 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005075 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005076" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005077
5078 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005079" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005080 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005081" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005082 let haskey= 1
5083 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005084" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005085 endif
5086
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005087 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005088" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005089 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005090 if has_key(w:netrw_treedict,treedir."/")
5091 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005092" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005093 let haskey = 1
5094 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005095" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005096 endif
5097 endif
5098
5099 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005100" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005101 if !haskey && treedir =~ '/$'
5102 let treedir= substitute(treedir,'/$','','')
5103 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005104" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005105 let haskey = 1
5106 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005107" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005108 endif
5109 endif
5110
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005111" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005112 if haskey
5113 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005114" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005115 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005116" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5117" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005118 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005119 else
5120 " go down one directory
5121 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005122" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5123" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005124 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005125 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005126" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005127 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005128
5129 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005130 " ----------------------------------------
5131 " NetrwBrowseChgDir: Go down one directory {{{3
5132 " ----------------------------------------
5133 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005134" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005135 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005136 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005137 endif
5138
Bram Moolenaar97d62492012-11-15 21:28:22 +01005139 " --------------------------------------
5140 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5141 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005142 if dorestore
5143 " dorestore is zero'd when a local file was hidden or bufhidden;
5144 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005145" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005146 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005147" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005148" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005149 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005150 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005151" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005152 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005153" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5154" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005155 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005156" 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 +02005157 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005158" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5159" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005160 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005161" 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 +02005162 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005163 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005164 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005165 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005166
Bram Moolenaar446cb832008-06-24 21:56:24 +00005167" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5168 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005169endfun
5170
5171" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005172" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5173" for thin, long, and wide: cursor placed just after banner
5174" for tree, keeps cursor on current filename
5175fun! s:NetrwBrowseUpDir(islocal)
5176" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005177 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5178 " this test needed because occasionally this function seems to be incorrectly called
5179 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005180 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005181 " directories.
5182" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5183 return
5184 endif
5185
Bram Moolenaara6878372014-03-22 21:02:50 +01005186 norm! 0
5187 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005188" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005189 let curline= getline(".")
5190 let swwline= winline() - 1
5191 if exists("w:netrw_treetop")
5192 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005193 elseif exists("b:netrw_curdir")
5194 let w:netrw_treetop= b:netrw_curdir
5195 else
5196 let w:netrw_treetop= getcwd()
5197 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005198 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005199 let curfile = getline(".")
5200 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005201 if a:islocal
5202 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5203 else
5204 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5205 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005206" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5207" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5208 if w:netrw_treetop == '/'
5209 keepj call search('^\M'.curfile,"w")
5210 elseif curfile == '../'
5211 keepj call search('^\M'.curfile,"wb")
5212 else
5213" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5214 while 1
5215 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5216 let treepath= s:NetrwTreePath(w:netrw_treetop)
5217" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5218 if treepath == curpath
5219 break
5220 endif
5221 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005222 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005223
Bram Moolenaara6878372014-03-22 21:02:50 +01005224 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005225" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005226 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005227 if exists("b:netrw_curdir")
5228 let curdir= b:netrw_curdir
5229 else
5230 let curdir= expand(getcwd())
5231 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005232 if a:islocal
5233 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5234 else
5235 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5236 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005237 call s:RestorePosn(s:netrw_posn)
5238 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005239 let curdir= '\<'. escape(curdir, '~'). '/'
5240 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005241 endif
5242" call Dret("s:NetrwBrowseUpDir")
5243endfun
5244
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005245func s:redir()
5246 " set up redirection (avoids browser messages)
5247 " by default if not set, g:netrw_suppress_gx_mesg is true
5248 if get(g:, 'netrw_suppress_gx_mesg', 1)
5249 if &srr =~# "%s"
5250 return printf(&srr, has("win32") ? "nul" : "/dev/null")
5251 else
5252 return &srr .. (has("win32") ? "nul" : "/dev/null")
5253 endif
5254 endif
5255 return ''
5256endfunc
5257
5258if has('unix')
5259 if has('win32unix')
5260 " Cygwin provides cygstart
5261 if executable('cygstart')
5262 fun! netrw#Launch(args)
5263 exe 'silent ! cygstart --hide' a:args s:redir() | redraw!
5264 endfun
5265 elseif !empty($MSYSTEM) && executable('start')
5266 " MSYS2/Git Bash comes by default without cygstart; see
5267 " https://www.msys2.org/wiki/How-does-MSYS2-differ-from-Cygwin
5268 " Instead it provides /usr/bin/start script running `cmd.exe //c start`
5269 " Adding "" //b` sets void title, hides cmd window and blocks path conversion
5270 " of /b to \b\ " by MSYS2; see https://www.msys2.org/docs/filesystem-paths/
5271 fun! netrw#Launch(args)
5272 exe 'silent !start "" //b' a:args s:redir() | redraw!
5273 endfun
5274 else
5275 " imitate /usr/bin/start script for other environments and hope for the best
5276 fun! netrw#Launch(args)
5277 exe 'silent !cmd //c start "" //b' a:args s:redir() | redraw!
5278 endfun
5279 endif
5280 elseif exists('$WSL_DISTRO_NAME') " use cmd.exe to start GUI apps in WSL
5281 fun! netrw#Launch(args)
5282 let args = a:args
5283 exe 'silent !' ..
5284 \ ((args =~? '\v<\f+\.(exe|com|bat|cmd)>') ?
5285 \ 'cmd.exe /c start "" /b ' .. args :
5286 \ 'nohup ' .. args .. ' ' .. s:redir() .. ' &')
5287 \ | redraw!
5288 endfun
5289 else
5290 fun! netrw#Launch(args)
5291 exe ':silent ! nohup' a:args s:redir() '&' | redraw!
5292 endfun
5293 endif
5294elseif has('win32')
5295 fun! netrw#Launch(args)
5296 exe 'silent !' .. (&shell =~? '\<cmd\.exe\>' ? '' : 'cmd.exe /c')
5297 \ 'start "" /b' a:args s:redir() | redraw!
5298 endfun
5299else
5300 fun! netrw#Launch(dummy)
5301 echom 'No common launcher found'
5302 endfun
5303endif
5304
5305" Git Bash
5306if has('win32unix')
5307 " (cyg)start suffices
5308 let s:os_viewer = ''
5309" Windows / WSL
5310elseif executable('explorer.exe')
5311 let s:os_viewer = 'explorer.exe'
5312" Linux / BSD
5313elseif executable('xdg-open')
5314 let s:os_viewer = 'xdg-open'
5315" MacOS
5316elseif executable('open')
5317 let s:os_viewer = 'open'
5318endif
5319
5320fun! s:viewer()
5321 if exists('g:netrw_browsex_viewer') && executable(g:netrw_browsex_viewer)
5322 " extract any viewing options. Assumes that they're set apart by spaces.
5323 " call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
5324 if g:netrw_browsex_viewer =~ '\s'
5325 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5326 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5327 let oviewer = ''
5328 let cnt = 1
5329 while !executable(viewer) && viewer != oviewer
5330 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5331 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5332 let cnt = cnt + 1
5333 let oviewer = viewer
5334 " call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
5335 endwhile
5336 else
5337 let viewer = g:netrw_browsex_viewer
5338 let viewopt = ""
5339 endif
5340 " call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
5341 return viewer .. ' ' .. viewopt
5342 else
5343 if !exists('s:os_viewer')
5344 call netrw#ErrorMsg(s:ERROR,"No program to open this path found. See :help Open for more information.",106)
5345 else
5346 return s:os_viewer
5347 endif
5348 endif
5349endfun
5350
5351fun! netrw#Open(file) abort
5352 call netrw#Launch(s:viewer() .. ' ' .. shellescape(a:file, 1))
5353endf
5354
5355if !exists('g:netrw_regex_url')
5356 let g:netrw_regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}'
5357endif
5358
Bram Moolenaara6878372014-03-22 21:02:50 +01005359" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005360" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005361" given filename; typically this means given their extension.
5362" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005363fun! netrw#BrowseX(fname,remote)
Bram Moolenaar91359012019-11-30 17:57:03 +01005364 if a:remote == 0 && isdirectory(a:fname)
5365 " if its really just a local directory, then do a "gf" instead
Bram Moolenaar29634562020-01-09 21:46:04 +01005366 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005367 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5368 " remote directory, not a webpage access, looks like an attempt to do a directory listing
Bram Moolenaar91359012019-11-30 17:57:03 +01005369 norm! gf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005370 endif
5371
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005372 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5373 let remote = a:remote
5374 else
5375 let remote = 0
5376 endif
5377
Bram Moolenaar97d62492012-11-15 21:28:22 +01005378 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005379 let screenposn = winsaveview()
Bram Moolenaar97d62492012-11-15 21:28:22 +01005380
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005381 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5382 let awkeep = &aw
5383 set noaw
5384
Bram Moolenaar5c736222010-01-06 20:54:52 +01005385 " special core dump handler
5386 if a:fname =~ '/core\(\.\d\+\)\=$'
5387 if exists("g:Netrw_corehandler")
5388 if type(g:Netrw_corehandler) == 2
5389 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005390 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005391 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005392 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005393 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005394 if type(Fncref) == 2
5395 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005396 endif
5397 endfor
5398 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005399 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005400 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005401 let &aw= awkeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005402 return
5403 endif
5404 endif
5405
Bram Moolenaar446cb832008-06-24 21:56:24 +00005406 " set up the filename
5407 " (lower case the extension, make a local copy of a remote file)
5408 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005409 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005410 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005411 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005412 if exten =~ "[\\/]"
5413 let exten= ""
5414 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005415
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005416 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005417 " create a local copy
Bram Moolenaarff034192013-04-24 18:51:19 +02005418 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005419 call netrw#NetRead(3,a:fname)
5420 " attempt to rename tempfile
5421 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005422 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02005423 if s:netrw_tmpfile != newname && newname != ""
5424 if rename(s:netrw_tmpfile,newname) == 0
5425 " renaming succeeded
Bram Moolenaar85850f32019-07-19 22:05:51 +02005426 let fname= newname
5427 else
5428 " renaming failed
Bram Moolenaar85850f32019-07-19 22:05:51 +02005429 let fname= s:netrw_tmpfile
5430 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005431 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005432 let fname= s:netrw_tmpfile
5433 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005434 else
5435 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005436 " special ~ handler for local
5437 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005438 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005439 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005440 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005441
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005442 " although shellescape(..., 1) is used in netrw#Open(), it's insufficient
5443 call netrw#Open(escape(fname, '#%'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005444
Bram Moolenaar446cb832008-06-24 21:56:24 +00005445 " cleanup: remove temporary file,
5446 " delete current buffer if success with handler,
5447 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005448 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005449 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005450" if remote == 1 && fname != a:fname
Bram Moolenaarc236c162008-07-13 17:41:49 +00005451" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005452" endif
5453
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005454 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005455 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005456 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005457 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005458 endif
Christian Brabandt9f320692024-10-30 18:36:20 +01005459 exe "sil! NetrwKeepj norm! \<c-o>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005460 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005461 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005462 let @@ = ykeep
5463 let &aw= awkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005464endfun
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 Brabandt8b0fa7a2024-10-31 09:21:23 +01005735 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
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005749 return filelist
5750endfun
5751
5752" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005753" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5754fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005755" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005756 if a:newfile =~ '[/@*=|\\]$'
5757 let newfile= substitute(a:newfile,'.$','','')
5758 else
5759 let newfile= a:newfile
5760 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005761 if a:islocal
5762 call s:NetrwBrowseChgDir(a:islocal,newfile)
5763 else
5764 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5765 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005766" call Dret("s:NetrwForceFile")
5767endfun
5768
5769" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005770" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5771" and switches the hiding mode. The actual hiding is done by
5772" s:NetrwListHide().
5773" g:netrw_hide= 0: show all
5774" 1: show not-hidden files
5775" 2: show hidden files only
5776fun! s:NetrwHide(islocal)
5777" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005778 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005779 let svpos= winsaveview()
5780" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005781
5782 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005783" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5784" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005785
5786 " hide the files in the markfile list
5787 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005788" 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 +00005789 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5790 " remove fname from hiding list
5791 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5792 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5793 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005794" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005795 else
5796 " append fname to hiding list
5797 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5798 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5799 else
5800 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5801 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005802" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005803 endif
5804 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005805 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005806 let g:netrw_hide= 1
5807
5808 else
5809
5810 " switch between show-all/show-not-hidden/show-hidden
5811 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005812 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005813 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005814 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005815 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005816" call Dret("NetrwHide")
5817 return
5818 endif
5819 endif
5820
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005821 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005822" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5823 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005824 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005825" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005826endfun
5827
5828" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005829" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5830fun! s:NetrwHideEdit(islocal)
5831" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5832
5833 let ykeep= @@
5834 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005835 let svpos= winsaveview()
5836" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005837
5838 " get new hiding list from user
5839 call inputsave()
5840 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5841 call inputrestore()
5842 let g:netrw_list_hide= newhide
5843" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5844
5845 " refresh the listing
5846 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5847
5848 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005849" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5850 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005851 let @@= ykeep
5852
5853" call Dret("NetrwHideEdit")
5854endfun
5855
5856" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005857" s:NetrwHidden: invoked by "gh" {{{2
5858fun! s:NetrwHidden(islocal)
5859" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005860 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005861 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005862 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005863" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005864
5865 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005866 " remove .file pattern from hiding list
5867" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005868 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005869 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005870" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005871 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5872 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005873" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005874 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5875 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005876 if g:netrw_list_hide =~ '^,'
5877 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5878 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005879
5880 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005881 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005882" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5883 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005884 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005885" call Dret("s:NetrwHidden")
5886endfun
5887
5888" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005889" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5890fun! s:NetrwHome()
5891 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005892 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005893 else
5894 " go to vim plugin home
5895 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005896 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005897 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005898 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005899 let home= basehome."/.vim"
5900 break
5901 endif
5902 endfor
5903 if home == ""
5904 " just pick the first directory
5905 let home= substitute(&rtp,',.*$','','')
5906 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005907 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005908 let home= substitute(home,'/','\\','g')
5909 endif
5910 endif
5911 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005912 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005913" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005914 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005915" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005916 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005917 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005918" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005919 call mkdir(home)
5920 endif
5921 endif
5922 let g:netrw_home= home
5923 return home
5924endfun
5925
5926" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005927" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5928fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005929 if exists("s:netrwdrag")
5930 return
5931 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005932 if &ft != "netrw"
5933 return
5934 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005935" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005936
Bram Moolenaar97d62492012-11-15 21:28:22 +01005937 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005938 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005939 while getchar(0) != 0
5940 "clear the input stream
5941 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005942 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005943 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005944 let mouse_lnum = v:mouse_lnum
5945 let wlastline = line('w$')
5946 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005947" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
5948" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005949 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5950 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005951 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005952" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
5953 return
5954 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005955 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005956 " 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 +01005957 " without this test when its disabled.
5958 " 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 +01005959" 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 +01005960 if v:mouse_col > virtcol('.')
5961 let @@= ykeep
5962" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
5963 return
5964 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005965
Bram Moolenaar446cb832008-06-24 21:56:24 +00005966 if a:islocal
5967 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005968 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005969 endif
5970 else
5971 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005972 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005973 endif
5974 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005975 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005976" call Dret("s:NetrwLeftmouse")
5977endfun
5978
5979" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005980" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
5981fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005982 if &ft != "netrw"
5983 return
5984 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005985" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
5986 call s:NetrwMarkFileTgt(a:islocal)
5987" call Dret("s:NetrwCLeftmouse")
5988endfun
5989
5990" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005991" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
5992" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02005993" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005994" a:islocal=2 : <c-r> used, remote
5995" a:islocal=3 : <c-r> used, local
5996fun! s:NetrwServerEdit(islocal,fname)
5997" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
5998 let islocal = a:islocal%2 " =0: remote =1: local
5999 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006000" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006001
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006002 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006003 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006004 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006005" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006006 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006007 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006008 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6009 unlet s:netrw_browse_split_{winnr()}
6010 endif
6011 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6012" call Dret("s:NetrwServerEdit")
6013 return
6014 endif
6015
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006016" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006017 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006018" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006019
6020 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006021" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006022 let srvrname = g:netrw_browse_split[0]
6023 let tabnum = g:netrw_browse_split[1]
6024 let winnum = g:netrw_browse_split[2]
6025
6026 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006027" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006028
6029 if !ctrlr
6030 " user must have closed the server window and the user did not use <c-r>, but
6031 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006032" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006033 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006034 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006035 endif
6036 let g:netrw_browse_split= 0
6037 if exists("s:netrw_browse_split_".winnr())
6038 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6039 endif
6040 call s:NetrwBrowseChgDir(islocal,a:fname)
6041" call Dret("s:NetrwServerEdit")
6042 return
6043
6044 elseif has("win32") && executable("start")
6045 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006046" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006047 call system("start gvim --servername ".srvrname)
6048
6049 else
6050 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006051" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006052 call system("gvim --servername ".srvrname)
6053 endif
6054 endif
6055
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006056" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006057 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6058 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006059 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006060
6061 else
6062
6063 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6064
6065 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006066" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006067 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006068 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006069 endif
6070 let g:netrw_browse_split= 0
6071 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6072" call Dret("s:NetrwServerEdit")
6073 return
6074
6075 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006076" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006077 if has("win32") && executable("start")
6078 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006079" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006080 call system("start gvim --servername ".g:netrw_servername)
6081 else
6082 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006083" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006084 call system("gvim --servername ".g:netrw_servername)
6085 endif
6086 endif
6087 endif
6088
6089 while 1
6090 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006091" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6092 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006093 break
6094 catch /^Vim\%((\a\+)\)\=:E241/
6095 sleep 200m
6096 endtry
6097 endwhile
6098
6099 if exists("g:netrw_browse_split")
6100 if type(g:netrw_browse_split) != 3
6101 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6102 endif
6103 unlet g:netrw_browse_split
6104 endif
6105 let g:netrw_browse_split= [g:netrw_servername,1,1]
6106 endif
6107
6108 else
6109 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6110 endif
6111
6112" call Dret("s:NetrwServerEdit")
6113endfun
6114
6115" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006116" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6117fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006118 if &ft != "netrw"
6119 return
6120 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006121" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006122
Bram Moolenaar8d043172014-01-23 14:24:41 +01006123 let s:ngw= s:NetrwGetWord()
6124 call s:NetrwMarkFile(a:islocal,s:ngw)
6125
6126" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006127endfun
6128
6129" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006130" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6131" Used to mark multiple files.
6132fun! s:NetrwSLeftdrag(islocal)
6133" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6134 if !exists("s:netrwdrag")
6135 let s:netrwdrag = winnr()
6136 if a:islocal
6137 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006138 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006139 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006140 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006141 endif
6142 let ngw = s:NetrwGetWord()
6143 if !exists("s:ngw") || s:ngw != ngw
6144 call s:NetrwMarkFile(a:islocal,ngw)
6145 endif
6146 let s:ngw= ngw
6147" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6148endfun
6149
6150" ---------------------------------------------------------------------
6151" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6152fun! s:NetrwSLeftrelease(islocal)
6153" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6154 if exists("s:netrwdrag")
6155 nunmap <s-leftrelease>
6156 let ngw = s:NetrwGetWord()
6157 if !exists("s:ngw") || s:ngw != ngw
6158 call s:NetrwMarkFile(a:islocal,ngw)
6159 endif
6160 if exists("s:ngw")
6161 unlet s:ngw
6162 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006163 unlet s:netrwdrag
6164 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006165" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006166endfun
6167
6168" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006169" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6170" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006171fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006172" 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 +02006173" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006174 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006175
6176 " 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 +02006177 " How-it-works: take the hiding command, convert it into a range.
6178 " Duplicate characters don't matter.
6179 " Remove all such characters from the '/~@#...890' string.
6180 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006181" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006182 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006183 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006184" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006185
6186 while listhide != ""
6187 if listhide =~ ','
6188 let hide = substitute(listhide,',.*$','','e')
6189 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6190 else
6191 let hide = listhide
6192 let listhide = ""
6193 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006194" 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 +01006195 if g:netrw_sort_by =~ '^[ts]'
6196 if hide =~ '^\^'
6197" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6198 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6199 elseif hide =~ '^\\(\^'
6200 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6201 endif
6202" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6203 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006204
6205 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006206" 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 +00006207 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006208" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006209 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006210 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006211" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006212 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006213 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006214" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006215 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006216
Bram Moolenaar446cb832008-06-24 21:56:24 +00006217 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006218 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006219" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006220 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006221" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006222 endif
6223
Bram Moolenaaradc21822011-04-01 18:03:16 +02006224 " remove any blank lines that have somehow remained.
6225 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006226 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006227
Bram Moolenaar97d62492012-11-15 21:28:22 +01006228 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006229" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006230endfun
6231
6232" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006233" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006234" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006235fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006236" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006237
Bram Moolenaar97d62492012-11-15 21:28:22 +01006238 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006239 " get name of new directory from user. A bare <CR> will skip.
6240 " if its currently a directory, also request will be skipped, but with
6241 " a message.
6242 call inputsave()
6243 let newdirname= input("Please give directory name: ")
6244 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006245" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006246
6247 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006248 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006249" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006250 return
6251 endif
6252
6253 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006254" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006255
6256 " Local mkdir:
6257 " sanity checks
6258 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006259" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6260 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006261 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006262 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006263 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006264 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006265" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006266 return
6267 endif
6268 if s:FileReadable(fullnewdir)
6269 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006270 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006271 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006272 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006273" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006274 return
6275 endif
6276
6277 " requested new local directory is neither a pre-existing file or
6278 " directory, so make it!
6279 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006280 if has("unix")
6281 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6282 else
6283 call mkdir(fullnewdir,"p")
6284 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006285 else
6286 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006287 if s:NetrwLcd(b:netrw_curdir)
6288" call Dret("s:NetrwMakeDir : lcd failure")
6289 return
6290 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006291" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006292 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006293 if v:shell_error != 0
6294 let @@= ykeep
6295 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 +01006296" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006297 return
6298 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006299 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006300" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006301 if s:NetrwLcd(netrw_origdir)
6302" call Dret("s:NetrwBrowse : lcd failure")
6303 return
6304 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006305 endif
6306 endif
6307
6308 if v:shell_error == 0
6309 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006310" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006311 let svpos= winsaveview()
6312" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006313 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006314" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6315 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006316 elseif !exists("g:netrw_quiet")
6317 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6318 endif
6319" redraw!
6320
6321 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006322 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006323" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006324 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6325 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006326 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006327 if v:shell_error == 0
6328 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006329 let svpos= winsaveview()
6330" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006331 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006332" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6333 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006334 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006335 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006336 endif
6337" redraw!
6338
6339 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006340 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006341 let svpos= winsaveview()
6342" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006343" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006344 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006345" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006346 let remotepath= b:netrw_fname
6347 else
6348 let remotepath= ""
6349 endif
6350 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006351 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006352" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6353 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006354
Bram Moolenaar446cb832008-06-24 21:56:24 +00006355 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006356 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006357 let svpos= winsaveview()
6358" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006359" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006360 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006361" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006362 let remotepath= b:netrw_fname
6363 else
6364 let remotepath= ""
6365 endif
6366 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006367 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006368" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6369 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006370 endif
6371
Bram Moolenaar97d62492012-11-15 21:28:22 +01006372 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006373" call Dret("s:NetrwMakeDir")
6374endfun
6375
6376" ---------------------------------------------------------------------
6377" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6378fun! s:TreeSqueezeDir(islocal)
6379" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6380 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6381 " its a tree-listing style
6382 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006383 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006384 let depth = strchars(substitute(curdepth,' ','','g'))
6385 let srch = -1
6386" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6387" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006388" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006389" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6390 if depth >= 2
6391 NetrwKeepj norm! 0
6392 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6393 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6394" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6395" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6396 elseif depth == 1
6397 NetrwKeepj norm! 0
6398 let treedepthchr= substitute(s:treedepthstring,' ','','')
6399 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6400" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6401 endif
6402 if srch > 0
6403" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6404 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6405 exe srch
6406 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006407 endif
6408" call Dret("s:TreeSqueezeDir")
6409endfun
6410
6411" ---------------------------------------------------------------------
6412" s:NetrwMaps: {{{2
6413fun! s:NetrwMaps(islocal)
6414" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6415
Bram Moolenaar85850f32019-07-19 22:05:51 +02006416 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006417 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006418" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006419 if !hasmapto("<Plug>NetrwReturn")
6420 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006421" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006422 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6423 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006424" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006425 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6426 endif
6427 endif
6428 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006429" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006430 endif
6431
Bram Moolenaar85850f32019-07-19 22:05:51 +02006432 " generate default <Plug> maps {{{3
6433 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006434 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006435 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6436 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6437 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6438 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6439 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6440 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6441 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6442 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6443 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6444 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6445" ---------------------------------------------------------------------
6446" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6447" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6448" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6449" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6450" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6451" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6452" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6453" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6454" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6455" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6456" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6457" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6458" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6459" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6460" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6461" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6462" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6463" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6464" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6465" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6466" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6467" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6468" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6469" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6470" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6471" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6472" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6473" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6474" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6475" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6476" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6477" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6478" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6479" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6480" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6481" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6482" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6483" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6484" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6485" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6486" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6487" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6488" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6489" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6490" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6491" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6492" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6493
Bram Moolenaara6878372014-03-22 21:02:50 +01006494 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006495" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006496 " local normal-mode maps {{{3
6497 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6498 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6499 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6500 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6501 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6502 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6503 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6504 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6505 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6506 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6507 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6508" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006509 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6510 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6511 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006512 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006513 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006514 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6515 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6516 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6517 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006518 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6519 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6520 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6521 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6522 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6523 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6524 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6525 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6526 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6527 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6528 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6529 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6530 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006531 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006532 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006533 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6534 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6535 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6536 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6537 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006538 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006539 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006540 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6541 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006542 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6543 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6544 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006545 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006546 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006547 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6548 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006549 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006550 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006551 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6552 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6553 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006554 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6555 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006556
6557 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 +01006558 if !hasmapto('<Plug>NetrwHideEdit')
6559 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006560 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006561 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006562 if !hasmapto('<Plug>NetrwRefresh')
6563 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006564 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006565 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 +01006566 if s:didstarstar || !mapcheck("<s-down>","n")
6567 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006568 endif
6569 if s:didstarstar || !mapcheck("<s-up>","n")
6570 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006571 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006572 if !hasmapto('<Plug>NetrwTreeSqueeze')
6573 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006574 endif
6575 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006576 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6577 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006578 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6579 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6580 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6581 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6582 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6583 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6584 imap <buffer> <leftmouse> <Plug>ILeftmouse
6585 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006586 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6587 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6588 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6589 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6590 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006591 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006592 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6593 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006594 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006595 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6596 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6597 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6598 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6599 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6600 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6601 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006602 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6603
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006604 " support user-specified maps
6605 call netrw#UserMaps(1)
6606
Bram Moolenaar85850f32019-07-19 22:05:51 +02006607 else
6608 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006609" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006610 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006611 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6612 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6613 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6614 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6615 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6616 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6617 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6618 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6619 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6620 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6621 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6622" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006623 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6624 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6625 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6626 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6627 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6628 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6629 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6630 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006631 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006632 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006633 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6634 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6635 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6636 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6637 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6638 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6639 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6640 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6641 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6642 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6643 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006644 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006645 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006646 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6647 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6648 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6649 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6650 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006651 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6652 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6653 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6654 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006655 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006656 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6657 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006658 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006659 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 +01006660 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6661 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6662 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6663 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6664 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6665 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6666 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6667 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6668 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Konfekt3d7e5672024-10-27 22:16:49 +01006669 nmap <buffer> <nowait> gx x
Bram Moolenaara6878372014-03-22 21:02:50 +01006670 if !hasmapto('<Plug>NetrwHideEdit')
6671 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006672 endif
6673 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6674 if !hasmapto('<Plug>NetrwRefresh')
6675 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006676 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006677 if !hasmapto('<Plug>NetrwTreeSqueeze')
6678 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006679 endif
6680 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006681
6682 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006683 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006684
6685 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6686 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006687 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006688 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006689 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006690 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006691 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006692 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006693 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006694 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006695 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006696 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006697 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6698 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6699 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006700 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006701 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006702 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6703 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006704 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006705 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6706 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6707 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6708 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6709 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6710 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6711 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006712 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006713
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006714 " support user-specified maps
6715 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006716 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006717
6718" call Dret("s:NetrwMaps")
6719endfun
6720
6721" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006722" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006723" If -buffer, the command is only available from within netrw buffers
6724" Otherwise, the command is available from any window, so long as netrw
6725" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006726fun! s:NetrwCommands(islocal)
6727" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6728
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006729 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6730 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006731 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 +01006732 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006733 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006734 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006735 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006736 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006737 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006738
6739" call Dret("s:NetrwCommands")
6740endfun
6741
6742" ---------------------------------------------------------------------
6743" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6744" glob()ing only works with local files
6745fun! s:NetrwMarkFiles(islocal,...)
6746" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006747 let curdir = s:NetrwGetCurdir(a:islocal)
6748 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006749 while i <= a:0
6750 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006751 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006752 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006753 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006754 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006755 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006756 else
6757 let mffiles= [a:{i}]
6758 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006759" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006760 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006761" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006762 call s:NetrwMarkFile(a:islocal,mffile)
6763 endfor
6764 let i= i + 1
6765 endwhile
6766" call Dret("s:NetrwMarkFiles")
6767endfun
6768
6769" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006770" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006771fun! s:NetrwMarkTarget(...)
6772" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6773 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006774 let curdir = s:NetrwGetCurdir(1)
6775 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006776 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006777 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6778 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006779 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006780" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006781 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006782 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6783 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006784 let svpos = winsaveview()
6785" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006786 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006787" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6788 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006789" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006790endfun
6791
6792" ---------------------------------------------------------------------
6793" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6794" mark and unmark files. If a markfile list exists,
6795" then the rename and delete functions will use it instead
6796" of whatever may happen to be under the cursor at that
6797" moment. When the mouse and gui are available,
6798" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006799"
6800" Creates two lists
6801" s:netrwmarkfilelist -- holds complete paths to all marked files
6802" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6803"
6804" Creates a marked file match string
6805" s:netrwmarfilemtch_# -- used with 2match to display marked files
6806"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006807" Creates a buffer version of islocal
6808" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006809fun! s:NetrwMarkFile(islocal,fname)
6810" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006811" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006812
6813 " sanity check
6814 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006815" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006816 return
6817 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006818 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006819
Bram Moolenaar97d62492012-11-15 21:28:22 +01006820 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006821 let curbufnr= bufnr("%")
yasudac18a9d52024-09-19 18:09:51 +02006822 let leader= '\%(^\|\s\)\zs'
Bram Moolenaara6878372014-03-22 21:02:50 +01006823 if a:fname =~ '\a$'
6824 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6825 else
6826 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6827 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006828
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006829 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006830 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006831" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6832" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6833" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006834 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006835
6836 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006837 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006838" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006839 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006840 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006841
6842 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006843 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006844" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006845 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6846 if s:netrwmarkfilelist_{curbufnr} == []
6847 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006848" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006849 call s:NetrwUnmarkList(curbufnr,curdir)
6850 else
6851 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006852" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006853 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006854 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006855 for fname in s:netrwmarkfilelist_{curbufnr}
6856 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006857 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006858 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006859 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006860 endif
6861 let first= 0
6862 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006863" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006864 endif
6865 endif
6866
6867 else
6868 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006869" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006870
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006871" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006872 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006873 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6874" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006875
6876 " build initial markfile matching pattern
6877 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006878 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006879 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006880 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006881 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006882" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006883 endif
6884
6885 " handle global markfilelist
6886 if exists("s:netrwmarkfilelist")
6887 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6888 if index(s:netrwmarkfilelist,dname) == -1
6889 " append new filename to global markfilelist
6890 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006891" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006892 else
6893 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006894" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6895" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006896 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006897" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006898 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006899" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006900 unlet s:netrwmarkfilelist
6901 endif
6902 endif
6903 else
6904 " initialize new global-directory markfilelist
6905 let s:netrwmarkfilelist= []
6906 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006907" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006908 endif
6909
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006910 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006911 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6912 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6913" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6914 if exists("g:did_drchip_netrwlist_syntax")
6915 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6916 endif
6917 else
6918" " call Decho("2match none",'~'.expand("<slnum>"))
6919 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006920 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006921 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006922 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006923" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6924" 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 +00006925endfun
6926
6927" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006928" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6929" mA: move the argument list to marked file list (tomflist=1)
6930" Uses the global marked file list
6931fun! s:NetrwMarkFileArgList(islocal,tomflist)
6932" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
6933
6934 let svpos = winsaveview()
6935" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6936 let curdir = s:NetrwGetCurdir(a:islocal)
6937 let curbufnr = bufnr("%")
6938
6939 if a:tomflist
6940 " mA: move argument list to marked file list
6941 while argc()
6942 let fname= argv(0)
6943" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
6944 exe "argdel ".fnameescape(fname)
6945 call s:NetrwMarkFile(a:islocal,fname)
6946 endwhile
6947
6948 else
6949 " ma: move marked file list to argument list
6950 if exists("s:netrwmarkfilelist")
6951
6952 " for every filename in the marked list
6953 for fname in s:netrwmarkfilelist
6954" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
6955 exe "argadd ".fnameescape(fname)
6956 endfor " for every file in the marked list
6957
6958 " unmark list and refresh
6959 call s:NetrwUnmarkList(curbufnr,curdir)
6960 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
6961" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6962 NetrwKeepj call winrestview(svpos)
6963 endif
6964 endif
6965
6966" call Dret("s:NetrwMarkFileArgList")
6967endfun
6968
6969" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006970" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
6971" compress/decompress files using the programs
6972" in g:netrw_compress and g:netrw_uncompress,
6973" using g:netrw_compress_suffix to know which to
6974" do. By default:
6975" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006976" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00006977fun! s:NetrwMarkFileCompress(islocal)
6978" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006979 let svpos = winsaveview()
6980" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006981 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006982 let curbufnr = bufnr("%")
6983
Bram Moolenaarff034192013-04-24 18:51:19 +02006984 " sanity check
6985 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006986 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006987" call Dret("s:NetrwMarkFileCompress")
6988 return
6989 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006990" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006991
Bram Moolenaar446cb832008-06-24 21:56:24 +00006992 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02006993
6994 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00006995 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02006996 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006997" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006998 if exists("g:netrw_decompress['".sfx."']")
6999 " fname has a suffix indicating that its compressed; apply associated decompression routine
7000 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007001" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007002 let exe= netrw#WinPath(exe)
7003 if a:islocal
7004 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007005 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007006 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007007 call system(exe." ".fname)
7008 if v:shell_error
7009 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007010 endif
7011 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007012 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7013 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007014 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007015
Bram Moolenaarff034192013-04-24 18:51:19 +02007016 endif
7017 unlet sfx
7018
Bram Moolenaar446cb832008-06-24 21:56:24 +00007019 if exists("exe")
7020 unlet exe
7021 elseif a:islocal
7022 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007023 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007024 if v:shell_error
7025 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7026 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007027 else
7028 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007029 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007030 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007031 endfor " for every file in the marked list
7032
Bram Moolenaar446cb832008-06-24 21:56:24 +00007033 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007034 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007035" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7036 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007037 endif
7038" call Dret("s:NetrwMarkFileCompress")
7039endfun
7040
7041" ---------------------------------------------------------------------
7042" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7043" If no marked files, then set up directory as the
7044" target. Currently does not support copying entire
7045" directories. Uses the local-buffer marked file list.
7046" Returns 1=success (used by NetrwMarkFileMove())
7047" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007048fun! s:NetrwMarkFileCopy(islocal,...)
7049" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7050
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007051 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007052 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007053 if b:netrw_curdir !~ '/$'
7054 if !exists("b:netrw_curdir")
7055 let b:netrw_curdir= curdir
7056 endif
7057 let b:netrw_curdir= b:netrw_curdir."/"
7058 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007059
Bram Moolenaarff034192013-04-24 18:51:19 +02007060 " sanity check
7061 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007062 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007063" call Dret("s:NetrwMarkFileCopy")
7064 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007065 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007066" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007067
Bram Moolenaar446cb832008-06-24 21:56:24 +00007068 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007069 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007070" call Dret("s:NetrwMarkFileCopy 0")
7071 return 0
7072 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007073" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007074
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007075 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007076 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007077" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007078 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007079 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7080" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7081 return
7082 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007083
7084 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02007085 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007086 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7087 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007088" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007089 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007090 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7091 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007092" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007093 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007094 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007095 let oldname = a:1
7096 else
7097 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007098" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007099 let s:recursive= 1
7100 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7101 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7102 if ret == 0
7103 break
7104 endif
7105 endfor
7106 unlet s:recursive
7107 call s:NetrwUnmarkList(curbufnr,curdir)
7108" call Dret("s:NetrwMarkFileCopy ".ret)
7109 return ret
7110 endif
7111
7112 call inputsave()
7113 let newname= input("Copy ".oldname." to : ",oldname,"file")
7114 call inputrestore()
7115 if newname == ""
7116" call Dret("s:NetrwMarkFileCopy 0")
7117 return 0
7118 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007119 let args= s:ShellEscape(oldname)
7120 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007121 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007122 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7123 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007124 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007125 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007126 let args= substitute(args,'/','\\','g')
7127 let tgt = substitute(tgt, '/','\\','g')
7128 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007129 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7130 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7131 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7132 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7133" call Decho("args <".args.">",'~'.expand("<slnum>"))
7134" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007135 if isdirectory(s:NetrwFile(args))
7136" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007137 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007138" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007139 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007140 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7141 " contents to a target. One must append the source directory name to the target to get xcopy to
7142 " do the right thing.
7143 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007144" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007145 endif
7146 else
7147 let copycmd= g:netrw_localcopycmd
7148 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007149 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007150 let copycmd = substitute(copycmd,'\s.*$','','')
7151 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007152 let copycmd = netrw#WinPath(copycmd).copycmdargs
7153 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007154 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007155 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007156" call Decho("args <".args.">",'~'.expand("<slnum>"))
7157" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7158" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7159" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007160 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007161 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02007162 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007163 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 +01007164 else
7165 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7166 endif
7167" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007168 return 0
7169 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007170
7171 elseif a:islocal && !s:netrwmftgt_islocal
7172 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007173" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007174 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007175
7176 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007177 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007178" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007179 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007180
7181 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007182 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007183" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007184 let curdir = getcwd()
7185 let tmpdir = s:GetTempfile("")
7186 if tmpdir !~ '/'
7187 let tmpdir= curdir."/".tmpdir
7188 endif
7189 if exists("*mkdir")
7190 call mkdir(tmpdir)
7191 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007192 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007193 if v:shell_error != 0
7194 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 +01007195" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007196 return
7197 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007198 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007199 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007200 if s:NetrwLcd(tmpdir)
7201" call Dret("s:NetrwMarkFileCopy : lcd failure")
7202 return
7203 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007204 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007205 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007206 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007207 if getcwd() == tmpdir
7208 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007209 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007210 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007211 if s:NetrwLcd(curdir)
7212" call Dret("s:NetrwMarkFileCopy : lcd failure")
7213 return
7214 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007215 if delete(tmpdir,"d")
7216 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007217 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007218 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007219 if s:NetrwLcd(curdir)
7220" call Dret("s:NetrwMarkFileCopy : lcd failure")
7221 return
7222 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007223 endif
7224 endif
7225 endif
7226
7227 " -------
7228 " cleanup
7229 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007230" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007231 " remove markings from local buffer
7232 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007233" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7234" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7235" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7236" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7237" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7238" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7239 if exists("s:recursive")
7240" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7241 else
7242" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007243 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007244 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007245 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007246 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007247 else
7248 " refresh local and targets for fast browsing
7249 if !exists("s:recursive")
7250 " remove markings from local buffer
7251" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7252 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7253 endif
7254
7255 " refresh buffers
7256 if s:netrwmftgt_islocal
7257" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7258 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7259 endif
7260 if a:islocal && s:netrwmftgt != curdir
7261" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7262 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7263 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007264 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007265
Bram Moolenaar446cb832008-06-24 21:56:24 +00007266" call Dret("s:NetrwMarkFileCopy 1")
7267 return 1
7268endfun
7269
7270" ---------------------------------------------------------------------
7271" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7272" invoke vim's diff mode on the marked files.
7273" Either two or three files can be so handled.
7274" Uses the global marked file list.
7275fun! s:NetrwMarkFileDiff(islocal)
7276" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7277 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007278
Bram Moolenaarff034192013-04-24 18:51:19 +02007279 " sanity check
7280 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007281 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007282" call Dret("s:NetrwMarkFileDiff")
7283 return
7284 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007285 let curdir= s:NetrwGetCurdir(a:islocal)
7286" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007287
Bram Moolenaara6878372014-03-22 21:02:50 +01007288 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007289 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007290 for fname in s:netrwmarkfilelist
7291 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007292 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007293" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007294 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007295 diffthis
7296 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007297 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007298" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007299 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007300 diffthis
7301 else
7302 break
7303 endif
7304 endfor
7305 call s:NetrwUnmarkList(curbufnr,curdir)
7306 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007307
Bram Moolenaar446cb832008-06-24 21:56:24 +00007308" call Dret("s:NetrwMarkFileDiff")
7309endfun
7310
7311" ---------------------------------------------------------------------
7312" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7313" Uses global markfilelist
7314fun! s:NetrwMarkFileEdit(islocal)
7315" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7316
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007317 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007318 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007319
7320 " sanity check
7321 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007322 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007323" call Dret("s:NetrwMarkFileEdit")
7324 return
7325 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007326" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007327
Bram Moolenaar446cb832008-06-24 21:56:24 +00007328 if exists("s:netrwmarkfilelist_{curbufnr}")
7329 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007330 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007331 " unmark markedfile list
7332" call s:NetrwUnmarkList(curbufnr,curdir)
7333 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007334" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007335 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007336 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007337 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007338
Bram Moolenaar446cb832008-06-24 21:56:24 +00007339" call Dret("s:NetrwMarkFileEdit")
7340endfun
7341
7342" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007343" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007344fun! s:NetrwMarkFileQFEL(islocal,qfel)
7345" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7346 call s:NetrwUnmarkAll()
7347 let curbufnr= bufnr("%")
7348
7349 if !empty(a:qfel)
7350 for entry in a:qfel
7351 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007352" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007353 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007354" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007355 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7356 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7357 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7358 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007359" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007360 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7361 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007362" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007363 endif
7364 endfor
7365 echo "(use me to edit marked files)"
7366 else
7367 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7368 endif
7369
7370" call Dret("s:NetrwMarkFileQFEL")
7371endfun
7372
7373" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007374" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7375" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7376" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7377fun! s:NetrwMarkFileExe(islocal,enbloc)
7378" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007379 let svpos = winsaveview()
7380" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007381 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007382 let curbufnr = bufnr("%")
7383
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007384 if a:enbloc == 0
7385 " individually apply command to files, one at a time
7386 " sanity check
7387 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7388 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7389" call Dret("s:NetrwMarkFileExe")
7390 return
7391 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007392" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007393
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007394 if exists("s:netrwmarkfilelist_{curbufnr}")
7395 " get the command
7396 call inputsave()
7397 let cmd= input("Enter command: ","","file")
7398 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007399" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007400 if cmd == ""
7401" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7402 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007403 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007404
7405 " apply command to marked files, individually. Substitute: filename -> %
7406 " If no %, then append a space and the filename to the command
7407 for fname in s:netrwmarkfilelist_{curbufnr}
7408 if a:islocal
7409 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007410 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007411 endif
7412 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007413 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007414 endif
7415 if cmd =~ '%'
7416 let xcmd= substitute(cmd,'%',fname,'g')
7417 else
7418 let xcmd= cmd.' '.fname
7419 endif
7420 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007421" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007422 let ret= system(xcmd)
7423 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007424" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007425 let ret= s:RemoteSystem(xcmd)
7426 endif
7427 if v:shell_error < 0
7428 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7429 break
7430 else
yasudac75dad02024-08-22 21:06:32 +02007431 if ret !=# ''
7432 echo "\n"
7433 " skip trailing new line
7434 echo ret[0:-2]
7435 else
7436 echo ret
7437 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007438 endif
7439 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007440
7441 " unmark marked file list
7442 call s:NetrwUnmarkList(curbufnr,curdir)
7443
7444 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007445 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007446" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7447 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007448 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007449 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007450 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007451
7452 else " apply command to global list of files, en bloc
7453
7454 call inputsave()
7455 let cmd= input("Enter command: ","","file")
7456 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007457" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007458 if cmd == ""
7459" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7460 return
7461 endif
7462 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007463 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007464 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007465 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007466 endif
7467 if a:islocal
7468 call system(cmd)
7469 if v:shell_error < 0
7470 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7471 endif
7472 else
7473 let ret= s:RemoteSystem(cmd)
7474 endif
7475 call s:NetrwUnmarkAll()
7476
7477 " refresh the listing
7478 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007479" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7480 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007481
7482 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007483
Bram Moolenaar446cb832008-06-24 21:56:24 +00007484" call Dret("s:NetrwMarkFileExe")
7485endfun
7486
7487" ---------------------------------------------------------------------
7488" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7489" as the marked file(s) (toggles suffix presence)
7490" Uses the local marked file list.
7491fun! s:NetrwMarkHideSfx(islocal)
7492" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007493 let svpos = winsaveview()
7494" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007495 let curbufnr = bufnr("%")
7496
7497 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7498 if exists("s:netrwmarkfilelist_{curbufnr}")
7499
7500 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007501" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007502 " construct suffix pattern
7503 if fname =~ '\.'
7504 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7505 else
7506 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7507 endif
7508 " determine if its in the hiding list or not
7509 let inhidelist= 0
7510 if g:netrw_list_hide != ""
7511 let itemnum = 0
7512 let hidelist= split(g:netrw_list_hide,',')
7513 for hidepat in hidelist
7514 if sfxpat == hidepat
7515 let inhidelist= 1
7516 break
7517 endif
7518 let itemnum= itemnum + 1
7519 endfor
7520 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007521" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007522 if inhidelist
7523 " remove sfxpat from list
7524 call remove(hidelist,itemnum)
7525 let g:netrw_list_hide= join(hidelist,",")
7526 elseif g:netrw_list_hide != ""
7527 " append sfxpat to non-empty list
7528 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7529 else
7530 " set hiding list to sfxpat
7531 let g:netrw_list_hide= sfxpat
7532 endif
7533 endfor
7534
7535 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007536 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007537" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7538 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007539 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007540 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007541 endif
7542
7543" call Dret("s:NetrwMarkHideSfx")
7544endfun
7545
7546" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007547" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007548" Uses the local marked-file list.
7549fun! s:NetrwMarkFileVimCmd(islocal)
7550" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007551 let svpos = winsaveview()
7552" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007553 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007554 let curbufnr = bufnr("%")
7555
Bram Moolenaarff034192013-04-24 18:51:19 +02007556 " sanity check
7557 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007558 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007559" call Dret("s:NetrwMarkFileVimCmd")
7560 return
7561 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007562" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007563
Bram Moolenaar15146672011-10-20 22:22:38 +02007564 if exists("s:netrwmarkfilelist_{curbufnr}")
7565 " get the command
7566 call inputsave()
7567 let cmd= input("Enter vim command: ","","file")
7568 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007569" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007570 if cmd == ""
7571" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7572 return
7573 endif
7574
7575 " apply command to marked files. Substitute: filename -> %
7576 " If no %, then append a space and the filename to the command
7577 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007578" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007579 if a:islocal
7580 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007581 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007582" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007583 exe cmd
7584 exe "sil! keepalt wq!"
7585 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007586" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007587 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007588 endif
7589 endfor
7590
7591 " unmark marked file list
7592 call s:NetrwUnmarkList(curbufnr,curdir)
7593
7594 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007595 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007596" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7597 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007598 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007599 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007600 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007601
Bram Moolenaar15146672011-10-20 22:22:38 +02007602" call Dret("s:NetrwMarkFileVimCmd")
7603endfun
7604
7605" ---------------------------------------------------------------------
7606" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7607" as the marked file(s) (toggles suffix presence)
7608" Uses the local marked file list.
7609fun! s:NetrwMarkHideSfx(islocal)
7610" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007611 let svpos = winsaveview()
7612" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007613 let curbufnr = bufnr("%")
7614
7615 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7616 if exists("s:netrwmarkfilelist_{curbufnr}")
7617
7618 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007619" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007620 " construct suffix pattern
7621 if fname =~ '\.'
7622 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7623 else
7624 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7625 endif
7626 " determine if its in the hiding list or not
7627 let inhidelist= 0
7628 if g:netrw_list_hide != ""
7629 let itemnum = 0
7630 let hidelist= split(g:netrw_list_hide,',')
7631 for hidepat in hidelist
7632 if sfxpat == hidepat
7633 let inhidelist= 1
7634 break
7635 endif
7636 let itemnum= itemnum + 1
7637 endfor
7638 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007639" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007640 if inhidelist
7641 " remove sfxpat from list
7642 call remove(hidelist,itemnum)
7643 let g:netrw_list_hide= join(hidelist,",")
7644 elseif g:netrw_list_hide != ""
7645 " append sfxpat to non-empty list
7646 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7647 else
7648 " set hiding list to sfxpat
7649 let g:netrw_list_hide= sfxpat
7650 endif
7651 endfor
7652
7653 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007654 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007655" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7656 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007657 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007658 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007659 endif
7660
7661" call Dret("s:NetrwMarkHideSfx")
7662endfun
7663
7664" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007665" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7666" Uses the global markfilelist
7667fun! s:NetrwMarkFileGrep(islocal)
7668" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007669 let svpos = winsaveview()
7670" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007671 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007672 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007673
7674 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007675" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007676 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007677" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007678 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007679 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007680" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007681 let netrwmarkfilelist= "*"
7682 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007683
Bram Moolenaarff034192013-04-24 18:51:19 +02007684 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007685" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007686 call inputsave()
7687 let pat= input("Enter pattern: ","")
7688 call inputrestore()
7689 let patbang = ""
7690 if pat =~ '^!'
7691 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007692 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007693 endif
7694 if pat =~ '^\i'
7695 let pat = escape(pat,'/')
7696 let pat = '/'.pat.'/'
7697 else
7698 let nonisi = pat[0]
7699 endif
7700
7701 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007702" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007703 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007704 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007705 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007706 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007707" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7708 return
7709 endtry
7710 echo "(use :cn, :cp to navigate, :Rex to return)"
7711
7712 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007713" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7714 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007715
7716 if exists("nonisi")
7717 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007718" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007719 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007720 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007721 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007722 endif
7723
7724" call Dret("s:NetrwMarkFileGrep")
7725endfun
7726
7727" ---------------------------------------------------------------------
7728" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7729" uses the global marked file list
7730" s:netrwmfloc= 0: target directory is remote
7731" = 1: target directory is local
7732fun! s:NetrwMarkFileMove(islocal)
7733" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007734 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007735 let curbufnr = bufnr("%")
7736
7737 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007738 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007739 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007740" call Dret("s:NetrwMarkFileMove")
7741 return
7742 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007743" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007744
Bram Moolenaar446cb832008-06-24 21:56:24 +00007745 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007746 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007747" call Dret("s:NetrwMarkFileCopy 0")
7748 return 0
7749 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007750" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007751
7752 if a:islocal && s:netrwmftgt_islocal
7753 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007754" call Decho("move from local to local",'~'.expand("<slnum>"))
7755" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007756 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007757 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7758" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7759 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007760 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007761 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007762" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007763 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007764 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007765" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007766 if g:netrw_localmovecmd =~ '\s'
7767 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7768 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7769 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007770" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007771 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007772 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007773" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007774 endif
7775 else
7776 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007777" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007778 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007779 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007780 if g:netrw_keepdir
7781 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7782 let fname= b:netrw_curdir."/".fname
7783 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007784 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007785 let fname= substitute(fname,'/','\\','g')
7786 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007787" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007788 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007789 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007790 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007791 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 +01007792 else
7793 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7794 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007795 break
7796 endif
7797 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007798
7799 elseif a:islocal && !s:netrwmftgt_islocal
7800 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007801" call Decho("move from local to remote",'~'.expand("<slnum>"))
7802" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007803 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007804 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007805" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007806 for fname in mflist
7807 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7808 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7809 endfor
7810 unlet mflist
7811
7812 elseif !a:islocal && s:netrwmftgt_islocal
7813 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007814" call Decho("move from remote to local",'~'.expand("<slnum>"))
7815" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007816 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007817 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007818" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007819 for fname in mflist
7820 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7821 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7822 endfor
7823 unlet mflist
7824
7825 elseif !a:islocal && !s:netrwmftgt_islocal
7826 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007827" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7828" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007829 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007830 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007831" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007832 for fname in mflist
7833 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7834 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7835 endfor
7836 unlet mflist
7837 endif
7838
7839 " -------
7840 " cleanup
7841 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007842" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007843
7844 " remove markings from local buffer
7845 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7846
7847 " refresh buffers
7848 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007849" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007850 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007851 endif
7852 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007853" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007854 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007855 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007856 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007857" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007858 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007859 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007860
Bram Moolenaar446cb832008-06-24 21:56:24 +00007861" call Dret("s:NetrwMarkFileMove")
7862endfun
7863
7864" ---------------------------------------------------------------------
7865" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7866" using the hardcopy command. Local marked-file list only.
7867fun! s:NetrwMarkFilePrint(islocal)
7868" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7869 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007870
7871 " sanity check
7872 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007873 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007874" call Dret("s:NetrwMarkFilePrint")
7875 return
7876 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007877" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7878 let curdir= s:NetrwGetCurdir(a:islocal)
7879
Bram Moolenaar446cb832008-06-24 21:56:24 +00007880 if exists("s:netrwmarkfilelist_{curbufnr}")
7881 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007882 call s:NetrwUnmarkList(curbufnr,curdir)
7883 for fname in netrwmarkfilelist
7884 if a:islocal
7885 if g:netrw_keepdir
7886 let fname= s:ComposePath(curdir,fname)
7887 endif
7888 else
7889 let fname= curdir.fname
7890 endif
7891 1split
7892 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007893" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007894 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007895" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007896 hardcopy
7897 q
7898 endfor
7899 2match none
7900 endif
7901" call Dret("s:NetrwMarkFilePrint")
7902endfun
7903
7904" ---------------------------------------------------------------------
7905" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7906" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007907" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007908fun! s:NetrwMarkFileRegexp(islocal)
7909" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7910
7911 " get the regular expression
7912 call inputsave()
7913 let regexp= input("Enter regexp: ","","file")
7914 call inputrestore()
7915
7916 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007917 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007918" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007919 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007920" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007921 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007922 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007923 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007924 else
7925 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007926 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007927 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007928" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007929
7930 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007931 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007932 if fname =~ '^'.fnameescape(curdir)
7933" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7934 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7935 else
7936" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7937 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7938 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007939 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007940
7941 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007942" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007943
7944 " convert displayed listing into a filelist
7945 let eikeep = &ei
7946 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007947 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007948 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007949" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007950 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007951 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02007952 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007953 sil NetrwKeepj norm! "ap
7954 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007955 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007956 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007957 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007958 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007959 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007960 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007961 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007962 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007963 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007964 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007965 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7966 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007967 call histdel("/",-1)
7968 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007969 endif
7970 " convert regexp into the more usual glob-style format
7971 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007972" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007973 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01007974 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007975 let filelist= getline(1,line("$"))
7976 q!
7977 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007978 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007979 endfor
7980 unlet filelist
7981 let @a = areg
7982 let &ei = eikeep
7983 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007984 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007985
7986" call Dret("s:NetrwMarkFileRegexp")
7987endfun
7988
7989" ---------------------------------------------------------------------
7990" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
7991" Uses the local marked file list.
7992fun! s:NetrwMarkFileSource(islocal)
7993" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
7994 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007995
7996 " sanity check
7997 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007998 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007999" call Dret("s:NetrwMarkFileSource")
8000 return
8001 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008002" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8003 let curdir= s:NetrwGetCurdir(a:islocal)
8004
Bram Moolenaar446cb832008-06-24 21:56:24 +00008005 if exists("s:netrwmarkfilelist_{curbufnr}")
8006 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008007 call s:NetrwUnmarkList(curbufnr,curdir)
8008 for fname in netrwmarkfilelist
8009 if a:islocal
8010 if g:netrw_keepdir
8011 let fname= s:ComposePath(curdir,fname)
8012 endif
8013 else
8014 let fname= curdir.fname
8015 endif
8016 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008017" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008018 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008019 endfor
8020 2match none
8021 endif
8022" call Dret("s:NetrwMarkFileSource")
8023endfun
8024
8025" ---------------------------------------------------------------------
8026" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8027" Uses the global markfilelist
8028fun! s:NetrwMarkFileTag(islocal)
8029" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008030 let svpos = winsaveview()
8031" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008032 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008033 let curbufnr = bufnr("%")
8034
Bram Moolenaarff034192013-04-24 18:51:19 +02008035 " sanity check
8036 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008037 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008038" call Dret("s:NetrwMarkFileTag")
8039 return
8040 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008041" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008042
Bram Moolenaar446cb832008-06-24 21:56:24 +00008043 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008044" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8045 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008046 call s:NetrwUnmarkAll()
8047
8048 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008049
8050" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8051 call system(g:netrw_ctags." ".netrwmarkfilelist)
8052 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008053 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8054 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008055
Bram Moolenaar446cb832008-06-24 21:56:24 +00008056 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008057 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008058 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008059 let curdir= b:netrw_curdir
8060 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008061 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008062 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008063" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008064 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008065 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008066 wq!
8067 endif
8068 2match none
8069 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008070" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8071 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008072 endif
8073
8074" call Dret("s:NetrwMarkFileTag")
8075endfun
8076
8077" ---------------------------------------------------------------------
8078" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008079" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008080" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008081" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008082" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008083fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008084" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8085 let svpos = winsaveview()
8086" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008087 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008088 let hadtgt = exists("s:netrwmftgt")
8089 if !exists("w:netrw_bannercnt")
8090 let w:netrw_bannercnt= b:netrw_bannercnt
8091 endif
8092
8093 " set up target
8094 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008095" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008096 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8097 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008098" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008099 unlet s:netrwmftgt s:netrwmftgt_islocal
8100 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008101 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008102 endif
8103 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008104" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8105 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008106" call Dret("s:NetrwMarkFileTgt : removed target")
8107 return
8108 else
8109 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008110" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008111 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008112
8113 else
8114 " get word under cursor.
8115 " * If directory, use it for the target.
8116 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008117" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008118 let curword= s:NetrwGetWord()
8119 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008120 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008121 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008122" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008123 elseif !a:islocal && tgtdir =~ '/$'
8124 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008125" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008126 else
8127 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008128" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008129 endif
8130 endif
8131 if a:islocal
8132 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8133 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008134" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008135 endif
8136 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008137 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008138 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8139 endif
8140 let s:netrwmftgt_islocal= a:islocal
8141
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008142 " need to do refresh so that the banner will be updated
8143 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008144 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008145" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008146 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008147 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008148" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008149 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008150 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8151 else
8152 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8153 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008154" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8155 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008156 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008157 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008158 endif
8159
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008160" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8161" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008162" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8163endfun
8164
8165" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008166" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8167fun! s:NetrwGetCurdir(islocal)
8168" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8169
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008170 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008171 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8172" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8173 elseif !exists("b:netrw_curdir")
8174 let b:netrw_curdir= getcwd()
8175" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8176 endif
8177
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008178" 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 +01008179 if b:netrw_curdir !~ '\<\a\{3,}://'
8180 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008181" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008182 if g:netrw_keepdir == 0
8183 call s:NetrwLcd(curdir)
8184 endif
8185 endif
8186
8187" call Dret("s:NetrwGetCurdir <".curdir.">")
8188 return b:netrw_curdir
8189endfun
8190
8191" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008192" s:NetrwOpenFile: query user for a filename and open it {{{2
8193fun! s:NetrwOpenFile(islocal)
8194" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008195 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008196 call inputsave()
8197 let fname= input("Enter filename: ")
8198 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008199" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8200
8201 " determine if Lexplore is in use
8202 if exists("t:netrw_lexbufnr")
8203 " check if t:netrw_lexbufnr refers to a netrw window
8204" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8205 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8206 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8207" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8208 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8209 exe "NetrwKeepj e ".fnameescape(fname)
8210 let @@= ykeep
8211" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8212 endif
8213 endif
8214
8215 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008216 if fname !~ '[/\\]'
8217 if exists("b:netrw_curdir")
8218 if exists("g:netrw_quiet")
8219 let netrw_quiet_keep = g:netrw_quiet
8220 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008221 let g:netrw_quiet = 1
8222 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008223 let s:rexposn_{bufnr("%")}= winsaveview()
8224" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008225 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008226 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008227 else
8228 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8229 endif
8230 if exists("netrw_quiet_keep")
8231 let g:netrw_quiet= netrw_quiet_keep
8232 else
8233 unlet g:netrw_quiet
8234 endif
8235 endif
8236 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008237 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008238 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008239 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008240" call Dret("s:NetrwOpenFile")
8241endfun
8242
8243" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008244" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8245" For the mapping to this function be made via
8246" netrwPlugin, you'll need to have had
8247" g:netrw_usetab set to non-zero.
8248fun! netrw#Shrink()
8249" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8250 let curwin = winnr()
8251 let wiwkeep = &wiw
8252 set wiw=1
8253
8254 if &ft == "netrw"
8255 if winwidth(0) > g:netrw_wiw
8256 let t:netrw_winwidth= winwidth(0)
8257 exe "vert resize ".g:netrw_wiw
8258 wincmd l
8259 if winnr() == curwin
8260 wincmd h
8261 endif
8262" call Decho("vert resize 0",'~'.expand("<slnum>"))
8263 else
8264 exe "vert resize ".t:netrw_winwidth
8265" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8266 endif
8267
8268 elseif exists("t:netrw_lexbufnr")
8269 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8270 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8271 let t:netrw_winwidth= winwidth(0)
8272 exe "vert resize ".g:netrw_wiw
8273 wincmd l
8274 if winnr() == curwin
8275 wincmd h
8276 endif
8277" call Decho("vert resize 0",'~'.expand("<slnum>"))
8278 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8279 exe "vert resize ".t:netrw_winwidth
8280" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01008281 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008282 call netrw#Lexplore(0,0)
8283 endif
8284
8285 else
8286 call netrw#Lexplore(0,0)
8287 endif
8288 let wiw= wiwkeep
8289
8290" call Dret("netrw#Shrink")
8291endfun
8292
8293" ---------------------------------------------------------------------
8294" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8295fun! s:NetSortSequence(islocal)
8296" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8297
8298 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008299 let svpos= winsaveview()
8300" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008301 call inputsave()
8302 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8303 call inputrestore()
8304
8305 " refresh the listing
8306 let g:netrw_sort_sequence= newsortseq
8307 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008308" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8309 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008310 let @@= ykeep
8311
8312" call Dret("NetSortSequence")
8313endfun
8314
8315" ---------------------------------------------------------------------
8316" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8317" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008318" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008319fun! s:NetrwUnmarkList(curbufnr,curdir)
8320" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8321
8322 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008323 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008324 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8325 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8326 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8327 call remove(s:netrwmarkfilelist,idx) " remove from global list
8328 endfor
8329 if s:netrwmarkfilelist == []
8330 unlet s:netrwmarkfilelist
8331 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008332
Bram Moolenaar446cb832008-06-24 21:56:24 +00008333 " getting rid of the local marked-file lists is easy
8334 unlet s:netrwmarkfilelist_{a:curbufnr}
8335 endif
8336 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8337 unlet s:netrwmarkfilemtch_{a:curbufnr}
8338 endif
8339 2match none
8340" call Dret("s:NetrwUnmarkList")
8341endfun
8342
8343" ---------------------------------------------------------------------
8344" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8345fun! s:NetrwUnmarkAll()
8346" call Dfunc("s:NetrwUnmarkAll()")
8347 if exists("s:netrwmarkfilelist")
8348 unlet s:netrwmarkfilelist
8349 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008350 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008351 2match none
8352" call Dret("s:NetrwUnmarkAll")
8353endfun
8354
8355" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008356" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008357fun! s:NetrwUnmarkAll2()
8358" call Dfunc("s:NetrwUnmarkAll2()")
8359 redir => netrwmarkfilelist_let
8360 let
8361 redir END
8362 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008363 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008364 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8365 for flist in netrwmarkfilelist_list
8366 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8367 unlet s:netrwmarkfilelist_{curbufnr}
8368 unlet s:netrwmarkfilemtch_{curbufnr}
8369 endfor
8370" call Dret("s:NetrwUnmarkAll2")
8371endfun
8372
8373" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008374" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8375"
8376" Marked files are in two types of lists:
8377" s:netrwmarkfilelist -- holds complete paths to all marked files
8378" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8379"
8380" Marked files suitable for use with 2match are in:
8381" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008382fun! s:NetrwUnMarkFile(islocal)
8383" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008384 let svpos = winsaveview()
8385" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008386 let curbufnr = bufnr("%")
8387
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008388 " unmark marked file list
8389 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8390 if exists("s:netrwmarkfilelist")
8391" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008392 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008393 endif
8394
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008395 let ibuf= 1
8396 while ibuf < bufnr("$")
8397 if exists("s:netrwmarkfilelist_".ibuf)
8398 unlet s:netrwmarkfilelist_{ibuf}
8399 unlet s:netrwmarkfilemtch_{ibuf}
8400 endif
8401 let ibuf = ibuf + 1
8402 endwhile
8403 2match none
8404
Bram Moolenaar446cb832008-06-24 21:56:24 +00008405" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008406"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8407call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008408" call Dret("s:NetrwUnMarkFile")
8409endfun
8410
8411" ---------------------------------------------------------------------
8412" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8413fun! s:NetrwMenu(domenu)
8414
8415 if !exists("g:NetrwMenuPriority")
8416 let g:NetrwMenuPriority= 80
8417 endif
8418
Bram Moolenaaradc21822011-04-01 18:03:16 +02008419 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008420" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8421
8422 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008423" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008424 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008425 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8426 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8427 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8428 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8429 if g:netrw_dirhistmax > 0
8430 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8431 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8432 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8433 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8434 else
8435 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8436 endif
8437 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8438 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8439 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8440 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8441 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8442 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8443 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8444 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8445 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8446 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8447 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8448 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8449 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8450 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8451 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 +01008452 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 +02008453 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8454 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8455 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8456 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8457 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8458 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8459 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8460 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8461 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8462 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8463 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8464 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8465 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8466 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8467 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8468 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8469 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8470 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8471 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8472 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8473 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8474 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8475 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8476 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8477 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8478 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8479 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8480 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8481 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8482 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>'
8483 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>'
8484 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>'
8485 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8486 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>'
8487 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>'
8488 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 +01008489 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 +02008490 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8491 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008492 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008493 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8494 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008495
8496 elseif !a:domenu
8497 let s:netrwcnt = 0
8498 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008499 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008500 exe curwin."wincmd w"
8501
8502 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008503" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008504 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008505" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008506 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008507 endif
8508 endif
8509" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008510 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008511 endif
8512
8513endfun
8514
8515" ---------------------------------------------------------------------
8516" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8517" Used by the O maps (as <SID>NetrwObtain())
8518fun! s:NetrwObtain(islocal)
8519" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8520
Bram Moolenaar97d62492012-11-15 21:28:22 +01008521 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008522 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008523 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008524 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008525 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8526 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008527 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008528 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008529 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008530
8531" call Dret("NetrwObtain")
8532endfun
8533
8534" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008535" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8536" If there's only one window, then the window will first be split.
8537" Returns:
8538" choice = 0 : didn't have to choose
8539" choice = 1 : saved modified file in window first
8540" choice = 2 : didn't save modified file, opened window
8541" choice = 3 : cancel open
8542fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008543" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008544
Bram Moolenaar97d62492012-11-15 21:28:22 +01008545 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008546 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008547 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008548" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008549
8550 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008551 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008552 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008553" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8554" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8555 let curword = s:NetrwGetWord()
8556 let choice = 0
8557 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8558" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008559 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008560" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008561 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008562" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008563" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008564" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008565
Bram Moolenaar8d043172014-01-23 14:24:41 +01008566 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008567 if lastwinnr == 1
8568 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008569" 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 +02008570 " g:netrw_preview=0: preview window shown in a horizontally split window
8571 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008572 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008573 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008574 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008575" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008576 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008577 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008578 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008579 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008580" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008581 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008582 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008583 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008584" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008585
8586 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008587" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008588 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008589" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008590 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008591" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008592 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008593" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008594 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008595" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008596" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008597" call Decho("COMBAK#12: mod=".&mod)
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01008598
Bram Moolenaar71badf92023-04-22 22:40:14 +01008599 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8600 " whoops -- user trying to open file in the Lexplore window.
8601 " Use Lexplore's opening-file window instead.
8602" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8603" exe g:netrw_chgwin."wincmd w"
8604 wincmd p
8605 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8606 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008607
8608 " prevwinnr: the window number of the "prev" window
8609 " prevbufnr: the buffer number of the buffer in the "prev" window
8610 " bnrcnt : the qty of windows open on the "prev" buffer
8611 let prevwinnr = winnr()
8612 let prevbufnr = bufnr("%")
8613 let prevbufname = bufname("%")
8614 let prevmod = &mod
8615 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008616" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008617 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008618" 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 +01008619" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008620
8621 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008622 " and it doesn't appear in any other extant window, then ask the
8623 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008624 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008625" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008626 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008627" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008628 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008629" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008630
8631 if bnrcnt == 1 && &hidden == 0
8632 " only one copy of the modified buffer in a window, and
8633 " hidden not set, so overwriting will lose the modified file. Ask first...
8634 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008635" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008636 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008637" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008638
8639 if choice == 1
8640 " Yes -- write file & then browse
8641 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008642 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008643 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008644 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008645 exe origwin."wincmd w"
8646 let &ei = eikeep
8647 let @@ = ykeep
8648" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008649 return choice
8650 endif
8651
8652 elseif choice == 2
8653 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008654" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008655 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008656
8657 else
8658 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008659" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008660 exe origwin."wincmd w"
8661 let &ei= eikeep
8662 let @@ = ykeep
8663" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008664 return choice
8665 endif
8666 endif
8667 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008668 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008669 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008670" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008671
8672 " restore b:netrw_curdir (window split/enew may have lost it)
8673 let b:netrw_curdir= curdir
8674 if a:islocal < 2
8675 if a:islocal
8676 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8677 else
8678 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8679 endif
8680 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008681 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008682" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008683 return choice
8684endfun
8685
8686" ---------------------------------------------------------------------
8687" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8688" Always assumed to be local -> remote
8689" call s:NetrwUpload(filename, target)
8690" call s:NetrwUpload(filename, target, fromdirectory)
8691fun! s:NetrwUpload(fname,tgt,...)
8692" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8693
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008694 if a:tgt =~ '^\a\{3,}://'
8695 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008696 else
8697 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8698 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008699" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008700
8701 if a:0 > 0
8702 let fromdir= a:1
8703 else
8704 let fromdir= getcwd()
8705 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008706" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008707
8708 if type(a:fname) == 1
8709 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008710" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008711 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008712" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8713 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8714" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008715 if a:tgt =~ '/$'
8716 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008717" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008718 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008719 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008720" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008721 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008722" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008723 endif
8724 q!
8725
8726 elseif type(a:fname) == 3
8727 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008728" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008729 let curdir= getcwd()
8730 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008731 if s:NetrwLcd(fromdir)
8732" call Dret("s:NetrwUpload : lcd failure")
8733 return
8734 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008735 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008736 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008737 if exists("g:netrw_port") && g:netrw_port != ""
8738 let useport= " ".g:netrw_scpport." ".g:netrw_port
8739 else
8740 let useport= ""
8741 endif
8742 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8743 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008744 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 +02008745 if s:NetrwLcd(curdir)
8746" call Dret("s:NetrwUpload : lcd failure")
8747 return
8748 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008749
8750 elseif a:tgt =~ '^ftp:'
8751 call s:NetrwMethod(a:tgt)
8752
8753 if b:netrw_method == 2
8754 " handle uploading a list of files via ftp+.netrc
8755 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008756 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008757" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008758
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008759 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008760" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008761
8762 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008763 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008764" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008765 endif
8766
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008767 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008768" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008769
Bram Moolenaaradc21822011-04-01 18:03:16 +02008770 if tgtdir == ""
8771 let tgtdir= '/'
8772 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008773 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008774" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008775
8776 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008777 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8778" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008779 endfor
8780
8781 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008782 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 +00008783 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008784" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8785 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008786 endif
8787 " 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 +01008788 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008789 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008790 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8791 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8792 else
8793 bw!|q
8794 endif
8795
8796 elseif b:netrw_method == 3
8797 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8798 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008799 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008800 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008801 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008802
8803 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008804 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008805" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008806 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008807 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008808" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008809 endif
8810
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008811 if exists("g:netrw_uid") && g:netrw_uid != ""
8812 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008813 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008814" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008815 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008816 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008817 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008818" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008819 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008820 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008821" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008822 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008823 endif
8824
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008825 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008826" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008827
8828 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008829 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008830" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008831 endif
8832
8833 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008834 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008835" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008836 endif
8837
8838 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008839 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008840" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008841 endfor
8842
8843 " perform ftp:
8844 " -i : turns off interactive prompting from ftp
8845 " -n unix : DON'T use <.netrc>, even though it exists
8846 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008847 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008848 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008849 " 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 +01008850 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008851 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008852 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8853 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008854 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008855 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8856 let &debug = debugkeep
8857 let mod = 1
8858 else
8859 bw!|q
8860 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008861 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008862" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008863 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008864 endif
8865 else
8866 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8867 endif
8868 endif
8869
8870" call Dret("s:NetrwUpload")
8871endfun
8872
8873" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008874" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008875fun! s:NetrwPreview(path) range
8876" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008877" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8878" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008879 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008880 NetrwKeepj call s:NetrwOptionsSave("s:")
8881 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8882 NetrwKeepj call s:NetrwOptionsSafe(1)
8883 else
8884 NetrwKeepj call s:NetrwOptionsSafe(0)
8885 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008886 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008887" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008888 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008889" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8890 if g:netrw_preview
8891 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008892 let pvhkeep = &pvh
8893 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8894 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008895" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8896 else
8897 " horizontal split
8898 let pvhkeep = &pvh
8899 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8900 let &pvh = winheight(0) - winsz
8901" 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 +02008902 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008903 " g:netrw_preview g:netrw_alto
8904 " 1 : vert 1: top -- preview window is vertically split off and on the left
8905 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8906 " 0 : 1: top -- preview window is horizontally split off and on the top
8907 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8908 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008909 " 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 +02008910 " the BufEnter event set up in netrwPlugin.vim
8911" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8912 let eikeep = &ei
8913 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008914 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008915 let &ei= eikeep
8916" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008917 if exists("pvhkeep")
8918 let &pvh= pvhkeep
8919 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008920 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008921 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008922 endif
8923 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008924 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 +00008925 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008926 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008927 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008928" call Dret("NetrwPreview")
8929endfun
8930
8931" ---------------------------------------------------------------------
8932" s:NetrwRefresh: {{{2
8933fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008934" 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 +00008935 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008936 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008937" call Decho("setl ma noro",'~'.expand("<slnum>"))
8938" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008939 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008940 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8941 if !exists("w:netrw_treetop")
8942 if exists("b:netrw_curdir")
8943 let w:netrw_treetop= b:netrw_curdir
8944 else
8945 let w:netrw_treetop= getcwd()
8946 endif
8947 endif
8948 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
8949 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008950
8951 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008952 let screenposn = winsaveview()
8953" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008954
8955" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
8956" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
8957 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008958 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008959 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008960 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008961 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008962 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008963
8964 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008965" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
8966 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008967
8968 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02008969 if has("syntax") && exists("g:syntax_on") && g:syntax_on
8970 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8971" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
8972 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8973 else
8974" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
8975 2match none
8976 endif
8977 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008978
Bram Moolenaar97d62492012-11-15 21:28:22 +01008979" restore
8980 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008981" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008982endfun
8983
8984" ---------------------------------------------------------------------
8985" s:NetrwRefreshDir: refreshes a directory by name {{{2
8986" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008987" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008988fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008989" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008990 if g:netrw_fastbrowse == 0
8991 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008992" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008993 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008994" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008995
8996 if tgtwin > 0
8997 " tgtwin is being displayed, so refresh it
8998 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008999" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009000 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009001 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009002 exe curwin."wincmd w"
9003
9004 elseif bufnr(a:dirname) > 0
9005 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009006" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9007 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009008 endif
9009
9010 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009011" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009012 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009013 endif
9014" call Dret("s:NetrwRefreshDir")
9015endfun
9016
9017" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009018" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9019" window number to do its editing in.
9020" Supports [count]C where the count, if present, is used to specify
9021" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009022fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009023" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009024 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009025" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009026 if a:1 == "" " :NetrwC win#
9027 let g:netrw_chgwin= winnr()
9028 else " :NetrwC
9029 let g:netrw_chgwin= a:1
9030 endif
9031 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009032 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009033 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009034 let g:netrw_chgwin= winnr()
9035 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009036 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009037" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009038endfun
9039
9040" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009041" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9042" What this function does is to compute a priority for the patterns
9043" in the g:netrw_sort_sequence. It applies a substitute to any
9044" "files" that satisfy each pattern, putting the priority / in
9045" front. An "*" pattern handles the default priority.
9046fun! s:NetrwSetSort()
9047" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009048 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009049 if w:netrw_liststyle == s:LONGLIST
9050 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9051 else
9052 let seqlist = g:netrw_sort_sequence
9053 endif
9054 " sanity check -- insure that * appears somewhere
9055 if seqlist == ""
9056 let seqlist= '*'
9057 elseif seqlist !~ '\*'
9058 let seqlist= seqlist.',*'
9059 endif
9060 let priority = 1
9061 while seqlist != ""
9062 if seqlist =~ ','
9063 let seq = substitute(seqlist,',.*$','','e')
9064 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9065 else
9066 let seq = seqlist
9067 let seqlist = ""
9068 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009069 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009070 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009071 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009072 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009073 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009074 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009075 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009076" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009077
9078 " sanity check
9079 if w:netrw_bannercnt > line("$")
9080 " apparently no files were left after a Hiding pattern was used
9081" call Dret("SetSort : no files left after hiding")
9082 return
9083 endif
9084 if seq == '*'
9085 let starpriority= spriority
9086 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009087 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009088 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009089 " sometimes multiple sorting patterns will match the same file or directory.
9090 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009091 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9092 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009093 endif
9094 let priority = priority + 1
9095 endwhile
9096 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009097 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9098 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009099 endif
9100
9101 " Following line associated with priority -- items that satisfy a priority
9102 " pattern get prefixed by ###/ which permits easy sorting by priority.
9103 " Sometimes files can satisfy multiple priority patterns -- only the latest
9104 " priority pattern needs to be retained. So, at this point, these excess
9105 " priority prefixes need to be removed, but not directories that happen to
9106 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009107 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9108 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009109 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009110
9111" call Dret("SetSort")
9112endfun
9113
Bram Moolenaarff034192013-04-24 18:51:19 +02009114" ---------------------------------------------------------------------
9115" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9116" Implements [count]Tb (bookhist<b>)
9117" [count]Th (bookhist<h>)
9118" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009119fun! s:NetrwSetTgt(islocal,bookhist,choice)
9120" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009121
9122 if a:bookhist == 'b'
9123 " supports choosing a bookmark as a target using a qb-generated list
9124 let choice= a:choice - 1
9125 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009126 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009127 else
9128 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9129 endif
9130
9131 elseif a:bookhist == 'h'
9132 " supports choosing a history stack entry as a target using a qb-generated list
9133 let choice= (a:choice % g:netrw_dirhistmax) + 1
9134 if exists("g:netrw_dirhist_".choice)
9135 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009136 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009137 else
9138 echomsg "Sorry, history#".a:choice." not available!"
9139 endif
9140 endif
9141
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009142 " refresh the display
9143 if !exists("b:netrw_curdir")
9144 let b:netrw_curdir= getcwd()
9145 endif
9146 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9147
Bram Moolenaarff034192013-04-24 18:51:19 +02009148" call Dret("s:NetrwSetTgt")
9149endfun
9150
Bram Moolenaar446cb832008-06-24 21:56:24 +00009151" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009152" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009153fun! s:NetrwSortStyle(islocal)
9154" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009155 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009156 let svpos= winsaveview()
9157" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009158
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009159 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 +01009160 NetrwKeepj norm! 0
9161 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009162" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9163 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009164
9165" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9166endfun
9167
9168" ---------------------------------------------------------------------
9169" s:NetrwSplit: mode {{{2
9170" =0 : net and o
9171" =1 : net and t
9172" =2 : net and v
9173" =3 : local and o
9174" =4 : local and t
9175" =5 : local and v
9176fun! s:NetrwSplit(mode)
9177" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9178
Bram Moolenaar97d62492012-11-15 21:28:22 +01009179 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009180 call s:SaveWinVars()
9181
9182 if a:mode == 0
9183 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009184 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009185 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009186" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009187 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009188 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009189 NetrwKeepj call s:RestoreWinVars()
9190 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009191 unlet s:didsplit
9192
9193 elseif a:mode == 1
9194 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009195 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009196" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009197 tabnew
9198 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009199 NetrwKeepj call s:RestoreWinVars()
9200 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009201 unlet s:didsplit
9202
9203 elseif a:mode == 2
9204 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009205 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009206 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009207" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009208 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009209 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009210 NetrwKeepj call s:RestoreWinVars()
9211 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009212 unlet s:didsplit
9213
9214 elseif a:mode == 3
9215 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009216 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009217 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009218" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009219 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009220 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009221 NetrwKeepj call s:RestoreWinVars()
9222 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009223 unlet s:didsplit
9224
9225 elseif a:mode == 4
9226 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009227 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009228 let eikeep = &ei
9229 let netrw_winnr = winnr()
9230 let netrw_line = line(".")
9231 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009232 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009233 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009234 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009235 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9236 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009237 let &ei = eikeep
9238 let netrw_curdir = s:NetrwTreeDir(0)
9239" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009240 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009241 let b:netrw_curdir = netrw_curdir
9242 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009243 NetrwKeepj call s:RestoreWinVars()
9244 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009245 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009246 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009247 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9248 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009249 let &ei= eikeep
9250 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009251 unlet s:didsplit
9252
9253 elseif a:mode == 5
9254 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009255 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009256 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009257" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009258 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009259 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009260 NetrwKeepj call s:RestoreWinVars()
9261 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009262 unlet s:didsplit
9263
9264 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009265 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009266 endif
9267
Bram Moolenaar97d62492012-11-15 21:28:22 +01009268 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009269" call Dret("s:NetrwSplit")
9270endfun
9271
9272" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009273" s:NetrwTgtMenu: {{{2
9274fun! s:NetrwTgtMenu()
9275 if !exists("s:netrw_menucnt")
9276 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009277 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009278" call Dfunc("s:NetrwTgtMenu()")
9279
9280 " the following test assures that gvim is running, has menus available, and has menus enabled.
9281 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9282 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009283" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009284 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9285 endif
9286 if !exists("s:netrw_initbookhist")
9287 call s:NetrwBookHistRead()
9288 endif
9289
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009290 " try to cull duplicate entries
9291 let tgtdict={}
9292
Bram Moolenaarff034192013-04-24 18:51:19 +02009293 " target bookmarked places
9294 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009295" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009296 let cnt= 1
9297 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009298 if has_key(tgtdict,bmd)
9299 let cnt= cnt + 1
9300 continue
9301 endif
9302 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009303 let ebmd= escape(bmd,g:netrw_menu_escape)
9304 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009305" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009306 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 +02009307 let cnt= cnt + 1
9308 endfor
9309 endif
9310
9311 " target directory browsing history
9312 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009313" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009314 let histcnt = 1
9315 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009316 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009317 if exists("g:netrw_dirhist_{histcnt}")
9318 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009319 if has_key(tgtdict,histentry)
9320 let histcnt = histcnt + 1
9321 continue
9322 endif
9323 let tgtdict[histentry] = histcnt
9324 let ehistentry = escape(histentry,g:netrw_menu_escape)
9325" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009326 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 +02009327 endif
9328 let histcnt = histcnt + 1
9329 endwhile
9330 endif
9331 endif
9332" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009333endfun
9334
9335" ---------------------------------------------------------------------
9336" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9337" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009338fun! s:NetrwTreeDir(islocal)
9339" 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 +02009340" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009341" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9342" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9343" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009344" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009345
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009346 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009347 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009348" 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 +01009349 let treedir= s:treedir
9350 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009351 unlet s:prevwinopen
9352" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009353 return treedir
9354 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009355 if exists("s:prevwinopen")
9356 unlet s:prevwinopen
9357 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009358" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009359
Bram Moolenaar8d043172014-01-23 14:24:41 +01009360 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9361 let b:netrw_curdir= getcwd()
9362 endif
9363 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009364" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009365" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009366
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009367 let s:treecurpos= winsaveview()
9368" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009369" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009370
9371 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009372" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9373" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009374" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009375
9376 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009377 let curline= substitute(getline('.'),"\t -->.*$",'','')
9378 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009379" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009380 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009381" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9382 elseif curline =~ '@$'
9383" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009384 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009385" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009386 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009387" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009388 let treedir= ""
9389 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009390" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009391
9392 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009393" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9394" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009395" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009396 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009397" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009398 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009399" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9400 sil! NetrwKeepj %d _
9401" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009402 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009403" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009404" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009405 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009406" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009407
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009408" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009409" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009410" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009411
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009412 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9413" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9414" let newdir = w:netrw_treetop.'/'.potentialdir
9415" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9416" let treedir = s:NetrwTreePath(newdir)
9417" let w:netrw_treetop = newdir
9418" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9419" else
9420" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009421 if a:islocal && curline =~ '@$'
9422 if isdirectory(s:NetrwFile(potentialdir))
9423 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9424 let w:netrw_treetop = treedir
9425 endif
9426 else
9427 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9428 let treedir = s:NetrwTreePath(w:netrw_treetop)
9429 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009430 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009431" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009432
9433 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009434 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009435" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009436" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009437
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009438" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009439 return treedir
9440endfun
9441
9442" ---------------------------------------------------------------------
9443" s:NetrwTreeDisplay: recursive tree display {{{2
9444fun! s:NetrwTreeDisplay(dir,depth)
9445" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9446
9447 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009448 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009449
9450 " install ../ and shortdir
9451 if a:depth == ""
9452 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009453" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009454 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009455 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009456 if a:dir == w:netrw_treetop
9457 let shortdir= a:dir
9458 else
9459 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9460 endif
9461 call setline(line("$")+1,a:depth.shortdir)
9462 else
9463 let shortdir= substitute(a:dir,'^.*/','','e')
9464 call setline(line("$")+1,a:depth.shortdir.'/')
9465 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009466" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009467 " append a / to dir if its missing one
9468 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009469
9470 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009471 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009472" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009473
Bram Moolenaar85850f32019-07-19 22:05:51 +02009474 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9475 if g:netrw_hide == 1
9476 " hide given patterns
9477 let listhide= split(g:netrw_list_hide,',')
9478" call Decho("listhide=".string(listhide))
9479 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009480 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009481 endfor
9482
9483 elseif g:netrw_hide == 2
9484 " show given patterns (only)
9485 let listhide= split(g:netrw_list_hide,',')
9486" call Decho("listhide=".string(listhide))
9487 let entries=[]
9488 for entry in w:netrw_treedict[dir]
9489 for pat in listhide
9490 if entry =~ pat
9491 call add(entries,entry)
9492 break
9493 endif
9494 endfor
9495 endfor
9496 let w:netrw_treedict[dir]= entries
9497 endif
9498 if depth != ""
9499 " always remove "." and ".." entries when there's depth
9500 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9501 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9502 endif
9503
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009504" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009505 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009506 if dir =~ '/$'
9507 let direntry= substitute(dir.entry,'[@/]$','','e')
9508 else
9509 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9510 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009511" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009512 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009513" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009514 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009515 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009516" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9517 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9518 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9519" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009520 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009521 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009522" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009523 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009524 endif
9525 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009526" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009527
Bram Moolenaar446cb832008-06-24 21:56:24 +00009528" call Dret("NetrwTreeDisplay")
9529endfun
9530
9531" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009532" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9533fun! s:NetrwRefreshTreeDict(dir)
9534" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009535 if !exists("w:netrw_treedict")
9536" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9537 return
9538 endif
9539
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009540 for entry in w:netrw_treedict[a:dir]
9541 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9542" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9543
9544 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9545" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9546 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009547 let liststar = s:NetrwGlob(direntry,'*',1)
9548 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009549 let w:netrw_treedict[direntry] = liststar + listdotstar
9550" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9551
9552 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9553" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9554 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009555 let liststar = s:NetrwGlob(direntry.'/','*',1)
9556 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009557 let w:netrw_treedict[direntry]= liststar + listdotstar
9558" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9559
9560 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9561" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9562 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009563 let liststar = s:NetrwGlob(direntry.'/','*',1)
9564 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009565" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9566
9567 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009568" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009569 endif
9570 endfor
9571" call Dret("s:NetrwRefreshTreeDict")
9572endfun
9573
9574" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009575" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009576" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009577fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009578 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009579" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009580" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9581" 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>"))
9582" 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 +00009583
9584 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009585 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009586" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009587 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009588 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009589" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009590 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 +02009591" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009592 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009593 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009594" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009595 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009596 if exists("w:netrw_treetop")
9597 let s:netrw_treetop= w:netrw_treetop
9598 else
9599 let w:netrw_treetop= getcwd()
9600 let s:netrw_treetop= w:netrw_treetop
9601 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009602
Bram Moolenaar446cb832008-06-24 21:56:24 +00009603 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009604 " insure that we have a treedict, albeit empty
9605" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009606 let w:netrw_treedict= {}
9607 endif
9608
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009609 " update the dictionary for the current directory
9610" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009611" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009612 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009613 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009614" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009615 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009616
9617 " if past banner, record word
9618 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9619 let fname= expand("<cword>")
9620 else
9621 let fname= ""
9622 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009623" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9624" 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 +00009625
9626 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009627" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009628 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009629" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009630
9631 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9632 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009633" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009634 1d
9635 endwhile
9636
Bram Moolenaar13600302014-05-22 18:26:40 +02009637 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009638
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009639" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009640 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009641 endif
9642endfun
9643
9644" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009645" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009646" Normally, treetop is w:netrw_treetop, but a
9647" user of the function ( netrw#SetTreetop() )
9648" wipes that out prior to calling this function
9649fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009650" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9651 if line(".") < w:netrw_bannercnt + 2
9652 let treedir= a:treetop
9653 if treedir !~ '/$'
9654 let treedir= treedir.'/'
9655 endif
9656" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9657 return treedir
9658 endif
9659
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009660 let svpos = winsaveview()
9661" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009662 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009663" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009664 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009665" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9666 let curline= getline('.')
9667" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9668 if curline =~ '/$'
9669" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9670 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9671" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9672 elseif curline =~ '@\s\+-->'
9673" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9674 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9675 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9676" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009677 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009678" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009679 let treedir= ""
9680 endif
9681 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009682" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9683" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009684 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9685 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9686 let treedir= dirname.treedir
9687 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009688" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009689 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009690" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009691 if a:treetop =~ '/$'
9692 let treedir= a:treetop.treedir
9693 else
9694 let treedir= a:treetop.'/'.treedir
9695 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009696" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009697 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009698" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009699" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9700 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009701" call Dret("s:NetrwTreePath <".treedir.">")
9702 return treedir
9703endfun
9704
9705" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009706" s:NetrwWideListing: {{{2
9707fun! s:NetrwWideListing()
9708
9709 if w:netrw_liststyle == s:WIDELIST
9710" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9711 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009712 " cpf: characters per filename
9713 " fpl: filenames per line
9714 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009715 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009716 let dict={}
9717 " save the unnamed register and register 0-9 and a
9718 let dict.a=[getreg('a'), getregtype('a')]
9719 for i in range(0, 9)
9720 let dict[i] = [getreg(i), getregtype(i)]
9721 endfor
9722 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009723" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009724 let b:netrw_cpf= 0
9725 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009726 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009727 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9728 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009729 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009730 " restore stored registers
9731 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009732" call Dret("NetrwWideListing")
9733 return
9734 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009735 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009736 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009737" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009738
9739 " determine qty files per line (fpl)
9740 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9741 if w:netrw_fpl <= 0
9742 let w:netrw_fpl= 1
9743 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009744" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009745
9746 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009747 " fpc: files per column of wide listing
9748 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009749 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009750 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9751 let newcolstart = w:netrw_bannercnt + fpc
9752 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009753" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009754 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009755" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009756 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009757 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009758 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009759 while line("$") >= newcolstart
9760 if newcolend > line("$") | let newcolend= line("$") | endif
9761 let newcolqty= newcolend - newcolstart
9762 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009763 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009764 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009765 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009766 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009767 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009768 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009769 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009770 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009771 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009772 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009773" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009774 if @* != keepregstar | sil! let @* = keepregstar | endif
9775 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009776 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009777 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9778 NetrwKeepj call histdel("/",-1)
9779 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9780 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009781" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009782 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009783 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009784" 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 +00009785" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009786 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009787 else
9788 if hasmapto("w","n")
9789 sil! nunmap <buffer> w
9790 endif
9791 if hasmapto("b","n")
9792 sil! nunmap <buffer> b
9793 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009794 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009795endfun
9796
9797" ---------------------------------------------------------------------
9798" s:PerformListing: {{{2
9799fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009800" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9801" 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 +02009802" 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>"))
9803 sil! NetrwKeepj %d _
9804" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009805
Bram Moolenaar15146672011-10-20 22:22:38 +02009806 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009807" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009808 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009809
Bram Moolenaar85850f32019-07-19 22:05:51 +02009810 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009811 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009812" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009813
9814" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009815" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009816" endif " Decho
9817
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009818" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009819 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9820 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009821" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9822 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009823 endif
9824
9825 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009826 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009827
9828 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009829 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009830" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009831 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009832 if exists("g:netrw_pchk")
9833 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9834 " failure detections.
9835 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009836 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009837 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9838 endif
9839 if exists("g:netrw_pchk")
9840 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9841 else
9842 let curdir= b:netrw_curdir
9843 endif
9844 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9845 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9846 else
9847 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009848 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009849 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009850 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009851 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009852" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009853 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009854 let w:netrw_bannercnt= 1
9855 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009856" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9857" 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 +00009858
Bram Moolenaar85850f32019-07-19 22:05:51 +02009859 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009860 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009861 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009862 let sortby= sortby." reversed"
9863 endif
9864
9865 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009866 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009867" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009868 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009869" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009870 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009871 NetrwKeepj put ='\" Sorted by '.sortby
9872 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009873 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9874 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009875" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009876 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009877 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009878 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9879 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009880 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009881" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009882" 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 +00009883 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009884
Bram Moolenaar85850f32019-07-19 22:05:51 +02009885 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009886 if g:netrw_banner
9887 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009888" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009889 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009890 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009891 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009892 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009893 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009894 endif
9895 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009896 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009897" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009898 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009899 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009900 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009901
9902 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009903 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009904" 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 +01009905 if g:netrw_list_hide != "" && g:netrw_hide
9906 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009907 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009908 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009909 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009910 endif
9911 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009912 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009913 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009914
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009915" 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 +01009916 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009917" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009918 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009919" 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 +01009920 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009921 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009922" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009923" 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 +00009924 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009925
9926 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009927 if g:netrw_banner
9928 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009929 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009930" 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 +01009931" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009932" 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 +01009933 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009934
Bram Moolenaar446cb832008-06-24 21:56:24 +00009935 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009936" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009937 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009938 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009939 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009940 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009941 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009942" 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 +01009943" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9944 return
9945 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009946 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009947
9948 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009949 if !exists("w:netrw_bannercnt")
9950 let w:netrw_bannercnt= 0
9951 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009952" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
9953" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
9954" 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 +01009955
Bram Moolenaar5c736222010-01-06 20:54:52 +01009956 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009957" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009958" 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 +00009959 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009960 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009961 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009962 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009963" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009964
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009965 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009966 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +02009967" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009968 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009969
Bram Moolenaar5c736222010-01-06 20:54:52 +01009970 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009971" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009972 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +02009973 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009974 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009975 else
9976 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009977 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009978 endif
9979 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009980
Bram Moolenaar446cb832008-06-24 21:56:24 +00009981 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009982" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009983 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
9984 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009985
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009986 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +02009987 " exten: sort by extension
9988 " The histdel(...,-1) calls remove the last search from the search history
9989" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009990 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
9991 NetrwKeepj call histdel("/",-1)
9992 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
9993 NetrwKeepj call histdel("/",-1)
9994 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
9995 NetrwKeepj call histdel("/",-1)
9996 if !g:netrw_banner || w:netrw_bannercnt < line("$")
9997" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009998 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009999 " normal direction sorting
10000 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10001 else
10002 " reverse direction sorting
10003 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10004 endif
10005 endif
10006 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10007 NetrwKeepj call histdel("/",-1)
10008
Bram Moolenaar446cb832008-06-24 21:56:24 +000010009 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010010 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010011" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010012 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010013" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010014 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010015 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010016" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010017 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010018 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010019" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010020 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10021 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010022 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010023 endif
10024
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010025 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010026" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010027 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010028 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010029 call histdel("/",-1)
10030 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010031 endif
10032 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010033" 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 +000010034
10035 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010036" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10037" 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 +010010038 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010039" 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 +010010040 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010041" 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 +000010042
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010043 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010044 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010045" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010046 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010047 endif
10048
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010049 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010050 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010051" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10052 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010053 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010054" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10055 else
10056" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10057" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10058" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10059" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010060 endif
10061
10062 " record previous current directory
10063 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010064" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010065
10066 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010067" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10068" 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 +010010069 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010070" 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 +020010071 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010072" 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 +000010073
10074 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010075" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010076 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010077" 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 +010010078 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010079" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010080 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10081 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010082" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010083" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010084
Bram Moolenaar8d043172014-01-23 14:24:41 +010010085 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010086" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10087" 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 +010010088" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10089 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010090 unlet s:treecurpos
10091 endif
10092
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010093" 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>"))
10094" 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 +000010095" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10096endfun
10097
10098" ---------------------------------------------------------------------
10099" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010100fun! s:SetupNetrwStatusLine(statline)
10101" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10102
10103 if !exists("s:netrw_setup_statline")
10104 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010105" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010106
10107 if !exists("s:netrw_users_stl")
10108 let s:netrw_users_stl= &stl
10109 endif
10110 if !exists("s:netrw_users_ls")
10111 let s:netrw_users_ls= &laststatus
10112 endif
10113
10114 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +020010115 let dict={}
10116 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +000010117 redir @a
10118 try
10119 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010120 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010121 if &bg == "dark"
10122 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10123 else
10124 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10125 endif
10126 endtry
10127 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +020010128 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010129 endif
10130
10131 " set up status line (may use User9 highlighting)
10132 " insure that windows have a statusline
10133 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010134 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010135 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010136" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010137 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010138
10139" call Dret("SetupNetrwStatusLine : stl=".&stl)
10140endfun
10141
Bram Moolenaar85850f32019-07-19 22:05:51 +020010142" =========================================
10143" Remote Directory Browsing Support: {{{1
10144" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010145
10146" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010147" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10148" This function assumes that a long listing will be received. Size, time,
10149" and reverse sorts will be requested of the server but not otherwise
10150" enforced here.
10151fun! s:NetrwRemoteFtpCmd(path,listcmd)
10152" 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 +010010153" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010154 " sanity check: {{{3
10155 if !exists("w:netrw_method")
10156 if exists("b:netrw_method")
10157 let w:netrw_method= b:netrw_method
10158 else
10159 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10160" call Dret("NetrwRemoteFtpCmd")
10161 return
10162 endif
10163 endif
10164
10165 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10166 let ffkeep= &ff
10167 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010168" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010169
10170 " clear off any older non-banner lines " {{{3
10171 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010172" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10173 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010174
10175 ".........................................
10176 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10177 " ftp + <.netrc>: Method #2
10178 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010179 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010180 endif
10181 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010182 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010183" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010184 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010185 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010186" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010187 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010188" 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>"))
10189 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 +010010190 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010191" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10192 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 +010010193 endif
10194
10195 ".........................................
10196 elseif w:netrw_method == 3 " {{{3
10197 " ftp + machine,id,passwd,filename: Method #3
10198 setl ff=unix
10199 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010200 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010201 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010202 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010203 endif
10204
10205 " handle userid and password
10206 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010207" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010208 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10209 call NetUserPass("ftp:".host)
10210 endif
10211 if exists("g:netrw_uid") && g:netrw_uid != ""
10212 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010213 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010214 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010215 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010216 endif
10217 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010218 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010219 endif
10220 endif
10221
10222 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010223 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010224 endif
10225 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010226 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010227" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010228 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010229 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010230
10231 " perform ftp:
10232 " -i : turns off interactive prompting from ftp
10233 " -n unix : DON'T use <.netrc>, even though it exists
10234 " -n win32: quit being obnoxious about password
10235 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010236" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010237 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010238" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010239" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10240" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010241 endif
10242
10243 ".........................................
10244 elseif w:netrw_method == 9 " {{{3
10245 " sftp username@machine: Method #9
10246 " s:netrw_sftp_cmd
10247 setl ff=unix
10248
10249 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010250 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010251" call Dret("NetrwRemoteFtpCmd")
10252 return
10253
10254 ".........................................
10255 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010256 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010257 endif
10258
10259 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010260 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010261 sil! NetrwKeepj %s/\r$//e
10262 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010263 endif
10264 if a:listcmd == "dir"
10265 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010266 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10267 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10268 NetrwKeepj call histdel("/",-1)
10269 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010270 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 +010010271 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10272 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010273 endif
10274 endif
10275
10276 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10277 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010278 exe 'NetrwKeepj '.w:netrw_bannercnt
10279 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010280 endif
10281 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010282 exe 'NetrwKeepj '.w:netrw_bannercnt
10283 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010284 endif
10285
10286 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010287 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010288" call Dret("NetrwRemoteFtpCmd")
10289endfun
10290
10291" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010292" s:NetrwRemoteListing: {{{2
10293fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010294" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010295
Bram Moolenaara6878372014-03-22 21:02:50 +010010296 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10297 let w:netrw_bannercnt= s:bannercnt
10298 endif
10299 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010300 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010301 endif
10302
Bram Moolenaar446cb832008-06-24 21:56:24 +000010303 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010304
Bram Moolenaar446cb832008-06-24 21:56:24 +000010305 " sanity check:
10306 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010307" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010308 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010309" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010310 if !exists("g:netrw_quiet")
10311 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10312 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010313 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010314" call Dret("s:NetrwRemoteListing -1")
10315 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010316 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010317
Bram Moolenaar8d043172014-01-23 14:24:41 +010010318 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010319" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010320 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010321 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010322 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 +000010323 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010324 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 +000010325 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010326 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010327
Bram Moolenaar85850f32019-07-19 22:05:51 +020010328 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010329" call Dret("s:NetrwRemoteListing -1")
10330 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010331 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010332" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010333
Bram Moolenaar446cb832008-06-24 21:56:24 +000010334 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010335" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010336 let w:netrw_method= b:netrw_method
10337 endif
10338
Bram Moolenaar13600302014-05-22 18:26:40 +020010339 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010340 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010341" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010342 let s:method = "ftp"
10343 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010344 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010345 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010346 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010347 let listcmd= g:netrw_ftp_sizelist_cmd
10348 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010349" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010350 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010351" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010352
Bram Moolenaara6878372014-03-22 21:02:50 +010010353 " report on missing file or directory messages
10354 if search('[Nn]o such file or directory\|Failed to change directory')
10355 let mesg= getline(".")
10356 if exists("w:netrw_bannercnt")
10357 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010358 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010359 setl noma
10360 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010361 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010362 call netrw#ErrorMsg(s:WARNING,mesg,96)
10363" call Dret("s:NetrwRemoteListing : -1")
10364 return -1
10365 endif
10366
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010367 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 +000010368 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010369" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010370 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010371
10372 " cleanup
10373 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010374 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10375 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010376 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010377 sil! NetrwKeepj %s/\r$//e
10378 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010379
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010380 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010381 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010382 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010383 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010384" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010385 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010386" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010387 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010388 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010389 exe "sil! NetrwKeepj ".line1
10390 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010391
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010392" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010393 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010394" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010395 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10396 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010397 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010398" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010399 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10400 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10401 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10402 NetrwKeepj call histdel("/",-1)
10403 NetrwKeepj call histdel("/",-1)
10404 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010405 endif
10406 endif
10407
Bram Moolenaar13600302014-05-22 18:26:40 +020010408 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010409 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010410" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010411 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010412" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010413 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010414" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10415 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010416 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010417 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10418 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10419 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10420 NetrwKeepj call histdel("/",-1)
10421 NetrwKeepj call histdel("/",-1)
10422 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010423 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010424 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10425 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010426 endif
10427 else
10428 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010429" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010430 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010431 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010432" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10433 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10434" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010435 endif
10436 endif
10437
10438 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010439 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010440" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010441 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10442 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010443 endif
10444 endif
10445
10446 if w:netrw_liststyle == s:LONGLIST
10447 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010448" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010449
10450 if s:method == "ftp"
10451 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010452 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010453 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010454 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010455 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010456 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010457 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010458 sil! NetrwKeepj 1
10459 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010460 let line2= line(".")
10461 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010462 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010463 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010464 endif
10465 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010466 exe "sil! NetrwKeepj ".line1
10467 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010468 endif
10469
10470 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010471" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010472 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 +000010473 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010474" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010475 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010476 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010477 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10478 NetrwKeepj call histdel("/",-1)
10479 NetrwKeepj call histdel("/",-1)
10480 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010481 endif
10482 endif
10483
10484" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010485" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010486" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010487
10488" call Dret("s:NetrwRemoteListing 0")
10489 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010490endfun
10491
Bram Moolenaar446cb832008-06-24 21:56:24 +000010492" ---------------------------------------------------------------------
10493" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10494fun! s:NetrwRemoteRm(usrhost,path) range
10495" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010496" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010497 let svpos= winsaveview()
10498" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010499
10500 let all= 0
10501 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10502 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010503" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010504 for fname in s:netrwmarkfilelist_{bufnr("%")}
10505 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010506 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010507 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010508 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010509 let all= 1
10510 endif
10511 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010512 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010513
10514 else
10515 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010516" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010517
10518 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010519 let keepsol = &l:sol
10520 setl nosol
10521 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010522
10523 " remove multiple files and directories
10524 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010525 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010526 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010527 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010528 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010529 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010530 let all= 1
10531 endif
10532 let ctr= ctr + 1
10533 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010534 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010535 endif
10536
10537 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010538" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010539 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010540" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10541 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010542
10543" call Dret("s:NetrwRemoteRm")
10544endfun
10545
10546" ---------------------------------------------------------------------
10547" s:NetrwRemoteRmFile: {{{2
10548fun! s:NetrwRemoteRmFile(path,rmfile,all)
10549" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10550
10551 let all= a:all
10552 let ok = ""
10553
10554 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10555 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010556" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010557 if !all
10558 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010559" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010560 call inputsave()
10561 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10562 call inputrestore()
10563 echohl NONE
10564 if ok == ""
10565 let ok="no"
10566 endif
10567 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010568 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010569 let all= 1
10570 endif
10571 endif
10572
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010573 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010574" 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 +000010575 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010576" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010577 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010578 if path =~ '^\a\{3,}://'
10579 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010580 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010581 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010582 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10583 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010584" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010585 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010586" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010587 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010588 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010589 let ok="q"
10590 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010591 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010592" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10593" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10594" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010595 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010596 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010597 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010598 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010599 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010600" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010601 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010602 if v:shell_error != 0
10603 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010604 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 +010010605 else
10606 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10607 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010608 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010609 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010610 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010611" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010612 endif
10613 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010614 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010615" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010616 endif
10617
10618 else
10619 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010620" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010621 if !all
10622 call inputsave()
10623 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10624 call inputrestore()
10625 if ok == ""
10626 let ok="no"
10627 endif
10628 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010629 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010630 let all= 1
10631 endif
10632 endif
10633
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010634 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010635 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010636 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010637 else
10638 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010639 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10640" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010641 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010642" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010643
10644 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010645" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10646 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10647" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010648 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010649" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010650
10651 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010652 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010653 endif
10654 endif
10655 endif
10656
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010657 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010658" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010659 endif
10660 endif
10661
10662" call Dret("s:NetrwRemoteRmFile ".ok)
10663 return ok
10664endfun
10665
10666" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010667" s:NetrwRemoteRename: rename a remote file or directory {{{2
10668fun! s:NetrwRemoteRename(usrhost,path) range
10669" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10670
10671 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010672 let svpos = winsaveview()
10673" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010674 let ctr = a:firstline
10675 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10676
10677 " rename files given by the markfilelist
10678 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10679 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010680" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010681 if exists("subfrom")
10682 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010683" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010684 else
10685 call inputsave()
10686 let newname= input("Moving ".oldname." to : ",oldname)
10687 call inputrestore()
10688 if newname =~ '^s/'
10689 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10690 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10691 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010692" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010693 endif
10694 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010695
Bram Moolenaar446cb832008-06-24 21:56:24 +000010696 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010697 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010698 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010699 let oldname= s:ShellEscape(a:path.oldname)
10700 let newname= s:ShellEscape(a:path.newname)
10701" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010702 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010703 endif
10704
10705 endfor
10706 call s:NetrwUnMarkFile(1)
10707
10708 else
10709
10710 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010711 let keepsol= &l:sol
10712 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010713 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010714 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010715
10716 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010717" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010718
10719 call inputsave()
10720 let newname= input("Moving ".oldname." to : ",oldname)
10721 call inputrestore()
10722
10723 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10724 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10725 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010726 let oldname= s:ShellEscape(a:path.oldname)
10727 let newname= s:ShellEscape(a:path.newname)
10728" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010729 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010730 endif
10731
10732 let ctr= ctr + 1
10733 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010734 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010735 endif
10736
10737 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010738 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010739" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10740 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010741
10742" call Dret("NetrwRemoteRename")
10743endfun
10744
Bram Moolenaar85850f32019-07-19 22:05:51 +020010745" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010746" Local Directory Browsing Support: {{{1
10747" ==========================================
10748
10749" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010750" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010751" Should accept: file://localhost/etc/fstab
10752" file:///etc/fstab
10753" file:///c:/WINDOWS/clock.avi
10754" file:///c|/WINDOWS/clock.avi
10755" file://localhost/c:/WINDOWS/clock.avi
10756" file://localhost/c|/WINDOWS/clock.avi
10757" file://c:/foo.txt
10758" file:///c:/foo.txt
10759" 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 +020010760fun! netrw#FileUrlEdit(fname)
10761" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010762 let fname = a:fname
10763 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010764" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010765 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010766" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010767 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010768 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010769 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010770" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010771 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010772" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010773 endif
10774 endif
10775 let fname2396 = netrw#RFC2396(fname)
10776 let fname2396e= fnameescape(fname2396)
10777 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010778 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010779" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010780 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010781" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010782 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10783 endif
10784 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010785
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010786" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10787" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010788 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010789 exe 'NetrwKeepj keepalt edit '.plainfname
10790 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10791
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010792" 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 +020010793" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010794 exe "sil doau BufReadPost ".fname2396e
10795endfun
10796
10797" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010798" netrw#LocalBrowseCheck: {{{2
10799fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010800 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010801 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10802 "
10803 " unfortunate interaction -- split window debugging can't be used here, must use
10804 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10805 " another call to LocalBrowseCheck() when attempts to write
10806 " to the DBG buffer are made.
10807 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010808 " The &ft == "netrw" test was installed because the BufEnter event
10809 " would hit when re-entering netrw windows, creating unexpected
10810 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010811" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010812" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010813" 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 +010010814 " getting E930: Cannot use :redir inside execute
10815"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010816" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10817" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010818
Bram Moolenaar97d62492012-11-15 21:28:22 +010010819 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010820 if isdirectory(s:NetrwFile(a:dirname))
10821" 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 +010010822
Bram Moolenaar97d62492012-11-15 21:28:22 +010010823 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010824" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10825" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010826 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010827
Bram Moolenaar446cb832008-06-24 21:56:24 +000010828 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010829" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010830 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010831
Bram Moolenaar5c736222010-01-06 20:54:52 +010010832 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010833" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010834 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010835 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010836 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010837" 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 +010010838" call Dret("netrw#LocalBrowseCheck")
10839 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010840 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010841
Bram Moolenaar85850f32019-07-19 22:05:51 +020010842 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010843 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10844 " AND IF the listing style is not a tree listing
10845 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010846" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010847 let ibuf = 1
10848 let buflast = bufnr("$")
10849 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010850 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10851 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010852 endif
10853 let ibuf= ibuf + 1
10854 endwhile
10855 endif
10856 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010857" 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>"))
10858" 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 +000010859 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010860" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010861endfun
10862
10863" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010864" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010865" performed any shell command. The idea is to cause all local-browsing
10866" buffers to be refreshed after a user has executed some shell command,
10867" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010868fun! s:LocalBrowseRefresh()
10869" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010870" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10871" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010872
Bram Moolenaar446cb832008-06-24 21:56:24 +000010873 " determine which buffers currently reside in a tab
10874 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010875" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010876 return
10877 endif
10878 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010879" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010880 return
10881 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010882 if !empty(getcmdwintype())
10883 " cannot move away from cmdline window, see :h E11
10884 return
10885 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010886 if exists("s:netrw_events") && s:netrw_events == 1
10887 " s:LocalFastBrowser gets called (indirectly) from a
10888 let s:netrw_events= 2
10889" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10890 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010891 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010892 let itab = 1
10893 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010894 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010895 while itab <= tabpagenr("$")
10896 let buftablist = buftablist + tabpagebuflist()
10897 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010898 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010899 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010900" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10901" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010902 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10903 " | refresh any netrw window
10904 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010905 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010906 let ibl = 0
10907 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010908" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010909 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10910 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010911 " (ibuf not shown in a current window AND
10912 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010913" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10914 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010915 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010916" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010917 continue
10918 elseif index(tabpagebuflist(),ibuf) != -1
10919 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010920" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010921 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010922 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010923 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10924 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10925 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10926 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010927" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010928 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10929 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10930 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010931 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010932 endif
10933 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010934" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010935 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010936" call Decho("restore window: win_gotoid(".curwinid.")")
10937 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010938 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010939
Bram Moolenaara6878372014-03-22 21:02:50 +010010940" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010941endfun
10942
10943" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010944" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10945"
10946" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010947" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010948" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10949" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010950" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010951"
10952" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
10953" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010010954" (re-using a buffer may not be as accurate)
10955"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010956" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010010957" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
10958" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
10959" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
10960" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010961fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020010962" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
10963" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
10964" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
10965" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010966
10967 " initialize browselist, a list of buffer numbers that the local browser has used
10968 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010969" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010970 let s:netrw_browselist= []
10971 endif
10972
10973 " append current buffer to fastbrowse list
10974 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010975" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010976 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010977" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010978 endif
10979
10980 " enable autocmd events to handle refreshing/removing local browser buffers
10981 " If local browse buffer is currently showing: refresh it
10982 " If local browse buffer is currently hidden : wipe it
10983 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
10984 " =1 : medium speed, re-use directory listing for remote only
10985 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010010986 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
10987 let s:netrw_events= 1
10988 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010989 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020010990 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010991" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010992 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010993 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010994" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010995 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010996 endif
10997 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010010998
10999 " user must have changed fastbrowse to its fast setting, so remove
11000 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011001 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011002" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011003 unlet s:netrw_events
11004 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011005 au!
11006 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011007 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011008 endif
11009
Bram Moolenaar85850f32019-07-19 22:05:51 +020011010" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011011endfun
11012
11013" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011014" s:LocalListing: does the job of "ls" for local directories {{{2
11015fun! s:LocalListing()
11016" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011017" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11018" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11019" 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 +010011020
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011021" 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
11022" 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
11023" 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 +010011024
11025 " get the list of files contained in the current directory
11026 let dirname = b:netrw_curdir
11027 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011028 let filelist = s:NetrwGlob(dirname,"*",0)
11029 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011030" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011031
Nir Lichtman1e34b952024-05-08 19:19:34 +020011032 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011033" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011034 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11035 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011036" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011037 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011038" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011039 endif
11040
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011041" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011042" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011043" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011044
11045 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11046 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11047 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011048" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11049" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011050 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011051" 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 +010011052
11053 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011054" call Decho(" ",'~'.expand("<slnum>"))
11055" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011056
11057 if getftype(filename) == "link"
11058 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011059" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011060 let pfile= filename."@"
11061
11062 elseif getftype(filename) == "socket"
11063 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011064" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011065 let pfile= filename."="
11066
11067 elseif getftype(filename) == "fifo"
11068 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011069" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011070 let pfile= filename."|"
11071
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011072 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011073 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011074" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011075 let pfile= filename."/"
11076
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011077 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011078 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011079 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11080 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011081" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011082 let pfile= filename."*"
11083 else
11084 " normal file
11085 let pfile= filename
11086 endif
11087 elseif executable(filename)
11088 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011089" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011090 let pfile= filename."*"
11091 else
11092 " normal file
11093 let pfile= filename
11094 endif
11095
11096 else
11097 " normal file
11098 let pfile= filename
11099 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011100" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011101
11102 if pfile =~ '//$'
11103 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011104" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011105 endif
11106 let pfile= strpart(pfile,dirnamelen)
11107 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011108" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11109" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011110
11111 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011112 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11113 let sz = getfsize(filename)
11114 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11115 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011116
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011117 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011118 let sz= s:NetrwHumanReadable(sz)
11119 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011120 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011121 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011122" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011123 endif
11124
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011125 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011126 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011127 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011128" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011129" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011130 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011131 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011132" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011133 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011134 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011135
11136 elseif g:netrw_sort_by =~ "^s"
11137 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011138" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011139" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011140 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011141 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011142" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011143 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011144 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011145
11146 else
11147 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011148" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011149" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011150 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011151 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011152" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011153 endfor
11154
11155 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011156 sil! NetrwKeepj g/^$/d
11157 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011158 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011159" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011160 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11161
11162" call Dret("s:LocalListing")
11163endfun
11164
11165" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011166" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11167fun! s:NetrwLocalExecute(cmd)
11168" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11169 let ykeep= @@
11170 " sanity check
11171 if !executable(a:cmd)
11172 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11173 let @@= ykeep
11174" call Dret("s:NetrwLocalExecute")
11175 return
11176 endif
11177
11178 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011179" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011180 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011181" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011182
11183 " strip any ansi escape sequences off
11184 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11185
11186 " show user the result(s)
11187 echomsg result
11188 let @@= ykeep
11189
11190" call Dret("s:NetrwLocalExecute")
11191endfun
11192
11193" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011194" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011195fun! s:NetrwLocalRename(path) range
11196" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11197
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011198 if !exists("w:netrw_bannercnt")
11199 let w:netrw_bannercnt= b:netrw_bannercnt
11200 endif
11201
Bram Moolenaar97d62492012-11-15 21:28:22 +010011202 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011203 let ykeep = @@
11204 let ctr = a:firstline
11205 let svpos = winsaveview()
11206 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011207" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011208
11209 " rename files given by the markfilelist
11210 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11211 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011212" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011213 if exists("subfrom")
11214 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011215" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011216 else
11217 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011218 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011219 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011220 if newname =~ ''
11221 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11222 let newname = substitute(newname,'^.*','','')
11223 elseif newname =~ ''
11224 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11225 let newname = substitute(newname,'[^/]*','','')
11226 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011227 if newname =~ '^s/'
11228 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11229 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011230" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011231 let newname = substitute(oldname,subfrom,subto,'')
11232 endif
11233 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011234 if !all && filereadable(newname)
11235 call inputsave()
11236 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11237 call inputrestore()
11238 if response == "all"
11239 let all= 1
11240 elseif response != "y" && response != "yes"
11241 " refresh the directory
11242" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11243 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11244" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11245 NetrwKeepj call winrestview(svpos)
11246 let @@= ykeep
11247" call Dret("NetrwLocalRename")
11248 return
11249 endif
11250 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011251 call rename(oldname,newname)
11252 endfor
11253 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011254
Bram Moolenaar97d62492012-11-15 21:28:22 +010011255 else
11256
11257 " attempt to rename files/directories
11258 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011259 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011260
11261 " sanity checks
11262 if line(".") < w:netrw_bannercnt
11263 let ctr= ctr + 1
11264 continue
11265 endif
11266 let curword= s:NetrwGetWord()
11267 if curword == "./" || curword == "../"
11268 let ctr= ctr + 1
11269 continue
11270 endif
11271
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011272 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011273 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011274" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011275
11276 call inputsave()
11277 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11278 call inputrestore()
11279
11280 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011281" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011282
11283 let ctr= ctr + 1
11284 endwhile
11285 endif
11286
11287 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011288" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011289 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011290" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11291 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011292 let @@= ykeep
11293
11294" call Dret("NetrwLocalRename")
11295endfun
11296
11297" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011298" s:NetrwLocalRm: {{{2
11299fun! s:NetrwLocalRm(path) range
11300" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011301" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011302
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011303 if !exists("w:netrw_bannercnt")
11304 let w:netrw_bannercnt= b:netrw_bannercnt
11305 endif
11306
Bram Moolenaar446cb832008-06-24 21:56:24 +000011307 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011308 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011309 let ret = 0
11310 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011311 let svpos = winsaveview()
11312" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011313
11314 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11315 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011316" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011317 for fname in s:netrwmarkfilelist_{bufnr("%")}
11318 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011319 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011320 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011321 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011322 let all= 1
11323 endif
11324 endfor
11325 call s:NetrwUnMarkFile(1)
11326
11327 else
11328 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011329" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011330
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011331 let keepsol= &l:sol
11332 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011333 let ctr = a:firstline
11334 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011335 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011336
11337 " sanity checks
11338 if line(".") < w:netrw_bannercnt
11339 let ctr= ctr + 1
11340 continue
11341 endif
11342 let curword= s:NetrwGetWord()
11343 if curword == "./" || curword == "../"
11344 let ctr= ctr + 1
11345 continue
11346 endif
11347 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011348 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011349 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011350 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011351 let all= 1
11352 endif
11353 let ctr= ctr + 1
11354 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011355 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011356 endif
11357
11358 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011359" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011360 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011361 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011362" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11363 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011364 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011365 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011366
11367" call Dret("s:NetrwLocalRm")
11368endfun
11369
11370" ---------------------------------------------------------------------
11371" s:NetrwLocalRmFile: remove file fname given the path {{{2
11372" Give confirmation prompt unless all==1
11373fun! s:NetrwLocalRmFile(path,fname,all)
11374" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011375
Bram Moolenaar446cb832008-06-24 21:56:24 +000011376 let all= a:all
11377 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011378 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020011379 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011380" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011381
11382 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11383 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011384" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011385 if !all
11386 echohl Statement
11387 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011388 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011389 call inputrestore()
11390 echohl NONE
11391 if ok == ""
11392 let ok="no"
11393 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011394" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011395 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011396" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011397 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011398 let all= 1
11399 endif
11400 endif
11401
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011402 if all || ok =~# '^y\%[es]$' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011403 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011404" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011405 endif
11406
11407 else
11408 " attempt to remove directory
11409 if !all
11410 echohl Statement
11411 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011412 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011413 call inputrestore()
11414 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11415 if ok == ""
11416 let ok="no"
11417 endif
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011418 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011419 let all= 1
11420 endif
11421 endif
11422 let rmfile= substitute(rmfile,'[\/]$','','e')
11423
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011424 if all || ok =~# '^y\%[es]$' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011425 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011426 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011427 endif
11428 endif
11429 endif
11430
11431" call Dret("s:NetrwLocalRmFile ".ok)
11432 return ok
11433endfun
11434
Bram Moolenaar85850f32019-07-19 22:05:51 +020011435" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011436" Support Functions: {{{1
11437
Bram Moolenaar488c6512005-08-11 20:09:58 +000011438" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011439" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11440" 0: marked file list of current buffer
11441" 1: marked file target
11442fun! netrw#Access(ilist)
11443 if a:ilist == 0
11444 if exists("s:netrwmarkfilelist_".bufnr('%'))
11445 return s:netrwmarkfilelist_{bufnr('%')}
11446 else
11447 return "no-list-buf#".bufnr('%')
11448 endif
11449 elseif a:ilist == 1
11450 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011451 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011452endfun
11453
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011454" ---------------------------------------------------------------------
11455" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11456fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011457 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011458endfun
11459
Bram Moolenaara6878372014-03-22 21:02:50 +010011460" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011461" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11462" I expect this function to be used in
11463" :PChkAssert netrw#Expose("netrwmarkfilelist")
11464" for example.
11465fun! netrw#Expose(varname)
11466" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011467 if exists("s:".a:varname)
11468 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011469" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011470 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011471" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011472 if type(retval) == 3
11473 let retval = copy(retval)
11474 let i = 0
11475 while i < len(retval)
11476 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11477 let i = i + 1
11478 endwhile
11479 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011480" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011481 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011482 else
11483" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011484 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011485 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011486" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011487 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011488 endif
11489
11490" call Dret("netrw#Expose ".string(retval))
11491 return retval
11492endfun
11493
11494" ---------------------------------------------------------------------
11495" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11496fun! netrw#Modify(varname,newvalue)
11497" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11498 exe "let s:".a:varname."= ".string(a:newvalue)
11499" call Dret("netrw#Modify")
11500endfun
11501
11502" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011503" netrw#RFC2396: converts %xx into characters {{{2
11504fun! netrw#RFC2396(fname)
11505" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011506 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011507" call Dret("netrw#RFC2396 ".fname)
11508 return fname
11509endfun
11510
11511" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011512" netrw#UserMaps: supports user-specified maps {{{2
11513" see :help function()
11514"
11515" g:Netrw_UserMaps is a List with members such as:
11516" [[keymap sequence, function reference],...]
11517"
11518" The referenced function may return a string,
11519" refresh : refresh the display
11520" -other- : this string will be executed
11521" or it may return a List of strings.
11522"
11523" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011524" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011525" Related functions:
11526" netrw#Expose(varname) -- see s:varname variables
11527" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11528" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11529fun! netrw#UserMaps(islocal)
11530" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11531" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11532
11533 " set up usermaplist
11534 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11535" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11536 for umap in g:Netrw_UserMaps
11537" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11538" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11539 " if umap[0] is a string and umap[1] is a string holding a function name
11540 if type(umap[0]) == 1 && type(umap[1]) == 1
11541" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11542 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11543 else
11544 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11545 endif
11546 endfor
11547 endif
11548" call Dret("netrw#UserMaps")
11549endfun
11550
11551" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011552" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11553fun! netrw#WinPath(path)
11554" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011555 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011556 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011557 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011558 " remove trailing slash (Win95)
11559 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11560 " remove escaped spaces
11561 let path = substitute(path, '\ ', ' ', 'g')
11562 " convert slashes to backslashes
11563 let path = substitute(path, '/', '\', 'g')
11564 else
11565 let path= a:path
11566 endif
11567" call Dret("netrw#WinPath <".path.">")
11568 return path
11569endfun
11570
11571" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020011572" s:StripTrailingSlash: removes trailing slashes from a path {{{2
11573fun! s:StripTrailingSlash(path)
11574 " remove trailing slash
11575 return substitute(a:path, '[/\\]$', '', 'g')
11576endfun
11577
Travis Sheltone34d0e32024-07-30 21:08:56 +020011578" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011579" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11580" cb : bl2mf=0 add marked files to buffer list
11581" cB : bl2mf=1 use bufferlist to mark files
11582" (mnemonic: cb = copy (marked files) to buffer list)
11583fun! s:NetrwBadd(islocal,bl2mf)
11584" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11585 if a:bl2mf
11586 " cB: add buffer list to marked files
11587 redir => bufl
11588 ls
11589 redir END
11590 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11591 for fname in bufl
11592 call s:NetrwMarkFile(a:islocal,fname)
11593 endfor
11594 else
11595 " cb: add marked files to buffer list
11596 for fname in s:netrwmarkfilelist_{bufnr("%")}
11597" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11598 exe "badd ".fnameescape(fname)
11599 endfor
11600 let curbufnr = bufnr("%")
11601 let curdir = s:NetrwGetCurdir(a:islocal)
11602 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11603 endif
11604" call Dret("s:NetrwBadd")
11605endfun
11606
11607" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011608" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11609fun! s:ComposePath(base,subdir)
11610" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11611
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011612 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011613" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011614 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011615 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011616 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011617 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011618 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011619 endif
11620
Bram Moolenaar85850f32019-07-19 22:05:51 +020011621 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011622 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011623" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011624 let ret= a:subdir
11625
Nir Lichtman1e34b952024-05-08 19:19:34 +020011626 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011627" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011628 if a:base =~ '[/\\]$'
11629 let ret= a:base.a:subdir
11630 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011631 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011632 endif
11633
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011634 elseif a:base =~ '^\a\{3,}://'
11635" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011636 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11637 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11638 if a:subdir == '../'
11639 if curpath =~ '[^/]/[^/]\+/$'
11640 let curpath= substitute(curpath,'[^/]\+/$','','')
11641 else
11642 let curpath=""
11643 endif
11644 let ret= urlbase.curpath
11645 else
11646 let ret= urlbase.curpath.a:subdir
11647 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011648" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11649" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11650" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011651
11652 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011653" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011654 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11655 if a:base =~ '^//'
11656 " keeping initial '//' for the benefit of network share listing support
11657 let ret= '/'.ret
11658 endif
11659 let ret= simplify(ret)
11660 endif
11661
11662" call Dret("s:ComposePath ".ret)
11663 return ret
11664endfun
11665
11666" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011667" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11668" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11669fun! s:DeleteBookmark(fname)
11670" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11671 call s:MergeBookmarks()
11672
11673 if exists("g:netrw_bookmarklist")
11674 let indx= index(g:netrw_bookmarklist,a:fname)
11675 if indx == -1
11676 let indx= 0
11677 while indx < len(g:netrw_bookmarklist)
11678 if g:netrw_bookmarklist[indx] =~ a:fname
11679 call remove(g:netrw_bookmarklist,indx)
11680 let indx= indx - 1
11681 endif
11682 let indx= indx + 1
11683 endwhile
11684 else
11685 " remove exact match
11686 call remove(g:netrw_bookmarklist,indx)
11687 endif
11688 endif
11689
11690" call Dret("s:DeleteBookmark")
11691endfun
11692
11693" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011694" s:FileReadable: o/s independent filereadable {{{2
11695fun! s:FileReadable(fname)
11696" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11697
11698 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011699 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011700 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011701 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011702 endif
11703
11704" call Dret("s:FileReadable ".ret)
11705 return ret
11706endfun
11707
11708" ---------------------------------------------------------------------
11709" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11710" Places correct suffix on end of temporary filename,
11711" using the suffix provided with fname
11712fun! s:GetTempfile(fname)
11713" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11714
11715 if !exists("b:netrw_tmpfile")
11716 " get a brand new temporary filename
11717 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011718" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011719
Bram Moolenaarc236c162008-07-13 17:41:49 +000011720 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011721" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011722
Bram Moolenaar9964e462007-05-05 17:54:07 +000011723 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011724 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11725" 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 +010011726 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011727" call Dret("s:GetTempfile getcwd<".getcwd().">")
11728 return ""
11729 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011730
Bram Moolenaar9964e462007-05-05 17:54:07 +000011731 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011732 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011733" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011734
Bram Moolenaar9964e462007-05-05 17:54:07 +000011735 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011736 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011737 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011738 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011739 if !exists("+shellslash") || !&ssl
11740 let tmpfile = substitute(tmpfile,'/','\','g')
11741 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011742 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011743 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011744 endif
11745 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011746" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011747 else
11748 " re-use temporary filename
11749 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011750" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011751 endif
11752
11753 " use fname's suffix for the temporary file
11754 if a:fname != ""
11755 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011756" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011757 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011758 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011759 elseif a:fname =~ '.txz$'
11760 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011761 else
11762 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11763 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011764" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011765 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011766" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011767 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011768" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011769 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11770 endif
11771 endif
11772
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011773" 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 +000011774" call Dret("s:GetTempfile <".tmpfile.">")
11775 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011776endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011777
11778" ---------------------------------------------------------------------
11779" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011780" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011781fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011782" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011783 if s:user == ""
11784 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11785 else
11786 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11787 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011788 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011789 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011790 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011791 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011792 else
11793 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11794 endif
11795" call Dret("s:MakeSshCmd <".sshcmd.">")
11796 return sshcmd
11797endfun
11798
11799" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011800" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11801fun! s:MakeBookmark(fname)
11802" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11803
11804 if !exists("g:netrw_bookmarklist")
11805 let g:netrw_bookmarklist= []
11806 endif
11807
11808 if index(g:netrw_bookmarklist,a:fname) == -1
11809 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011810 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011811 call add(g:netrw_bookmarklist,a:fname.'/')
11812 elseif a:fname !~ '/'
11813 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11814 else
11815 call add(g:netrw_bookmarklist,a:fname)
11816 endif
11817 call sort(g:netrw_bookmarklist)
11818 endif
11819
11820" call Dret("s:MakeBookmark")
11821endfun
11822
11823" ---------------------------------------------------------------------
11824" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11825fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011826" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011827 " get bookmarks from .netrwbook file
11828 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011829 if filereadable(s:NetrwFile(savefile))
11830" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011831 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011832" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011833 NetrwKeepj call delete(savefile)
11834 endif
11835" call Dret("s:MergeBookmarks")
11836endfun
11837
11838" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011839" s:NetrwBMShow: {{{2
11840fun! s:NetrwBMShow()
11841" call Dfunc("s:NetrwBMShow()")
11842 redir => bmshowraw
11843 menu
11844 redir END
11845 let bmshowlist = split(bmshowraw,'\n')
11846 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011847 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011848 if bmshowfuncs != []
11849 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011850 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011851 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011852 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011853 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011854 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011855" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11856endfun
11857
11858" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011859" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011860fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011861 if !exists("w:netrw_liststyle")
11862 let w:netrw_liststyle= g:netrw_liststyle
11863 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011864" 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 +020011865
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011866" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11867
Bram Moolenaaradc21822011-04-01 18:03:16 +020011868 if &ft != "netrw"
11869 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11870 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011871" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011872
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011873 elseif g:netrw_cursor == 8
11874 if w:netrw_liststyle == s:WIDELIST
11875 setl cursorline
11876 setl cursorcolumn
11877 else
11878 setl cursorline
11879 endif
11880 elseif g:netrw_cursor == 7
11881 setl cursorline
11882 elseif g:netrw_cursor == 6
11883 if w:netrw_liststyle == s:WIDELIST
11884 setl cursorline
11885 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011886 elseif g:netrw_cursor == 4
11887 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011888" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011889 setl cursorline
11890 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011891
11892 elseif g:netrw_cursor == 3
11893 " thin-long-tree: cursorline, user's cursorcolumn
11894 " wide : cursorline, cursorcolumn
11895 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011896" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011897 setl cursorline
11898 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011899 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011900" 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 +020011901 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011902 endif
11903
11904 elseif g:netrw_cursor == 2
11905 " thin-long-tree: cursorline, user's cursorcolumn
11906 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011907" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011908 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011909
11910 elseif g:netrw_cursor == 1
11911 " thin-long-tree: user's cursorline, user's cursorcolumn
11912 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011913 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011914" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011915 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011916 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011917" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011918 endif
11919
11920 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011921 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011922" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011923 let &l:cursorline = s:netrw_usercul
11924 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011925 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011926
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011927" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011928" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011929endfun
11930
11931" ---------------------------------------------------------------------
11932" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11933fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011934" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011935 if exists("s:netrw_usercul")
11936 let &l:cursorline = s:netrw_usercul
11937 endif
11938 if exists("s:netrw_usercuc")
11939 let &l:cursorcolumn = s:netrw_usercuc
11940 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011941" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011942" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11943endfun
11944
Christian Brabandt62f7b552024-06-23 20:23:40 +020011945" s:RestoreRegister: restores all registers given in the dict {{{2
11946fun! s:RestoreRegister(dict)
11947 for [key, val] in items(a:dict)
11948 if key == 'unnamed'
11949 let key = ''
11950 endif
11951 call setreg(key, val[0], val[1])
11952 endfor
11953endfun
11954
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011955" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011956" s:NetrwDelete: Deletes a file. {{{2
11957" Uses Steve Hall's idea to insure that Windows paths stay
11958" acceptable. No effect on Unix paths.
11959" Examples of use: let result= s:NetrwDelete(path)
11960fun! s:NetrwDelete(path)
11961" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11962
Bram Moolenaar5c736222010-01-06 20:54:52 +010011963 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011964 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000011965 if exists("+shellslash")
11966 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011967 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011968 let result = delete(path)
11969 let &shellslash = sskeep
11970 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011971" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011972 let result= delete(path)
11973 endif
11974 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011975" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011976 let result= delete(path)
11977 endif
11978 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011979 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011980 endif
11981
11982" call Dret("s:NetrwDelete ".result)
11983 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000011984endfun
11985
11986" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011987" s:NetrwBufRemover: removes a buffer that: {{{2s
11988" has buffer-id > 1
11989" is unlisted
11990" is unnamed
11991" does not appear in any window
11992fun! s:NetrwBufRemover(bufid)
11993" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
11994" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
11995" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
11996" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
11997" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
11998
yasuda4dbb2662023-10-04 20:50:35 +020011999 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012000" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012001 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012002 endif
12003
12004" call Dret("s:NetrwBufRemover")
12005endfun
12006
12007" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012008" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012009fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012010" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012011" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012012
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010012013 " Clean out the last buffer:
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012014 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12015 " If so, delete it.
12016 call s:NetrwBufRemover(bufnr("$"))
12017
Bram Moolenaar446cb832008-06-24 21:56:24 +000012018 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012019" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012020 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12021 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12022 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12023 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12024 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12025 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12026 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12027 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12028 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12029 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12030 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12031 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12032 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12033 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12034 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12035 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12036
Bram Moolenaar85850f32019-07-19 22:05:51 +020012037 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012038" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012039 " when tree listing uses file TreeListing... a new buffer is made.
12040 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012041 " COMBAK: this causes a problem, see P43
12042" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012043 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012044 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012045 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012046" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012047 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012048
Bram Moolenaar446cb832008-06-24 21:56:24 +000012049 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012050" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012051 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12052 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12053 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12054 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12055 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12056 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12057 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12058 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12059 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12060 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12061 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12062 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12063 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12064 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12065 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12066 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12067
Bram Moolenaar5c736222010-01-06 20:54:52 +010012068 if a:0 > 0
12069 let b:netrw_curdir= a:1
12070 if b:netrw_curdir =~ '/$'
12071 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012072 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012073 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012074 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012075 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12076 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012077 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012078 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012079 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012080 endif
12081 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012082 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12083 let &l:bexpr = "netrw#BalloonHelp()"
12084 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012085
Bram Moolenaar8d043172014-01-23 14:24:41 +010012086" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012087endfun
12088
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012089" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012090" s:NetrwExe: executes a string using "!" {{{2
12091fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012092" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Konfekt3d7e5672024-10-27 22:16:49 +010012093 if has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012094" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012095 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12096 set shell& shellcmdflag& shellxquote& shellxescape&
12097 set shellquote& shellpipe& shellredir& shellslash&
Konfekt3d7e5672024-10-27 22:16:49 +010012098 try
12099 exe a:cmd
12100 finally
12101 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12102 endtry
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012103 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012104" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012105 exe a:cmd
12106 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012107 if v:shell_error
12108 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12109 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012110" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012111endfun
12112
12113" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012114" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12115fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012116 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012117" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012118 let curbuf = bufnr("%")
12119 let curwin = winnr()
12120 let iwin = 1
12121 while iwin <= winnr("$")
12122 exe iwin."wincmd w"
12123 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12124 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12125 let winvars= w:
12126 break
12127 endif
12128 let iwin= iwin + 1
12129 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012130 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012131 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012132" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012133 for k in keys(winvars)
12134 let w:{k}= winvars[k]
12135 endfor
12136 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012137" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012138 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012139endfun
12140
Bram Moolenaara6878372014-03-22 21:02:50 +010012141" ---------------------------------------------------------------------
12142" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012143" Returns: 0=success
12144" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012145fun! s:NetrwLcd(newdir)
12146" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012147" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012148
Bram Moolenaar85850f32019-07-19 22:05:51 +020012149 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012150 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012151 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012152 catch /^Vim\%((\a\+)\)\=:E344/
12153 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12154 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012155 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012156 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12157 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012158 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012159 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12160 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012161 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012162 endif
12163 endif
12164 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012165 let err472= 1
12166 endtry
12167
12168 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012169 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12170 if exists("w:netrw_prvdir")
12171 let a:newdir= w:netrw_prvdir
12172 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012173 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012174" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012175 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012176" 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 +010012177 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012178 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012179" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12180 return -1
12181 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012182
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012183" call Decho("getcwd <".getcwd().">")
12184" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012185" call Dret("s:NetrwLcd 0")
12186 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012187endfun
12188
Bram Moolenaar9964e462007-05-05 17:54:07 +000012189" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012190" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12191" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12192fun! s:NetrwSaveWordPosn()
12193" call Dfunc("NetrwSaveWordPosn()")
12194 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12195" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12196endfun
12197
12198" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012199" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12200" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12201fun! s:NetrwHumanReadable(sz)
12202" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12203
12204 if g:netrw_sizestyle == 'h'
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010012205 if a:sz >= 1000000000
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012206 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12207 elseif a:sz >= 10000000
12208 let sz = printf("%d",a:sz/1000000)."m"
12209 elseif a:sz >= 1000000
12210 let sz = printf("%.1f",a:sz/1000000.0)."m"
12211 elseif a:sz >= 10000
12212 let sz = printf("%d",a:sz/1000)."k"
12213 elseif a:sz >= 1000
12214 let sz = printf("%.1f",a:sz/1000.0)."k"
12215 else
12216 let sz= a:sz
12217 endif
12218
12219 elseif g:netrw_sizestyle == 'H'
12220 if a:sz >= 1073741824
12221 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12222 elseif a:sz >= 10485760
12223 let sz = printf("%d",a:sz/1048576)."M"
12224 elseif a:sz >= 1048576
12225 let sz = printf("%.1f",a:sz/1048576.0)."M"
12226 elseif a:sz >= 10240
12227 let sz = printf("%d",a:sz/1024)."K"
12228 elseif a:sz >= 1024
12229 let sz = printf("%.1f",a:sz/1024.0)."K"
12230 else
12231 let sz= a:sz
12232 endif
12233
12234 else
12235 let sz= a:sz
12236 endif
12237
12238" call Dret("s:NetrwHumanReadable ".sz)
12239 return sz
12240endfun
12241
12242" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012243" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12244" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12245fun! s:NetrwRestoreWordPosn()
12246" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012247 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012248" call Dret("NetrwRestoreWordPosn")
12249endfun
12250
12251" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012252" s:RestoreBufVars: {{{2
12253fun! s:RestoreBufVars()
12254" call Dfunc("s:RestoreBufVars()")
12255
12256 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12257 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12258 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12259 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12260 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12261 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12262
12263" call Dret("s:RestoreBufVars")
12264endfun
12265
12266" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012267" s:RemotePathAnalysis: {{{2
12268fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012269" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012270
Bram Moolenaara6878372014-03-22 21:02:50 +010012271 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012272 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012273 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012274 let s:user = substitute(a:dirname,dirpat,'\3','')
12275 let s:machine = substitute(a:dirname,dirpat,'\4','')
12276 let s:port = substitute(a:dirname,dirpat,'\5','')
12277 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012278 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012279 if s:machine =~ '@'
12280 let dirpat = '^\(.*\)@\(.\{-}\)$'
12281 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12282 let s:machine = substitute(s:machine,dirpat,'\2','')
12283 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012284
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012285" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12286" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12287" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12288" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12289" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12290" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012291
12292" call Dret("s:RemotePathAnalysis")
12293endfun
12294
12295" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012296" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12297" Returns status
12298" Runs system() on
12299" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012300" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012301fun! s:RemoteSystem(cmd)
12302" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12303 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012304 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 +000012305 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012306 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012307 else
12308 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12309 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12310 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012311 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012312 else
12313 let cmd= cmd.' '
12314 endif
12315 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012316" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012317 let ret= system(cmd)
12318 endif
12319" call Dret("s:RemoteSystem ".ret)
12320 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012321endfun
12322
12323" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012324" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012325fun! s:RestoreWinVars()
12326" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012327 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012328 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12329 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12330 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12331 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12332 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12333 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12334 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12335 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12336 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12337 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12338 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12339 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012340 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12341 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012342 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12343 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12344 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12345" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012346endfun
12347
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012348" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012349" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12350"
12351" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12352" is true) and a command, :Rexplore, which call this function.
12353"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012354" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012355"
12356" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012357fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012358 if exists("s:netrwdrag")
12359 return
12360 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012361" 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 +010012362" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12363" 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 +010012364
12365 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012366 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012367" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012368 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012369 unlet w:netrw_rexfile
12370" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012371 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012372" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012373" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12374" 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 +020012375 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012376
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012377 " ---------------------------
12378 " :Rex issued while in a file
12379 " ---------------------------
12380
Bram Moolenaara6878372014-03-22 21:02:50 +010012381 " record current file so :Rex can return to it from netrw
12382 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012383" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012384
12385 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012386" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012387 return
12388 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012389" 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 +020012390 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012391 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012392 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012393 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012394 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012395 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012396 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012397 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012398 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012399" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12400 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012401" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12402 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012403 if exists("s:rexposn_".bufnr('%'))
12404 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012405 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012406 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012407" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012408 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012409
Bram Moolenaar85850f32019-07-19 22:05:51 +020012410 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12411 if exists("s:explore_match")
12412 exe "2match netrwMarkFile /".s:explore_match."/"
12413 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012414 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012415
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012416" 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 +010012417" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012418endfun
12419
12420" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012421" s:SaveBufVars: save selected b: variables to s: variables {{{2
12422" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012423fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012424" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012425
12426 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12427 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12428 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12429 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12430 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12431 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12432
12433" call Dret("s:SaveBufVars")
12434endfun
12435
12436" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012437" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12438fun! s:SavePosn(posndict)
12439" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12440
Bram Moolenaar85850f32019-07-19 22:05:51 +020012441 if !exists("a:posndict[bufnr('%')]")
12442 let a:posndict[bufnr("%")]= []
12443 endif
12444" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12445 call add(a:posndict[bufnr("%")],winsaveview())
12446" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012447
12448" call Dret("s:SavePosn posndict")
12449 return a:posndict
12450endfun
12451
12452" ---------------------------------------------------------------------
12453" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12454fun! s:RestorePosn(posndict)
12455" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012456 if exists("a:posndict")
12457 if has_key(a:posndict,bufnr("%"))
12458" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12459 let posnlen= len(a:posndict[bufnr("%")])
12460 if posnlen > 0
12461 let posnlen= posnlen - 1
12462" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12463 call winrestview(a:posndict[bufnr("%")][posnlen])
12464 call remove(a:posndict[bufnr("%")],posnlen)
12465" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12466 endif
12467 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012468 endif
12469" call Dret("s:RestorePosn")
12470endfun
12471
12472" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012473" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012474fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012475" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012476 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12477 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12478 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12479 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12480 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12481 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12482 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12483 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12484 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12485 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12486 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12487 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12488 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12489 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12490 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12491 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12492 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12493 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12494" call Dret("s:SaveWinVars")
12495endfun
12496
12497" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012498" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012499" To allow separate windows to have their own activities, such as
12500" Explore **/pattern, several variables have been made window-oriented.
12501" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012502" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012503" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012504fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012505" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012506 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12507 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12508 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12509 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12510 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12511 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12512 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12513 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12514 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12515 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12516" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012517endfun
12518
12519" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012520" s:SetRexDir: set directory for :Rexplore {{{2
12521fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012522" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012523 let w:netrw_rexdir = a:dirname
12524 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012525 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012526" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12527" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012528" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012529" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012530" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012531endfun
12532
12533" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012534" s:ShowLink: used to modify thin and tree listings to show links {{{2
12535fun! s:ShowLink()
12536" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012537" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12538" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012539 if exists("b:netrw_curdir")
12540 norm! $?\a
12541 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12542 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012543" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12544" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12545" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12546 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012547 let dirlen = strlen(b:netrw_curdir)
12548 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012549" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012550 endif
12551 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012552" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12553" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012554 setl noro ma
12555 call setline(".",modline)
12556 setl ro noma nomod
12557 endif
12558" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12559endfun
12560
12561" ---------------------------------------------------------------------
12562" s:ShowStyle: {{{2
12563fun! s:ShowStyle()
12564 if !exists("w:netrw_liststyle")
12565 let liststyle= g:netrw_liststyle
12566 else
12567 let liststyle= w:netrw_liststyle
12568 endif
12569 if liststyle == s:THINLIST
12570 return s:THINLIST.":thin"
12571 elseif liststyle == s:LONGLIST
12572 return s:LONGLIST.":long"
12573 elseif liststyle == s:WIDELIST
12574 return s:WIDELIST.":wide"
12575 elseif liststyle == s:TREELIST
12576 return s:TREELIST.":tree"
12577 else
12578 return 'n/a'
12579 endif
12580endfun
12581
12582" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012583" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12584" Solution from Nicolai Weibull, vim docs (:help strlen()),
12585" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012586fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012587" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12588
12589 if v:version >= 703 && exists("*strdisplaywidth")
12590 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012591
Bram Moolenaar8d043172014-01-23 14:24:41 +010012592 elseif type(g:Align_xstrlen) == 1
12593 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12594 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012595
Bram Moolenaar8d043172014-01-23 14:24:41 +010012596 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012597 " number of codepoints (Latin a + combining circumflex is two codepoints)
12598 " (comment from TM, solution from NW)
12599 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012600
Bram Moolenaar8d043172014-01-23 14:24:41 +010012601 elseif g:Align_xstrlen == 2
12602 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012603 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12604 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012605 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012606
Bram Moolenaar8d043172014-01-23 14:24:41 +010012607 elseif g:Align_xstrlen == 3
12608 " virtual length (counting, for instance, tabs as anything between 1 and
12609 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012610 " preceded by lam, one otherwise, etc.)
12611 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012612 let modkeep= &l:mod
12613 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012614 call setline(line("."),a:x)
12615 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012616 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012617 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012618 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012619
Bram Moolenaar446cb832008-06-24 21:56:24 +000012620 else
12621 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012622 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012623 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012624" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012625 return ret
12626endfun
12627
12628" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012629" s:ShellEscape: shellescape(), or special windows handling {{{2
12630fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012631 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012632 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010012633 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012634 let f = a:0 > 0 ? a:1 : 0
12635 return shellescape(a:s, f)
12636endfun
12637
12638" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012639" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012640fun! s:TreeListMove(dir)
12641" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012642 let curline = getline('.')
12643 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12644 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12645 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12646 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12647 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12648 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12649" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12650" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12651" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12652" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12653" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12654 " COMBAK : need to handle when on a directory
12655 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012656 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012657 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012658 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012659 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012660" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012661 elseif a:dir == '[]' && nxtline != ''
12662 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012663" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012664 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12665 if nl != 0
12666 NetrwKeepj norm! k
12667 else
12668 NetrwKeepj norm! G
12669 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012670" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012671 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012672 endif
12673
12674" call Dret("s:TreeListMove")
12675endfun
12676
12677" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012678" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12679" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12680" can't be called except via emenu. But due to locale, that menu line may not be called
12681" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12682fun! s:UpdateBuffersMenu()
12683" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012684 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012685 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012686 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012687 catch /^Vim\%((\a\+)\)\=:E/
12688 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012689 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012690 endtry
12691 endif
12692" call Dret("s:UpdateBuffersMenu")
12693endfun
12694
12695" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012696" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012697" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012698fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012699" call Dfunc("s:UseBufWinVars()")
12700 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012701 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12702 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12703 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12704 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12705 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12706 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12707 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12708 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12709 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 +000012710" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012711endfun
12712
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012713" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012714" s:UserMaps: supports user-defined UserMaps {{{2
12715" * calls a user-supplied funcref(islocal,curdir)
12716" * interprets result
12717" See netrw#UserMaps()
12718fun! s:UserMaps(islocal,funcname)
12719" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12720
12721 if !exists("b:netrw_curdir")
12722 let b:netrw_curdir= getcwd()
12723 endif
12724 let Funcref = function(a:funcname)
12725 let result = Funcref(a:islocal)
12726
12727 if type(result) == 1
12728 " if result from user's funcref is a string...
12729" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12730 if result == "refresh"
12731" call Decho("refreshing display",'~'.expand("<slnum>"))
12732 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12733 elseif result != ""
12734" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12735 exe result
12736 endif
12737
12738 elseif type(result) == 3
12739 " if result from user's funcref is a List...
12740" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12741 for action in result
12742 if action == "refresh"
12743" call Decho("refreshing display",'~'.expand("<slnum>"))
12744 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12745 elseif action != ""
12746" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12747 exe action
12748 endif
12749 endfor
12750 endif
12751
12752" call Dret("s:UserMaps")
12753endfun
12754
Bram Moolenaar85850f32019-07-19 22:05:51 +020012755" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012756" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012757" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012758let &cpo= s:keepcpo
12759unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012760
Bram Moolenaar85850f32019-07-19 22:05:51 +020012761" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012762" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012763" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012764" vim:ts=8 fdm=marker