blob: d11c43a494a15c56a47b12aeac320ce831902af5 [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" netrw.vim: Handles file transfer and remote directory listing across
2" AUTOLOAD SECTION
Christian Brabandtf9ca1392024-02-19 20:37:11 +01003" Maintainer: This runtime file is looking for a new maintainer.
4" Date: May 03, 2023
Christian Brabandtcb0c1132023-11-21 18:48:16 +00005" Version: 173a
Travis Sheltone34d0e32024-07-30 21:08:56 +02006" Last Change: {{{1
Luca Saccarolaa7d45612024-10-21 21:27:03 +02007" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
8" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
Christian Brabandt8fad5d52024-02-29 18:12:30 +01009" 2024 Feb 19 by Vim Project: (announce adoption)
10" 2024 Feb 29 by Vim Project: handle symlinks in tree mode correctly
Christian Brabandt08d24012024-04-03 22:44:27 +020011" 2024 Apr 03 by Vim Project: detect filetypes for remote edited files
Nir Lichtman1e34b952024-05-08 19:19:34 +020012" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
Nir Lichtmance2ad9f2024-05-09 20:20:36 +020013" 2024 May 09 by Vim Project: remove hard-coded private.ppk
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020014" 2024 May 10 by Vim Project: recursively delete directories by default
Christian Brabandt43f2edc2024-05-13 20:56:43 +020015" 2024 May 13 by Vim Project: prefer scp over pscp
Christian Brabandt98b73eb2024-06-04 18:15:57 +020016" 2024 Jun 04 by Vim Project: set bufhidden if buffer changed, nohidden is set and buffer shall be switched (#14915)
Christian Brabandt14879472024-06-13 21:25:35 +020017" 2024 Jun 13 by Vim Project: glob() on Windows fails when a directory name contains [] (#14952)
Enno3146d632024-07-04 19:44:42 +020018" 2024 Jun 23 by Vim Project: save ad restore registers when liststyle = WIDELIST (#15077, #15114)
Damien9d57ea52024-07-22 20:23:48 +020019" 2024 Jul 22 by Vim Project: avoid endless recursion (#15318)
Christian Brabandt581d4a72024-07-23 21:14:06 +020020" 2024 Jul 23 by Vim Project: escape filename before trying to delete it (#15330)
Travis Sheltone34d0e32024-07-30 21:08:56 +020021" 2024 Jul 30 by Vim Project: handle mark-copy to same target directory (#12112)
Ivan Shapovalovc527d902024-08-02 19:43:12 +020022" 2024 Aug 02 by Vim Project: honor g:netrw_alt{o,v} for :{S,H,V}explore (#15417)
Damien7c754112024-08-15 21:58:57 +020023" 2024 Aug 15 by Vim Project: style changes, prevent E121 (#15501)
yasuda38cfa2b2024-08-22 20:54:47 +020024" 2024 Aug 22 by Vim Project: fix mf-selection highlight (#15551)
yasudac75dad02024-08-22 21:06:32 +020025" 2024 Aug 22 by Vim Project: adjust echo output of mx command (#15550)
Christian Brabandt0f5effb2024-09-15 19:17:23 +020026" 2024 Sep 15 by Vim Project: more strict confirmation dialog (#15680)
yasudac18a9d52024-09-19 18:09:51 +020027" 2024 Sep 19 by Vim Project: mf-selection highlight uses wrong pattern (#15700)
Peter Aronoffbe551da2024-09-22 11:29:40 +020028" 2024 Sep 21 by Vim Project: remove extraneous closing bracket (#15718)
Luca Saccarolaa7d45612024-10-21 21:27:03 +020029" 2024 Oct 21 by Vim Project: remove netrwFileHandlers (#15895)
Konfekt3d7e5672024-10-27 22:16:49 +010030" 2024 Oct 27 by Vim Project: clean up gx mapping (#15721)
Christian Brabandtaa2ce6f2024-10-30 18:27:03 +010031" 2024 Oct 30 by Vim Project: fix filetype detection for remote files (#15961)
Christian Brabandt9f320692024-10-30 18:36:20 +010032" 2024 Oct 30 by Vim Project: fix x mapping on cygwin (#13687)
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010033" 2024 Oct 31 by Vim Project: add netrw#Launch() and netrw#Open() (#15962)
Tom Benham4d618002024-10-31 10:47:23 +010034" 2024 Oct 31 by Vim Project: fix E874 when browsing remote dir (#15964)
Christian Brabandta063b222024-11-07 14:30:30 +010035" 2024 Nov 07 by Vim Project: use keeppatterns to prevent polluting the search history
Tom Benham64a536d2024-11-07 21:15:03 +010036" 2024 Nov 07 by Vim Project: fix a few issues with netrw tree listing (#15996)
Christian Brabandt5b63b232024-11-10 20:22:34 +010037" 2024 Nov 10 by Vim Project: directory symlink not resolved in tree view (#16020)
Travis Sheltone34d0e32024-07-30 21:08:56 +020038" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010039" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000040" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010041" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000042" Permission is hereby granted to use and distribute this code,
43" with or without modifications, provided that this copyright
44" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000045" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000046" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000047" expressed or implied. By using this plugin, you agree that
48" in no event will the copyright holder be liable for any damages
49" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010050"
51" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
52" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
53"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020054"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000055"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000056" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000057" (James 1:22 RSV)
58" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000059" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000060if &cp || exists("g:loaded_netrw")
61 finish
62endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020063
64" Check that vim has patches that netrw requires.
65" Patches needed for v7.4: 1557, and 213.
66" (netrw will benefit from vim's having patch#656, too)
67let s:needspatches=[1557,213]
68if exists("s:needspatches")
69 for ptch in s:needspatches
70 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
71 if !exists("s:needpatch{ptch}")
72 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
73 endif
74 let s:needpatch{ptch}= 1
75 finish
76 endif
77 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020078endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020079
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010080let g:loaded_netrw = "v173"
Bram Moolenaar446cb832008-06-24 21:56:24 +000081
Bram Moolenaar1afcace2005-11-25 19:54:28 +000082let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010083setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020084"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010085"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010086"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000087
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000088" ======================
89" Netrw Variables: {{{1
90" ======================
91
Bram Moolenaar071d4272004-06-13 20:20:40 +000092" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020093" netrw#ErrorMsg: {{{2
94" 0=note = s:NOTE
95" 1=warning = s:WARNING
96" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010097" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
98" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
99" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +0100100" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200101fun! netrw#ErrorMsg(level,msg,errnum)
102" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
103
104 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200105" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200106 return
107 endif
108
109 if a:level == 1
110 let level= "**warning** (netrw) "
111 elseif a:level == 2
112 let level= "**error** (netrw) "
113 else
114 let level= "**note** (netrw) "
115 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100116" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200117
Damienb4d11642024-08-15 22:00:45 +0200118 if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200119 " use popup window
120 if type(a:msg) == 3
121 let msg = [level]+a:msg
122 else
123 let msg= level.a:msg
124 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200125 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200126 let s:popuperr_text= ""
127 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200128 " (default) netrw creates a one-line window to show error/warning
129 " messages (reliably displayed)
130
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100131 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200132 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100133" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200134
135 " getting messages out reliably is just plain difficult!
136 " This attempt splits the current window, creating a one line window.
137 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100138" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200139 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100140" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200141 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100142 if type(a:msg) == 3
143 for msg in a:msg
144 NetrwKeepj call setline(line("$")+1,level.msg)
145 endfor
146 else
147 NetrwKeepj call setline(line("$")+1,level.a:msg)
148 endif
149 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200150 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100151" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200152 bo 1split
153 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200154 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200155 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100156 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100157" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200158 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100159 if type(a:msg) == 3
160 for msg in a:msg
161 NetrwKeepj call setline(line("$")+1,level.msg)
162 endfor
163 else
164 NetrwKeepj call setline(line("$"),level.a:msg)
165 endif
166 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200167 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100168" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200169 if &fo !~ '[ta]'
170 syn clear
171 syn match netrwMesgNote "^\*\*note\*\*"
172 syn match netrwMesgWarning "^\*\*warning\*\*"
173 syn match netrwMesgError "^\*\*error\*\*"
174 hi link netrwMesgWarning WarningMsg
175 hi link netrwMesgError Error
176 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100177" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200178 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200179
180 else
181 " (optional) netrw will show messages using echomsg. Even if the
182 " message doesn't appear, at least it'll be recallable via :messages
183" redraw!
184 if a:level == s:WARNING
185 echohl WarningMsg
186 elseif a:level == s:ERROR
187 echohl Error
188 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100189
190 if type(a:msg) == 3
191 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100192 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100193 endfor
194 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100195 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100196 endif
197
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100198" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200199 echohl None
200 endif
201
202" call Dret("netrw#ErrorMsg")
203endfun
204
205" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100206" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100207" Loosely, varname = value.
208fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100209" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100210 if !exists(a:varname)
211 if type(a:value) == 0
212 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200213 elseif type(a:value) == 1 && a:value =~ '^[{[]'
214 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100215 elseif type(a:value) == 1
216 exe "let ".a:varname."="."'".a:value."'"
217 else
218 exe "let ".a:varname."=".a:value
219 endif
220 endif
221endfun
222
223" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000224" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200225call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000226if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100227 call s:NetrwInit("s:THINLIST",0)
228 call s:NetrwInit("s:LONGLIST",1)
229 call s:NetrwInit("s:WIDELIST",2)
230 call s:NetrwInit("s:TREELIST",3)
231 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000232endif
233
Damien7c754112024-08-15 21:58:57 +0200234let s:NOTE = 0
235let s:WARNING = 1
236let s:ERROR = 2
237call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
238
Bram Moolenaar9964e462007-05-05 17:54:07 +0000239" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200240" Default option values: {{{2
241let g:netrw_localcopycmdopt = ""
242let g:netrw_localcopydircmdopt = ""
243let g:netrw_localmkdiropt = ""
244let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200245
246" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000247" Default values for netrw's global protocol variables {{{2
Damienb4d11642024-08-15 22:00:45 +0200248if exists("*popup_atcursor")
249\ && has("syntax")
250\ && exists("g:syntax_on")
251\ && has("mouse")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200252 call s:NetrwInit("g:netrw_use_errorwindow",2)
253else
254 call s:NetrwInit("g:netrw_use_errorwindow",1)
255endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200256
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000257if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100258 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000259 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100260 elseif executable("curl")
261 let g:netrw_dav_cmd = "curl"
262 else
263 let g:netrw_dav_cmd = ""
264 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000265endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000266if !exists("g:netrw_fetch_cmd")
267 if executable("fetch")
268 let g:netrw_fetch_cmd = "fetch -o"
269 else
270 let g:netrw_fetch_cmd = ""
271 endif
272endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100273if !exists("g:netrw_file_cmd")
274 if executable("elinks")
275 call s:NetrwInit("g:netrw_file_cmd","elinks")
276 elseif executable("links")
277 call s:NetrwInit("g:netrw_file_cmd","links")
278 endif
279endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000280if !exists("g:netrw_ftp_cmd")
281 let g:netrw_ftp_cmd = "ftp"
282endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200283let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200284if !exists("g:netrw_ftp_options")
285 let g:netrw_ftp_options= "-i -n"
286endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000287if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100288 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100289 let g:netrw_http_cmd = "wget"
290 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100291 elseif executable("curl")
292 let g:netrw_http_cmd = "curl"
293 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200294 elseif executable("elinks")
295 let g:netrw_http_cmd = "elinks"
296 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000297 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100298 let g:netrw_http_cmd = "fetch"
299 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200300 elseif executable("links")
301 let g:netrw_http_cmd = "links"
302 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000303 else
304 let g:netrw_http_cmd = ""
305 endif
306endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100307call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100308call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100309call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
310call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200311call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200312if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200313 if executable("scp")
314 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
315 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200316 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200317 else
318 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
319 endif
320endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100321call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
322call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000323
Nir Lichtman1e34b952024-05-08 19:19:34 +0200324if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000325 \ && exists("g:netrw_use_nt_rcp")
326 \ && g:netrw_use_nt_rcp
327 \ && executable( $SystemRoot .'/system32/rcp.exe')
328 let s:netrw_has_nt_rcp = 1
329 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000330else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000331 let s:netrw_has_nt_rcp = 0
332 let s:netrw_rcpmode = ''
333endif
334
335" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000336" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000337" Cygwin Detection ------- {{{3
338if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200339 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
340 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000341 else
342 let g:netrw_cygwin= 0
343 endif
344endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000345" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100346call s:NetrwInit("g:netrw_alto" , &sb)
347call s:NetrwInit("g:netrw_altv" , &spr)
348call s:NetrwInit("g:netrw_banner" , 1)
349call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200350call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100351call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200352call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100353call s:NetrwInit("g:netrw_compress" , "gzip")
354call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200355if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
356 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
357 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000358endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200359call s:NetrwInit("g:netrw_cursor" , 2)
360let s:netrw_usercul = &cursorline
361let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200362"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100363call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000364" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200365call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200366call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200367call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100368call s:NetrwInit("g:netrw_dirhistmax" , 10)
369call s:NetrwInit("g:netrw_fastbrowse" , 1)
370call 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 +0000371if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000372 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
373 let g:netrw_ftp_list_cmd = "ls -lF"
374 let g:netrw_ftp_timelist_cmd = "ls -tlF"
375 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000376 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000377 let g:netrw_ftp_list_cmd = "dir"
378 let g:netrw_ftp_timelist_cmd = "dir"
379 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000380 endif
381endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100382call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000383" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100384call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000385if !exists("g:netrw_ignorenetrc")
386 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
387 let g:netrw_ignorenetrc= 1
388 else
389 let g:netrw_ignorenetrc= 0
390 endif
391endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100392call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000393if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000394 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100395 if exists("g:netrw_list_cmd_options")
396 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
397 else
398 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
399 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000400 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200401 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100402 if exists("g:netrw_list_cmd_options")
403 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
404 else
405 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
406 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000407 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100408" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000409 let g:netrw_list_cmd= ""
410 endif
411endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100412call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000413" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200414if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200415 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200416 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
417endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100418if !exists("g:netrw_localcmdshell")
419 let g:netrw_localcmdshell= ""
420endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000421if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200422 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000423 if g:netrw_cygwin
424 let g:netrw_localcopycmd= "cp"
425 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000426 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200427 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000428 endif
429 elseif has("unix") || has("macunix")
430 let g:netrw_localcopycmd= "cp"
431 else
432 let g:netrw_localcopycmd= ""
433 endif
434endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100435if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200436 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100437 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200438 let g:netrw_localcopydircmd = "cp"
439 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100440 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000441 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200442 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100443 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200444 elseif has("unix")
445 let g:netrw_localcopydircmd = "cp"
446 let g:netrw_localcopydircmdopt= " -R"
447 elseif has("macunix")
448 let g:netrw_localcopydircmd = "cp"
449 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100450 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200451 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100452 endif
453endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200454if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100455 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200456 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
457endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200458if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200459 if g:netrw_cygwin
460 call s:NetrwInit("g:netrw_localmkdir","mkdir")
461 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000462 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200463 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200464 endif
465else
466 call s:NetrwInit("g:netrw_localmkdir","mkdir")
467endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200468call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200469if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200470 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200471 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
472endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000473if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200474 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000475 if g:netrw_cygwin
476 let g:netrw_localmovecmd= "mv"
477 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000478 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200479 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000480 endif
481 elseif has("unix") || has("macunix")
482 let g:netrw_localmovecmd= "mv"
483 else
484 let g:netrw_localmovecmd= ""
485 endif
486endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100487" following serves as an example for how to insert a version&patch specific test
488"if v:version < 704 || (v:version == 704 && !has("patch1107"))
489"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100490call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
491" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000492if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000493 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000494endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000495if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000496 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
497endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000498" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100499call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
500call s:NetrwInit("g:netrw_maxfilenamelen", 32)
501call s:NetrwInit("g:netrw_menu" , 1)
502call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200503call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100504call s:NetrwInit("g:netrw_retmap" , 0)
505if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
506 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200507elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100508 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
509else
510 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000511endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100512call s:NetrwInit("g:netrw_preview" , 0)
513call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100514call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100515call s:NetrwInit("g:netrw_sshport" , "-p")
516call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
517call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
518call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100519call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
520" Default values - q-s ---------- {{{3
521call s:NetrwInit("g:netrw_quickhelp",0)
522let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100523 \ "(create new) %:file d:directory",
524 \ "(windows split&open) o:horz v:vert p:preview",
525 \ "i:style qf:file info O:obtain r:reverse",
526 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
527 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
528 \ "(history) qb:list u:go up U:go down",
529 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100530" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
531call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100532if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
533 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
534else
535 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
536endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100537call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
538call s:NetrwInit("g:netrw_sort_options" , "")
539call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000540if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100541 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200542 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100543 else
544 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000545 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000546endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100547call s:NetrwInit("g:netrw_special_syntax" , 0)
548call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaara6878372014-03-22 21:02:50 +0100549call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100550call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000551" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100552call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200553if !exists("g:netrw_xstrlen")
554 if exists("g:Align_xstrlen")
555 let g:netrw_xstrlen= g:Align_xstrlen
556 elseif exists("g:drawit_xstrlen")
557 let g:netrw_xstrlen= g:drawit_xstrlen
558 elseif &enc == "latin1" || !has("multi_byte")
559 let g:netrw_xstrlen= 0
560 else
561 let g:netrw_xstrlen= 1
562 endif
563endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100564call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200565call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100566call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200567if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000568" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000569" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100570call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200571if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200572 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200573else
Bram Moolenaarff034192013-04-24 18:51:19 +0200574 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200575endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200576call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100577call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
578call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100579if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100580 let s:treedepthstring= "│ "
581else
582 let s:treedepthstring= "| "
583endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200584call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000585
586" BufEnter event ignored by decho when following variable is true
587" Has a side effect that doau BufReadPost doesn't work, so
588" files read by network transfer aren't appropriately highlighted.
589"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590
Bram Moolenaaradc21822011-04-01 18:03:16 +0200591" ======================
592" Netrw Initialization: {{{1
593" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200594if 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 +0100595" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100596 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200597" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100598 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100599 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
600 au VimEnter * let s:initbeval= &beval
601"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100602" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
603" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
604" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
605" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
606" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
607" 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 +0200608endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200609au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200610
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200611if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100612 com! -nargs=* NetrwKeepj keepj <args>
613else
614 let g:netrw_keepj= ""
615 com! -nargs=* NetrwKeepj <args>
616endif
617
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000618" ==============================
619" Netrw Utility Functions: {{{1
620" ==============================
621
Bram Moolenaaradc21822011-04-01 18:03:16 +0200622" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100623" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100624if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100625" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100626 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100627 if &ft != "netrw"
628 return ""
629 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200630 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
631 " popup error window is still showing
632 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
633 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
634 " text under mouse hasn't changed; only close window when it changes
635 call popup_close(s:popuperr_id)
636 unlet s:popuperr_text
637 else
638 let s:popuperr_text= v:beval_text
639 endif
640 let mesg= ""
641 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 +0100642 let mesg= ""
643 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
644 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
645 elseif getline(v:beval_lnum) =~ '^"\s*/'
646 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
647 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100648 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100649 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
650 let mesg = "S: edit sorting sequence"
651 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
652 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
653 elseif v:beval_text == "Quick" || v:beval_text == "Help"
654 let mesg = "Help: press <F1>"
655 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
656 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
657 else
658 let mesg= ""
659 endif
660 return mesg
661 endfun
662"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100663" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
664" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
665" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
666" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
667" 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 +0200668endif
669
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200671" netrw#Explore: launch the local browser in the directory of the current file {{{2
672" indx: == -1: Nexplore
673" == -2: Pexplore
674" == +: this is overloaded:
675" * If Nexplore/Pexplore is in use, then this refers to the
676" indx'th item in the w:netrw_explore_list[] of items which
677" matched the */pattern **/pattern *//pattern **//pattern
678" * If Hexplore or Vexplore, then this will override
679" g:netrw_winsize to specify the qty of rows or columns the
680" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100681" 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 +0200682" dosplit==1: the window will be split before running the local browser
683" style == 0: Explore style == 1: Explore!
684" == 2: Hexplore style == 3: Hexplore!
685" == 4: Vexplore style == 5: Vexplore!
686" == 6: Texplore
687fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaarff034192013-04-24 18:51:19 +0200688 if !exists("b:netrw_curdir")
689 let b:netrw_curdir= getcwd()
Bram Moolenaarff034192013-04-24 18:51:19 +0200690 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100691
692 " record current file for Rexplore's benefit
693 if &ft != "netrw"
694 let w:netrw_rexfile= expand("%:p")
695 endif
696
697 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200698 let curdir = simplify(b:netrw_curdir)
699 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200700 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200701 let curdir= substitute(curdir,'\','/','g')
702 endif
Bram 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
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100708 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200709 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
710 if a1 != a:1
711 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
712 return
713 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100714 endif
715 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200716
717 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200718 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100719" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100720 sil! let keepregstar = @*
721 sil! let keepregplus = @+
722 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200723 sil! let keepregslash= @/
724
Bram Moolenaar8d043172014-01-23 14:24:41 +0100725 " if dosplit
726 " -or- file has been modified AND file not hidden when abandoned
727 " -or- Texplore used
728 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaarff034192013-04-24 18:51:19 +0200729 call s:SaveWinVars()
730 let winsz= g:netrw_winsize
731 if a:indx > 0
732 let winsz= a:indx
733 endif
734
735 if a:style == 0 " Explore, Sexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200736 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200737 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200738 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200739
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200740 elseif a:style == 1 " Explore!, Sexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200741 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200742 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200743 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200744
745 elseif a:style == 2 " Hexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200746 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200747 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200748 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200749
750 elseif a:style == 3 " Hexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200751 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200752 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200753 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200754
755 elseif a:style == 4 " Vexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200756 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200757 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200758 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200759
760 elseif a:style == 5 " Vexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200761 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200762 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200763 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200764
765 elseif a:style == 6 " Texplore
766 call s:SaveBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200767 exe "keepalt tabnew ".fnameescape(curdir)
768 call s:RestoreBufVars()
769 endif
770 call s:RestoreWinVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200771 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100772 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200773
774 if a:0 > 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200775 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaarff034192013-04-24 18:51:19 +0200776 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaarff034192013-04-24 18:51:19 +0200777 elseif a:1 == '.'
Bram Moolenaarff034192013-04-24 18:51:19 +0200778 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
779 if dirname !~ '/$'
780 let dirname= dirname."/"
781 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200782 elseif a:1 =~ '\$'
Bram Moolenaarff034192013-04-24 18:51:19 +0200783 let dirname= simplify(expand(a:1))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200784 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaarff034192013-04-24 18:51:19 +0200785 let dirname= simplify(a:1)
Bram Moolenaarff034192013-04-24 18:51:19 +0200786 else
Bram Moolenaarff034192013-04-24 18:51:19 +0200787 let dirname= a:1
788 endif
789 else
790 " clear explore
Bram Moolenaarff034192013-04-24 18:51:19 +0200791 call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200792 return
793 endif
794
Bram Moolenaarff034192013-04-24 18:51:19 +0200795 if dirname =~ '\.\./\=$'
796 let dirname= simplify(fnamemodify(dirname,':p:h'))
797 elseif dirname =~ '\.\.' || dirname == '.'
798 let dirname= simplify(fnamemodify(dirname,':p'))
799 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200800
801 if dirname =~ '^\*//'
802 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200803 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
804 let starpat= 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200805 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
806
807 elseif dirname =~ '^\*\*//'
808 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200809 let pattern= substitute(dirname,'^\*\*//','','')
810 let starpat= 2
Bram Moolenaarff034192013-04-24 18:51:19 +0200811
812 elseif dirname =~ '/\*\*/'
813 " handle .../**/.../filepat
Bram Moolenaarff034192013-04-24 18:51:19 +0200814 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200815 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200816 let b:netrw_curdir = prefixdir
817 else
818 let b:netrw_curdir= getcwd().'/'.prefixdir
819 endif
820 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
821 let starpat= 4
Bram Moolenaarff034192013-04-24 18:51:19 +0200822
823 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200824 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200825 let starpat= 3
Bram Moolenaarff034192013-04-24 18:51:19 +0200826
827 elseif dirname=~ '^\*\*/'
828 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
829 let starpat= 4
Bram Moolenaarff034192013-04-24 18:51:19 +0200830
831 else
832 let starpat= 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200833 endif
834
835 if starpat == 0 && a:indx >= 0
836 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaarff034192013-04-24 18:51:19 +0200837 if dirname == ""
838 let dirname= curfiledir
Bram Moolenaarff034192013-04-24 18:51:19 +0200839 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200840 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200841 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200842 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200843 if dirname == ""
844 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200845 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100846 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100847 " depending on whether backslashes have been converted to forward slashes by earlier code).
848 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200849 let dirname= b:netrw_curdir."/".dirname
850 endif
851 elseif dirname !~ '^/'
852 let dirname= b:netrw_curdir."/".dirname
853 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200854 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200855 endif
856 if exists("w:netrw_bannercnt")
857 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
858 " If one wants to return the same place in the netrw window, use :Rex instead.
859 exe w:netrw_bannercnt
860 endif
861
Bram Moolenaarff034192013-04-24 18:51:19 +0200862
863 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
864 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
865 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
866 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
867 elseif a:indx <= 0
868 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaarff034192013-04-24 18:51:19 +0200869 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaarff034192013-04-24 18:51:19 +0200870 let s:didstarstar= 1
871 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
872 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
873 endif
874
875 if has("path_extra")
Bram Moolenaarff034192013-04-24 18:51:19 +0200876 if !exists("w:netrw_explore_indx")
877 let w:netrw_explore_indx= 0
878 endif
879
880 let indx = a:indx
Bram Moolenaarff034192013-04-24 18:51:19 +0200881
882 if indx == -1
883 " Nexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200884 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100885 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 +0200886 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100887 if @* != keepregstar | sil! let @* = keepregstar | endif
888 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100889 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200890 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200891 return
892 endif
893 let indx= w:netrw_explore_indx
894 if indx < 0 | let indx= 0 | endif
895 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
896 let curfile= w:netrw_explore_list[indx]
Bram Moolenaarff034192013-04-24 18:51:19 +0200897 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
898 let indx= indx + 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200899 endwhile
900 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200901
902 elseif indx == -2
903 " Pexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200904 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100905 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 +0200906 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100907 if @* != keepregstar | sil! let @* = keepregstar | endif
908 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100909 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200910 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200911 return
912 endif
913 let indx= w:netrw_explore_indx
914 if indx < 0 | let indx= 0 | endif
915 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
916 let curfile= w:netrw_explore_list[indx]
Bram Moolenaarff034192013-04-24 18:51:19 +0200917 while indx >= 0 && curfile == w:netrw_explore_list[indx]
918 let indx= indx - 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200919 endwhile
920 if indx < 0 | let indx= 0 | endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200921
922 else
923 " Explore -- initialize
924 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100925 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200926 let w:netrw_explore_indx= 0
927 if !exists("b:netrw_curdir")
928 let b:netrw_curdir= getcwd()
929 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200930
931 " switch on starpat to build the w:netrw_explore_list of files
932 if starpat == 1
933 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200934 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100935 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200936 catch /^Vim\%((\a\+)\)\=:E480/
937 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +0200938 return
939 endtry
940 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
941 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
942
943 elseif starpat == 2
944 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200945 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100946 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200947 catch /^Vim\%((\a\+)\)\=:E480/
948 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
949 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200950 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100951 if @* != keepregstar | sil! let @* = keepregstar | endif
952 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100953 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200954 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200955 return
956 endtry
957 let s:netrw_curdir = b:netrw_curdir
958 let w:netrw_explore_list = getqflist()
959 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
960 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
961
962 elseif starpat == 3
963 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200964 let filepat= substitute(dirname,'^\*/','','')
965 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaarff034192013-04-24 18:51:19 +0200966 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
967 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
968
969 elseif starpat == 4
970 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200971 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
972 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
973 endif " switch on starpat to build w:netrw_explore_list
974
975 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaarff034192013-04-24 18:51:19 +0200976
977 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100978 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200979 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100980 if @* != keepregstar | sil! let @* = keepregstar | endif
981 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100982 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200983 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200984 return
985 endif
986 endif " if indx ... endif
987
988 " NetrwStatusLine support - for exploring support
989 let w:netrw_explore_indx= indx
Bram Moolenaarff034192013-04-24 18:51:19 +0200990
991 " wrap the indx around, but issue a note
992 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200993 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
994 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100995 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +0200996 endif
997
998 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaarff034192013-04-24 18:51:19 +0200999 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaarff034192013-04-24 18:51:19 +02001000
Bram Moolenaarff034192013-04-24 18:51:19 +02001001 call netrw#LocalBrowseCheck(newdir)
1002 if !exists("w:netrw_liststyle")
1003 let w:netrw_liststyle= g:netrw_liststyle
1004 endif
1005 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001006 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001007 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001008 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001009 endif
1010 let w:netrw_explore_mtchcnt = indx + 1
1011 let w:netrw_explore_bufnr = bufnr("%")
1012 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001013 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaarff034192013-04-24 18:51:19 +02001014
1015 else
Bram Moolenaarff034192013-04-24 18:51:19 +02001016 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001017 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 +02001018 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001019 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001020 if @* != keepregstar | sil! let @* = keepregstar | endif
1021 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001022 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001023 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +02001024 return
1025 endif
1026
1027 else
Bram Moolenaarff034192013-04-24 18:51:19 +02001028 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1029 sil! unlet w:netrw_treedict
1030 sil! unlet w:netrw_treetop
1031 endif
1032 let newdir= dirname
1033 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001034 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001035 else
Tom Benham64a536d2024-11-07 21:15:03 +01001036 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir,0))
Bram Moolenaarff034192013-04-24 18:51:19 +02001037 endif
1038 endif
1039
1040 " visual display of **/ **// */ Exploration files
Bram Moolenaarff034192013-04-24 18:51:19 +02001041 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaarff034192013-04-24 18:51:19 +02001042 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001043 " only update match list when current directory isn't the same as before
Bram Moolenaarff034192013-04-24 18:51:19 +02001044 let s:explore_prvdir = b:netrw_curdir
1045 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001046 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001047 if b:netrw_curdir !~ '/$'
1048 let dirlen= dirlen + 1
1049 endif
1050 let prvfname= ""
1051 for fname in w:netrw_explore_list
Bram Moolenaarff034192013-04-24 18:51:19 +02001052 if fname =~ '^'.b:netrw_curdir
1053 if s:explore_match == ""
1054 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1055 else
1056 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1057 endif
1058 elseif fname !~ '^/' && fname != prvfname
1059 if s:explore_match == ""
1060 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1061 else
1062 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1063 endif
1064 endif
1065 let prvfname= fname
1066 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02001067 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1068 exe "2match netrwMarkFile /".s:explore_match."/"
1069 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001070 endif
1071 echo "<s-up>==Pexplore <s-down>==Nexplore"
1072 else
1073 2match none
1074 if exists("s:explore_match") | unlet s:explore_match | endif
1075 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001076 endif
1077
Bram Moolenaara6878372014-03-22 21:02:50 +01001078 " since Explore may be used to initialize netrw's browser,
1079 " there's no danger of a late FocusGained event on initialization.
1080 " Consequently, set s:netrw_events to 2.
1081 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001082 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001083 if @* != keepregstar | sil! let @* = keepregstar | endif
1084 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001085 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001086 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +02001087endfun
1088
1089" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001090" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001091" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1092" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1093" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1094" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1095" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001096fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001097" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001098 let curwin= winnr()
1099
Bram Moolenaara6878372014-03-22 21:02:50 +01001100 if a:0 > 0 && a:1 != ""
1101 " if a netrw window is already on the left-side of the tab
1102 " and a directory has been specified, explore with that
1103 " directory.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001104 let a1 = expand(a:1)
Bram Moolenaara6878372014-03-22 21:02:50 +01001105 exe "1wincmd w"
1106 if &ft == "netrw"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001107 exe "Explore ".fnameescape(a1)
1108 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001109 let s:lexplore_win= curwin
1110 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001111 if exists("t:netrw_lexposn")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001112 unlet t:netrw_lexposn
1113 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001114 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001115 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001116 exe curwin."wincmd w"
1117 else
1118 let a1= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01001119 endif
1120
Bram Moolenaar8d043172014-01-23 14:24:41 +01001121 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001122 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001123 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001124 else
1125 let lexwinnr= 0
1126 endif
1127
1128 if lexwinnr > 0
1129 " close down netrw explorer window
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001130 exe lexwinnr."wincmd w"
1131 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001132 let t:netrw_lexposn = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001133 close
1134 if lexwinnr < curwin
1135 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001136 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001137 if lexwinnr != curwin
1138 exe curwin."wincmd w"
1139 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001140 unlet t:netrw_lexbufnr
1141
1142 else
1143 " open netrw explorer window
1144 exe "1wincmd w"
1145 let keep_altv = g:netrw_altv
1146 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001147 if a:count != 0
1148 let netrw_winsize = g:netrw_winsize
1149 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001150 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001151 let curfile= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001152 exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
1153 if a:0 > 0 && a1 != ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001154 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001155 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001156 elseif curfile =~ '^\a\{3,}://'
Bram Moolenaar85850f32019-07-19 22:05:51 +02001157 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001158 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02001159 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001160 endif
1161 if a:count != 0
1162 let g:netrw_winsize = netrw_winsize
1163 endif
1164 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001165 let g:netrw_altv = keep_altv
1166 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001167 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1168 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001169 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001170 set bh=wipe
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001171 if exists("t:netrw_lexposn")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001172 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001173 unlet t:netrw_lexposn
1174 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001175 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001176
1177 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001178 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001179 if a:rightside
1180 let g:netrw_chgwin= 1
1181 else
1182 let g:netrw_chgwin= 2
1183 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001184 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001185
Bram Moolenaar8d043172014-01-23 14:24:41 +01001186endfun
1187
1188" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001189" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001190" supports :NetrwClean -- remove netrw from first directory on runtimepath
1191" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001192fun! netrw#Clean(sys)
1193" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001194
1195 if a:sys
1196 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1197 else
1198 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1199 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001200" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001201 let diddel= 0
1202 let diddir= ""
1203
1204 if choice == 1
1205 for dir in split(&rtp,',')
1206 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001207" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001208 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1209 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1210 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1211 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1212 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1213 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 +00001214 let diddir= dir
1215 let diddel= diddel + 1
1216 if !a:sys|break|endif
1217 endif
1218 endfor
1219 endif
1220
1221 echohl WarningMsg
1222 if diddel == 0
1223 echomsg "netrw is either not installed or not removable"
1224 elseif diddel == 1
1225 echomsg "removed one copy of netrw from <".diddir.">"
1226 else
1227 echomsg "removed ".diddel." copies of netrw"
1228 endif
1229 echohl None
1230
Bram Moolenaara6878372014-03-22 21:02:50 +01001231" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001232endfun
1233
Bram Moolenaar5c736222010-01-06 20:54:52 +01001234" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001235" netrw#MakeTgt: make a target out of the directory name provided {{{2
1236fun! netrw#MakeTgt(dname)
1237" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1238 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001239 let svpos = winsaveview()
1240" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001241 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1242" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001243 if s:netrwmftgt_islocal
1244 let netrwmftgt= simplify(a:dname)
1245 else
1246 let netrwmftgt= a:dname
1247 endif
1248 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1249 " re-selected target, so just clear it
1250 unlet s:netrwmftgt s:netrwmftgt_islocal
1251 else
1252 let s:netrwmftgt= netrwmftgt
1253 endif
1254 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001255 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001256 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001257" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1258 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001259" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001260endfun
1261
Bram Moolenaara6878372014-03-22 21:02:50 +01001262" ---------------------------------------------------------------------
1263" netrw#Obtain: {{{2
1264" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001265" islocal=0 obtain from remote source
1266" =1 obtain from local source
1267" fname : a filename or a list of filenames
1268" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001269fun! netrw#Obtain(islocal,fname,...)
1270" 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 +02001271 " NetrwStatusLine support - for obtaining support
1272
1273 if type(a:fname) == 1
1274 let fnamelist= [ a:fname ]
1275 elseif type(a:fname) == 3
1276 let fnamelist= a:fname
1277 else
1278 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 +01001279" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001280 return
1281 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001282" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001283 if a:0 > 0
1284 let tgtdir= a:1
1285 else
1286 let tgtdir= getcwd()
1287 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001288" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001289
1290 if exists("b:netrw_islocal") && b:netrw_islocal
1291 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001292" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001293 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1294 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001295 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001296 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001297" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001298 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001299" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001300 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001301 if v:shell_error != 0
1302 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 +01001303" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001304 return
1305 endif
1306 endfor
1307 else
1308 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001309" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1310 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1311" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001312 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001313 if v:shell_error != 0
1314 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 +01001315" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001316 return
1317 endif
1318 endif
1319 elseif !exists("b:netrw_curdir")
1320 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1321 else
1322 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1323 endif
1324
1325 else
1326 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001327" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001328 if type(a:fname) == 1
1329 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1330 endif
1331 call s:NetrwMethod(b:netrw_curdir)
1332
1333 if b:netrw_method == 4
1334 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001335" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001336 if exists("g:netrw_port") && g:netrw_port != ""
1337 let useport= " ".g:netrw_scpport." ".g:netrw_port
1338 else
1339 let useport= ""
1340 endif
1341 if b:netrw_fname =~ '/'
1342 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1343 else
1344 let path= ""
1345 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001346 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001347 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 +02001348
1349 elseif b:netrw_method == 2
1350 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001351" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001352 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001353 let tmpbufnr= bufnr("%")
1354 setl ff=unix
1355 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001356 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001357" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001358 endif
1359
1360 if exists("b:netrw_fname") && b:netrw_fname != ""
1361 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001362" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001363 endif
1364
1365 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001366 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001367" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001368 endif
1369 for fname in fnamelist
1370 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001371" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001372 endfor
1373 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001374 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 +02001375 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001376 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001377 endif
1378 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1379 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1380 let debugkeep= &debug
1381 setl debug=msg
1382 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1383 let &debug= debugkeep
1384 endif
1385
1386 elseif b:netrw_method == 3
1387 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001388" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001389 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001390 let tmpbufnr= bufnr("%")
1391 setl ff=unix
1392
1393 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001394 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001395" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001396 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001397 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001398" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001399 endif
1400
1401 if exists("g:netrw_uid") && g:netrw_uid != ""
1402 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001403 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001404" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001405 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001406 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001407 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001408" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001409 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001410 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001411" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001412 endif
1413 endif
1414
1415 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001416 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001417" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001418 endif
1419
1420 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001421 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001422" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001423 endif
1424
1425 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001426 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001427" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001428 endif
1429
1430 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001431 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001432" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001433 endif
1434 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001435 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001436 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001437" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001438
1439 " perform ftp:
1440 " -i : turns off interactive prompting from ftp
1441 " -n unix : DON'T use <.netrc>, even though it exists
1442 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001443 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1444 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001445 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001446 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1447 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001448" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001449 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001450 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001451 endif
1452 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001453
1454 elseif b:netrw_method == 9
1455 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001456" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001457 if a:fname =~ '/'
1458 let localfile= substitute(a:fname,'^.*/','','')
1459 else
1460 let localfile= a:fname
1461 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001462 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 +02001463
Bram Moolenaarff034192013-04-24 18:51:19 +02001464 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001465 " probably a badly formed url; protocol not recognized
1466" call Dret("netrw#Obtain : unsupported method")
1467 return
1468
1469 else
1470 " protocol recognized but not supported for Obtain (yet?)
1471 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001472 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001473 endif
1474" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001475 return
1476 endif
1477
1478 " restore status line
1479 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001480 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001481 endif
1482
1483 endif
1484
1485 " cleanup
1486 if exists("tmpbufnr")
1487 if bufnr("%") != tmpbufnr
1488 exe tmpbufnr."bw!"
1489 else
1490 q!
1491 endif
1492 endif
1493
Bram Moolenaara6878372014-03-22 21:02:50 +01001494" call Dret("netrw#Obtain")
1495endfun
1496
1497" ---------------------------------------------------------------------
1498" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1499fun! netrw#Nread(mode,fname)
1500" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001501 let svpos= winsaveview()
1502" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001503 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001504" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1505 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001506
1507 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1508 if exists("w:netrw_bannercnt")
1509 " start with cursor just after the banner
1510 exe w:netrw_bannercnt
1511 endif
1512 endif
1513" call Dret("netrw#Nread")
1514endfun
1515
1516" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001517" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1518" Options get restored by s:NetrwOptionsRestore()
1519"
1520" Option handling:
1521" * save user's options (s:NetrwOptionsSave)
1522" * set netrw-safe options (s:NetrwOptionsSafe)
1523" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1524" * restore user's options (s:netrwOPtionsRestore)
1525" - restore a user option when != safe option (s:NetrwRestoreSetting)
1526" vt: (variable type) normally its either "w:" or "s:"
1527fun! s:NetrwOptionsSave(vt)
1528" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1529" 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 +02001530" 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>"))
1531" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001532
1533 if !exists("{a:vt}netrw_optionsave")
1534 let {a:vt}netrw_optionsave= 1
1535 else
1536" call Dret("s:NetrwOptionsSave : options already saved")
1537 return
1538 endif
1539" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1540
1541 " Save current settings and current directory
1542" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1543 let s:yykeep = @@
1544 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1545 let {a:vt}netrw_aikeep = &l:ai
1546 let {a:vt}netrw_awkeep = &l:aw
1547 let {a:vt}netrw_bhkeep = &l:bh
1548 let {a:vt}netrw_blkeep = &l:bl
1549 let {a:vt}netrw_btkeep = &l:bt
1550 let {a:vt}netrw_bombkeep = &l:bomb
1551 let {a:vt}netrw_cedit = &cedit
1552 let {a:vt}netrw_cikeep = &l:ci
1553 let {a:vt}netrw_cinkeep = &l:cin
1554 let {a:vt}netrw_cinokeep = &l:cino
1555 let {a:vt}netrw_comkeep = &l:com
1556 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001557 let {a:vt}netrw_cuckeep = &l:cuc
1558 let {a:vt}netrw_culkeep = &l:cul
1559" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001560 let {a:vt}netrw_diffkeep = &l:diff
1561 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001562 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1563 let {a:vt}netrw_ffkeep = &l:ff
1564 endif
1565 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1566 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001567 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001568 let {a:vt}netrw_hidkeep = &l:hidden
1569 let {a:vt}netrw_imkeep = &l:im
1570 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001571 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001572 let {a:vt}netrw_lskeep = &l:ls
1573 let {a:vt}netrw_makeep = &l:ma
1574 let {a:vt}netrw_magickeep = &l:magic
1575 let {a:vt}netrw_modkeep = &l:mod
1576 let {a:vt}netrw_nukeep = &l:nu
1577 let {a:vt}netrw_rnukeep = &l:rnu
1578 let {a:vt}netrw_repkeep = &l:report
1579 let {a:vt}netrw_rokeep = &l:ro
1580 let {a:vt}netrw_selkeep = &l:sel
1581 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001582 if !g:netrw_use_noswf
1583 let {a:vt}netrw_swfkeep = &l:swf
1584 endif
1585 let {a:vt}netrw_tskeep = &l:ts
1586 let {a:vt}netrw_twkeep = &l:tw " textwidth
1587 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1588 let {a:vt}netrw_wrapkeep = &l:wrap
1589 let {a:vt}netrw_writekeep = &l:write
1590
1591 " save a few selected netrw-related variables
1592" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1593 if g:netrw_keepdir
1594 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001595" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001596 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001597 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001598 sil! let {a:vt}netrw_starkeep = @*
1599 sil! let {a:vt}netrw_pluskeep = @+
1600 endif
1601 sil! let {a:vt}netrw_slashkeep= @/
1602
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001603" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001604" 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>"))
1605" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1606endfun
1607
1608" ---------------------------------------------------------------------
1609" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1610" Use s:NetrwSaveOptions() to save user settings
1611" Use s:NetrwOptionsRestore() to restore user settings
1612fun! s:NetrwOptionsSafe(islocal)
1613" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1614" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1615" 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>"))
1616 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1617 call s:NetrwSetSafeSetting("&l:ai",0)
1618 call s:NetrwSetSafeSetting("&l:aw",0)
1619 call s:NetrwSetSafeSetting("&l:bl",0)
1620 call s:NetrwSetSafeSetting("&l:bomb",0)
1621 if a:islocal
1622 call s:NetrwSetSafeSetting("&l:bt","nofile")
1623 else
1624 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1625 endif
1626 call s:NetrwSetSafeSetting("&l:ci",0)
1627 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001628 if g:netrw_fastbrowse > a:islocal
1629 call s:NetrwSetSafeSetting("&l:bh","hide")
1630 else
1631 call s:NetrwSetSafeSetting("&l:bh","delete")
1632 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001633 call s:NetrwSetSafeSetting("&l:cino","")
1634 call s:NetrwSetSafeSetting("&l:com","")
1635 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1636 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1637 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001638 if &go =~ 'a' | set go-=a | endif
1639 if &go =~ 'A' | set go-=A | endif
1640 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001641 call s:NetrwSetSafeSetting("&l:hid",0)
1642 call s:NetrwSetSafeSetting("&l:im",0)
1643 setl isk+=@ isk+=* isk+=/
1644 call s:NetrwSetSafeSetting("&l:magic",1)
1645 if g:netrw_use_noswf
1646 call s:NetrwSetSafeSetting("swf",0)
1647 endif
1648 call s:NetrwSetSafeSetting("&l:report",10000)
1649 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1650 call s:NetrwSetSafeSetting("&l:spell",0)
1651 call s:NetrwSetSafeSetting("&l:tw",0)
1652 call s:NetrwSetSafeSetting("&l:wig","")
1653 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001654
1655 " set up cuc and cul based on g:netrw_cursor and listing style
1656 " COMBAK -- cuc cul related
1657 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001658
1659 " allow the user to override safe options
1660" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1661 if &ft == "netrw"
1662" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1663 keepalt NetrwKeepj doau FileType netrw
1664 endif
1665
1666" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1667" 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>"))
1668" call Dret("s:NetrwOptionsSafe")
1669endfun
1670
1671" ---------------------------------------------------------------------
1672" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1673fun! s:NetrwOptionsRestore(vt)
Bram Moolenaara6878372014-03-22 21:02:50 +01001674 if !exists("{a:vt}netrw_optionsave")
Christian Brabandtaa2ce6f2024-10-30 18:27:03 +01001675 " filereadable() returns zero for remote files (e.g. scp://user@localhost//etc/fstab)
1676 " Note: @ may not be in 'isfname', so '^\w\+://\f\+/' may not match
1677 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+'
Bram Moolenaar71badf92023-04-22 22:40:14 +01001678 filetype detect
Bram Moolenaar71badf92023-04-22 22:40:14 +01001679 else
1680 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001681 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001682 return
1683 endif
1684 unlet {a:vt}netrw_optionsave
1685
1686 if exists("+acd")
1687 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara6878372014-03-22 21:02:50 +01001688 let curdir = getcwd()
1689 let &l:acd = {a:vt}netrw_acdkeep
1690 unlet {a:vt}netrw_acdkeep
1691 if &l:acd
1692 call s:NetrwLcd(curdir)
1693 endif
1694 endif
1695 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001696 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1697 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1698 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1699 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1700 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
1701 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1702 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1703 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1704 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1705 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
1706 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1707 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1708 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1709 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1710 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001711 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001712 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1713 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001714 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001715 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001716 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1717 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001718 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001719 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1720 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001721 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001722 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1723 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001724 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1725 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1726 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1727 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001728 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001729 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1730 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1731 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001732 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
1733 call s:NetrwRestoreSetting("s:yykeep","@@")
1734 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1735 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1736 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1737 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1738
Bram Moolenaara6878372014-03-22 21:02:50 +01001739 if exists("{a:vt}netrw_swfkeep")
1740 if &directory == ""
1741 " user hasn't specified a swapfile directory;
1742 " netrw will temporarily set the swapfile directory
1743 " to the current directory as returned by getcwd().
1744 let &l:directory= getcwd()
1745 sil! let &l:swf = {a:vt}netrw_swfkeep
1746 setl directory=
1747 unlet {a:vt}netrw_swfkeep
1748 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001749 if !g:netrw_use_noswf
1750 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1751 sil! let &l:swf= {a:vt}netrw_swfkeep
1752 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001753 unlet {a:vt}netrw_swfkeep
1754 endif
1755 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001756 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001757 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1758 if exists("{a:vt}netrw_dirkeep")
1759 call s:NetrwLcd(dirkeep)
1760 unlet {a:vt}netrw_dirkeep
1761 endif
1762 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001763 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001764 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1765 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001766 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001767 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001768
Bram Moolenaara6878372014-03-22 21:02:50 +01001769 " Moved the filetype detect here from NetrwGetFile() because remote files
1770 " were having their filetype detect-generated settings overwritten by
1771 " NetrwOptionRestore.
1772 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001773 filetype detect
Bram Moolenaara6878372014-03-22 21:02:50 +01001774 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001775endfun
1776
1777" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001778" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1779" but only when the options' value and the safe setting differ
1780" Doing this means that netrw will not come up as having changed a
1781" setting last when it really didn't actually change it.
1782"
1783" Called from s:NetrwOptionsSafe
1784" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1785fun! s:NetrwSetSafeSetting(setting,safesetting)
1786" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001787
Bram Moolenaar85850f32019-07-19 22:05:51 +02001788 if a:setting =~ '^&'
1789" call Decho("fyi: a:setting starts with &")
1790 exe "let settingval= ".a:setting
1791" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001792
Bram Moolenaar85850f32019-07-19 22:05:51 +02001793 if settingval != a:safesetting
1794" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1795 if type(a:safesetting) == 0
1796 exe "let ".a:setting."=".a:safesetting
1797 elseif type(a:safesetting) == 1
1798 exe "let ".a:setting."= '".a:safesetting."'"
1799 else
1800 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1801 endif
1802 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001803 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001804
Bram Moolenaar85850f32019-07-19 22:05:51 +02001805" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001806endfun
1807
1808" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001809" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1810" but only if the setting value differs from the associated keepvar.
1811" Doing this means that netrw will not come up as having changed a
1812" setting last when it really didn't actually change it.
1813"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001814" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001815" keepvars are set up by s:NetrwOptionsSave
1816fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001817""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001818
Bram Moolenaar85850f32019-07-19 22:05:51 +02001819 " typically called from s:NetrwOptionsRestore
1820 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1821 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001822 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001823 if exists(a:keepvar)
1824 exe "let keepvarval= ".a:keepvar
1825 exe "let setting= ".a:setting
1826
1827"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1828"" call Decho("fyi: keepvarval=".keepvarval)
1829"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1830
1831 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001832"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001833 if type(a:setting) == 0
1834 exe "let ".a:setting."= ".keepvarval
1835 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001836 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001837 else
1838 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1839 endif
1840 endif
1841
1842 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001843 endif
1844
Bram Moolenaar85850f32019-07-19 22:05:51 +02001845"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001846endfun
1847
1848" ---------------------------------------------------------------------
1849" NetrwStatusLine: {{{2
1850fun! NetrwStatusLine()
1851
1852" vvv NetrwStatusLine() debugging vvv
1853" let g:stlmsg=""
1854" if !exists("w:netrw_explore_bufnr")
1855" let g:stlmsg="!X<explore_bufnr>"
1856" elseif w:netrw_explore_bufnr != bufnr("%")
1857" let g:stlmsg="explore_bufnr!=".bufnr("%")
1858" endif
1859" if !exists("w:netrw_explore_line")
1860" let g:stlmsg=" !X<explore_line>"
1861" elseif w:netrw_explore_line != line(".")
1862" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
1863" endif
1864" if !exists("w:netrw_explore_list")
1865" let g:stlmsg=" !X<explore_list>"
1866" endif
1867" ^^^ NetrwStatusLine() debugging ^^^
1868
1869 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")
1870 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09001871 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02001872 let &laststatus = s:netrw_users_ls
1873 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
1874 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
1875 return ""
1876 else
1877 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
1878 endif
1879endfun
1880
Bram Moolenaar85850f32019-07-19 22:05:51 +02001881" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001882" Netrw Transfer Functions: {{{1
1883" ===============================
1884
Bram Moolenaar071d4272004-06-13 20:20:40 +00001885" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001886" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001887" mode: =0 read remote file and insert before current line
1888" =1 read remote file and insert after current line
1889" =2 replace with remote file
1890" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001891fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02001892" 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 +00001893
Bram Moolenaar5c736222010-01-06 20:54:52 +01001894 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02001895 call s:NetrwOptionsSave("w:")
1896 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001897 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001898 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
1899 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
1900 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02001901" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001902
Bram Moolenaar5c736222010-01-06 20:54:52 +01001903 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001904 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001905 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001906 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001907 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001908 elseif a:mode == 2 " replace with remote file
1909 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00001910 elseif a:mode == 3 " skip read of file (leave as temporary)
1911 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001912 else
1913 exe a:mode
1914 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001915 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001916 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001917" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001918
Bram Moolenaar5c736222010-01-06 20:54:52 +01001919 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00001920 let tmpfile= s:GetTempfile("")
1921 if tmpfile == ""
1922" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001923 return
1924 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001925
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001926 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001927
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001928 " attempt to repeat with previous host-file-etc
1929 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001930" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001931 let choice = b:netrw_lastfile
1932 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001933
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001934 else
1935 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001936" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001937
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001938 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001939 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001940 echomsg 'NetRead Usage:'
1941 echomsg ':Nread machine:path uses rcp'
1942 echomsg ':Nread "machine path" uses ftp with <.netrc>'
1943 echomsg ':Nread "machine id password path" uses ftp'
1944 echomsg ':Nread dav://machine[:port]/path uses cadaver'
1945 echomsg ':Nread fetch://machine/path uses fetch'
1946 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
1947 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001948 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01001949 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001950 echomsg ':Nread rcp://[user@]machine/path uses rcp'
1951 echomsg ':Nread rsync://machine[:port]/path uses rsync'
1952 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
1953 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00001954 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001955 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001956
Bram Moolenaar9964e462007-05-05 17:54:07 +00001957 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001958 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001959" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00001960 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001961 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02001962 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001963 else
1964 " case "... ... ..."
1965 let choice = strpart(choice,1,strlen(choice)-1)
1966 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001967
Bram Moolenaar9964e462007-05-05 17:54:07 +00001968 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001969 let wholechoice = wholechoice . " " . choice
1970 let ichoice = ichoice + 1
1971 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09001972 if !exists("g:netrw_quiet")
1973 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
1974 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00001975" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001976 return
1977 endif
1978 let choice= a:{ichoice}
1979 endwhile
1980 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
1981 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001982 endif
1983 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001984
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001985" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001986 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001987
Bram Moolenaar5c736222010-01-06 20:54:52 +01001988 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00001989 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01001990 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001991" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001992 return
1993 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00001994 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001995
Bram Moolenaar8d043172014-01-23 14:24:41 +01001996 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001997" 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 +02001998 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001999" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002000 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002001" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002002 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002003 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002004
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002005 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002006 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002007 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002008 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2009 echo "(netrw) Processing your read request..."
2010 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002011
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002012 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002013 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002014 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002015" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002016 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002017 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002018 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002019 " ER: the tmpfile is full path: rcp sees C:\... as host C
2020 if s:netrw_has_nt_rcp == 1
2021 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2022 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2023 else
2024 " Any way needed it machine contains a '.'
2025 let uid_machine = g:netrw_machine .'.'. $USERNAME
2026 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002027 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002028 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2029 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2030 else
2031 let uid_machine = g:netrw_machine
2032 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002033 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002034 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 +00002035 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002036 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002037
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002038 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002039 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002040 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002041" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002042 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002043 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002044 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002045 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002046 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002047" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002048 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002049 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002050" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002051 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002052 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002053" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002054 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002055 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 +00002056 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002057 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002058 endif
2059 " 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 +00002060 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002061 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002062 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002063 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002064 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002065 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002066 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002067 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002068 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2069 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002070 q!
2071 endif
2072 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002073 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002074 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002075
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002076 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002077 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002078 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2079 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002080" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002081 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002082 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002083 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002084 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002085 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002086 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002087" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002088 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002089 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002090" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002091 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002092
Bram Moolenaar97d62492012-11-15 21:28:22 +01002093 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002094 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002095 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002096" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002097 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002098 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002099 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002100" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002101 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002102 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002103" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002104 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002105 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002106
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002107 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002108 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002109" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002110 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002111 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002112 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002113" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002114 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002115 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002116" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002117
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002118 " perform ftp:
2119 " -i : turns off interactive prompting from ftp
2120 " -n unix : DON'T use <.netrc>, even though it exists
2121 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002122 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002123 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002124 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2125 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002126" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002127 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002128 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002129 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002130 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002131 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002132 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002133 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002134
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002135 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002136 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002137 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002138" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002139 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002140 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002141 else
2142 let useport= ""
2143 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002144 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2145 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002146 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002147 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2148 else
2149 let tmpfile_get = tmpfile
2150 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002151 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 +00002152 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002153 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002154
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002155 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002156 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002157 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002158" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002159 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002160 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002161 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002162 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002163" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002164 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002165 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002166
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002167 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2168 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002169" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002170 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002171 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 +00002172 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002173 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 +00002174 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002175 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002176
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002177 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002178 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002179" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002180 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2181 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002182" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2183" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2184 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 +00002185 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002186" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002187 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002188 endif
2189 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002190" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002191 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002192
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002193 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002194 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002195 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002196" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002197
Bram Moolenaar5c736222010-01-06 20:54:52 +01002198 if !executable(g:netrw_dav_cmd)
2199 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2200" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2201 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002202 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002203 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002204 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 +01002205 else
2206 " Construct execution string (four lines) which will be passed through filter
2207 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2208 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002209 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002210 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002211 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002212 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002213 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002214 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002215 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002216 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002217 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002218 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2219 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002220
Bram Moolenaar5c736222010-01-06 20:54:52 +01002221 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002222 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002223 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002224 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002225 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002226 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002227 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002228
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002229 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002230 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002231 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002232" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002233 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 +00002234 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002235 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002236
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002237 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002238 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002239 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002240 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002241" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002242 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002243 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002244 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002245 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002246" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002247 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002248 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002249 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002250 let netrw_option= "http"
2251 else
2252 let netrw_option= "ftp"
2253 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002254" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002255
Bram Moolenaar446cb832008-06-24 21:56:24 +00002256 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002257 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 +00002258 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002259 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 +00002260 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002261
Bram Moolenaar446cb832008-06-24 21:56:24 +00002262 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002263 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002264" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002265 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002266
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002267 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002268 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002269 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002270" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2271 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 +00002272 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002273 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002274
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002275 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002276 " NetRead: (file) NetRead Method #10 {{{3
2277 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002278" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2279 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002280 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2281 let b:netrw_lastfile = choice
2282
2283 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002284 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002285 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002286 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002287 endif
2288 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002289
Bram Moolenaar5c736222010-01-06 20:54:52 +01002290 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002291 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002292" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002293 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002294 unlet b:netrw_fname
2295 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002296 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 +01002297" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002298 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002299 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002300 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002301
Bram Moolenaar9964e462007-05-05 17:54:07 +00002302" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002303endfun
2304
2305" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002306" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002307fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002308" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002309
Bram Moolenaar5c736222010-01-06 20:54:52 +01002310 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002311 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002312 call s:NetrwOptionsSave("w:")
2313 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002314
Bram Moolenaar5c736222010-01-06 20:54:52 +01002315 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002316 let tmpfile= s:GetTempfile("")
2317 if tmpfile == ""
2318" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002319 return
2320 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002321
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002322 if a:0 == 0
2323 let ichoice = 0
2324 else
2325 let ichoice = 1
2326 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002327
Bram Moolenaar9964e462007-05-05 17:54:07 +00002328 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002329" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002330 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002331 " For binary writes, always write entire file.
2332 " (line numbers don't really make sense for that).
2333 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002334" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002335 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002336 elseif g:netrw_cygwin
2337 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002338 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002339" 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 +01002340 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002341 else
2342 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002343" 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 +01002344 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002345 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002346
Bram Moolenaar9964e462007-05-05 17:54:07 +00002347 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002348 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002349 " on the temporary file's name. Deletion of the temporary file during
2350 " cleanup then causes an error message.
2351 0file!
2352 endif
2353
Bram Moolenaar5c736222010-01-06 20:54:52 +01002354 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002355 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002356
Bram Moolenaar9964e462007-05-05 17:54:07 +00002357 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002358 " attempt to repeat with previous host-file-etc
2359 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002360" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002361 let choice = b:netrw_lastfile
2362 let ichoice= ichoice + 1
2363 else
2364 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002365
Bram Moolenaar8d043172014-01-23 14:24:41 +01002366 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002367 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002368 echomsg 'NetWrite Usage:"'
2369 echomsg ':Nwrite machine:path uses rcp'
2370 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2371 echomsg ':Nwrite "machine id password path" uses ftp'
2372 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2373 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2374 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2375 echomsg ':Nwrite rcp://machine/path uses rcp'
2376 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2377 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2378 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002379 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002380 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002381
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002382 elseif match(choice,"^\"") != -1
2383 if match(choice,"\"$") != -1
2384 " case "..."
2385 let choice=strpart(choice,1,strlen(choice)-2)
2386 else
2387 " case "... ... ..."
2388 let choice = strpart(choice,1,strlen(choice)-1)
2389 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002390
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002391 while match(choice,"\"$") == -1
2392 let wholechoice= wholechoice . " " . choice
2393 let ichoice = ichoice + 1
2394 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002395 if !exists("g:netrw_quiet")
2396 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2397 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002398" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002399 return
2400 endif
2401 let choice= a:{ichoice}
2402 endwhile
2403 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2404 endif
2405 endif
2406 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002407 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002408" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002409
Bram Moolenaar9964e462007-05-05 17:54:07 +00002410 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002411 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002412 if !exists("b:netrw_method") || b:netrw_method < 0
2413" call Dfunc("netrw#NetWrite : unsupported method")
2414 return
2415 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002416
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002417 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002418 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002419 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002420 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2421 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002422" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002423 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002424
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002425 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002426 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002427 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002428" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002429 if s:netrw_has_nt_rcp == 1
2430 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2431 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2432 else
2433 let uid_machine = g:netrw_machine .'.'. $USERNAME
2434 endif
2435 else
2436 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2437 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2438 else
2439 let uid_machine = g:netrw_machine
2440 endif
2441 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002442 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 +00002443 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002444
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002445 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002446 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002447 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002448" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002449 let netrw_fname = b:netrw_fname
2450
2451 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2452 let bhkeep = &l:bh
2453 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002454 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002455 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002456
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002457" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002458 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002459 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002460" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002461 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002462 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002463" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002464 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002465 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002466" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002467 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002468 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 +00002469 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002470" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2471 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002472 endif
2473 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2474 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002475 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002476 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002477 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002478 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002479 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002480
2481 " remove enew buffer (quietly)
2482 let filtbuf= bufnr("%")
2483 exe curbuf."b!"
2484 let &l:bh = bhkeep
2485 exe filtbuf."bw!"
2486
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002488
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002489 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002490 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002491 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002492 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002493" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002494 let netrw_fname = b:netrw_fname
2495 let bhkeep = &l:bh
2496
2497 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2498 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002499 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002500 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002501 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002502
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002503 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002504 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002505" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002506 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002507 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002508" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002509 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002510 if exists("g:netrw_uid") && g:netrw_uid != ""
2511 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002512 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002513" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002514 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002515 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002516 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002517" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002518 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002519 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002520" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002521 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002522 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002523 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002524" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002525 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002526 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002527" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002528 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002529 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002530" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002531 " save choice/id/password for future use
2532 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002533
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002534 " perform ftp:
2535 " -i : turns off interactive prompting from ftp
2536 " -n unix : DON'T use <.netrc>, even though it exists
2537 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002538 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002539 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002540 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2541 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002542 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002543 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002544 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002545 let mod=1
2546 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002547
2548 " remove enew buffer (quietly)
2549 let filtbuf= bufnr("%")
2550 exe curbuf."b!"
2551 let &l:bh= bhkeep
2552 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002553
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002554 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002555 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002556 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002557" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002558 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002559 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002560 else
2561 let useport= ""
2562 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002563 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 +00002564 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002565
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002566 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002567 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002568 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002569" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002570 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2571 if executable(curl)
2572 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002573 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 +01002574 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002575 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002576 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002577
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002578 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002579 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002580 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002581" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002582
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002583 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002584 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2585 let bhkeep = &l:bh
2586
2587 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2588 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002589 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002590 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002591
Bram Moolenaarff034192013-04-24 18:51:19 +02002592 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002593 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002594 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002595 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002596 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002597 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002598 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002599 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002600 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002601 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002602
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002603 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002604 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002605 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002606
2607 " remove enew buffer (quietly)
2608 let filtbuf= bufnr("%")
2609 exe curbuf."b!"
2610 let &l:bh = bhkeep
2611 exe filtbuf."bw!"
2612
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002613 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002614
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002615 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002616 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002617 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002618" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002619 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 +00002620 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002621
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002622 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002623 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002624 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002625" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002626 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002627 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2628 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2629 else
2630 let uid_machine = g:netrw_machine
2631 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002632
2633 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2634 let bhkeep = &l:bh
2635 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002636 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002637 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002638
Bram Moolenaarff034192013-04-24 18:51:19 +02002639 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002640 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002641" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002642 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002643 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002644 let filtbuf= bufnr("%")
2645 exe curbuf."b!"
2646 let &l:bh = bhkeep
2647 exe filtbuf."bw!"
2648 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002649
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002650 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002651 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002652 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002653 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002654 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002656 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002657
Bram Moolenaar5c736222010-01-06 20:54:52 +01002658 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002659" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002660 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002661" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002662 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002663 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002664 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002665
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002666 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002667 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002668 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002669" 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 +02002670 elseif !exists("leavemod")
2671 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002672" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002673 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002674" 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 +00002675 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002676
Bram Moolenaar9964e462007-05-05 17:54:07 +00002677" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002678endfun
2679
2680" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002681" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002682" uses NetRead to get a copy of the file into a temporarily file,
2683" then sources that file,
2684" then removes that file.
2685fun! netrw#NetSource(...)
2686" call Dfunc("netrw#NetSource() a:0=".a:0)
2687 if a:0 > 0 && a:1 == '?'
2688 " give help
2689 echomsg 'NetSource Usage:'
2690 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2691 echomsg ':Nsource fetch://machine/path uses fetch'
2692 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002693 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002694 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2695 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2696 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2697 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2698 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002699 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002700 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002701 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002702 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002703" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002704 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002705" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002706 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002707" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002708 if delete(s:netrw_tmpfile)
2709 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2710 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002711 unlet s:netrw_tmpfile
2712 else
2713 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2714 endif
2715 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002716 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002717 endif
2718" call Dret("netrw#NetSource")
2719endfun
2720
Bram Moolenaar8d043172014-01-23 14:24:41 +01002721" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002722" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2723" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002724fun! netrw#SetTreetop(iscmd,...)
Bram Moolenaara6878372014-03-22 21:02:50 +01002725
Bram Moolenaar85850f32019-07-19 22:05:51 +02002726 " iscmd==0: netrw#SetTreetop called using gn mapping
2727 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
Bram Moolenaar8d043172014-01-23 14:24:41 +01002728 " clear out the current tree
2729 if exists("w:netrw_treetop")
2730 let inittreetop= w:netrw_treetop
2731 unlet w:netrw_treetop
2732 endif
2733 if exists("w:netrw_treedict")
2734 unlet w:netrw_treedict
2735 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002736
Bram Moolenaar85850f32019-07-19 22:05:51 +02002737 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002738 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaar8d043172014-01-23 14:24:41 +01002739 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002740 if isdirectory(s:NetrwFile(a:1))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002741 let treedir = a:1
2742 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002743 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002744 let treedir = b:netrw_curdir."/".a:1
2745 let s:netrw_treetop = treedir
Bram Moolenaar8d043172014-01-23 14:24:41 +01002746 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002747 " normally the cursor is left in the message window.
2748 " However, here this results in the directory being listed in the message window, which is not wanted.
2749 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002750 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002751 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002752 let treedir = "."
2753 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002754 endif
2755 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002756
2757 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002758 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar85850f32019-07-19 22:05:51 +02002759
2760 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002761 if islocal
Tom Benham64a536d2024-11-07 21:15:03 +01002762 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir,0))
Bram Moolenaara6878372014-03-22 21:02:50 +01002763 else
Tom Benham64a536d2024-11-07 21:15:03 +01002764 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir,0))
Bram Moolenaara6878372014-03-22 21:02:50 +01002765 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002766
Bram Moolenaar8d043172014-01-23 14:24:41 +01002767endfun
2768
Bram Moolenaar9964e462007-05-05 17:54:07 +00002769" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002770" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002771" readcmd == %r : replace buffer with newly read file
2772" == 0r : read file at top of buffer
2773" == r : read file after current line
2774" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002775fun! s:NetrwGetFile(readcmd, tfile, method)
2776" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002777
2778 " readcmd=='t': simply do nothing
2779 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002780" 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 +01002781" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002782 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002783 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002784
Bram Moolenaar9964e462007-05-05 17:54:07 +00002785 " get name of remote filename (ie. url and all)
2786 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002787" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002788
Bram Moolenaar9964e462007-05-05 17:54:07 +00002789 if exists("*NetReadFixup")
2790 " for the use of NetReadFixup (not otherwise used internally)
2791 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002792 endif
2793
Bram Moolenaar9964e462007-05-05 17:54:07 +00002794 if a:readcmd[0] == '%'
2795 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002796" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002797
2798 " rename the current buffer to the temp file (ie. tfile)
2799 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002800 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002801 else
2802 let tfile= a:tfile
2803 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002804 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002805
2806 " edit temporary file (ie. read the temporary file in)
2807 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002808" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002809 call zip#Browse(tfile)
2810 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002811" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002812 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002813 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002814" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002815 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002816 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002817" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002818 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002819 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002820" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002821 call tar#Browse(tfile)
2822 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002823" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002824 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002825 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002826" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002827 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002828 endif
2829
2830 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002831 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002832
Bram Moolenaar71badf92023-04-22 22:40:14 +01002833 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002834 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002835 " Note that isk must not include a "/" for scripts.vim
2836 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002837" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2838" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002839" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002840" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
2841 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01002842 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01002843 filetype detect
2844" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09002845 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02002846" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002847 let line1 = 1
2848 let line2 = line("$")
2849
Bram Moolenaar8d043172014-01-23 14:24:41 +01002850 elseif !&ma
2851 " 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 +01002852 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002853" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002854 return
2855
Bram Moolenaar9964e462007-05-05 17:54:07 +00002856 elseif s:FileReadable(a:tfile)
2857 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002858" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002859 let curline = line(".")
2860 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002861" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002862 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002863 let line1= curline + 1
2864 let line2= line("$") - lastline + 1
2865
2866 else
2867 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002868" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
2869" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002870 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002871" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002872 return
2873 endif
2874
2875 " User-provided (ie. optional) fix-it-up command
2876 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002877" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002878 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002879" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002880" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002881 endif
2882
Bram Moolenaaradc21822011-04-01 18:03:16 +02002883 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00002884 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002885 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00002886 endif
2887
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002888" 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 +00002889
2890 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00002891" redraw!
2892
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002893" 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 +00002894" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002895endfun
2896
Bram Moolenaar9964e462007-05-05 17:54:07 +00002897" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002898" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01002899" Input:
2900" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
2901" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002902" b:netrw_method= 1: rcp
2903" 2: ftp + <.netrc>
2904" 3: ftp + machine, id, password, and [path]filename
2905" 4: scp
2906" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002907" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002908" 7: rsync
2909" 8: fetch
2910" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002911" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01002912" g:netrw_machine= hostname
2913" b:netrw_fname = filename
2914" g:netrw_port = optional port number (for ftp)
2915" g:netrw_choice = copy of input url (choice)
2916fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002917" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002918
Bram Moolenaar251e1912011-06-19 05:09:16 +02002919 " sanity check: choice should have at least three slashes in it
2920 if strlen(substitute(a:choice,'[^/]','','g')) < 3
2921 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
2922 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02002923" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02002924 return
2925 endif
2926
Bram Moolenaar5c736222010-01-06 20:54:52 +01002927 " record current g:netrw_machine, if any
2928 " curmachine used if protocol == ftp and no .netrc
2929 if exists("g:netrw_machine")
2930 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002931" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002932 else
2933 let curmachine= "N O T A HOST"
2934 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002935 if exists("g:netrw_port")
2936 let netrw_port= g:netrw_port
2937 endif
2938
2939 " insure that netrw_ftp_cmd starts off every method determination
2940 " with the current g:netrw_ftp_cmd
2941 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01002942
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002943 " initialization
2944 let b:netrw_method = 0
2945 let g:netrw_machine = ""
2946 let b:netrw_fname = ""
2947 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002948 let g:netrw_choice = a:choice
2949
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002950 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002951 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00002952 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
2953 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002954 " rcpurm : rcp://[user@]host/filename Use rcp
2955 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002956 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02002957 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01002958 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002959 " rsyncurm : rsync://host[:port]/path Use rsync
2960 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
2961 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002962 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002963 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
2964 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02002965 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
2966 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002967 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002968 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02002969 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00002970 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002971 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02002972 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002973 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002974 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002975
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002976" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002977 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02002978 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002979 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002980" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00002981 let b:netrw_method = 1
2982 let userid = substitute(a:choice,rcpurm,'\1',"")
2983 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
2984 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002985 if userid != ""
2986 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00002987 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002988
Bram Moolenaaradc21822011-04-01 18:03:16 +02002989 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002990 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002991" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002992 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00002993 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
2994 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
2995 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002996
Bram Moolenaar15146672011-10-20 22:22:38 +02002997 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002998 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002999" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003000 let b:netrw_method = 5
3001 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3002 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003003 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003004
Bram Moolenaaradc21822011-04-01 18:03:16 +02003005 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003006 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003007" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003008 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003009 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003010 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3011 else
3012 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3013 endif
3014 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003015
Bram Moolenaaradc21822011-04-01 18:03:16 +02003016 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003017 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003018" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003019 let b:netrw_method = 7
3020 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3021 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003022
Bram Moolenaaradc21822011-04-01 18:03:16 +02003023 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003024 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003025" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003026 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003027 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3028 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3029 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003030" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003031 if userid != ""
3032 let g:netrw_uid= userid
3033 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003034
Bram Moolenaaradc21822011-04-01 18:03:16 +02003035 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003036 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003037 call NetUserPass("ftp:".g:netrw_machine)
3038 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003039 " if there's a change in hostname, require password re-entry
3040 unlet s:netrw_passwd
3041 endif
3042 if exists("netrw_port")
3043 unlet netrw_port
3044 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003045 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003046
Bram Moolenaar446cb832008-06-24 21:56:24 +00003047 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003048 let b:netrw_method = 3
3049 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003050 let host= substitute(g:netrw_machine,'\..*$','','')
3051 if exists("s:netrw_hup[host]")
3052 call NetUserPass("ftp:".host)
3053
Nir Lichtman1e34b952024-05-08 19:19:34 +02003054 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003055" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3056" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003057 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003058 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003059" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003060 endif
3061 let b:netrw_method= 2
3062 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003063" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003064 let b:netrw_method= 2
3065 else
3066 if !exists("g:netrw_uid") || g:netrw_uid == ""
3067 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003068 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003069 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003070 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003071 endif
3072 let b:netrw_method= 3
3073 endif
3074 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003075
Bram Moolenaaradc21822011-04-01 18:03:16 +02003076 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003077 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003078" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003079 let b:netrw_method = 8
3080 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3081 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3082 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3083 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003084
Bram Moolenaaradc21822011-04-01 18:03:16 +02003085 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003086 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003087" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003089 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3090 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003091 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003092 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003093 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003094
Bram Moolenaaradc21822011-04-01 18:03:16 +02003095 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003096 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003097" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003098 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003099 let b:netrw_method = 3
3100 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3101 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003102
Bram Moolenaar9964e462007-05-05 17:54:07 +00003103 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003104 let b:netrw_method = 2
3105 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3106 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3107 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003108
Bram Moolenaaradc21822011-04-01 18:03:16 +02003109 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003110 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003111" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003112 let b:netrw_method = 9
3113 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3114 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003115
Bram Moolenaaradc21822011-04-01 18:03:16 +02003116 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003117 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003118" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003119 let b:netrw_method = 1
3120 let userid = substitute(a:choice,rcphf,'\2',"")
3121 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3122 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003123" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3124" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3125" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3126" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003127 if userid != ""
3128 let g:netrw_uid= userid
3129 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003130
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003131 " Method#10: file://user@hostname/...path-to-file {{{3
3132 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003133" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003134 let b:netrw_method = 10
3135 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003136" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003137
Bram Moolenaaradc21822011-04-01 18:03:16 +02003138 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003139 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003140 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003141 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003142 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003143 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003145 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003146
Bram Moolenaar81695252004-12-29 20:58:21 +00003147 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003148 " remove any leading [:#] from port number
3149 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3150 elseif exists("netrw_port")
3151 " retain port number as implicit for subsequent ftp operations
3152 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003153 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003154
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003155" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3156" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3157" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3158" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003159" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003160" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003161" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003162" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003163" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003164" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003165" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003166" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003168
Bram Moolenaar9964e462007-05-05 17:54:07 +00003169" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003170" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003171" Usage: :call NetUserPass() -- will prompt for userid and password
3172" :call NetUserPass("uid") -- will prompt for password
3173" :call NetUserPass("uid","password") -- sets global userid and password
3174" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3175" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176fun! NetUserPass(...)
3177
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003178" call Dfunc("NetUserPass() a:0=".a:0)
3179
3180 if !exists('s:netrw_hup')
3181 let s:netrw_hup= {}
3182 endif
3183
Bram Moolenaar071d4272004-06-13 20:20:40 +00003184 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003185 " case: no input arguments
3186
3187 " change host and username if not previously entered; get new password
3188 if !exists("g:netrw_machine")
3189 let g:netrw_machine= input('Enter hostname: ')
3190 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003192 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003193 let g:netrw_uid= input('Enter username: ')
3194 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003195 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003196 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003197
3198 " set up hup database
3199 let host = substitute(g:netrw_machine,'\..*$','','')
3200 if !exists('s:netrw_hup[host]')
3201 let s:netrw_hup[host]= {}
3202 endif
3203 let s:netrw_hup[host].uid = g:netrw_uid
3204 let s:netrw_hup[host].passwd = s:netrw_passwd
3205
3206 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003207 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003208
3209 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003210 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003211 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003212" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003213 let host = substitute(a:1,'^ftp:','','')
3214 let host = substitute(host,'\..*','','')
3215 if exists("s:netrw_hup[host]")
3216 let g:netrw_uid = s:netrw_hup[host].uid
3217 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003218" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3219" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003220 else
3221 let g:netrw_uid = input("Enter UserId: ")
3222 let s:netrw_passwd = inputsecret("Enter Password: ")
3223 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003224
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003225 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003226 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003227" 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 +02003228 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003229 if g:netrw_machine =~ '[0-9.]\+'
3230 let host= g:netrw_machine
3231 else
3232 let host= substitute(g:netrw_machine,'\..*$','','')
3233 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003234 else
3235 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003236 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003237 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003238" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003239 if exists("g:netrw_passwd")
3240 " ask for password if one not previously entered
3241 let s:netrw_passwd= g:netrw_passwd
3242 else
3243 let s:netrw_passwd = inputsecret("Enter Password: ")
3244 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003245 endif
3246
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003247" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003248 if exists("host")
3249 if !exists('s:netrw_hup[host]')
3250 let s:netrw_hup[host]= {}
3251 endif
3252 let s:netrw_hup[host].uid = g:netrw_uid
3253 let s:netrw_hup[host].passwd = s:netrw_passwd
3254 endif
3255
3256 elseif a:0 == 2
3257 let g:netrw_uid = a:1
3258 let s:netrw_passwd = a:2
3259
3260 elseif a:0 == 3
3261 " enter hostname, user-id, and password into the hup dictionary
3262 let host = substitute(a:1,'^\a\+:','','')
3263 let host = substitute(host,'\..*$','','')
3264 if !exists('s:netrw_hup[host]')
3265 let s:netrw_hup[host]= {}
3266 endif
3267 let s:netrw_hup[host].uid = a:2
3268 let s:netrw_hup[host].passwd = a:3
3269 let g:netrw_uid = s:netrw_hup[host].uid
3270 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003271" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3272" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003273 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003274
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003275" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003276endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003277
Bram Moolenaar85850f32019-07-19 22:05:51 +02003278" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003279" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003280" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003281
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003282" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003283" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3284fun! s:ExplorePatHls(pattern)
3285" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3286 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003287" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003288 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003289" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003290 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3291" call Dret("s:ExplorePatHls repat<".repat.">")
3292 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003293endfun
3294
3295" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003296" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003297" 0: (user: <mb>) bookmark current directory
3298" 1: (user: <gb>) change to the bookmarked directory
3299" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003300" 3: (browsing) records current directory history
3301" 4: (user: <u>) go up (previous) directory, using history
3302" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003303" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003304fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003305" 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 +02003306 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3307" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3308 return
3309 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003310
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003311 let ykeep = @@
3312 let curbufnr = bufnr("%")
3313
Bram Moolenaar9964e462007-05-05 17:54:07 +00003314 if a:chg == 0
3315 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003316" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003317 if exists("s:netrwmarkfilelist_{curbufnr}")
3318 call s:NetrwBookmark(0)
3319 echo "bookmarked marked files"
3320 else
3321 call s:MakeBookmark(a:curdir)
3322 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003323 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003324
KSR-Yasudaf4498252023-10-06 03:34:17 +09003325 try
3326 call s:NetrwBookHistSave()
3327 catch
3328 endtry
3329
Bram Moolenaar9964e462007-05-05 17:54:07 +00003330 elseif a:chg == 1
3331 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003332" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003333 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003334" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003335 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003336 else
3337 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3338 endif
3339
3340 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003341" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003342 let didwork= 0
3343 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003344" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003345 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003346" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003347 let cnt= 1
3348 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003349" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003350 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003351 let didwork = 1
3352 let cnt = cnt + 1
3353 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003354 endif
3355
3356 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003357 " Note: history is saved only when PerformListing is done;
3358 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3359 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003360 let first = 1
3361 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003362 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003363 while ( first || cnt != g:netrw_dirhistcnt )
3364" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003365 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003366" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003367 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003368 let didwork= 1
3369 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003370 let histcnt = histcnt + 1
3371 let first = 0
3372 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003373 if cnt < 0
3374 let cnt= cnt + g:netrw_dirhistmax
3375 endif
3376 endwhile
3377 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003378 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003379 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003380 if didwork
3381 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3382 endif
3383
3384 elseif a:chg == 3
3385 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003386" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003387 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 +02003388 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003389 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3390 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003391 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003392" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003393 endif
3394
3395 elseif a:chg == 4
3396 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003397" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003398 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003399 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3400 if g:netrw_dirhistcnt < 0
3401 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003402 endif
3403 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003404 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003405 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003406 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3407" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003408 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003409 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003410" call Decho("setl ma noro",'~'.expand("<slnum>"))
3411 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003412 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003413" call Decho("setl nomod",'~'.expand("<slnum>"))
3414" 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 +00003415 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003416" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3417 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003418 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003419 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003420 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003421 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003422 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003423 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003424 echo "Sorry, no predecessor directory exists yet"
3425 endif
3426
3427 elseif a:chg == 5
3428 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003429" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003430 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003431 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3432 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3433" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003434 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003435" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003436 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003437 sil! NetrwKeepj %d _
3438" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3439" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003440 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003441" 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 +02003442 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003443" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3444 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003445 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003446 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3447 if g:netrw_dirhistcnt < 0
3448 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003449 endif
3450 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003451 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003452 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003453 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003454 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003455 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003456
3457 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003458" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003459 if exists("s:netrwmarkfilelist_{curbufnr}")
3460 call s:NetrwBookmark(1)
3461 echo "removed marked files from bookmarks"
3462 else
3463 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003464 let iremove = v:count
3465 let dremove = g:netrw_bookmarklist[iremove - 1]
3466" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003467 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003468" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3469 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3470 echo "removed ".dremove." from g:netrw_bookmarklist"
3471" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003472 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003473" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003474
3475 try
3476 call s:NetrwBookHistSave()
3477 catch
3478 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003479 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003480 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003481 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003482 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003483" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003484endfun
3485
3486" ---------------------------------------------------------------------
3487" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003488" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003489" Sister function: s:NetrwBookHistSave()
3490fun! s:NetrwBookHistRead()
3491" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003492 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003493" 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 +02003494 return
3495 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003496 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003497
3498 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003499 if !exists("s:netrw_initbookhist")
3500 let home = s:NetrwHome()
3501 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003502 if filereadable(s:NetrwFile(savefile))
3503" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003504 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003505 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003506
3507 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003508 if g:netrw_dirhistmax > 0
3509 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003510 if filereadable(s:NetrwFile(savefile))
3511" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003512 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003513 endif
3514 let s:netrw_initbookhist= 1
3515 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003516 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003517 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003518
Bram Moolenaar97d62492012-11-15 21:28:22 +01003519 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003520" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3521" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003522" call Dret("s:NetrwBookHistRead")
3523endfun
3524
3525" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003526" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003527" Sister function: s:NetrwBookHistRead()
3528" I used to do this via viminfo but that appears to
3529" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003530" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3531" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003532" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003533fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003534" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003535 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003536" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003537 return
3538 endif
3539
Bram Moolenaar5c736222010-01-06 20:54:52 +01003540 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003541" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003542 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003543
3544 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003545 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003546" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003547 if g:netrw_use_noswf
3548 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3549 else
3550 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3551 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003552 setl nocin noai noci magic nospell nohid wig= noaw
3553 setl ma noro write
3554 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003555 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003556
Bram Moolenaar85850f32019-07-19 22:05:51 +02003557 " rename enew'd file: .netrwhist -- no attempt to merge
3558 " record dirhistmax and current dirhistcnt
3559 " save history
3560" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003561 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003562 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003563 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3564 if g:netrw_dirhistmax > 0
3565 let lastline = line("$")
3566 let cnt = g:netrw_dirhistcnt
3567 let first = 1
3568 while ( first || cnt != g:netrw_dirhistcnt )
3569 let lastline= lastline + 1
3570 if exists("g:netrw_dirhist_{cnt}")
3571 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3572" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3573 endif
3574 let first = 0
3575 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3576 if cnt < 0
3577 let cnt= cnt + g:netrw_dirhistmax
3578 endif
3579 endwhile
3580 exe "sil! w! ".savefile
3581" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3582 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003583
Bram Moolenaar85850f32019-07-19 22:05:51 +02003584 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003585 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003586 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003587" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003588 " merge and write .netrwbook
3589 let savefile= s:NetrwHome()."/.netrwbook"
3590
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003591 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003592 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003593 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003594 for bdm in booklist
3595 if index(g:netrw_bookmarklist,bdm) == -1
3596 call add(g:netrw_bookmarklist,bdm)
3597 endif
3598 endfor
3599 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003600 endif
3601
3602 " construct and save .netrwbook
3603 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003604 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003605" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003606 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003607
3608 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003609 let bgone= bufnr("%")
3610 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003611 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003612
3613" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003614endfun
3615
3616" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003617" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3618" list of the contents of a local or remote directory. It is assumed that the
3619" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3620" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003621" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003622fun! s:NetrwBrowse(islocal,dirname)
3623 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaara6878372014-03-22 21:02:50 +01003624
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003625 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3626 " This is useful when one edits a local file, then :e ., then :Rex
3627 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3628 let w:netrw_rexfile= bufname("#")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003629 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003630
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003631 " s:NetrwBrowse : initialize history {{{3
3632 if !exists("s:netrw_initbookhist")
3633 NetrwKeepj call s:NetrwBookHistRead()
3634 endif
3635
3636 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003637 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003638 let dirname= simplify(a:dirname)
3639 else
3640 let dirname= a:dirname
3641 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003642
Bram Moolenaar85850f32019-07-19 22:05:51 +02003643 " repoint t:netrw_lexbufnr if appropriate
3644 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02003645 let repointlexbufnr= 1
3646 endif
3647
3648 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003649 if exists("s:netrw_skipbrowse")
3650 unlet s:netrw_skipbrowse
Bram Moolenaar446cb832008-06-24 21:56:24 +00003651 return
3652 endif
3653 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003654 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003655 return
3656 endif
3657 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003658 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003659 return
3660 endif
3661
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003662 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003663 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003664
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003665 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003666 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3667 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaar85850f32019-07-19 22:05:51 +02003668 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3669 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003670 endif
3671
3672 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003673 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003674 if s:NetrwLcd(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003675 return
3676 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003677
Bram Moolenaar5c736222010-01-06 20:54:52 +01003678 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003679 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003680 if bufname(dirname) != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003681 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003682 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003683 " attempt transfer of remote regular file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003684
3685 " remove any filetype indicator from end of dirname, except for the
3686 " "this is a directory" indicator (/).
3687 " There shouldn't be one of those here, anyway.
3688 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003689 call s:RemotePathAnalysis(dirname)
3690
3691 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3692 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003693 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003694 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003695 let b:netrw_curdir = dirname
3696 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003697 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003698 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3699 sil call netrw#NetRead(2,url)
3700 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003701 if s:path =~ '.bz2'
3702 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3703 elseif s:path =~ '.gz'
3704 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3705 elseif s:path =~ '.gz'
3706 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3707 else
3708 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3709 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003710 endif
3711
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003712 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003713 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003714 call s:NetrwOptionsRestore("w:")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003715 setl ma nomod noro
Bram Moolenaar446cb832008-06-24 21:56:24 +00003716 return
3717 endif
3718
Bram Moolenaaradc21822011-04-01 18:03:16 +02003719 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003720 call s:UseBufWinVars()
3721
3722 " set up some variables {{{3
3723 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003724 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003725 let s:last_sort_by = g:netrw_sort_by
3726
3727 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003728 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003729
Bram Moolenaar97d62492012-11-15 21:28:22 +01003730 " get/set-up buffer {{{3
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003731 let svpos = winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01003732
3733 " NetrwGetBuffer might change buffers but s:rexposn_X was set for the
3734 " previous buffer
3735 let prevbufnr = bufnr('%')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003736 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Tom Benham64a536d2024-11-07 21:15:03 +01003737 if exists("s:rexposn_".prevbufnr)
3738 let s:rexposn_{bufnr('%')} = s:rexposn_{prevbufnr}
3739 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003740
Bram Moolenaar446cb832008-06-24 21:56:24 +00003741 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003742 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3743 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02003744 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3745 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003746 2match none
3747 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003748 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003749 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003750 call s:NetrwOptionsRestore("w:")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003751 setl noma nomod nowrap
Bram Moolenaar446cb832008-06-24 21:56:24 +00003752 return
3753 endif
3754
3755 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003756 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003757 if b:netrw_curdir =~ '[/\\]$'
3758 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3759 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003760 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003761 let b:netrw_curdir= b:netrw_curdir."/"
3762 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003763 if b:netrw_curdir == ''
3764 if has("amiga")
3765 " On the Amiga, the empty string connotes the current directory
3766 let b:netrw_curdir= getcwd()
3767 else
3768 " under unix, when the root directory is encountered, the result
3769 " from the preceding substitute is an empty string.
3770 let b:netrw_curdir= '/'
3771 endif
3772 endif
3773 if !a:islocal && b:netrw_curdir !~ '/$'
3774 let b:netrw_curdir= b:netrw_curdir.'/'
3775 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003776
3777 " ------------
3778 " (local only) {{{3
3779 " ------------
3780 if a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00003781 " Set up ShellCmdPost handling. Append current buffer to browselist
3782 call s:LocalFastBrowser()
3783
3784 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3785 if !g:netrw_keepdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003786 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003787 if s:NetrwLcd(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003788 return
3789 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003790 endif
3791 endif
3792
3793 " --------------------------------
3794 " remote handling: {{{3
3795 " --------------------------------
3796 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00003797
Bram Moolenaar97d62492012-11-15 21:28:22 +01003798 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003799 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003800 let dirname= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003801 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3802 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3803 if dirname !~ '/$'
3804 let dirname= dirname.'/'
3805 endif
3806 let b:netrw_curdir = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003807 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003808 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003809 endif
3810
3811 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
3812 if dirname !~ dirpat
3813 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003814 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003815 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003816 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003817 setl noma nomod nowrap
Bram Moolenaar446cb832008-06-24 21:56:24 +00003818 return
3819 endif
3820 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003821 endif " (additional remote handling)
3822
Bram Moolenaar85850f32019-07-19 22:05:51 +02003823 " -------------------------------
3824 " Perform Directory Listing: {{{3
3825 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003826 NetrwKeepj call s:NetrwMaps(a:islocal)
3827 NetrwKeepj call s:NetrwCommands(a:islocal)
3828 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003829
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003830 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003831 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003832
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003833 " If there is a rexposn: restore position with rexposn
3834 " Otherwise : set rexposn
3835 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003836 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
3837 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
3838 NetrwKeepj exe w:netrw_bannercnt
3839 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003840 else
3841 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
3842 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02003843 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01003844 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara6878372014-03-22 21:02:50 +01003845 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02003846 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003847
Bram Moolenaar85850f32019-07-19 22:05:51 +02003848 " repoint t:netrw_lexbufnr if appropriate
3849 if exists("repointlexbufnr")
3850 let t:netrw_lexbufnr= bufnr("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02003851 endif
3852
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003853 " restore position
3854 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003855 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003856 endif
3857
Bram Moolenaara6878372014-03-22 21:02:50 +01003858 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003859 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
3860 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaar446cb832008-06-24 21:56:24 +00003861 return
3862endfun
3863
3864" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003865" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
3866" may not apply correctly; ie. netrw's idea of the current directory may
3867" differ from vim's. This function insures that netrw's idea of the current
3868" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003869" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003870fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003871" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
3872" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
3873" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
3874" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
3875" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003876
3877 " clean up any leading treedepthstring
3878 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
3879 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02003880" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003881 else
3882 let fname= a:fname
3883 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003884
3885 if g:netrw_keepdir
3886 " vim's idea of the current directory possibly may differ from netrw's
3887 if !exists("b:netrw_curdir")
3888 let b:netrw_curdir= getcwd()
3889 endif
3890
Nir Lichtman1e34b952024-05-08 19:19:34 +02003891 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003892 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003893 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003894 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003895" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003896 else
3897 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003898 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003899" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003900 endif
3901
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003902 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003903 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003904 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003905" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003906 else
3907 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003908 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003909" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003910 endif
3911 else
3912 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003913 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003914" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
3915" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
3916" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003917 endif
3918
Bram Moolenaar85850f32019-07-19 22:05:51 +02003919" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003920 return ret
3921endfun
3922
3923" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003924" s:NetrwFileInfo: supports qf (query for file information) {{{2
3925fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01003926" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01003927 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00003928 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003929 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003930 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003931 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003932 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003933 let lsopt= "-lsadh --si"
3934 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02003935" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003936 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003937
3938 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003939 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003940" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003941
Bram Moolenaara6878372014-03-22 21:02:50 +01003942 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003943 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003944" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003945
3946 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003947 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003948" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003949
Bram Moolenaar446cb832008-06-24 21:56:24 +00003950 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003951" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003952 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003953" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003954 endif
3955 else
3956 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003957" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
3958 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003959 let fname= substitute(a:fname,".$","","")
3960 else
3961 let fname= a:fname
3962 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003963 let t = getftime(s:NetrwFile(fname))
3964 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003965 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003966 let sz= s:NetrwHumanReadable(sz)
3967 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003968 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
3969" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003970 endif
3971 else
3972 echo "sorry, \"qf\" not supported yet for remote files"
3973 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003974 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00003975" call Dret("s:NetrwFileInfo")
3976endfun
3977
3978" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003979" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
3980fun! s:NetrwFullPath(filename)
3981" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
3982 let filename= a:filename
3983 if filename !~ '^/'
3984 let filename= resolve(getcwd().'/'.filename)
3985 endif
3986 if filename != "/" && filename =~ '/$'
3987 let filename= substitute(filename,'/$','','')
3988 endif
3989" " call Dret("s:NetrwFullPath <".filename.">")
3990 return filename
3991endfun
3992
3993" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003994" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003995" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003996" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02003997" 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 +00003998fun! s:NetrwGetBuffer(islocal,dirname)
3999" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004000" 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 +02004001" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4002" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004003 let dirname= a:dirname
4004
4005 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004006" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004007 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004008" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004009 let s:netrwbuf= {}
4010 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004011" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4012" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4013
4014 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4015 let bufnum = -1
4016
4017 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4018 if has_key(s:netrwbuf,"NetrwTreeListing")
4019 let bufnum= s:netrwbuf["NetrwTreeListing"]
4020 else
4021 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4022 endif
4023" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4024 if !bufexists(bufnum)
Peter Aronoffbe551da2024-09-22 11:29:40 +02004025 call remove(s:netrwbuf,"NetrwTreeListing")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004026 let bufnum= -1
4027 endif
4028 elseif bufnr("NetrwTreeListing") != -1
4029 let bufnum= bufnr("NetrwTreeListing")
4030" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4031 else
4032" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4033 let bufnum= -1
4034 endif
4035
4036 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004037 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004038" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004039 if !bufexists(bufnum)
4040 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4041 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004042 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004043
Bram Moolenaar446cb832008-06-24 21:56:24 +00004044 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004045" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004046 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004047 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004048" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4049
Bram Moolenaar71badf92023-04-22 22:40:14 +01004050 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004051 " IF the buffer already has the desired name
4052 " AND it is empty
4053 let curbuf = bufname("%")
4054 if curbuf == '.'
4055 let curbuf = getcwd()
4056 endif
4057" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004058" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004059" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4060" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4061" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4062" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4063 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004064" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4065 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004066 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004067" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004068 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004069 " 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 +00004070
4071 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004072 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004073" 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 +00004074 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004075" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004076 " name the buffer
4077 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4078 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004079" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004080 let w:netrw_treebufnr = bufnr("%")
4081 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004082 if g:netrw_use_noswf
4083 setl nobl bt=nofile noswf
4084 else
4085 setl nobl bt=nofile
4086 endif
4087 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4088 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4089 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4090 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004091" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004092 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004093 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004094 " enter the new buffer into the s:netrwbuf dictionary
4095 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4096" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4097" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004098 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004099" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004100
4101 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004102" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004103 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004104 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004105 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004106
4107 if &ft == "netrw"
4108" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4109 exe "sil! NetrwKeepj noswapfile b ".bufnum
4110" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004111 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004112" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4113 call s:NetrwEditBuf(bufnum)
4114" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004115 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004116" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004117 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004118 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004119 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004120
4121 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004122 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004123
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004124 if line("$") <= 1 && getline(1) == ""
4125 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004126 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004127" 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>"))
4128" 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 +01004129" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4130 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004131
Bram Moolenaar97d62492012-11-15 21:28:22 +01004132 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004133" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004134 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004135 sil NetrwKeepj %d _
4136" 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>"))
4137" 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 +01004138" 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 +00004139 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004140
Bram Moolenaar446cb832008-06-24 21:56:24 +00004141 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004142" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4143" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004144 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004145 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004146 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004147" 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>"))
4148" 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 +01004149" 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 +00004150 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004151
Bram Moolenaar446cb832008-06-24 21:56:24 +00004152 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004153" 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>"))
4154" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4155" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004156 return 1
4157 endif
4158 endif
4159
4160 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4161 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4162 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4163 " med 1 D H
4164 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004165" 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 +00004166 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004167 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004168 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004169
4170 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004171" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4172" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4173 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004174
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004175" 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>"))
4176" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4177" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004178 return 0
4179endfun
4180
4181" ---------------------------------------------------------------------
4182" s:NetrwGetcwd: get the current directory. {{{2
4183" Change backslashes to forward slashes, if any.
4184" If doesc is true, escape certain troublesome characters
4185fun! s:NetrwGetcwd(doesc)
4186" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4187 let curdir= substitute(getcwd(),'\\','/','ge')
4188 if curdir !~ '[\/]$'
4189 let curdir= curdir.'/'
4190 endif
4191 if a:doesc
4192 let curdir= fnameescape(curdir)
4193 endif
4194" call Dret("NetrwGetcwd <".curdir.">")
4195 return curdir
4196endfun
4197
4198" ---------------------------------------------------------------------
4199" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4200fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004201" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4202" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4203 let keepsol= &l:sol
4204 setl nosol
4205
Bram Moolenaar446cb832008-06-24 21:56:24 +00004206 call s:UseBufWinVars()
4207
4208 " insure that w:netrw_liststyle is set up
4209 if !exists("w:netrw_liststyle")
4210 if exists("g:netrw_liststyle")
4211 let w:netrw_liststyle= g:netrw_liststyle
4212 else
4213 let w:netrw_liststyle= s:THINLIST
4214 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004215" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004216 endif
4217
4218 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4219 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004220" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004221 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004222 let dirname= "./"
4223 let curline= getline('.')
4224
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004225 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004226 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004227 let s:netrw_skipbrowse= 1
4228 echo 'Pressing "s" also works'
4229
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004230 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004231 let s:netrw_skipbrowse= 1
4232 echo 'Press "S" to edit sorting sequence'
4233
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004234 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004235 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004236 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004237
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004238 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004239 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004240 let s:netrw_skipbrowse= 1
4241 echo 'Pressing "a" also works'
4242
4243 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004244 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004245 endif
4246
4247 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004248" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004249 NetrwKeepj norm! 0
4250 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004251
4252 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004253" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004254 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004255 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4256
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004257 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004258" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004259 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004260 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004261
4262 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004263" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004264 let dirname= getline('.')
4265
4266 if !exists("b:netrw_cpf")
4267 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004268 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 +01004269 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004270" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004271 endif
4272
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004273" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004274 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004275" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4276" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004277 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004278 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004279 else
4280 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004281 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004282 endif
Enno3146d632024-07-04 19:44:42 +02004283
4284 let dict={}
4285 " save the unnamed register and register 0-9 and a
4286 let dict.a=[getreg('a'), getregtype('a')]
4287 for i in range(0, 9)
4288 let dict[i] = [getreg(i), getregtype(i)]
4289 endfor
4290 let dict.unnamed = [getreg(''), getregtype('')]
4291
Bram Moolenaarc236c162008-07-13 17:41:49 +00004292 let eofname= filestart + b:netrw_cpf + 1
4293 if eofname <= col("$")
4294 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004295 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004296 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004297 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004298 endif
Enno3146d632024-07-04 19:44:42 +02004299
Bram Moolenaar446cb832008-06-24 21:56:24 +00004300 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004301 call s:RestoreRegister(dict)
4302
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004303" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004304 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004305" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004306 endif
4307
4308 " symlinks are indicated by a trailing "@". Remove it before further processing.
4309 let dirname= substitute(dirname,"@$","","")
4310
4311 " executables are indicated by a trailing "*". Remove it before further processing.
4312 let dirname= substitute(dirname,"\*$","","")
4313
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004314 let &l:sol= keepsol
4315
Bram Moolenaar446cb832008-06-24 21:56:24 +00004316" call Dret("s:NetrwGetWord <".dirname.">")
4317 return dirname
4318endfun
4319
4320" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004321" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4322" g:netrw_bufsettings will be used after the listing is produced.
4323" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004324fun! s:NetrwListSettings(islocal)
4325" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004326" 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 +00004327 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004328" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4329 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4330 setl bt=nofile nobl ma nonu nowrap noro nornu
4331 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004332 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004333 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004334 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004335" call Dredir("ls!","s:NetrwListSettings")
4336" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004337 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004338 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004339 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004340 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004341 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004342 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004343 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004344" 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 +00004345" call Dret("s:NetrwListSettings")
4346endfun
4347
4348" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004349" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004350" islocal=0: remote browsing
4351" =1: local browsing
4352fun! s:NetrwListStyle(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004353 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004354 let fname = s:NetrwGetWord()
4355 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004356 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004357 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00004358
Bram Moolenaar85850f32019-07-19 22:05:51 +02004359 " repoint t:netrw_lexbufnr if appropriate
4360 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02004361 let repointlexbufnr= 1
4362 endif
4363
Bram Moolenaar446cb832008-06-24 21:56:24 +00004364 if w:netrw_liststyle == s:THINLIST
4365 " use one column listing
Bram Moolenaar446cb832008-06-24 21:56:24 +00004366 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4367
4368 elseif w:netrw_liststyle == s:LONGLIST
4369 " use long list
Bram Moolenaar446cb832008-06-24 21:56:24 +00004370 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4371
4372 elseif w:netrw_liststyle == s:WIDELIST
4373 " give wide list
Bram Moolenaar446cb832008-06-24 21:56:24 +00004374 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4375
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004376 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00004377 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4378
4379 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004380 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004381 let g:netrw_liststyle = s:THINLIST
4382 let w:netrw_liststyle = g:netrw_liststyle
4383 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4384 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004385 setl ma noro
Bram Moolenaar446cb832008-06-24 21:56:24 +00004386
4387 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004388 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004389 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004390 setl nomod
Bram Moolenaar446cb832008-06-24 21:56:24 +00004391
4392 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01004393 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004394 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004395
Bram Moolenaar85850f32019-07-19 22:05:51 +02004396 " repoint t:netrw_lexbufnr if appropriate
4397 if exists("repointlexbufnr")
4398 let t:netrw_lexbufnr= bufnr("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004399 endif
4400
Bram Moolenaar13600302014-05-22 18:26:40 +02004401 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004402" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4403 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004404 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004405
Bram Moolenaar446cb832008-06-24 21:56:24 +00004406endfun
4407
4408" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004409" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4410fun! s:NetrwBannerCtrl(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004411 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004412 " toggle the banner (enable/suppress)
4413 let g:netrw_banner= !g:netrw_banner
4414
4415 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004416 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01004417 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004418
4419 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004420 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4421 let fname= s:NetrwGetWord()
4422 sil NetrwKeepj $
4423 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4424" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4425 if result <= 0 && exists("w:netrw_bannercnt")
4426 exe "NetrwKeepj ".w:netrw_bannercnt
4427 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004428 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004429 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004430" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4431endfun
4432
4433" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004434" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4435"
4436" No bang: enters files/directories into Netrw's bookmark system
4437" No argument and in netrw buffer:
4438" if there are marked files: bookmark marked files
4439" otherwise : bookmark file/directory under cursor
4440" No argument and not in netrw buffer: bookmarks current open file
4441" Has arguments: globs them individually and bookmarks them
4442"
4443" With bang: deletes files/directories from Netrw's bookmark system
4444fun! s:NetrwBookmark(del,...)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004445 if a:0 == 0
4446 if &ft == "netrw"
4447 let curbufnr = bufnr("%")
4448
4449 if exists("s:netrwmarkfilelist_{curbufnr}")
4450 " for every filename in the marked list
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004451 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004452 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004453 for fname in s:netrwmarkfilelist_{curbufnr}
4454 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4455 endfor
4456 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4457 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01004458 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004459 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004460 else
4461 let fname= s:NetrwGetWord()
4462 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4463 endif
4464
4465 else
4466 " bookmark currently open file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004467 let fname= expand("%")
4468 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4469 endif
4470
4471 else
4472 " bookmark specified files
4473 " attempts to infer if working remote or local
4474 " by deciding if the current file begins with an url
4475 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004476 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004477 let i = 1
4478 while i <= a:0
4479 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004480 if v:version > 704 || (v:version == 704 && has("patch656"))
4481 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004482 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004483 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004484 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004485 else
4486 let mbfiles= [a:{i}]
4487 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004488 for mbfile in mbfiles
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004489 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4490 endfor
4491 let i= i + 1
4492 endwhile
4493 endif
4494
4495 " update the menu
4496 call s:NetrwBookmarkMenu()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004497endfun
4498
4499" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004500" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4501" .2.[cnt] for bookmarks, and
4502" .3.[cnt] for history
4503" (see s:NetrwMenu())
4504fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004505 if !exists("s:netrw_menucnt")
4506 return
4507 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004508" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004509
4510 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004511 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004512 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004513" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004514 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4515 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004516 endif
4517 if !exists("s:netrw_initbookhist")
4518 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004519 endif
4520
4521 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004522 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004523 let cnt= 1
4524 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004525" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004526 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004527
4528 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004529 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004530
4531 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004532 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 +01004533 let cnt= cnt + 1
4534 endfor
4535
4536 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004537
4538 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004539 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004540 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004541 let first = 1
4542 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004543 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004544 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004545 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004546 if exists("g:netrw_dirhist_{cnt}")
4547 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004548" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004549 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4550 endif
4551 let first = 0
4552 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4553 if cnt < 0
4554 let cnt= cnt + g:netrw_dirhistmax
4555 endif
4556 endwhile
4557 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004558
Bram Moolenaar9964e462007-05-05 17:54:07 +00004559 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004560" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004561endfun
4562
4563" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004564" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4565" directory and a new directory name. Also, if the
4566" "new directory name" is actually a file,
4567" NetrwBrowseChgDir() edits the file.
Tom Benham64a536d2024-11-07 21:15:03 +01004568" cursor=0: newdir is relative to b:netrw_curdir
4569" =1: newdir is relative to the path to the word under the cursor in
4570" tree view
4571fun! s:NetrwBrowseChgDir(islocal,newdir,cursor,...)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004572 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004573 if !exists("b:netrw_curdir")
4574 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4575 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004576 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004577 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004578 endif
4579
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004580 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02004581 call s:SavePosn(s:netrw_posn)
4582 NetrwKeepj call s:NetrwOptionsSave("s:")
4583 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Tom Benham64a536d2024-11-07 21:15:03 +01004584
4585 let newdir = a:newdir
4586 if a:cursor && exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treetop")
4587 " dirname is the path to the word under the cursor
4588 let dirname = s:NetrwTreePath(w:netrw_treetop)
Christian Brabandt5b63b232024-11-10 20:22:34 +01004589 " newdir resolves to a directory and points to a directory in dirname
4590 " /tmp/test/folder_symlink/ -> /tmp/test/original_folder/
4591 if a:islocal && fnamemodify(dirname, ':t') == newdir && isdirectory(resolve(dirname)) && resolve(dirname) == resolve(newdir)
4592 let dirname = fnamemodify(resolve(dirname), ':p:h:h')
4593 let newdir = fnamemodify(resolve(newdir), ':t')
4594 endif
Tom Benham64a536d2024-11-07 21:15:03 +01004595 " Remove trailing "/"
4596 let dirname = substitute(dirname, "/$", "", "")
4597
4598 " If the word under the cursor is a directory (except for ../), NetrwTreePath
4599 " returns the full path, including the word under the cursor, remove it
4600 if newdir =~ "/$" && newdir != "../"
4601 let dirname = fnamemodify(dirname, ":h")
4602 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004603 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004604 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004605 endif
Tom Benham64a536d2024-11-07 21:15:03 +01004606 if has("win32")
4607 let dirname = substitute(dirname,'\\','/','ge')
4608 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004609 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004610 let dorestore = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01004611
4612 " ignore <cr>s when done in the banner
4613 if g:netrw_banner
Bram Moolenaara6878372014-03-22 21:02:50 +01004614 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004615 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +01004616 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaar13600302014-05-22 18:26:40 +02004617 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004618 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004619 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004620 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara6878372014-03-22 21:02:50 +01004621 endif
4622 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004623 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004624
Bram Moolenaar446cb832008-06-24 21:56:24 +00004625 " set up o/s-dependent directory recognition pattern
4626 if has("amiga")
4627 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004628 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004629 let dirpat= '[\/]$'
4630 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004631
4632 if dirname !~ dirpat
4633 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004634 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004635 let dirname= dirname.'/'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004636 endif
4637
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004638 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004639 " ------------------------------
4640 " NetrwBrowseChgDir: edit a file {{{3
4641 " ------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004642
Bram Moolenaar97d62492012-11-15 21:28:22 +01004643 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004644 let s:rexposn_{bufnr("%")}= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01004645
Bram Moolenaar446cb832008-06-24 21:56:24 +00004646 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004647 if dirname =~ '/$'
4648 let dirname= dirname.newdir
4649 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004650 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004651 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004652 elseif newdir =~ '^\(/\|\a:\)'
4653 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004654 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004655 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004656 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004657 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004658 if a:0 < 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004659 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004660 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004661 if !exists("s:didsplit")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004662 if type(g:netrw_browse_split) == 3
4663 " open file in server
4664 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004665 call s:NetrwServerEdit(a:islocal,dirname)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004666 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004667
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004668 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004669 " horizontally splitting the window first
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004670 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4671 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004672 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004673 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004674 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004675 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004676
Bram Moolenaar446cb832008-06-24 21:56:24 +00004677 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004678 " vertically splitting the window first
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004679 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4680 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004681 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004682 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004683 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004684 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004685
Bram Moolenaar446cb832008-06-24 21:56:24 +00004686 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004687 " open file in new tab
Bram Moolenaarff034192013-04-24 18:51:19 +02004688 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004689 if !exists("b:netrw_curdir")
4690 let b:netrw_curdir= getcwd()
4691 endif
4692 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004693
Bram Moolenaar446cb832008-06-24 21:56:24 +00004694 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004695 " act like "P" (ie. open previous window)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004696 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004697 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004698 return
4699 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004700 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004701
Bram Moolenaar9964e462007-05-05 17:54:07 +00004702 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004703 " handling a file, didn't split, so remove menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00004704 call s:NetrwMenu(0)
4705 " optional change to window
4706 if g:netrw_chgwin >= 1
Bram Moolenaar13600302014-05-22 18:26:40 +02004707 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004708 " if g:netrw_chgwin is set to one more than the last window, then
4709 " vertically split the last window to make that window available.
4710 let curwin= winnr()
4711 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4712 vs
4713 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004714 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004715 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004716 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004717 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004718 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004719
Bram Moolenaar9964e462007-05-05 17:54:07 +00004720 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004721
Bram Moolenaar446cb832008-06-24 21:56:24 +00004722 " the point where netrw actually edits the (local) file
4723 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004724 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004725 if !&mod
4726 " if e the new file would fail due to &mod, then don't change any of the flags
4727 let dolockout= 1
4728 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004729 if a:islocal
Bram Moolenaar8d043172014-01-23 14:24:41 +01004730 " some like c-^ to return to the last edited file
4731 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004732 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4733 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01004734 call s:NetrwEditFile("e","",dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004735 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02004736 if &hidden || &bufhidden == "hide"
4737 " file came from vim's hidden storage. Don't "restore" options with it.
4738 let dorestore= 0
4739 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004740 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00004741 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004742
4743 " handle g:Netrw_funcref -- call external-to-netrw functions
4744 " This code will handle g:Netrw_funcref as an individual function reference
4745 " or as a list of function references. It will ignore anything that's not
4746 " a function reference. See :help Funcref for information about function references.
4747 if exists("g:Netrw_funcref")
4748 if type(g:Netrw_funcref) == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004749 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004750 elseif type(g:Netrw_funcref) == 3
4751 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004752 if type(Fncref) == 2
4753 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004754 endif
4755 endfor
4756 endif
4757 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004758 endif
4759
4760 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004761 " ----------------------------------------------------
4762 " NetrwBrowseChgDir: just go to the new directory spec {{{3
4763 " ----------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004764 let dirname = newdir
4765 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004766 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004767 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004768
4769 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004770 " ---------------------------------------------
4771 " NetrwBrowseChgDir: refresh the directory list {{{3
4772 " ---------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004773 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004774 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004775
4776 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004777 " --------------------------------------
4778 " NetrwBrowseChgDir: go up one directory {{{3
4779 " --------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004780
4781 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
4782 " force a refresh
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004783 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004784 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004785 endif
4786
4787 if has("amiga")
4788 " amiga
Bram Moolenaar446cb832008-06-24 21:56:24 +00004789 if a:islocal
4790 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
4791 let dirname= substitute(dirname,'/$','','')
4792 else
4793 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
4794 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004795
Nir Lichtman1e34b952024-05-08 19:19:34 +02004796 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004797 " windows
4798 if a:islocal
4799 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4800 if dirname == ""
4801 let dirname= '/'
4802 endif
4803 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004804 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01004805 endif
4806 if dirname =~ '^\a:$'
4807 let dirname= dirname.'/'
4808 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01004809
Bram Moolenaar446cb832008-06-24 21:56:24 +00004810 else
4811 " unix or cygwin
Bram Moolenaar446cb832008-06-24 21:56:24 +00004812 if a:islocal
4813 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4814 if dirname == ""
4815 let dirname= '/'
4816 endif
4817 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004818 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004819 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004820 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004821 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004822 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004823
4824 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004825 " --------------------------------------
4826 " NetrwBrowseChgDir: Handle Tree Listing {{{3
4827 " --------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004828 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004829 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004830 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004831 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004832 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004833 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004834 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004835 let haskey = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004836
4837 " search treedict for tree dir as-is
4838 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004839 let haskey= 1
4840 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004841 endif
4842
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004843 " search treedict for treedir with a [/@] appended
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004844 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004845 if has_key(w:netrw_treedict,treedir."/")
4846 let treedir= treedir."/"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004847 let haskey = 1
4848 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004849 endif
4850 endif
4851
4852 " search treedict for treedir with any trailing / elided
4853 if !haskey && treedir =~ '/$'
4854 let treedir= substitute(treedir,'/$','','')
4855 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004856 let haskey = 1
4857 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004858 endif
4859 endif
4860
4861 if haskey
4862 " close tree listing for selected subdirectory
Bram Moolenaar446cb832008-06-24 21:56:24 +00004863 call remove(w:netrw_treedict,treedir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004864 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00004865 else
4866 " go down one directory
4867 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004868 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004869 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004870 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004871
4872 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01004873 " ----------------------------------------
4874 " NetrwBrowseChgDir: Go down one directory {{{3
4875 " ----------------------------------------
4876 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004877 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004878 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00004879 endif
4880
Bram Moolenaar97d62492012-11-15 21:28:22 +01004881 " --------------------------------------
4882 " NetrwBrowseChgDir: Restore and Cleanup {{{3
4883 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02004884 if dorestore
4885 " dorestore is zero'd when a local file was hidden or bufhidden;
4886 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004887 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02004888 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02004889 if dolockout && dorestore
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004890 if filewritable(dirname)
Bram Moolenaar13600302014-05-22 18:26:40 +02004891 setl ma noro nomod
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004892 else
Bram Moolenaar13600302014-05-22 18:26:40 +02004893 setl ma ro nomod
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004894 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004895 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004896 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004897 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004898
Bram Moolenaar446cb832008-06-24 21:56:24 +00004899 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00004900endfun
4901
4902" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004903" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
4904" for thin, long, and wide: cursor placed just after banner
4905" for tree, keeps cursor on current filename
4906fun! s:NetrwBrowseUpDir(islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004907 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
4908 " this test needed because occasionally this function seems to be incorrectly called
4909 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004910 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004911 " directories.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004912 return
4913 endif
4914
Bram Moolenaara6878372014-03-22 21:02:50 +01004915 norm! 0
4916 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara6878372014-03-22 21:02:50 +01004917 let curline= getline(".")
4918 let swwline= winline() - 1
4919 if exists("w:netrw_treetop")
4920 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02004921 elseif exists("b:netrw_curdir")
4922 let w:netrw_treetop= b:netrw_curdir
4923 else
4924 let w:netrw_treetop= getcwd()
4925 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01004926 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004927 let curfile = getline(".")
4928 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01004929 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01004930 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004931 else
Tom Benham64a536d2024-11-07 21:15:03 +01004932 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004933 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004934 if w:netrw_treetop == '/'
4935 keepj call search('^\M'.curfile,"w")
4936 elseif curfile == '../'
4937 keepj call search('^\M'.curfile,"wb")
4938 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004939 while 1
4940 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
4941 let treepath= s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004942 if treepath == curpath
4943 break
4944 endif
4945 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01004946 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004947
Bram Moolenaara6878372014-03-22 21:02:50 +01004948 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004949 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004950 if exists("b:netrw_curdir")
4951 let curdir= b:netrw_curdir
4952 else
4953 let curdir= expand(getcwd())
4954 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004955 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01004956 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004957 else
Tom Benham64a536d2024-11-07 21:15:03 +01004958 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004959 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004960 call s:RestorePosn(s:netrw_posn)
4961 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01004962 let curdir= '\<'. escape(curdir, '~'). '/'
4963 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01004964 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004965endfun
4966
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01004967func s:redir()
4968 " set up redirection (avoids browser messages)
4969 " by default if not set, g:netrw_suppress_gx_mesg is true
4970 if get(g:, 'netrw_suppress_gx_mesg', 1)
4971 if &srr =~# "%s"
4972 return printf(&srr, has("win32") ? "nul" : "/dev/null")
4973 else
4974 return &srr .. (has("win32") ? "nul" : "/dev/null")
4975 endif
4976 endif
4977 return ''
4978endfunc
4979
4980if has('unix')
4981 if has('win32unix')
4982 " Cygwin provides cygstart
4983 if executable('cygstart')
4984 fun! netrw#Launch(args)
4985 exe 'silent ! cygstart --hide' a:args s:redir() | redraw!
4986 endfun
4987 elseif !empty($MSYSTEM) && executable('start')
4988 " MSYS2/Git Bash comes by default without cygstart; see
4989 " https://www.msys2.org/wiki/How-does-MSYS2-differ-from-Cygwin
4990 " Instead it provides /usr/bin/start script running `cmd.exe //c start`
4991 " Adding "" //b` sets void title, hides cmd window and blocks path conversion
4992 " of /b to \b\ " by MSYS2; see https://www.msys2.org/docs/filesystem-paths/
4993 fun! netrw#Launch(args)
4994 exe 'silent !start "" //b' a:args s:redir() | redraw!
4995 endfun
4996 else
4997 " imitate /usr/bin/start script for other environments and hope for the best
4998 fun! netrw#Launch(args)
4999 exe 'silent !cmd //c start "" //b' a:args s:redir() | redraw!
5000 endfun
5001 endif
5002 elseif exists('$WSL_DISTRO_NAME') " use cmd.exe to start GUI apps in WSL
5003 fun! netrw#Launch(args)
5004 let args = a:args
5005 exe 'silent !' ..
5006 \ ((args =~? '\v<\f+\.(exe|com|bat|cmd)>') ?
5007 \ 'cmd.exe /c start "" /b ' .. args :
5008 \ 'nohup ' .. args .. ' ' .. s:redir() .. ' &')
5009 \ | redraw!
5010 endfun
5011 else
5012 fun! netrw#Launch(args)
5013 exe ':silent ! nohup' a:args s:redir() '&' | redraw!
5014 endfun
5015 endif
5016elseif has('win32')
5017 fun! netrw#Launch(args)
5018 exe 'silent !' .. (&shell =~? '\<cmd\.exe\>' ? '' : 'cmd.exe /c')
5019 \ 'start "" /b' a:args s:redir() | redraw!
5020 endfun
5021else
5022 fun! netrw#Launch(dummy)
5023 echom 'No common launcher found'
5024 endfun
5025endif
5026
5027" Git Bash
5028if has('win32unix')
5029 " (cyg)start suffices
5030 let s:os_viewer = ''
5031" Windows / WSL
5032elseif executable('explorer.exe')
5033 let s:os_viewer = 'explorer.exe'
5034" Linux / BSD
5035elseif executable('xdg-open')
5036 let s:os_viewer = 'xdg-open'
5037" MacOS
5038elseif executable('open')
5039 let s:os_viewer = 'open'
5040endif
5041
5042fun! s:viewer()
5043 if exists('g:netrw_browsex_viewer') && executable(g:netrw_browsex_viewer)
5044 " extract any viewing options. Assumes that they're set apart by spaces.
5045 " call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
5046 if g:netrw_browsex_viewer =~ '\s'
5047 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5048 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5049 let oviewer = ''
5050 let cnt = 1
5051 while !executable(viewer) && viewer != oviewer
5052 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5053 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5054 let cnt = cnt + 1
5055 let oviewer = viewer
5056 " call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
5057 endwhile
5058 else
5059 let viewer = g:netrw_browsex_viewer
5060 let viewopt = ""
5061 endif
5062 " call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
5063 return viewer .. ' ' .. viewopt
5064 else
5065 if !exists('s:os_viewer')
5066 call netrw#ErrorMsg(s:ERROR,"No program to open this path found. See :help Open for more information.",106)
5067 else
5068 return s:os_viewer
5069 endif
5070 endif
5071endfun
5072
5073fun! netrw#Open(file) abort
5074 call netrw#Launch(s:viewer() .. ' ' .. shellescape(a:file, 1))
5075endf
5076
5077if !exists('g:netrw_regex_url')
5078 let g:netrw_regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}'
5079endif
5080
Bram Moolenaara6878372014-03-22 21:02:50 +01005081" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005082" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005083" given filename; typically this means given their extension.
5084" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005085fun! netrw#BrowseX(fname,remote)
Bram Moolenaar91359012019-11-30 17:57:03 +01005086 if a:remote == 0 && isdirectory(a:fname)
5087 " if its really just a local directory, then do a "gf" instead
Bram Moolenaar29634562020-01-09 21:46:04 +01005088 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005089 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5090 " remote directory, not a webpage access, looks like an attempt to do a directory listing
Bram Moolenaar91359012019-11-30 17:57:03 +01005091 norm! gf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005092 endif
5093
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005094 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5095 let remote = a:remote
5096 else
5097 let remote = 0
5098 endif
5099
Bram Moolenaar97d62492012-11-15 21:28:22 +01005100 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005101 let screenposn = winsaveview()
Bram Moolenaar97d62492012-11-15 21:28:22 +01005102
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005103 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5104 let awkeep = &aw
5105 set noaw
5106
Bram Moolenaar5c736222010-01-06 20:54:52 +01005107 " special core dump handler
5108 if a:fname =~ '/core\(\.\d\+\)\=$'
5109 if exists("g:Netrw_corehandler")
5110 if type(g:Netrw_corehandler) == 2
5111 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005112 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005113 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005114 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005115 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005116 if type(Fncref) == 2
5117 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005118 endif
5119 endfor
5120 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005121 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005122 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005123 let &aw= awkeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005124 return
5125 endif
5126 endif
5127
Bram Moolenaar446cb832008-06-24 21:56:24 +00005128 " set up the filename
5129 " (lower case the extension, make a local copy of a remote file)
5130 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005131 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005132 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005133 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005134 if exten =~ "[\\/]"
5135 let exten= ""
5136 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005137
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005138 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005139 " create a local copy
Bram Moolenaarff034192013-04-24 18:51:19 +02005140 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005141 call netrw#NetRead(3,a:fname)
5142 " attempt to rename tempfile
5143 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005144 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02005145 if s:netrw_tmpfile != newname && newname != ""
5146 if rename(s:netrw_tmpfile,newname) == 0
5147 " renaming succeeded
Bram Moolenaar85850f32019-07-19 22:05:51 +02005148 let fname= newname
5149 else
5150 " renaming failed
Bram Moolenaar85850f32019-07-19 22:05:51 +02005151 let fname= s:netrw_tmpfile
5152 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005153 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005154 let fname= s:netrw_tmpfile
5155 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005156 else
5157 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005158 " special ~ handler for local
5159 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005160 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005161 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005162 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005163
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005164 " although shellescape(..., 1) is used in netrw#Open(), it's insufficient
5165 call netrw#Open(escape(fname, '#%'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005166
Bram Moolenaar446cb832008-06-24 21:56:24 +00005167 " cleanup: remove temporary file,
5168 " delete current buffer if success with handler,
5169 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005170 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005171 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005172" if remote == 1 && fname != a:fname
Bram Moolenaarc236c162008-07-13 17:41:49 +00005173" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005174" endif
5175
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005176 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005177 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005178 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005179 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005180 endif
Christian Brabandt9f320692024-10-30 18:36:20 +01005181 exe "sil! NetrwKeepj norm! \<c-o>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005182 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005183 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005184 let @@ = ykeep
5185 let &aw= awkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005186endfun
5187
5188" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005189" netrw#GX: gets word under cursor for gx support {{{2
5190" See also: netrw#BrowseXVis
5191" netrw#BrowseX
5192fun! netrw#GX()
5193" call Dfunc("netrw#GX()")
5194 if &ft == "netrw"
5195 let fname= s:NetrwGetWord()
5196 else
Konfekt3d7e5672024-10-27 22:16:49 +01005197 let fname= exists("g:netrw_gx")? expand(g:netrw_gx) : s:GetURL()
Bram Moolenaar85850f32019-07-19 22:05:51 +02005198 endif
5199" call Dret("netrw#GX <".fname.">")
5200 return fname
5201endfun
5202
Konfekt3d7e5672024-10-27 22:16:49 +01005203fun! s:GetURL() abort
5204 let URL = ''
5205 if exists('*Netrw_get_URL_' .. &filetype)
5206 let URL = call('Netrw_get_URL_' .. &filetype, [])
5207 endif
5208 if !empty(URL) | return URL | endif
5209 " URLs end in letter, digit or forward slash
5210 let URL = matchstr(expand("<cWORD>"), '\<' .. g:netrw_regex_url .. '\ze[^A-Za-z0-9/]*$')
5211 if !empty(URL) | return URL | endif
5212
5213 " Is it a file in the current work dir ...
5214 let file = expand("<cfile>")
5215 if filereadable(file) | return file | endif
5216 " ... or in that of the current buffer?
5217 let path = fnamemodify(expand('%'), ':p')
5218 if isdirectory(path)
5219 let dir = path
5220 elseif filereadable(path)
5221 let dir = fnamemodify(path, ':h')
5222 endif
5223 if exists('dir') && filereadable(dir..'/'..file) | return dir..'/'..file | endif
5224
5225 return ''
5226endf
5227
Bram Moolenaar85850f32019-07-19 22:05:51 +02005228" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005229" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5230fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005231 let dict={}
5232 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005233 norm! gv"ay
5234 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005235 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005236 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005237endfun
5238
5239" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005240" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5241" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5242" to become an unlisted buffer, so in that case don't bwipe it.
5243fun! s:NetrwBufRename(newname)
5244" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5245" call Dredir("ls!","s:NetrwBufRename (before rename)")
5246 let oldbufname= bufname(bufnr("%"))
5247" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5248
5249 if oldbufname != a:newname
5250" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5251 let b:junk= 1
5252" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5253 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005254" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005255 let oldbufnr= bufnr(oldbufname)
5256" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5257" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5258 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5259" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5260 exe "bwipe! ".oldbufnr
5261" else " Decho
5262" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005263" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5264" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5265" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005266 endif
5267" call Dredir("ls!","s:NetrwBufRename (after rename)")
5268" else " Decho
5269" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5270 endif
5271
5272" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5273endfun
5274
5275" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005276" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005277fun! netrw#CheckIfRemote(...)
5278" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5279 if a:0 > 0
5280 let curfile= a:1
5281 else
5282 let curfile= expand("%")
5283 endif
5284" call Decho("curfile<".curfile.">")
5285 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005286" call Dret("netrw#CheckIfRemote 1")
5287 return 1
5288 else
5289" call Dret("netrw#CheckIfRemote 0")
5290 return 0
5291 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005292endfun
5293
5294" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005295" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5296fun! s:NetrwChgPerm(islocal,curdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005297 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005298 call inputsave()
5299 let newperm= input("Enter new permission: ")
5300 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005301 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5302 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005303 call system(chgperm)
5304 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005305 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005306 endif
5307 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01005308 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005309 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005310 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005311endfun
5312
5313" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005314" s:CheckIfKde: checks if kdeinit is running {{{2
5315" Returns 0: kdeinit not running
5316" 1: kdeinit is running
5317fun! s:CheckIfKde()
5318" call Dfunc("s:CheckIfKde()")
5319 " seems kde systems often have gnome-open due to dependencies, even though
5320 " gnome-open's subsidiary display tools are largely absent. Kde systems
5321 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5322 if !exists("s:haskdeinit")
5323 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005324 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005325 if v:shell_error
5326 let s:haskdeinit = 0
5327 endif
5328 else
5329 let s:haskdeinit= 0
5330 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005331" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005332 endif
5333
5334" call Dret("s:CheckIfKde ".s:haskdeinit)
5335 return s:haskdeinit
5336endfun
5337
5338" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005339" s:NetrwClearExplore: clear explore variables (if any) {{{2
5340fun! s:NetrwClearExplore()
5341" call Dfunc("s:NetrwClearExplore()")
5342 2match none
5343 if exists("s:explore_match") |unlet s:explore_match |endif
5344 if exists("s:explore_indx") |unlet s:explore_indx |endif
5345 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5346 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5347 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5348 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5349 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5350 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5351 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5352" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005353" call Dret("s:NetrwClearExplore")
5354endfun
5355
5356" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005357" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5358fun! s:NetrwEditBuf(bufnum)
5359" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5360 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5361" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5362 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5363 else
5364" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005365 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005366 endif
5367" call Dret("s:NetrwEditBuf")
5368endfun
5369
5370" ---------------------------------------------------------------------
5371" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5372" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5373fun! s:NetrwEditFile(cmd,opt,fname)
5374" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5375 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5376" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5377 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5378 else
5379" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005380 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5381 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5382 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005383 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5384 endif
5385" call Dret("s:NetrwEditFile")
5386endfun
5387
5388" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005389" s:NetrwExploreListUniq: {{{2
5390fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005391 " this assumes that the list is already sorted
5392 let newexplist= []
5393 for member in a:explist
5394 if !exists("uniqmember") || member != uniqmember
5395 let uniqmember = member
5396 let newexplist = newexplist + [ member ]
5397 endif
5398 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01005399 return newexplist
5400endfun
5401
5402" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005403" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5404fun! s:NetrwForceChgDir(islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005405 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005406 if a:newdir !~ '/$'
5407 " ok, looks like force is needed to get directory-style treatment
5408 if a:newdir =~ '@$'
5409 let newdir= substitute(a:newdir,'@$','/','')
5410 elseif a:newdir =~ '[*=|\\]$'
5411 let newdir= substitute(a:newdir,'.$','/','')
5412 else
5413 let newdir= a:newdir.'/'
5414 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005415 else
5416 " should already be getting treatment as a directory
5417 let newdir= a:newdir
5418 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005419 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir,0)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005420 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005421 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005422endfun
5423
5424" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005425" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005426" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5427" expr : this is the expression to follow the directory. Will use s:ComposePath()
5428" pare =1: remove the current directory from the resulting glob() filelist
5429" =0: leave the current directory in the resulting glob() filelist
5430fun! s:NetrwGlob(direntry,expr,pare)
5431" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005432 if netrw#CheckIfRemote()
5433 keepalt 1sp
5434 keepalt enew
5435 let keep_liststyle = w:netrw_liststyle
5436 let w:netrw_liststyle = s:THINLIST
5437 if s:NetrwRemoteListing() == 0
5438 keepj keepalt %s@/@@
5439 let filelist= getline(1,$)
5440 q!
5441 else
5442 " remote listing error -- leave treedict unchanged
5443 let filelist= w:netrw_treedict[a:direntry]
5444 endif
5445 let w:netrw_liststyle= keep_liststyle
5446 else
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005447 let path= s:ComposePath(fnameescape(a:direntry), a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005448 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005449 " escape [ so it is not detected as wildcard character, see :h wildcard
5450 let path= substitute(path, '[', '[[]', 'g')
5451 endif
5452 if v:version > 704 || (v:version == 704 && has("patch656"))
5453 let filelist= glob(path,0,1,1)
5454 else
5455 let filelist= glob(path,0,1)
5456 endif
5457 if a:pare
5458 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5459 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005460 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005461 return filelist
5462endfun
5463
5464" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005465" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5466fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005467 if a:newfile =~ '[/@*=|\\]$'
5468 let newfile= substitute(a:newfile,'.$','','')
5469 else
5470 let newfile= a:newfile
5471 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005472 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01005473 call s:NetrwBrowseChgDir(a:islocal,newfile,0)
Bram Moolenaarff034192013-04-24 18:51:19 +02005474 else
Tom Benham64a536d2024-11-07 21:15:03 +01005475 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile,0))
Bram Moolenaarff034192013-04-24 18:51:19 +02005476 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005477endfun
5478
5479" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005480" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5481" and switches the hiding mode. The actual hiding is done by
5482" s:NetrwListHide().
5483" g:netrw_hide= 0: show all
5484" 1: show not-hidden files
5485" 2: show hidden files only
5486fun! s:NetrwHide(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005487 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005488 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005489
5490 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005491
5492 " hide the files in the markfile list
5493 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00005494 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5495 " remove fname from hiding list
5496 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5497 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5498 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005499 else
5500 " append fname to hiding list
5501 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5502 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5503 else
5504 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5505 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005506 endif
5507 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005508 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005509 let g:netrw_hide= 1
5510
5511 else
5512
5513 " switch between show-all/show-not-hidden/show-hidden
5514 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005515 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005516 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005517 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005518 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005519 return
5520 endif
5521 endif
5522
Tom Benham64a536d2024-11-07 21:15:03 +01005523 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005524 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005525 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005526endfun
5527
5528" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005529" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5530fun! s:NetrwHideEdit(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005531 let ykeep= @@
5532 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005533 let svpos= winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005534
5535 " get new hiding list from user
5536 call inputsave()
5537 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5538 call inputrestore()
5539 let g:netrw_list_hide= newhide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005540
5541 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01005542 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./",0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005543
5544 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005545 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005546 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005547endfun
5548
5549" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005550" s:NetrwHidden: invoked by "gh" {{{2
5551fun! s:NetrwHidden(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005552 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005553 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005554 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005555
5556 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005557 " remove .file pattern from hiding list
Bram Moolenaar446cb832008-06-24 21:56:24 +00005558 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005559 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005560 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5561 else
5562 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5563 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005564 if g:netrw_list_hide =~ '^,'
5565 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5566 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005567
5568 " refresh screen and return to saved position
Tom Benham64a536d2024-11-07 21:15:03 +01005569 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005570 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005571 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005572endfun
5573
5574" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005575" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5576fun! s:NetrwHome()
5577 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005578 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005579 else
5580 " go to vim plugin home
5581 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005582 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005583 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005584 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005585 let home= basehome."/.vim"
5586 break
5587 endif
5588 endfor
5589 if home == ""
5590 " just pick the first directory
5591 let home= substitute(&rtp,',.*$','','')
5592 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005593 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005594 let home= substitute(home,'/','\\','g')
5595 endif
5596 endif
5597 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005598 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005599" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005600 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005601" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005602 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005603 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005604" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005605 call mkdir(home)
5606 endif
5607 endif
5608 let g:netrw_home= home
5609 return home
5610endfun
5611
5612" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005613" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5614fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005615 if exists("s:netrwdrag")
5616 return
5617 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005618 if &ft != "netrw"
5619 return
5620 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005621
Bram Moolenaar97d62492012-11-15 21:28:22 +01005622 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005623 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005624 while getchar(0) != 0
5625 "clear the input stream
5626 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005627 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005628 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005629 let mouse_lnum = v:mouse_lnum
5630 let wlastline = line('w$')
5631 let lastline = line('$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005632 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5633 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005634 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005635 return
5636 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005637 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005638 " 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 +01005639 " without this test when its disabled.
5640 " May 26, 2014: edit file, :Lex, resize window -- causes refresh. Reinstated a modified test. See if problems develop.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005641 if v:mouse_col > virtcol('.')
5642 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005643 return
5644 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005645
Bram Moolenaar446cb832008-06-24 21:56:24 +00005646 if a:islocal
5647 if exists("b:netrw_curdir")
Tom Benham64a536d2024-11-07 21:15:03 +01005648 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005649 endif
5650 else
5651 if exists("b:netrw_curdir")
Tom Benham64a536d2024-11-07 21:15:03 +01005652 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005653 endif
5654 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005655 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005656endfun
5657
5658" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005659" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
5660fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005661 if &ft != "netrw"
5662 return
5663 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005664 call s:NetrwMarkFileTgt(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005665endfun
5666
5667" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005668" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
5669" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02005670" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005671" a:islocal=2 : <c-r> used, remote
5672" a:islocal=3 : <c-r> used, local
5673fun! s:NetrwServerEdit(islocal,fname)
5674" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
5675 let islocal = a:islocal%2 " =0: remote =1: local
5676 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
5677
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005678 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005679 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005680 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005681 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005682 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005683 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5684 unlet s:netrw_browse_split_{winnr()}
5685 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005686 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname,0))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005687 return
5688 endif
5689
5690 if has("clientserver") && executable("gvim")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005691
5692 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005693 let srvrname = g:netrw_browse_split[0]
5694 let tabnum = g:netrw_browse_split[1]
5695 let winnum = g:netrw_browse_split[2]
5696
5697 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005698 if !ctrlr
5699 " user must have closed the server window and the user did not use <c-r>, but
5700 " used something like <cr>.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005701 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09005702 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005703 endif
5704 let g:netrw_browse_split= 0
5705 if exists("s:netrw_browse_split_".winnr())
5706 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5707 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005708 call s:NetrwBrowseChgDir(islocal,a:fname,0)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005709 return
5710
5711 elseif has("win32") && executable("start")
5712 " start up remote netrw server under windows
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005713 call system("start gvim --servername ".srvrname)
5714
5715 else
5716 " start up remote netrw server under linux
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005717 call system("gvim --servername ".srvrname)
5718 endif
5719 endif
5720
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005721 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
5722 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005723 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005724 else
5725
5726 if serverlist() !~ '\<'.g:netrw_servername.'\>'
5727
5728 if !ctrlr
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005729 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09005730 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005731 endif
5732 let g:netrw_browse_split= 0
Tom Benham64a536d2024-11-07 21:15:03 +01005733 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname,0))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005734 return
5735
5736 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005737 if has("win32") && executable("start")
5738 " start up remote netrw server under windows
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005739 call system("start gvim --servername ".g:netrw_servername)
5740 else
5741 " start up remote netrw server under linux
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005742 call system("gvim --servername ".g:netrw_servername)
5743 endif
5744 endif
5745 endif
5746
5747 while 1
5748 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005749 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005750 break
5751 catch /^Vim\%((\a\+)\)\=:E241/
5752 sleep 200m
5753 endtry
5754 endwhile
5755
5756 if exists("g:netrw_browse_split")
5757 if type(g:netrw_browse_split) != 3
5758 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
5759 endif
5760 unlet g:netrw_browse_split
5761 endif
5762 let g:netrw_browse_split= [g:netrw_servername,1,1]
5763 endif
5764
5765 else
5766 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
5767 endif
5768
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005769endfun
5770
5771" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005772" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
5773fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005774 if &ft != "netrw"
5775 return
5776 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005777" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005778
Bram Moolenaar8d043172014-01-23 14:24:41 +01005779 let s:ngw= s:NetrwGetWord()
5780 call s:NetrwMarkFile(a:islocal,s:ngw)
5781
5782" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02005783endfun
5784
5785" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005786" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
5787" Used to mark multiple files.
5788fun! s:NetrwSLeftdrag(islocal)
5789" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
5790 if !exists("s:netrwdrag")
5791 let s:netrwdrag = winnr()
5792 if a:islocal
5793 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005794 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01005795 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005796 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005797 endif
5798 let ngw = s:NetrwGetWord()
5799 if !exists("s:ngw") || s:ngw != ngw
5800 call s:NetrwMarkFile(a:islocal,ngw)
5801 endif
5802 let s:ngw= ngw
5803" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5804endfun
5805
5806" ---------------------------------------------------------------------
5807" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
5808fun! s:NetrwSLeftrelease(islocal)
5809" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5810 if exists("s:netrwdrag")
5811 nunmap <s-leftrelease>
5812 let ngw = s:NetrwGetWord()
5813 if !exists("s:ngw") || s:ngw != ngw
5814 call s:NetrwMarkFile(a:islocal,ngw)
5815 endif
5816 if exists("s:ngw")
5817 unlet s:ngw
5818 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005819 unlet s:netrwdrag
5820 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005821" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02005822endfun
5823
5824" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01005825" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
5826" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00005827fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005828" 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 +02005829" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005830 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005831
5832 " 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 +02005833 " How-it-works: take the hiding command, convert it into a range.
5834 " Duplicate characters don't matter.
5835 " Remove all such characters from the '/~@#...890' string.
5836 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005837" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005838 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01005839 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005840" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005841
5842 while listhide != ""
5843 if listhide =~ ','
5844 let hide = substitute(listhide,',.*$','','e')
5845 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
5846 else
5847 let hide = listhide
5848 let listhide = ""
5849 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005850" 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 +01005851 if g:netrw_sort_by =~ '^[ts]'
5852 if hide =~ '^\^'
5853" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
5854 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
5855 elseif hide =~ '^\\(\^'
5856 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
5857 endif
5858" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
5859 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005860
5861 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005862" 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 +00005863 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005864" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005865 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005866 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005867" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005868 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005869 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005870" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005871 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02005872
Bram Moolenaar446cb832008-06-24 21:56:24 +00005873 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005874 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005875" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005876 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005877" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005878 endif
5879
Bram Moolenaaradc21822011-04-01 18:03:16 +02005880 " remove any blank lines that have somehow remained.
5881 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005882 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02005883
Bram Moolenaar97d62492012-11-15 21:28:22 +01005884 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005885" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005886endfun
5887
5888" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005889" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005890" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005891fun! s:NetrwMakeDir(usrhost)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005892
Bram Moolenaar97d62492012-11-15 21:28:22 +01005893 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005894 " get name of new directory from user. A bare <CR> will skip.
5895 " if its currently a directory, also request will be skipped, but with
5896 " a message.
5897 call inputsave()
5898 let newdirname= input("Please give directory name: ")
5899 call inputrestore()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005900
5901 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01005902 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005903 return
5904 endif
5905
5906 if a:usrhost == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005907
5908 " Local mkdir:
5909 " sanity checks
5910 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005911 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005912 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005913 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005914 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005915 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005916 return
5917 endif
5918 if s:FileReadable(fullnewdir)
5919 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005920 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005921 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005922 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005923 return
5924 endif
5925
5926 " requested new local directory is neither a pre-existing file or
5927 " directory, so make it!
5928 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005929 if has("unix")
5930 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
5931 else
5932 call mkdir(fullnewdir,"p")
5933 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005934 else
5935 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005936 if s:NetrwLcd(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005937 return
5938 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005939 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005940 if v:shell_error != 0
5941 let @@= ykeep
5942 call netrw#ErrorMsg(s:ERROR,"consider setting g:netrw_localmkdir<".g:netrw_localmkdir."> to something that works",80)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005943 return
5944 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005945 if !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02005946 if s:NetrwLcd(netrw_origdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005947 return
5948 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005949 endif
5950 endif
5951
5952 if v:shell_error == 0
5953 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005954 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01005955 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005956 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005957 elseif !exists("g:netrw_quiet")
5958 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
5959 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005960
5961 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01005962 " Remote mkdir: using ssh
Bram Moolenaar446cb832008-06-24 21:56:24 +00005963 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
5964 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005965 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005966 if v:shell_error == 0
5967 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005968 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01005969 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005970 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005971 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005972 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005973 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005974
5975 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01005976 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005977 let svpos= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01005978 if exists("b:netrw_fname")
Bram Moolenaara6878372014-03-22 21:02:50 +01005979 let remotepath= b:netrw_fname
5980 else
5981 let remotepath= ""
5982 endif
5983 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Tom Benham64a536d2024-11-07 21:15:03 +01005984 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005985 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01005986
Bram Moolenaar446cb832008-06-24 21:56:24 +00005987 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01005988 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005989 let svpos= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01005990 if exists("b:netrw_fname")
Bram Moolenaara6878372014-03-22 21:02:50 +01005991 let remotepath= b:netrw_fname
5992 else
5993 let remotepath= ""
5994 endif
5995 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Tom Benham64a536d2024-11-07 21:15:03 +01005996 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005997 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005998 endif
5999
Bram Moolenaar97d62492012-11-15 21:28:22 +01006000 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006001endfun
6002
6003" ---------------------------------------------------------------------
6004" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6005fun! s:TreeSqueezeDir(islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01006006 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6007 " its a tree-listing style
6008 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006009 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006010 let depth = strchars(substitute(curdepth,' ','','g'))
6011 let srch = -1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006012 if depth >= 2
6013 NetrwKeepj norm! 0
6014 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6015 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006016 elseif depth == 1
6017 NetrwKeepj norm! 0
6018 let treedepthchr= substitute(s:treedepthstring,' ','','')
6019 let srch = search('^[^'.treedepthchr.']','bW',stopline)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006020 endif
6021 if srch > 0
Tom Benham64a536d2024-11-07 21:15:03 +01006022 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord(),1))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006023 exe srch
6024 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006025 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006026endfun
6027
6028" ---------------------------------------------------------------------
6029" s:NetrwMaps: {{{2
6030fun! s:NetrwMaps(islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01006031
Bram Moolenaar85850f32019-07-19 22:05:51 +02006032 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006033 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006034" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006035 if !hasmapto("<Plug>NetrwReturn")
6036 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006037 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6038 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006039 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6040 endif
6041 endif
6042 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006043 endif
6044
Bram Moolenaar85850f32019-07-19 22:05:51 +02006045 " generate default <Plug> maps {{{3
6046 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006047 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006048 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6049 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6050 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6051 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6052 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6053 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6054 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6055 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6056 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6057 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006058
Bram Moolenaara6878372014-03-22 21:02:50 +01006059 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02006060 " local normal-mode maps {{{3
6061 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6062 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6063 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6064 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6065 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6066 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6067 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006068 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006069 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6070 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6071 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6072" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006073 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6074 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6075 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006076 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006077 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006078 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6079 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6080 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6081 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006082 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6083 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6084 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6085 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6086 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6087 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6088 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6089 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6090 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6091 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6092 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6093 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6094 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006095 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006096 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006097 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6098 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6099 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6100 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6101 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006102 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006103 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006104 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1,1))<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006105 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006106 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6107 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6108 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006109 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006110 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006111 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6112 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006113 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006114 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006115 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6116 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6117 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006118 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1,0),0)"<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006119 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006120
Tom Benham64a536d2024-11-07 21:15:03 +01006121 nnoremap <buffer> <silent> <nowait> r :<c-u>let g:netrw_sort_direction= (g:netrw_sort_direction =~# 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,'./',0))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006122 if !hasmapto('<Plug>NetrwHideEdit')
6123 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006124 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006125 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006126 if !hasmapto('<Plug>NetrwRefresh')
6127 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006128 endif
Tom Benham64a536d2024-11-07 21:15:03 +01006129 nnoremap <buffer> <silent> <Plug>NetrwRefresh <c-l>:call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,(exists("w:netrw_liststyle") && exists("w:netrw_treetop") && w:netrw_liststyle == 3)? w:netrw_treetop : './',0))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006130 if s:didstarstar || !mapcheck("<s-down>","n")
6131 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006132 endif
6133 if s:didstarstar || !mapcheck("<s-up>","n")
6134 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006135 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006136 if !hasmapto('<Plug>NetrwTreeSqueeze')
6137 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006138 endif
6139 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006140 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6141 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006142 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6143 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6144 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6145 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6146 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6147 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6148 imap <buffer> <leftmouse> <Plug>ILeftmouse
6149 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006150 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6151 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6152 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6153 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6154 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006155 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006156 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6157 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006158 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006159 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6160 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6161 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6162 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6163 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6164 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6165 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006166 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6167
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006168 " support user-specified maps
6169 call netrw#UserMaps(1)
6170
Bram Moolenaar85850f32019-07-19 22:05:51 +02006171 else
6172 " remote normal-mode maps {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006173 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006174 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6175 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6176 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6177 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6178 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6179 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6180 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006181 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./',0))<cr>
6182 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord(),1))<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006183 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6184 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6185" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006186 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6187 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6188 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6189 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6190 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6191 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6192 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6193 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006194 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006195 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006196 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6197 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6198 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6199 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6200 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6201 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6202 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6203 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6204 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6205 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6206 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006207 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006208 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006209 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6210 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6211 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6212 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6213 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006214 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6215 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006216 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1,1))<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006217 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006218 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006219 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6220 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006221 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006222 nnoremap <buffer> <silent> <nowait> r :<c-u>let g:netrw_sort_direction= (g:netrw_sort_direction =~# 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,'./',0))<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006223 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6224 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6225 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6226 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6227 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6228 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6229 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6230 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006231 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord(),1),1)<cr>
Konfekt3d7e5672024-10-27 22:16:49 +01006232 nmap <buffer> <nowait> gx x
Bram Moolenaara6878372014-03-22 21:02:50 +01006233 if !hasmapto('<Plug>NetrwHideEdit')
6234 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006235 endif
6236 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6237 if !hasmapto('<Plug>NetrwRefresh')
6238 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006239 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006240 if !hasmapto('<Plug>NetrwTreeSqueeze')
6241 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006242 endif
6243 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006244
6245 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006246 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006247
Tom Benham64a536d2024-11-07 21:15:03 +01006248 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./',0))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006249 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006250 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006251 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006252 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006253 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006254 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006255 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006256 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006257 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006258 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006259 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006260 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6261 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6262 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006263 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006264 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006265 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6266 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006267 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006268 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6269 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6270 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6271 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6272 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6273 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6274 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006275 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006276
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006277 " support user-specified maps
6278 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006279 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006280endfun
6281
6282" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006283" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006284" If -buffer, the command is only available from within netrw buffers
6285" Otherwise, the command is available from any window, so long as netrw
6286" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006287fun! s:NetrwCommands(islocal)
6288" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6289
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006290 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6291 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006292 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 +01006293 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006294 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006295 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006296 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006297 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006298 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006299
6300" call Dret("s:NetrwCommands")
6301endfun
6302
6303" ---------------------------------------------------------------------
6304" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6305" glob()ing only works with local files
6306fun! s:NetrwMarkFiles(islocal,...)
6307" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006308 let curdir = s:NetrwGetCurdir(a:islocal)
6309 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006310 while i <= a:0
6311 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006312 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006313 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006314 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006315 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006316 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006317 else
6318 let mffiles= [a:{i}]
6319 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006320" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006321 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006322" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006323 call s:NetrwMarkFile(a:islocal,mffile)
6324 endfor
6325 let i= i + 1
6326 endwhile
6327" call Dret("s:NetrwMarkFiles")
6328endfun
6329
6330" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006331" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006332fun! s:NetrwMarkTarget(...)
Bram Moolenaara6878372014-03-22 21:02:50 +01006333 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006334 let curdir = s:NetrwGetCurdir(1)
6335 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006336 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006337 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6338 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006339 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006340 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006341 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6342 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006343 let svpos = winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01006344 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006345 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006346endfun
6347
6348" ---------------------------------------------------------------------
6349" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6350" mark and unmark files. If a markfile list exists,
6351" then the rename and delete functions will use it instead
6352" of whatever may happen to be under the cursor at that
6353" moment. When the mouse and gui are available,
6354" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006355"
6356" Creates two lists
6357" s:netrwmarkfilelist -- holds complete paths to all marked files
6358" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6359"
6360" Creates a marked file match string
6361" s:netrwmarfilemtch_# -- used with 2match to display marked files
6362"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006363" Creates a buffer version of islocal
6364" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006365fun! s:NetrwMarkFile(islocal,fname)
6366" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006367" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006368
6369 " sanity check
6370 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006371" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006372 return
6373 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006374 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006375
Bram Moolenaar97d62492012-11-15 21:28:22 +01006376 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006377 let curbufnr= bufnr("%")
yasudac18a9d52024-09-19 18:09:51 +02006378 let leader= '\%(^\|\s\)\zs'
Bram Moolenaara6878372014-03-22 21:02:50 +01006379 if a:fname =~ '\a$'
6380 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6381 else
6382 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6383 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006384
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006385 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006386 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006387" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6388" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6389" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006390 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006391
6392 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006393 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006394" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006395 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006396 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006397
6398 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006399 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006400" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006401 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6402 if s:netrwmarkfilelist_{curbufnr} == []
6403 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006404" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006405 call s:NetrwUnmarkList(curbufnr,curdir)
6406 else
6407 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006408" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006409 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006410 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006411 for fname in s:netrwmarkfilelist_{curbufnr}
6412 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006413 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006414 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006415 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006416 endif
6417 let first= 0
6418 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006419" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006420 endif
6421 endif
6422
6423 else
6424 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006425" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006426
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006427" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006428 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006429 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6430" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006431
6432 " build initial markfile matching pattern
6433 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006434 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006435 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006436 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006437 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006438" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006439 endif
6440
6441 " handle global markfilelist
6442 if exists("s:netrwmarkfilelist")
6443 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6444 if index(s:netrwmarkfilelist,dname) == -1
6445 " append new filename to global markfilelist
6446 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006447" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006448 else
6449 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006450" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6451" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006452 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006453" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006454 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006455" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006456 unlet s:netrwmarkfilelist
6457 endif
6458 endif
6459 else
6460 " initialize new global-directory markfilelist
6461 let s:netrwmarkfilelist= []
6462 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006463" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006464 endif
6465
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006466 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006467 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6468 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6469" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6470 if exists("g:did_drchip_netrwlist_syntax")
6471 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6472 endif
6473 else
6474" " call Decho("2match none",'~'.expand("<slnum>"))
6475 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006476 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006477 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006478 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006479" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6480" 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 +00006481endfun
6482
6483" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006484" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6485" mA: move the argument list to marked file list (tomflist=1)
6486" Uses the global marked file list
6487fun! s:NetrwMarkFileArgList(islocal,tomflist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006488 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006489 let curdir = s:NetrwGetCurdir(a:islocal)
6490 let curbufnr = bufnr("%")
6491
6492 if a:tomflist
6493 " mA: move argument list to marked file list
6494 while argc()
6495 let fname= argv(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006496 exe "argdel ".fnameescape(fname)
6497 call s:NetrwMarkFile(a:islocal,fname)
6498 endwhile
6499
6500 else
6501 " ma: move marked file list to argument list
6502 if exists("s:netrwmarkfilelist")
6503
6504 " for every filename in the marked list
6505 for fname in s:netrwmarkfilelist
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006506 exe "argadd ".fnameescape(fname)
6507 endfor " for every file in the marked list
6508
6509 " unmark list and refresh
6510 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01006511 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006512 NetrwKeepj call winrestview(svpos)
6513 endif
6514 endif
6515
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006516endfun
6517
6518" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006519" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
6520" compress/decompress files using the programs
6521" in g:netrw_compress and g:netrw_uncompress,
6522" using g:netrw_compress_suffix to know which to
6523" do. By default:
6524" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006525" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00006526fun! s:NetrwMarkFileCompress(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006527 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006528 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006529 let curbufnr = bufnr("%")
6530
Bram Moolenaarff034192013-04-24 18:51:19 +02006531 " sanity check
6532 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006533 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006534 return
6535 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006536
Bram Moolenaar446cb832008-06-24 21:56:24 +00006537 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02006538
6539 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00006540 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02006541 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02006542 if exists("g:netrw_decompress['".sfx."']")
6543 " fname has a suffix indicating that its compressed; apply associated decompression routine
6544 let exe= g:netrw_decompress[sfx]
Bram Moolenaarff034192013-04-24 18:51:19 +02006545 let exe= netrw#WinPath(exe)
6546 if a:islocal
6547 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006548 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006549 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006550 call system(exe." ".fname)
6551 if v:shell_error
6552 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01006553 endif
6554 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006555 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
6556 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01006557 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006558
Bram Moolenaarff034192013-04-24 18:51:19 +02006559 endif
6560 unlet sfx
6561
Bram Moolenaar446cb832008-06-24 21:56:24 +00006562 if exists("exe")
6563 unlet exe
6564 elseif a:islocal
6565 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006566 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006567 if v:shell_error
6568 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
6569 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006570 else
6571 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006572 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006573 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006574 endfor " for every file in the marked list
6575
Bram Moolenaar446cb832008-06-24 21:56:24 +00006576 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01006577 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006578 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006579 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006580endfun
6581
6582" ---------------------------------------------------------------------
6583" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
6584" If no marked files, then set up directory as the
6585" target. Currently does not support copying entire
6586" directories. Uses the local-buffer marked file list.
6587" Returns 1=success (used by NetrwMarkFileMove())
6588" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006589fun! s:NetrwMarkFileCopy(islocal,...)
6590" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
6591
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006592 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006593 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006594 if b:netrw_curdir !~ '/$'
6595 if !exists("b:netrw_curdir")
6596 let b:netrw_curdir= curdir
6597 endif
6598 let b:netrw_curdir= b:netrw_curdir."/"
6599 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006600
Bram Moolenaarff034192013-04-24 18:51:19 +02006601 " sanity check
6602 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006603 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006604" call Dret("s:NetrwMarkFileCopy")
6605 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006606 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006607" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006608
Bram Moolenaar446cb832008-06-24 21:56:24 +00006609 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006610 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006611" call Dret("s:NetrwMarkFileCopy 0")
6612 return 0
6613 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006614" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006615
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006616 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006617 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006618" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006619 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006620 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
6621" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
6622 return
6623 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006624
6625 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02006626 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006627 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
6628 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006629" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006630 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006631 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
6632 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006633" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006634 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006635 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006636 let oldname = a:1
6637 else
6638 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006639" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006640 let s:recursive= 1
6641 for oldname in s:netrwmarkfilelist_{bufnr("%")}
6642 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
6643 if ret == 0
6644 break
6645 endif
6646 endfor
6647 unlet s:recursive
6648 call s:NetrwUnmarkList(curbufnr,curdir)
6649" call Dret("s:NetrwMarkFileCopy ".ret)
6650 return ret
6651 endif
6652
6653 call inputsave()
6654 let newname= input("Copy ".oldname." to : ",oldname,"file")
6655 call inputrestore()
6656 if newname == ""
6657" call Dret("s:NetrwMarkFileCopy 0")
6658 return 0
6659 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006660 let args= s:ShellEscape(oldname)
6661 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006662 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006663 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
6664 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006665 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02006666 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02006667 let args= substitute(args,'/','\\','g')
6668 let tgt = substitute(tgt, '/','\\','g')
6669 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006670 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
6671 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
6672 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
6673 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
6674" call Decho("args <".args.">",'~'.expand("<slnum>"))
6675" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006676 if isdirectory(s:NetrwFile(args))
6677" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006678 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006679" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02006680 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006681 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
6682 " contents to a target. One must append the source directory name to the target to get xcopy to
6683 " do the right thing.
6684 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006685" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006686 endif
6687 else
6688 let copycmd= g:netrw_localcopycmd
6689 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006690 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006691 let copycmd = substitute(copycmd,'\s.*$','','')
6692 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02006693 let copycmd = netrw#WinPath(copycmd).copycmdargs
6694 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006695 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02006696 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006697" call Decho("args <".args.">",'~'.expand("<slnum>"))
6698" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
6699" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
6700" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006701 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01006702 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02006703 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02006704 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 +01006705 else
6706 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
6707 endif
6708" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006709 return 0
6710 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006711
6712 elseif a:islocal && !s:netrwmftgt_islocal
6713 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006714" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006715 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006716
6717 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006718 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006719" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006720 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006721
6722 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006723 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006724" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006725 let curdir = getcwd()
6726 let tmpdir = s:GetTempfile("")
6727 if tmpdir !~ '/'
6728 let tmpdir= curdir."/".tmpdir
6729 endif
6730 if exists("*mkdir")
6731 call mkdir(tmpdir)
6732 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006733 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006734 if v:shell_error != 0
6735 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 +01006736" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01006737 return
6738 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006739 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006740 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006741 if s:NetrwLcd(tmpdir)
6742" call Dret("s:NetrwMarkFileCopy : lcd failure")
6743 return
6744 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006745 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006746 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006747 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006748 if getcwd() == tmpdir
6749 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006750 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006751 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02006752 if s:NetrwLcd(curdir)
6753" call Dret("s:NetrwMarkFileCopy : lcd failure")
6754 return
6755 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01006756 if delete(tmpdir,"d")
6757 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006758 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006759 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006760 if s:NetrwLcd(curdir)
6761" call Dret("s:NetrwMarkFileCopy : lcd failure")
6762 return
6763 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006764 endif
6765 endif
6766 endif
6767
6768 " -------
6769 " cleanup
6770 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006771" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006772 " remove markings from local buffer
6773 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006774" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
6775" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
6776" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
6777" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
6778" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
6779" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
6780 if exists("s:recursive")
6781" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
6782 else
6783" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006784 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006785 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01006786 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006787 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006788 else
6789 " refresh local and targets for fast browsing
6790 if !exists("s:recursive")
6791 " remove markings from local buffer
6792" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
6793 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
6794 endif
6795
6796 " refresh buffers
6797 if s:netrwmftgt_islocal
6798" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
6799 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
6800 endif
6801 if a:islocal && s:netrwmftgt != curdir
6802" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
6803 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
6804 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01006805 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006806
Bram Moolenaar446cb832008-06-24 21:56:24 +00006807" call Dret("s:NetrwMarkFileCopy 1")
6808 return 1
6809endfun
6810
6811" ---------------------------------------------------------------------
6812" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
6813" invoke vim's diff mode on the marked files.
6814" Either two or three files can be so handled.
6815" Uses the global marked file list.
6816fun! s:NetrwMarkFileDiff(islocal)
6817" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6818 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006819
Bram Moolenaarff034192013-04-24 18:51:19 +02006820 " sanity check
6821 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006822 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006823" call Dret("s:NetrwMarkFileDiff")
6824 return
6825 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006826 let curdir= s:NetrwGetCurdir(a:islocal)
6827" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006828
Bram Moolenaara6878372014-03-22 21:02:50 +01006829 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006830 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00006831 for fname in s:netrwmarkfilelist
6832 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006833 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006834" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006835 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006836 diffthis
6837 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09006838 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006839" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006840 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006841 diffthis
6842 else
6843 break
6844 endif
6845 endfor
6846 call s:NetrwUnmarkList(curbufnr,curdir)
6847 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006848
Bram Moolenaar446cb832008-06-24 21:56:24 +00006849" call Dret("s:NetrwMarkFileDiff")
6850endfun
6851
6852" ---------------------------------------------------------------------
6853" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
6854" Uses global markfilelist
6855fun! s:NetrwMarkFileEdit(islocal)
6856" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
6857
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006858 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006859 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02006860
6861 " sanity check
6862 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006863 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006864" call Dret("s:NetrwMarkFileEdit")
6865 return
6866 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006867" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006868
Bram Moolenaar446cb832008-06-24 21:56:24 +00006869 if exists("s:netrwmarkfilelist_{curbufnr}")
6870 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006871 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006872 " unmark markedfile list
6873" call s:NetrwUnmarkList(curbufnr,curdir)
6874 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006875" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02006876 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00006877 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006878 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006879
Bram Moolenaar446cb832008-06-24 21:56:24 +00006880" call Dret("s:NetrwMarkFileEdit")
6881endfun
6882
6883" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006884" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02006885fun! s:NetrwMarkFileQFEL(islocal,qfel)
6886" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
6887 call s:NetrwUnmarkAll()
6888 let curbufnr= bufnr("%")
6889
6890 if !empty(a:qfel)
6891 for entry in a:qfel
6892 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006893" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006894 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006895" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006896 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
6897 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
6898 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
6899 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006900" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006901 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
6902 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006903" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006904 endif
6905 endfor
6906 echo "(use me to edit marked files)"
6907 else
6908 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
6909 endif
6910
6911" call Dret("s:NetrwMarkFileQFEL")
6912endfun
6913
6914" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006915" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
6916" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
6917" mX enbloc=1: Uses the global marked-file list, applies command to entire list
6918fun! s:NetrwMarkFileExe(islocal,enbloc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006919 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006920 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006921 let curbufnr = bufnr("%")
6922
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006923 if a:enbloc == 0
6924 " individually apply command to files, one at a time
6925 " sanity check
6926 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6927 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006928 return
6929 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006930
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006931 if exists("s:netrwmarkfilelist_{curbufnr}")
6932 " get the command
6933 call inputsave()
6934 let cmd= input("Enter command: ","","file")
6935 call inputrestore()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006936 if cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006937 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006938 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006939
6940 " apply command to marked files, individually. Substitute: filename -> %
6941 " If no %, then append a space and the filename to the command
6942 for fname in s:netrwmarkfilelist_{curbufnr}
6943 if a:islocal
6944 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09006945 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006946 endif
6947 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006948 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006949 endif
6950 if cmd =~ '%'
6951 let xcmd= substitute(cmd,'%',fname,'g')
6952 else
6953 let xcmd= cmd.' '.fname
6954 endif
6955 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006956 let ret= system(xcmd)
6957 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006958 let ret= s:RemoteSystem(xcmd)
6959 endif
6960 if v:shell_error < 0
6961 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
6962 break
6963 else
yasudac75dad02024-08-22 21:06:32 +02006964 if ret !=# ''
6965 echo "\n"
6966 " skip trailing new line
6967 echo ret[0:-2]
6968 else
6969 echo ret
6970 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006971 endif
6972 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00006973
6974 " unmark marked file list
6975 call s:NetrwUnmarkList(curbufnr,curdir)
6976
6977 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01006978 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006979 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006980 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006981 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006982 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006983
6984 else " apply command to global list of files, en bloc
6985
6986 call inputsave()
6987 let cmd= input("Enter command: ","","file")
6988 call inputrestore()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006989 if cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006990 return
6991 endif
6992 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006993 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006994 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006995 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006996 endif
6997 if a:islocal
6998 call system(cmd)
6999 if v:shell_error < 0
7000 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7001 endif
7002 else
7003 let ret= s:RemoteSystem(cmd)
7004 endif
7005 call s:NetrwUnmarkAll()
7006
7007 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007008 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007009 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007010
7011 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007012endfun
7013
7014" ---------------------------------------------------------------------
7015" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7016" as the marked file(s) (toggles suffix presence)
7017" Uses the local marked file list.
7018fun! s:NetrwMarkHideSfx(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007019 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007020 let curbufnr = bufnr("%")
7021
7022 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7023 if exists("s:netrwmarkfilelist_{curbufnr}")
7024
7025 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007026 " construct suffix pattern
7027 if fname =~ '\.'
7028 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7029 else
7030 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7031 endif
7032 " determine if its in the hiding list or not
7033 let inhidelist= 0
7034 if g:netrw_list_hide != ""
7035 let itemnum = 0
7036 let hidelist= split(g:netrw_list_hide,',')
7037 for hidepat in hidelist
7038 if sfxpat == hidepat
7039 let inhidelist= 1
7040 break
7041 endif
7042 let itemnum= itemnum + 1
7043 endfor
7044 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007045 if inhidelist
7046 " remove sfxpat from list
7047 call remove(hidelist,itemnum)
7048 let g:netrw_list_hide= join(hidelist,",")
7049 elseif g:netrw_list_hide != ""
7050 " append sfxpat to non-empty list
7051 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7052 else
7053 " set hiding list to sfxpat
7054 let g:netrw_list_hide= sfxpat
7055 endif
7056 endfor
7057
7058 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007059 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007060 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007061 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007062 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007063 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007064endfun
7065
7066" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007067" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007068" Uses the local marked-file list.
7069fun! s:NetrwMarkFileVimCmd(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007070 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007071 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007072 let curbufnr = bufnr("%")
7073
Bram Moolenaarff034192013-04-24 18:51:19 +02007074 " sanity check
7075 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007076 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007077 return
7078 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007079
Bram Moolenaar15146672011-10-20 22:22:38 +02007080 if exists("s:netrwmarkfilelist_{curbufnr}")
7081 " get the command
7082 call inputsave()
7083 let cmd= input("Enter vim command: ","","file")
7084 call inputrestore()
Bram Moolenaar15146672011-10-20 22:22:38 +02007085 if cmd == ""
Bram Moolenaar15146672011-10-20 22:22:38 +02007086 return
7087 endif
7088
7089 " apply command to marked files. Substitute: filename -> %
7090 " If no %, then append a space and the filename to the command
7091 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar15146672011-10-20 22:22:38 +02007092 if a:islocal
7093 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007094 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaar15146672011-10-20 22:22:38 +02007095 exe cmd
7096 exe "sil! keepalt wq!"
7097 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007098 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007099 endif
7100 endfor
7101
7102 " unmark marked file list
7103 call s:NetrwUnmarkList(curbufnr,curdir)
7104
7105 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007106 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007107 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007108 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007109 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007110 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007111endfun
7112
7113" ---------------------------------------------------------------------
7114" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7115" as the marked file(s) (toggles suffix presence)
7116" Uses the local marked file list.
7117fun! s:NetrwMarkHideSfx(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007118 let svpos = winsaveview()
Bram Moolenaar15146672011-10-20 22:22:38 +02007119 let curbufnr = bufnr("%")
7120
7121 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7122 if exists("s:netrwmarkfilelist_{curbufnr}")
7123
7124 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar15146672011-10-20 22:22:38 +02007125 " construct suffix pattern
7126 if fname =~ '\.'
7127 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7128 else
7129 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7130 endif
7131 " determine if its in the hiding list or not
7132 let inhidelist= 0
7133 if g:netrw_list_hide != ""
7134 let itemnum = 0
7135 let hidelist= split(g:netrw_list_hide,',')
7136 for hidepat in hidelist
7137 if sfxpat == hidepat
7138 let inhidelist= 1
7139 break
7140 endif
7141 let itemnum= itemnum + 1
7142 endfor
7143 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007144 if inhidelist
7145 " remove sfxpat from list
7146 call remove(hidelist,itemnum)
7147 let g:netrw_list_hide= join(hidelist,",")
7148 elseif g:netrw_list_hide != ""
7149 " append sfxpat to non-empty list
7150 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7151 else
7152 " set hiding list to sfxpat
7153 let g:netrw_list_hide= sfxpat
7154 endif
7155 endfor
7156
7157 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007158 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007159 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007160 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007161 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007162 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007163endfun
7164
7165" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007166" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7167" Uses the global markfilelist
7168fun! s:NetrwMarkFileGrep(islocal)
7169" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007170 let svpos = winsaveview()
7171" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007172 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007173 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007174
7175 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007176" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007177 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007178" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007179 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007180 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007181" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007182 let netrwmarkfilelist= "*"
7183 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007184
Bram Moolenaarff034192013-04-24 18:51:19 +02007185 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007186" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007187 call inputsave()
7188 let pat= input("Enter pattern: ","")
7189 call inputrestore()
7190 let patbang = ""
7191 if pat =~ '^!'
7192 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007193 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007194 endif
7195 if pat =~ '^\i'
7196 let pat = escape(pat,'/')
7197 let pat = '/'.pat.'/'
7198 else
7199 let nonisi = pat[0]
7200 endif
7201
7202 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007203" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007204 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007205 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007206 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007207 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007208" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7209 return
7210 endtry
7211 echo "(use :cn, :cp to navigate, :Rex to return)"
7212
7213 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007214" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7215 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007216
7217 if exists("nonisi")
7218 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007219" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007220 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007221 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007222 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007223 endif
7224
7225" call Dret("s:NetrwMarkFileGrep")
7226endfun
7227
7228" ---------------------------------------------------------------------
7229" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7230" uses the global marked file list
7231" s:netrwmfloc= 0: target directory is remote
7232" = 1: target directory is local
7233fun! s:NetrwMarkFileMove(islocal)
7234" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007235 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007236 let curbufnr = bufnr("%")
7237
7238 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007239 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007240 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007241" call Dret("s:NetrwMarkFileMove")
7242 return
7243 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007244" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007245
Bram Moolenaar446cb832008-06-24 21:56:24 +00007246 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007247 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007248" call Dret("s:NetrwMarkFileCopy 0")
7249 return 0
7250 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007251" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007252
7253 if a:islocal && s:netrwmftgt_islocal
7254 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007255" call Decho("move from local to local",'~'.expand("<slnum>"))
7256" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007257 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007258 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7259" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7260 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007261 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007262 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007263" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007264 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007265 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007266" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007267 if g:netrw_localmovecmd =~ '\s'
7268 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7269 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7270 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007271" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007272 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007273 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007274" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007275 endif
7276 else
7277 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007278" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007279 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007280 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007281 if g:netrw_keepdir
7282 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7283 let fname= b:netrw_curdir."/".fname
7284 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007285 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007286 let fname= substitute(fname,'/','\\','g')
7287 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007288" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007289 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007290 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007291 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007292 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 +01007293 else
7294 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7295 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007296 break
7297 endif
7298 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007299
7300 elseif a:islocal && !s:netrwmftgt_islocal
7301 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007302" call Decho("move from local to remote",'~'.expand("<slnum>"))
7303" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007304 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007305 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007306" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007307 for fname in mflist
7308 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7309 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7310 endfor
7311 unlet mflist
7312
7313 elseif !a:islocal && s:netrwmftgt_islocal
7314 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007315" call Decho("move from remote to local",'~'.expand("<slnum>"))
7316" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007317 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007318 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007319" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007320 for fname in mflist
7321 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7322 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7323 endfor
7324 unlet mflist
7325
7326 elseif !a:islocal && !s:netrwmftgt_islocal
7327 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007328" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7329" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007330 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007331 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007332" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007333 for fname in mflist
7334 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7335 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7336 endfor
7337 unlet mflist
7338 endif
7339
7340 " -------
7341 " cleanup
7342 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007343" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007344
7345 " remove markings from local buffer
7346 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7347
7348 " refresh buffers
7349 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007350" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007351 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007352 endif
7353 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007354" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007355 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007356 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007357 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007358" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007359 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007360 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007361
Bram Moolenaar446cb832008-06-24 21:56:24 +00007362" call Dret("s:NetrwMarkFileMove")
7363endfun
7364
7365" ---------------------------------------------------------------------
7366" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7367" using the hardcopy command. Local marked-file list only.
7368fun! s:NetrwMarkFilePrint(islocal)
7369" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7370 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007371
7372 " sanity check
7373 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007374 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007375" call Dret("s:NetrwMarkFilePrint")
7376 return
7377 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007378" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7379 let curdir= s:NetrwGetCurdir(a:islocal)
7380
Bram Moolenaar446cb832008-06-24 21:56:24 +00007381 if exists("s:netrwmarkfilelist_{curbufnr}")
7382 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007383 call s:NetrwUnmarkList(curbufnr,curdir)
7384 for fname in netrwmarkfilelist
7385 if a:islocal
7386 if g:netrw_keepdir
7387 let fname= s:ComposePath(curdir,fname)
7388 endif
7389 else
7390 let fname= curdir.fname
7391 endif
7392 1split
7393 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007394" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007395 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007396" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007397 hardcopy
7398 q
7399 endfor
7400 2match none
7401 endif
7402" call Dret("s:NetrwMarkFilePrint")
7403endfun
7404
7405" ---------------------------------------------------------------------
7406" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7407" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007408" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007409fun! s:NetrwMarkFileRegexp(islocal)
7410" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7411
7412 " get the regular expression
7413 call inputsave()
7414 let regexp= input("Enter regexp: ","","file")
7415 call inputrestore()
7416
7417 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007418 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007419" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007420 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007421" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007422 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007423 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007424 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007425 else
7426 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007427 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007428 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007429" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007430
7431 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007432 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007433 if fname =~ '^'.fnameescape(curdir)
7434" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7435 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7436 else
7437" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7438 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7439 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007440 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007441
7442 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007443" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007444
7445 " convert displayed listing into a filelist
7446 let eikeep = &ei
7447 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007448 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007449 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007450" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007451 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007452 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02007453 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007454 sil NetrwKeepj norm! "ap
7455 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007456 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007457 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007458 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007459 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007460 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007461 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007462 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007463 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007464 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007465 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007466 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7467 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007468 call histdel("/",-1)
7469 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007470 endif
7471 " convert regexp into the more usual glob-style format
7472 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007473" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007474 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01007475 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007476 let filelist= getline(1,line("$"))
7477 q!
7478 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007479 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007480 endfor
7481 unlet filelist
7482 let @a = areg
7483 let &ei = eikeep
7484 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007485 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007486
7487" call Dret("s:NetrwMarkFileRegexp")
7488endfun
7489
7490" ---------------------------------------------------------------------
7491" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
7492" Uses the local marked file list.
7493fun! s:NetrwMarkFileSource(islocal)
7494" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
7495 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007496
7497 " sanity check
7498 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007499 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007500" call Dret("s:NetrwMarkFileSource")
7501 return
7502 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007503" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7504 let curdir= s:NetrwGetCurdir(a:islocal)
7505
Bram Moolenaar446cb832008-06-24 21:56:24 +00007506 if exists("s:netrwmarkfilelist_{curbufnr}")
7507 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007508 call s:NetrwUnmarkList(curbufnr,curdir)
7509 for fname in netrwmarkfilelist
7510 if a:islocal
7511 if g:netrw_keepdir
7512 let fname= s:ComposePath(curdir,fname)
7513 endif
7514 else
7515 let fname= curdir.fname
7516 endif
7517 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007518" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007519 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007520 endfor
7521 2match none
7522 endif
7523" call Dret("s:NetrwMarkFileSource")
7524endfun
7525
7526" ---------------------------------------------------------------------
7527" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
7528" Uses the global markfilelist
7529fun! s:NetrwMarkFileTag(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007530 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007531 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007532 let curbufnr = bufnr("%")
7533
Bram Moolenaarff034192013-04-24 18:51:19 +02007534 " sanity check
7535 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007536 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007537 return
7538 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007539
Bram Moolenaar446cb832008-06-24 21:56:24 +00007540 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007541 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007542 call s:NetrwUnmarkAll()
7543
7544 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02007545
Bram Moolenaar85850f32019-07-19 22:05:51 +02007546 call system(g:netrw_ctags." ".netrwmarkfilelist)
7547 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00007548 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
7549 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007550
Bram Moolenaar446cb832008-06-24 21:56:24 +00007551 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00007552 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01007553 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007554 let curdir= b:netrw_curdir
7555 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007556 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00007557 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007558 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01007559 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007560 wq!
7561 endif
7562 2match none
Tom Benham64a536d2024-11-07 21:15:03 +01007563 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007564 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007565 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007566endfun
7567
7568" ---------------------------------------------------------------------
7569" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007570" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02007571" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00007572" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02007573" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00007574fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007575 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007576 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007577 let hadtgt = exists("s:netrwmftgt")
7578 if !exists("w:netrw_bannercnt")
7579 let w:netrw_bannercnt= b:netrw_bannercnt
7580 endif
7581
7582 " set up target
7583 if line(".") < w:netrw_bannercnt
Bram Moolenaarff034192013-04-24 18:51:19 +02007584 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
7585 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaarff034192013-04-24 18:51:19 +02007586 unlet s:netrwmftgt s:netrwmftgt_islocal
7587 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007588 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02007589 endif
Tom Benham64a536d2024-11-07 21:15:03 +01007590 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007591 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007592 return
7593 else
7594 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaarff034192013-04-24 18:51:19 +02007595 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007596
7597 else
7598 " get word under cursor.
7599 " * If directory, use it for the target.
7600 " * If file, use b:netrw_curdir for the target
7601 let curword= s:NetrwGetWord()
7602 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007603 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007604 let s:netrwmftgt = tgtdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007605 elseif !a:islocal && tgtdir =~ '/$'
7606 let s:netrwmftgt = tgtdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007607 else
7608 let s:netrwmftgt = curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007609 endif
7610 endif
7611 if a:islocal
7612 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
7613 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007614 endif
7615 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007616 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007617 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
7618 endif
7619 let s:netrwmftgt_islocal= a:islocal
7620
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007621 " need to do refresh so that the banner will be updated
7622 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01007623 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007624 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007625 endif
Tom Benham64a536d2024-11-07 21:15:03 +01007626" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007627 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Tom Benham64a536d2024-11-07 21:15:03 +01007628 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop,0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007629 else
Tom Benham64a536d2024-11-07 21:15:03 +01007630 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007631 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007632 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007633 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007634 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00007635 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007636endfun
7637
7638" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007639" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
7640fun! s:NetrwGetCurdir(islocal)
7641" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
7642
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007643 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007644 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
7645" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
7646 elseif !exists("b:netrw_curdir")
7647 let b:netrw_curdir= getcwd()
7648" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
7649 endif
7650
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007651" 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 +01007652 if b:netrw_curdir !~ '\<\a\{3,}://'
7653 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007654" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007655 if g:netrw_keepdir == 0
7656 call s:NetrwLcd(curdir)
7657 endif
7658 endif
7659
7660" call Dret("s:NetrwGetCurdir <".curdir.">")
7661 return b:netrw_curdir
7662endfun
7663
7664" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00007665" s:NetrwOpenFile: query user for a filename and open it {{{2
7666fun! s:NetrwOpenFile(islocal)
7667" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007668 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00007669 call inputsave()
7670 let fname= input("Enter filename: ")
7671 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02007672" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
7673
7674 " determine if Lexplore is in use
7675 if exists("t:netrw_lexbufnr")
7676 " check if t:netrw_lexbufnr refers to a netrw window
7677" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
7678 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
7679 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
7680" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
7681 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
7682 exe "NetrwKeepj e ".fnameescape(fname)
7683 let @@= ykeep
7684" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
7685 endif
7686 endif
7687
7688 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00007689 if fname !~ '[/\\]'
7690 if exists("b:netrw_curdir")
7691 if exists("g:netrw_quiet")
7692 let netrw_quiet_keep = g:netrw_quiet
7693 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007694 let g:netrw_quiet = 1
7695 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007696 let s:rexposn_{bufnr("%")}= winsaveview()
7697" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007698 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007699 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007700 else
7701 exe "e ".fnameescape(b:netrw_curdir."/".fname)
7702 endif
7703 if exists("netrw_quiet_keep")
7704 let g:netrw_quiet= netrw_quiet_keep
7705 else
7706 unlet g:netrw_quiet
7707 endif
7708 endif
7709 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007710 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007711 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007712 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00007713" call Dret("s:NetrwOpenFile")
7714endfun
7715
7716" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007717" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
7718" For the mapping to this function be made via
7719" netrwPlugin, you'll need to have had
7720" g:netrw_usetab set to non-zero.
7721fun! netrw#Shrink()
7722" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
7723 let curwin = winnr()
7724 let wiwkeep = &wiw
7725 set wiw=1
7726
7727 if &ft == "netrw"
7728 if winwidth(0) > g:netrw_wiw
7729 let t:netrw_winwidth= winwidth(0)
7730 exe "vert resize ".g:netrw_wiw
7731 wincmd l
7732 if winnr() == curwin
7733 wincmd h
7734 endif
7735" call Decho("vert resize 0",'~'.expand("<slnum>"))
7736 else
7737 exe "vert resize ".t:netrw_winwidth
7738" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
7739 endif
7740
7741 elseif exists("t:netrw_lexbufnr")
7742 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
7743 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
7744 let t:netrw_winwidth= winwidth(0)
7745 exe "vert resize ".g:netrw_wiw
7746 wincmd l
7747 if winnr() == curwin
7748 wincmd h
7749 endif
7750" call Decho("vert resize 0",'~'.expand("<slnum>"))
7751 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
7752 exe "vert resize ".t:netrw_winwidth
7753" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01007754 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007755 call netrw#Lexplore(0,0)
7756 endif
7757
7758 else
7759 call netrw#Lexplore(0,0)
7760 endif
7761 let wiw= wiwkeep
7762
7763" call Dret("netrw#Shrink")
7764endfun
7765
7766" ---------------------------------------------------------------------
7767" s:NetSortSequence: allows user to edit the sorting sequence {{{2
7768fun! s:NetSortSequence(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007769 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007770 let svpos= winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007771 call inputsave()
7772 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
7773 call inputrestore()
7774
7775 " refresh the listing
7776 let g:netrw_sort_sequence= newsortseq
Tom Benham64a536d2024-11-07 21:15:03 +01007777 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007778 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007779 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007780endfun
7781
7782" ---------------------------------------------------------------------
7783" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
7784" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02007785" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00007786fun! s:NetrwUnmarkList(curbufnr,curdir)
7787" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
7788
7789 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007790 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007791 for mfile in s:netrwmarkfilelist_{a:curbufnr}
7792 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
7793 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
7794 call remove(s:netrwmarkfilelist,idx) " remove from global list
7795 endfor
7796 if s:netrwmarkfilelist == []
7797 unlet s:netrwmarkfilelist
7798 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007799
Bram Moolenaar446cb832008-06-24 21:56:24 +00007800 " getting rid of the local marked-file lists is easy
7801 unlet s:netrwmarkfilelist_{a:curbufnr}
7802 endif
7803 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
7804 unlet s:netrwmarkfilemtch_{a:curbufnr}
7805 endif
7806 2match none
7807" call Dret("s:NetrwUnmarkList")
7808endfun
7809
7810" ---------------------------------------------------------------------
7811" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
7812fun! s:NetrwUnmarkAll()
7813" call Dfunc("s:NetrwUnmarkAll()")
7814 if exists("s:netrwmarkfilelist")
7815 unlet s:netrwmarkfilelist
7816 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02007817 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007818 2match none
7819" call Dret("s:NetrwUnmarkAll")
7820endfun
7821
7822" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02007823" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007824fun! s:NetrwUnmarkAll2()
7825" call Dfunc("s:NetrwUnmarkAll2()")
7826 redir => netrwmarkfilelist_let
7827 let
7828 redir END
7829 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007830 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00007831 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
7832 for flist in netrwmarkfilelist_list
7833 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
7834 unlet s:netrwmarkfilelist_{curbufnr}
7835 unlet s:netrwmarkfilemtch_{curbufnr}
7836 endfor
7837" call Dret("s:NetrwUnmarkAll2")
7838endfun
7839
7840" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007841" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
7842"
7843" Marked files are in two types of lists:
7844" s:netrwmarkfilelist -- holds complete paths to all marked files
7845" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
7846"
7847" Marked files suitable for use with 2match are in:
7848" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00007849fun! s:NetrwUnMarkFile(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007850 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007851 let curbufnr = bufnr("%")
7852
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007853 " unmark marked file list
7854 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
7855 if exists("s:netrwmarkfilelist")
7856" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007857 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007858 endif
7859
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007860 let ibuf= 1
7861 while ibuf < bufnr("$")
7862 if exists("s:netrwmarkfilelist_".ibuf)
7863 unlet s:netrwmarkfilelist_{ibuf}
7864 unlet s:netrwmarkfilemtch_{ibuf}
7865 endif
7866 let ibuf = ibuf + 1
7867 endwhile
7868 2match none
7869
Tom Benham64a536d2024-11-07 21:15:03 +01007870" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007871call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007872endfun
7873
7874" ---------------------------------------------------------------------
7875" s:NetrwMenu: generates the menu for gvim and netrw {{{2
7876fun! s:NetrwMenu(domenu)
7877
7878 if !exists("g:NetrwMenuPriority")
7879 let g:NetrwMenuPriority= 80
7880 endif
7881
Bram Moolenaaradc21822011-04-01 18:03:16 +02007882 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00007883" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
7884
7885 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007886" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007887 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02007888 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
7889 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
7890 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
7891 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
7892 if g:netrw_dirhistmax > 0
7893 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
7894 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
7895 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
7896 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
7897 else
7898 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
7899 endif
7900 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
7901 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
7902 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
7903 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
7904 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
7905 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
7906 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
7907 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
7908 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
7909 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
7910 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
7911 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
7912 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
7913 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
7914 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 +01007915 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 +02007916 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
7917 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
7918 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
7919 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
7920 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
7921 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
7922 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
7923 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
7924 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
7925 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
7926 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
7927 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
7928 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
7929 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
7930 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
7931 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
7932 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
7933 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
7934 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
7935 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
7936 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
7937 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
7938 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
7939 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
7940 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
7941 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
7942 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
7943 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
7944 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
7945 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>'
7946 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>'
7947 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>'
7948 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
7949 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>'
7950 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>'
7951 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 +01007952 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 +02007953 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
7954 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00007955 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02007956 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
7957 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00007958
7959 elseif !a:domenu
7960 let s:netrwcnt = 0
7961 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007962 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007963 exe curwin."wincmd w"
7964
7965 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007966" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007967 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007968" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007969 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00007970 endif
7971 endif
7972" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007973 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007974 endif
7975
7976endfun
7977
7978" ---------------------------------------------------------------------
7979" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
7980" Used by the O maps (as <SID>NetrwObtain())
7981fun! s:NetrwObtain(islocal)
7982" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
7983
Bram Moolenaar97d62492012-11-15 21:28:22 +01007984 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00007985 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007986 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01007987 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00007988 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
7989 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007990 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007991 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007992 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00007993
7994" call Dret("NetrwObtain")
7995endfun
7996
7997" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007998" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
7999" If there's only one window, then the window will first be split.
8000" Returns:
8001" choice = 0 : didn't have to choose
8002" choice = 1 : saved modified file in window first
8003" choice = 2 : didn't save modified file, opened window
8004" choice = 3 : cancel open
8005fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008006 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008007 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008008 let curdir = b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008009
8010 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008011 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008012 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008013 let curword = s:NetrwGetWord()
8014 let choice = 0
8015 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008016 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01008017 let curdir = s:treedir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008018
Bram Moolenaar8d043172014-01-23 14:24:41 +01008019 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008020 if lastwinnr == 1
8021 " if only one window, open a new one first
Bram Moolenaar85850f32019-07-19 22:05:51 +02008022 " g:netrw_preview=0: preview window shown in a horizontally split window
8023 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008024 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008025 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008026 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar15146672011-10-20 22:22:38 +02008027 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008028 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008029 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008030 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar15146672011-10-20 22:22:38 +02008031 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008032 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008033 let didsplit = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00008034
8035 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008036 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008037 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01008038 setl ei=all
Bram Moolenaar446cb832008-06-24 21:56:24 +00008039 wincmd p
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01008040
Bram Moolenaar71badf92023-04-22 22:40:14 +01008041 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8042 " whoops -- user trying to open file in the Lexplore window.
8043 " Use Lexplore's opening-file window instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01008044" exe g:netrw_chgwin."wincmd w"
8045 wincmd p
Tom Benham64a536d2024-11-07 21:15:03 +01008046 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008047 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008048
8049 " prevwinnr: the window number of the "prev" window
8050 " prevbufnr: the buffer number of the buffer in the "prev" window
8051 " bnrcnt : the qty of windows open on the "prev" buffer
8052 let prevwinnr = winnr()
8053 let prevbufnr = bufnr("%")
8054 let prevbufname = bufname("%")
8055 let prevmod = &mod
8056 let bnrcnt = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008057 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008058
8059 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008060 " and it doesn't appear in any other extant window, then ask the
8061 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008062 if prevmod
Bram Moolenaar8d043172014-01-23 14:24:41 +01008063 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008064 exe prevwinnr."wincmd w"
8065
8066 if bnrcnt == 1 && &hidden == 0
8067 " only one copy of the modified buffer in a window, and
8068 " hidden not set, so overwriting will lose the modified file. Ask first...
8069 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008070 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008071
8072 if choice == 1
8073 " Yes -- write file & then browse
8074 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008075 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008076 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008077 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008078 exe origwin."wincmd w"
8079 let &ei = eikeep
8080 let @@ = ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008081 return choice
8082 endif
8083
8084 elseif choice == 2
8085 " No -- don't worry about changed file, just browse anyway
Bram Moolenaar8d043172014-01-23 14:24:41 +01008086 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008087
8088 else
8089 " Cancel -- don't do this
Bram Moolenaar8d043172014-01-23 14:24:41 +01008090 exe origwin."wincmd w"
8091 let &ei= eikeep
8092 let @@ = ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008093 return choice
8094 endif
8095 endif
8096 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008097 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008098 endif
8099
8100 " restore b:netrw_curdir (window split/enew may have lost it)
8101 let b:netrw_curdir= curdir
8102 if a:islocal < 2
8103 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01008104 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword,0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008105 else
Tom Benham64a536d2024-11-07 21:15:03 +01008106 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword,0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008107 endif
8108 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008109 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008110 return choice
8111endfun
8112
8113" ---------------------------------------------------------------------
8114" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8115" Always assumed to be local -> remote
8116" call s:NetrwUpload(filename, target)
8117" call s:NetrwUpload(filename, target, fromdirectory)
8118fun! s:NetrwUpload(fname,tgt,...)
8119" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8120
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008121 if a:tgt =~ '^\a\{3,}://'
8122 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008123 else
8124 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8125 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008126" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008127
8128 if a:0 > 0
8129 let fromdir= a:1
8130 else
8131 let fromdir= getcwd()
8132 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008133" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008134
8135 if type(a:fname) == 1
8136 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008137" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008138 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008139" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8140 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8141" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008142 if a:tgt =~ '/$'
8143 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008144" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008145 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008146 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008147" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008148 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008149" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008150 endif
8151 q!
8152
8153 elseif type(a:fname) == 3
8154 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008155" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008156 let curdir= getcwd()
8157 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008158 if s:NetrwLcd(fromdir)
8159" call Dret("s:NetrwUpload : lcd failure")
8160 return
8161 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008162 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008163 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008164 if exists("g:netrw_port") && g:netrw_port != ""
8165 let useport= " ".g:netrw_scpport." ".g:netrw_port
8166 else
8167 let useport= ""
8168 endif
8169 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8170 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008171 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 +02008172 if s:NetrwLcd(curdir)
8173" call Dret("s:NetrwUpload : lcd failure")
8174 return
8175 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008176
8177 elseif a:tgt =~ '^ftp:'
8178 call s:NetrwMethod(a:tgt)
8179
8180 if b:netrw_method == 2
8181 " handle uploading a list of files via ftp+.netrc
8182 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008183 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008184" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008185
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008186 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008187" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008188
8189 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008190 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008191" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008192 endif
8193
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008194 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008195" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008196
Bram Moolenaaradc21822011-04-01 18:03:16 +02008197 if tgtdir == ""
8198 let tgtdir= '/'
8199 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008200 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008201" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008202
8203 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008204 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8205" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008206 endfor
8207
8208 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008209 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 +00008210 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008211" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8212 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008213 endif
8214 " 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 +01008215 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008216 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008217 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8218 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8219 else
8220 bw!|q
8221 endif
8222
8223 elseif b:netrw_method == 3
8224 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8225 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008226 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008227 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008228 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008229
8230 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008231 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008232" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008233 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008234 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008235" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008236 endif
8237
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008238 if exists("g:netrw_uid") && g:netrw_uid != ""
8239 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008240 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008241" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008242 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008243 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008244 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008245" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008246 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008247 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008248" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008249 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008250 endif
8251
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008252 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008253" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008254
8255 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008256 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008257" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008258 endif
8259
8260 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008261 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008262" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008263 endif
8264
8265 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008266 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008267" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008268 endfor
8269
8270 " perform ftp:
8271 " -i : turns off interactive prompting from ftp
8272 " -n unix : DON'T use <.netrc>, even though it exists
8273 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008274 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008275 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008276 " 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 +01008277 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008278 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008279 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8280 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008281 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008282 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8283 let &debug = debugkeep
8284 let mod = 1
8285 else
8286 bw!|q
8287 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008288 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008289" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008290 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008291 endif
8292 else
8293 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8294 endif
8295 endif
8296
8297" call Dret("s:NetrwUpload")
8298endfun
8299
8300" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008301" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008302fun! s:NetrwPreview(path) range
8303" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008304" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8305" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008306 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008307 NetrwKeepj call s:NetrwOptionsSave("s:")
8308 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8309 NetrwKeepj call s:NetrwOptionsSafe(1)
8310 else
8311 NetrwKeepj call s:NetrwOptionsSafe(0)
8312 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008313 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008314" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008315 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008316" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8317 if g:netrw_preview
8318 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008319 let pvhkeep = &pvh
8320 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8321 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008322" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8323 else
8324 " horizontal split
8325 let pvhkeep = &pvh
8326 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8327 let &pvh = winheight(0) - winsz
8328" 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 +02008329 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008330 " g:netrw_preview g:netrw_alto
8331 " 1 : vert 1: top -- preview window is vertically split off and on the left
8332 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8333 " 0 : 1: top -- preview window is horizontally split off and on the top
8334 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8335 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008336 " 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 +02008337 " the BufEnter event set up in netrwPlugin.vim
8338" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8339 let eikeep = &ei
8340 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008341 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008342 let &ei= eikeep
8343" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008344 if exists("pvhkeep")
8345 let &pvh= pvhkeep
8346 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008347 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008348 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008349 endif
8350 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008351 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 +00008352 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008353 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008354 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008355" call Dret("NetrwPreview")
8356endfun
8357
8358" ---------------------------------------------------------------------
8359" s:NetrwRefresh: {{{2
8360fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008361" 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 +00008362 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008363 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008364" call Decho("setl ma noro",'~'.expand("<slnum>"))
8365" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008366 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008367 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8368 if !exists("w:netrw_treetop")
8369 if exists("b:netrw_curdir")
8370 let w:netrw_treetop= b:netrw_curdir
8371 else
8372 let w:netrw_treetop= getcwd()
8373 endif
8374 endif
8375 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
8376 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008377
8378 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008379 let screenposn = winsaveview()
8380" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008381
8382" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
8383" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
8384 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008385 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008386 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008387 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008388 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008389 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008390
8391 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008392" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
8393 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008394
8395 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02008396 if has("syntax") && exists("g:syntax_on") && g:syntax_on
8397 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8398" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
8399 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8400 else
8401" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
8402 2match none
8403 endif
8404 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008405
Bram Moolenaar97d62492012-11-15 21:28:22 +01008406" restore
8407 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008408" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008409endfun
8410
8411" ---------------------------------------------------------------------
8412" s:NetrwRefreshDir: refreshes a directory by name {{{2
8413" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008414" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008415fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008416 if g:netrw_fastbrowse == 0
8417 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008418 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008419
8420 if tgtwin > 0
8421 " tgtwin is being displayed, so refresh it
8422 let curwin= winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008423 exe tgtwin."wincmd w"
Tom Benham64a536d2024-11-07 21:15:03 +01008424 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008425 exe curwin."wincmd w"
8426
8427 elseif bufnr(a:dirname) > 0
8428 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008429 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00008430 endif
8431
8432 elseif g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008433 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008434 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008435endfun
8436
8437" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02008438" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
8439" window number to do its editing in.
8440" Supports [count]C where the count, if present, is used to specify
8441" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008442fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02008443" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008444 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008445" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008446 if a:1 == "" " :NetrwC win#
8447 let g:netrw_chgwin= winnr()
8448 else " :NetrwC
8449 let g:netrw_chgwin= a:1
8450 endif
8451 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02008452 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008453 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02008454 let g:netrw_chgwin= winnr()
8455 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008456 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008457" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02008458endfun
8459
8460" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008461" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
8462" What this function does is to compute a priority for the patterns
8463" in the g:netrw_sort_sequence. It applies a substitute to any
8464" "files" that satisfy each pattern, putting the priority / in
8465" front. An "*" pattern handles the default priority.
8466fun! s:NetrwSetSort()
8467" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008468 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008469 if w:netrw_liststyle == s:LONGLIST
8470 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
8471 else
8472 let seqlist = g:netrw_sort_sequence
8473 endif
8474 " sanity check -- insure that * appears somewhere
8475 if seqlist == ""
8476 let seqlist= '*'
8477 elseif seqlist !~ '\*'
8478 let seqlist= seqlist.',*'
8479 endif
8480 let priority = 1
8481 while seqlist != ""
8482 if seqlist =~ ','
8483 let seq = substitute(seqlist,',.*$','','e')
8484 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
8485 else
8486 let seq = seqlist
8487 let seqlist = ""
8488 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008489 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01008490 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008491 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01008492 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008493 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01008494 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008495 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008496" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008497
8498 " sanity check
8499 if w:netrw_bannercnt > line("$")
8500 " apparently no files were left after a Hiding pattern was used
8501" call Dret("SetSort : no files left after hiding")
8502 return
8503 endif
8504 if seq == '*'
8505 let starpriority= spriority
8506 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008507 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008508 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008509 " sometimes multiple sorting patterns will match the same file or directory.
8510 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008511 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
8512 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008513 endif
8514 let priority = priority + 1
8515 endwhile
8516 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008517 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
8518 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008519 endif
8520
8521 " Following line associated with priority -- items that satisfy a priority
8522 " pattern get prefixed by ###/ which permits easy sorting by priority.
8523 " Sometimes files can satisfy multiple priority patterns -- only the latest
8524 " priority pattern needs to be retained. So, at this point, these excess
8525 " priority prefixes need to be removed, but not directories that happen to
8526 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008527 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
8528 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008529 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008530
8531" call Dret("SetSort")
8532endfun
8533
Bram Moolenaarff034192013-04-24 18:51:19 +02008534" ---------------------------------------------------------------------
8535" s:NetrwSetTgt: sets the target to the specified choice index {{{2
8536" Implements [count]Tb (bookhist<b>)
8537" [count]Th (bookhist<h>)
8538" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008539fun! s:NetrwSetTgt(islocal,bookhist,choice)
8540" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02008541
8542 if a:bookhist == 'b'
8543 " supports choosing a bookmark as a target using a qb-generated list
8544 let choice= a:choice - 1
8545 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01008546 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02008547 else
8548 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
8549 endif
8550
8551 elseif a:bookhist == 'h'
8552 " supports choosing a history stack entry as a target using a qb-generated list
8553 let choice= (a:choice % g:netrw_dirhistmax) + 1
8554 if exists("g:netrw_dirhist_".choice)
8555 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01008556 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02008557 else
8558 echomsg "Sorry, history#".a:choice." not available!"
8559 endif
8560 endif
8561
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008562 " refresh the display
8563 if !exists("b:netrw_curdir")
8564 let b:netrw_curdir= getcwd()
8565 endif
8566 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
8567
Bram Moolenaarff034192013-04-24 18:51:19 +02008568" call Dret("s:NetrwSetTgt")
8569endfun
8570
Bram Moolenaar446cb832008-06-24 21:56:24 +00008571" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02008572" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008573fun! s:NetrwSortStyle(islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008574 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008575 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008576
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008577 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 +01008578 NetrwKeepj norm! 0
Tom Benham64a536d2024-11-07 21:15:03 +01008579 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008580 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008581endfun
8582
8583" ---------------------------------------------------------------------
8584" s:NetrwSplit: mode {{{2
8585" =0 : net and o
8586" =1 : net and t
8587" =2 : net and v
8588" =3 : local and o
8589" =4 : local and t
8590" =5 : local and v
8591fun! s:NetrwSplit(mode)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008592
Bram Moolenaar97d62492012-11-15 21:28:22 +01008593 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008594 call s:SaveWinVars()
8595
8596 if a:mode == 0
8597 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02008598 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008599 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008600 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008601 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008602 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008603 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008604 unlet s:didsplit
8605
8606 elseif a:mode == 1
8607 " remote and t
Tom Benham64a536d2024-11-07 21:15:03 +01008608 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008609 tabnew
8610 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008611 NetrwKeepj call s:RestoreWinVars()
8612 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008613 unlet s:didsplit
8614
8615 elseif a:mode == 2
8616 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02008617 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008618 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008619 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008620 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008621 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008622 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008623 unlet s:didsplit
8624
8625 elseif a:mode == 3
8626 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02008627 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008628 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008629 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008630 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008631 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008632 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008633 unlet s:didsplit
8634
8635 elseif a:mode == 4
8636 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00008637 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008638 let eikeep = &ei
8639 let netrw_winnr = winnr()
8640 let netrw_line = line(".")
8641 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008642 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01008643 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01008644 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008645 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
8646 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008647 let &ei = eikeep
8648 let netrw_curdir = s:NetrwTreeDir(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008649 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01008650 let b:netrw_curdir = netrw_curdir
8651 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008652 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008653 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword,0))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008654 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01008655 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008656 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
8657 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01008658 let &ei= eikeep
8659 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008660 unlet s:didsplit
8661
8662 elseif a:mode == 5
8663 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02008664 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008665 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008666 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008667 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008668 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008669 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008670 unlet s:didsplit
8671
8672 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008673 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008674 endif
8675
Bram Moolenaar97d62492012-11-15 21:28:22 +01008676 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008677endfun
8678
8679" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008680" s:NetrwTgtMenu: {{{2
8681fun! s:NetrwTgtMenu()
8682 if !exists("s:netrw_menucnt")
8683 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008684 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008685" call Dfunc("s:NetrwTgtMenu()")
8686
8687 " the following test assures that gvim is running, has menus available, and has menus enabled.
8688 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
8689 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008690" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008691 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
8692 endif
8693 if !exists("s:netrw_initbookhist")
8694 call s:NetrwBookHistRead()
8695 endif
8696
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008697 " try to cull duplicate entries
8698 let tgtdict={}
8699
Bram Moolenaarff034192013-04-24 18:51:19 +02008700 " target bookmarked places
8701 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008702" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008703 let cnt= 1
8704 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008705 if has_key(tgtdict,bmd)
8706 let cnt= cnt + 1
8707 continue
8708 endif
8709 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02008710 let ebmd= escape(bmd,g:netrw_menu_escape)
8711 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008712" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008713 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 +02008714 let cnt= cnt + 1
8715 endfor
8716 endif
8717
8718 " target directory browsing history
8719 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008720" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008721 let histcnt = 1
8722 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02008723 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02008724 if exists("g:netrw_dirhist_{histcnt}")
8725 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008726 if has_key(tgtdict,histentry)
8727 let histcnt = histcnt + 1
8728 continue
8729 endif
8730 let tgtdict[histentry] = histcnt
8731 let ehistentry = escape(histentry,g:netrw_menu_escape)
8732" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008733 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 +02008734 endif
8735 let histcnt = histcnt + 1
8736 endwhile
8737 endif
8738 endif
8739" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008740endfun
8741
8742" ---------------------------------------------------------------------
8743" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
8744" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008745fun! s:NetrwTreeDir(islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008746
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008747 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008748 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
8749 let treedir= s:treedir
8750 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008751 unlet s:prevwinopen
Bram Moolenaar8d043172014-01-23 14:24:41 +01008752 return treedir
8753 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008754 if exists("s:prevwinopen")
8755 unlet s:prevwinopen
8756 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008757
Bram Moolenaar8d043172014-01-23 14:24:41 +01008758 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
8759 let b:netrw_curdir= getcwd()
8760 endif
8761 let treedir = b:netrw_curdir
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008762 let s:treecurpos= winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008763
8764 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar5c736222010-01-06 20:54:52 +01008765
8766 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008767 let curline= substitute(getline('.'),"\t -->.*$",'','')
8768 if curline =~ '/$'
Bram Moolenaar8d043172014-01-23 14:24:41 +01008769 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008770 elseif curline =~ '@$'
Tom Benham64a536d2024-11-07 21:15:03 +01008771 let potentialdir= resolve(s:NetrwTreePath(w:netrw_treetop))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008772 else
8773 let treedir= ""
8774 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008775
8776 " detect user attempting to close treeroot
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008777 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008778 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008779 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008780 return b:netrw_curdir
8781 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008782
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008783 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
8784" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
8785" let newdir = w:netrw_treetop.'/'.potentialdir
Christian Brabandt56b7da32024-02-29 17:48:14 +01008786 if a:islocal && curline =~ '@$'
8787 if isdirectory(s:NetrwFile(potentialdir))
Tom Benham64a536d2024-11-07 21:15:03 +01008788 let treedir = potentialdir
Christian Brabandt56b7da32024-02-29 17:48:14 +01008789 let w:netrw_treetop = treedir
8790 endif
8791 else
8792 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
8793 let treedir = s:NetrwTreePath(w:netrw_treetop)
8794 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008795 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008796
8797 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00008798 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008799 return treedir
8800endfun
8801
8802" ---------------------------------------------------------------------
8803" s:NetrwTreeDisplay: recursive tree display {{{2
8804fun! s:NetrwTreeDisplay(dir,depth)
Tom Benham64a536d2024-11-07 21:15:03 +01008805 " ensure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02008806 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00008807
8808 " install ../ and shortdir
8809 if a:depth == ""
8810 call setline(line("$")+1,'../')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008811 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008812 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008813 if a:dir == w:netrw_treetop
8814 let shortdir= a:dir
8815 else
8816 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
8817 endif
8818 call setline(line("$")+1,a:depth.shortdir)
8819 else
8820 let shortdir= substitute(a:dir,'^.*/','','e')
8821 call setline(line("$")+1,a:depth.shortdir.'/')
8822 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008823 " append a / to dir if its missing one
8824 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008825
8826 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008827 let depth= s:treedepthstring.a:depth
Bram Moolenaar446cb832008-06-24 21:56:24 +00008828
Bram Moolenaar85850f32019-07-19 22:05:51 +02008829 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
8830 if g:netrw_hide == 1
8831 " hide given patterns
8832 let listhide= split(g:netrw_list_hide,',')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008833 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02008834 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008835 endfor
8836
8837 elseif g:netrw_hide == 2
8838 " show given patterns (only)
8839 let listhide= split(g:netrw_list_hide,',')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008840 let entries=[]
8841 for entry in w:netrw_treedict[dir]
8842 for pat in listhide
8843 if entry =~ pat
8844 call add(entries,entry)
8845 break
8846 endif
8847 endfor
8848 endfor
8849 let w:netrw_treedict[dir]= entries
8850 endif
8851 if depth != ""
8852 " always remove "." and ".." entries when there's depth
8853 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
Tom Benham64a536d2024-11-07 21:15:03 +01008854 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\./$"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008855 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
Tom Benham64a536d2024-11-07 21:15:03 +01008856 call filter(w:netrw_treedict[dir],'v:val !~ "\\./$"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008857 endif
8858
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008859 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008860 if dir =~ '/$'
8861 let direntry= substitute(dir.entry,'[@/]$','','e')
8862 else
8863 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
8864 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008865 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008866 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008867 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008868 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
8869 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
Tom Benham64a536d2024-11-07 21:15:03 +01008870 NetrwKeepj call s:NetrwTreeDisplay(direntry.'@',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008871 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008872 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008873 endif
8874 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008875endfun
8876
8877" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008878" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
8879fun! s:NetrwRefreshTreeDict(dir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008880 if !exists("w:netrw_treedict")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008881 return
8882 endif
8883
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008884 for entry in w:netrw_treedict[a:dir]
8885 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008886
8887 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008888 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Tom Benham64a536d2024-11-07 21:15:03 +01008889 let filelist = s:NetrwLocalListingList(direntry,0)
8890 let w:netrw_treedict[direntry] = sort(filelist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008891
8892 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008893 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Tom Benham64a536d2024-11-07 21:15:03 +01008894 let filelist = s:NetrwLocalListingList(direntry.'/',0)
8895 let w:netrw_treedict[direntry] = sort(filelist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008896
8897 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008898 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008899 let liststar = s:NetrwGlob(direntry.'/','*',1)
8900 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008901
8902 else
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008903 endif
8904 endfor
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008905endfun
8906
8907" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008908" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008909" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008910fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008911 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00008912
8913 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00008914 if !exists("w:netrw_treetop")
8915 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008916 let s:netrw_treetop= w:netrw_treetop
Tom Benham4d618002024-10-31 10:47:23 +01008917 " use \V in case the directory contains specials chars like '$' or '~'
8918 elseif (w:netrw_treetop =~ ('^'.'\V'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop))
8919 \ || a:dirname !~ ('^'.'\V'.w:netrw_treetop)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008920 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008921 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00008922 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008923 if exists("w:netrw_treetop")
8924 let s:netrw_treetop= w:netrw_treetop
8925 else
8926 let w:netrw_treetop= getcwd()
8927 let s:netrw_treetop= w:netrw_treetop
8928 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008929
Bram Moolenaar446cb832008-06-24 21:56:24 +00008930 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008931 " insure that we have a treedict, albeit empty
Bram Moolenaar446cb832008-06-24 21:56:24 +00008932 let w:netrw_treedict= {}
8933 endif
8934
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008935 " update the dictionary for the current directory
Christian Brabandta063b222024-11-07 14:30:30 +01008936 exe "sil! NetrwKeepj keepp ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008937 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008938 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008939
8940 " if past banner, record word
8941 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
8942 let fname= expand("<cword>")
8943 else
8944 let fname= ""
8945 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008946
8947 " display from treetop on down
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008948 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008949
8950 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
8951 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaar8d043172014-01-23 14:24:41 +01008952 1d
8953 endwhile
8954
Bram Moolenaar13600302014-05-22 18:26:40 +02008955 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00008956
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008957 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008958 endif
8959endfun
8960
8961" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008962" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01008963" Normally, treetop is w:netrw_treetop, but a
8964" user of the function ( netrw#SetTreetop() )
8965" wipes that out prior to calling this function
8966fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008967" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
8968 if line(".") < w:netrw_bannercnt + 2
8969 let treedir= a:treetop
8970 if treedir !~ '/$'
8971 let treedir= treedir.'/'
8972 endif
8973" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
8974 return treedir
8975 endif
8976
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008977 let svpos = winsaveview()
8978" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008979 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008980" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008981 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008982" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
8983 let curline= getline('.')
8984" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
8985 if curline =~ '/$'
8986" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
8987 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
8988" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
8989 elseif curline =~ '@\s\+-->'
8990" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
8991 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
8992 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
8993" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008994 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008995" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008996 let treedir= ""
8997 endif
8998 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008999" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9000" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009001 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9002 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9003 let treedir= dirname.treedir
9004 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009005" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009006 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009007" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009008 if a:treetop =~ '/$'
9009 let treedir= a:treetop.treedir
9010 else
9011 let treedir= a:treetop.'/'.treedir
9012 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009013" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009014 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009015" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009016" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9017 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009018" call Dret("s:NetrwTreePath <".treedir.">")
9019 return treedir
9020endfun
9021
9022" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009023" s:NetrwWideListing: {{{2
9024fun! s:NetrwWideListing()
9025
9026 if w:netrw_liststyle == s:WIDELIST
9027" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9028 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009029 " cpf: characters per filename
9030 " fpl: filenames per line
9031 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009032 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009033 let dict={}
9034 " save the unnamed register and register 0-9 and a
9035 let dict.a=[getreg('a'), getregtype('a')]
9036 for i in range(0, 9)
9037 let dict[i] = [getreg(i), getregtype(i)]
9038 endfor
9039 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009040" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009041 let b:netrw_cpf= 0
9042 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009043 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009044 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9045 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009046 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009047 " restore stored registers
9048 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009049" call Dret("NetrwWideListing")
9050 return
9051 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009052 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009053 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009054" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009055
9056 " determine qty files per line (fpl)
9057 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9058 if w:netrw_fpl <= 0
9059 let w:netrw_fpl= 1
9060 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009061" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009062
9063 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009064 " fpc: files per column of wide listing
9065 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009066 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009067 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9068 let newcolstart = w:netrw_bannercnt + fpc
9069 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009070" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009071 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009072" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009073 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009074 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009075 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009076 while line("$") >= newcolstart
9077 if newcolend > line("$") | let newcolend= line("$") | endif
9078 let newcolqty= newcolend - newcolstart
9079 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009080 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009081 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009082 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009083 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009084 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009085 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009086 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009087 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009088 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009089 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009090" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009091 if @* != keepregstar | sil! let @* = keepregstar | endif
9092 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009093 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009094 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9095 NetrwKeepj call histdel("/",-1)
9096 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9097 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009098" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009099 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009100 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009101" 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 +00009102" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009103 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009104 else
9105 if hasmapto("w","n")
9106 sil! nunmap <buffer> w
9107 endif
9108 if hasmapto("b","n")
9109 sil! nunmap <buffer> b
9110 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009111 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009112endfun
9113
9114" ---------------------------------------------------------------------
9115" s:PerformListing: {{{2
9116fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009117" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9118" 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 +02009119" 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>"))
9120 sil! NetrwKeepj %d _
9121" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009122
Bram Moolenaar15146672011-10-20 22:22:38 +02009123 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009124" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009125 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009126
Bram Moolenaar85850f32019-07-19 22:05:51 +02009127 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009128 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009129" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009130
9131" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009132" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009133" endif " Decho
9134
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009135" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009136 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9137 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009138" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9139 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009140 endif
9141
9142 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009143 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009144
9145 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009146 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009147" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009148 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009149 if exists("g:netrw_pchk")
9150 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9151 " failure detections.
9152 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009153 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009154 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9155 endif
9156 if exists("g:netrw_pchk")
9157 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9158 else
9159 let curdir= b:netrw_curdir
9160 endif
9161 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9162 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9163 else
9164 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009165 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009166 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009167 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009168 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009169" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009170 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009171 let w:netrw_bannercnt= 1
9172 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009173" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9174" 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 +00009175
Bram Moolenaar85850f32019-07-19 22:05:51 +02009176 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009177 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009178 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009179 let sortby= sortby." reversed"
9180 endif
9181
9182 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009183 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009184" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009185 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009186" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009187 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009188 NetrwKeepj put ='\" Sorted by '.sortby
9189 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009190 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9191 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009192" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009193 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009194 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009195 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9196 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009197 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009198" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009199" 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 +00009200 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009201
Bram Moolenaar85850f32019-07-19 22:05:51 +02009202 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009203 if g:netrw_banner
9204 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009205" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009206 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009207 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009208 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009209 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009210 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009211 endif
9212 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009213 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009214" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009215 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009216 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009217 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009218
9219 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009220 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009221" 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 +01009222 if g:netrw_list_hide != "" && g:netrw_hide
9223 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009224 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009225 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009226 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009227 endif
9228 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009229 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009230 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009231
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009232" 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 +01009233 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009234" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009235 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009236" 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 +01009237 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009238 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009239" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009240" 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 +00009241 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009242
9243 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009244 if g:netrw_banner
9245 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009246 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009247" 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 +01009248" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009249" 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 +01009250 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009251
Bram Moolenaar446cb832008-06-24 21:56:24 +00009252 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009253" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009254 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009255 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009256 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009257 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009258 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009259" 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 +01009260" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9261 return
9262 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009263 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009264
9265 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009266 if !exists("w:netrw_bannercnt")
9267 let w:netrw_bannercnt= 0
9268 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009269" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
9270" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
9271" 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 +01009272
Bram Moolenaar5c736222010-01-06 20:54:52 +01009273 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009274" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009275" 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 +00009276 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009277 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009278 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009279 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009280" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009281
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009282 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009283 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +02009284" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009285 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009286
Bram Moolenaar5c736222010-01-06 20:54:52 +01009287 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009288" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009289 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +02009290 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009291 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009292 else
9293 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009294 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009295 endif
9296 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009297
Bram Moolenaar446cb832008-06-24 21:56:24 +00009298 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009299" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009300 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
9301 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009302
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009303 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +02009304 " exten: sort by extension
9305 " The histdel(...,-1) calls remove the last search from the search history
9306" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009307 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
9308 NetrwKeepj call histdel("/",-1)
9309 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
9310 NetrwKeepj call histdel("/",-1)
9311 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
9312 NetrwKeepj call histdel("/",-1)
9313 if !g:netrw_banner || w:netrw_bannercnt < line("$")
9314" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009315 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009316 " normal direction sorting
9317 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
9318 else
9319 " reverse direction sorting
9320 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
9321 endif
9322 endif
9323 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
9324 NetrwKeepj call histdel("/",-1)
9325
Bram Moolenaar446cb832008-06-24 21:56:24 +00009326 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01009327 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009328" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009329 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009330" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009331 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009332 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009333" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009334 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009335 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009336" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009337 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
9338 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009339 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009340 endif
9341
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009342 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009343" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009344 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009345 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009346 call histdel("/",-1)
9347 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009348 endif
9349 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009350" 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 +00009351
9352 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009353" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
9354" 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 +01009355 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009356" 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 +01009357 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009358" 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 +00009359
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009360 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009361 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009362" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Christian Brabandta063b222024-11-07 14:30:30 +01009363 sil! keepp g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009364 endif
9365
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009366 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009367 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009368" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
9369 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009370 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009371" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
9372 else
9373" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
9374" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
9375" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
9376" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009377 endif
9378
9379 " record previous current directory
9380 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009381" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009382
9383 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009384" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
9385" 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 +01009386 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009387" 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 +02009388 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009389" 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 +00009390
9391 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009392" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02009393 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009394" 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 +01009395 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009396" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009397 exe "setl ts=".(g:netrw_maxfilenamelen+1)
9398 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009399" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009400" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009401
Bram Moolenaar8d043172014-01-23 14:24:41 +01009402 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009403" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
9404" 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 +01009405" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
9406 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009407 unlet s:treecurpos
9408 endif
9409
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009410" 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>"))
9411" 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 +00009412" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
9413endfun
9414
9415" ---------------------------------------------------------------------
9416" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00009417fun! s:SetupNetrwStatusLine(statline)
9418" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
9419
9420 if !exists("s:netrw_setup_statline")
9421 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009422" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00009423
9424 if !exists("s:netrw_users_stl")
9425 let s:netrw_users_stl= &stl
9426 endif
9427 if !exists("s:netrw_users_ls")
9428 let s:netrw_users_ls= &laststatus
9429 endif
9430
9431 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +02009432 let dict={}
9433 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +00009434 redir @a
9435 try
9436 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009437 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +00009438 if &bg == "dark"
9439 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
9440 else
9441 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
9442 endif
9443 endtry
9444 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +02009445 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +00009446 endif
9447
9448 " set up status line (may use User9 highlighting)
9449 " insure that windows have a statusline
9450 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +09009451 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +02009452 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009453" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009454 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +00009455
9456" call Dret("SetupNetrwStatusLine : stl=".&stl)
9457endfun
9458
Bram Moolenaar85850f32019-07-19 22:05:51 +02009459" =========================================
9460" Remote Directory Browsing Support: {{{1
9461" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00009462
9463" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01009464" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
9465" This function assumes that a long listing will be received. Size, time,
9466" and reverse sorts will be requested of the server but not otherwise
9467" enforced here.
9468fun! s:NetrwRemoteFtpCmd(path,listcmd)
9469" 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 +01009470" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009471 " sanity check: {{{3
9472 if !exists("w:netrw_method")
9473 if exists("b:netrw_method")
9474 let w:netrw_method= b:netrw_method
9475 else
9476 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
9477" call Dret("NetrwRemoteFtpCmd")
9478 return
9479 endif
9480 endif
9481
9482 " WinXX ftp uses unix style input, so set ff to unix " {{{3
9483 let ffkeep= &ff
9484 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009485" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009486
9487 " clear off any older non-banner lines " {{{3
9488 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009489" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
9490 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +01009491
9492 ".........................................
9493 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
9494 " ftp + <.netrc>: Method #2
9495 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009496 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009497 endif
9498 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009499 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009500" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009501 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009502 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009503" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +01009504 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009505" 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>"))
9506 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 +01009507 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009508" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
9509 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 +01009510 endif
9511
9512 ".........................................
9513 elseif w:netrw_method == 3 " {{{3
9514 " ftp + machine,id,passwd,filename: Method #3
9515 setl ff=unix
9516 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009517 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +01009518 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009519 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +01009520 endif
9521
9522 " handle userid and password
9523 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009524" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009525 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
9526 call NetUserPass("ftp:".host)
9527 endif
9528 if exists("g:netrw_uid") && g:netrw_uid != ""
9529 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009530 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +01009531 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009532 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009533 endif
9534 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009535 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009536 endif
9537 endif
9538
9539 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009540 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009541 endif
9542 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009543 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009544" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009545 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009546 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +01009547
9548 " perform ftp:
9549 " -i : turns off interactive prompting from ftp
9550 " -n unix : DON'T use <.netrc>, even though it exists
9551 " -n win32: quit being obnoxious about password
9552 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009553" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009554 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +01009555" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009556" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
9557" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009558 endif
9559
9560 ".........................................
9561 elseif w:netrw_method == 9 " {{{3
9562 " sftp username@machine: Method #9
9563 " s:netrw_sftp_cmd
9564 setl ff=unix
9565
9566 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +09009567 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +01009568" call Dret("NetrwRemoteFtpCmd")
9569 return
9570
9571 ".........................................
9572 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009573 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +01009574 endif
9575
9576 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +02009577 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009578 sil! NetrwKeepj %s/\r$//e
9579 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009580 endif
9581 if a:listcmd == "dir"
9582 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009583 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
9584 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
9585 NetrwKeepj call histdel("/",-1)
9586 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009587 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 +01009588 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
9589 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009590 endif
9591 endif
9592
9593 " ftp's listing doesn't seem to include ./ or ../ " {{{3
9594 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009595 exe 'NetrwKeepj '.w:netrw_bannercnt
9596 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +01009597 endif
9598 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009599 exe 'NetrwKeepj '.w:netrw_bannercnt
9600 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +01009601 endif
9602
9603 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +09009604 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +01009605" call Dret("NetrwRemoteFtpCmd")
9606endfun
9607
9608" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009609" s:NetrwRemoteListing: {{{2
9610fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009611" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00009612
Bram Moolenaara6878372014-03-22 21:02:50 +01009613 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
9614 let w:netrw_bannercnt= s:bannercnt
9615 endif
9616 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +09009617 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009618 endif
9619
Bram Moolenaar446cb832008-06-24 21:56:24 +00009620 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009621
Bram Moolenaar446cb832008-06-24 21:56:24 +00009622 " sanity check:
9623 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009624" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009625 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009626" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009627 if !exists("g:netrw_quiet")
9628 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
9629 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009630 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009631" call Dret("s:NetrwRemoteListing -1")
9632 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00009633 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009634
Bram Moolenaar8d043172014-01-23 14:24:41 +01009635 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009636" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009637 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009638 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009639 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 +00009640 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009641 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 +00009642 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009643 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009644
Bram Moolenaar85850f32019-07-19 22:05:51 +02009645 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009646" call Dret("s:NetrwRemoteListing -1")
9647 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009648 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009649" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009650
Bram Moolenaar446cb832008-06-24 21:56:24 +00009651 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009652" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009653 let w:netrw_method= b:netrw_method
9654 endif
9655
Bram Moolenaar13600302014-05-22 18:26:40 +02009656 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +02009657 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009658" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009659 let s:method = "ftp"
9660 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009661 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009662 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009663 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009664 let listcmd= g:netrw_ftp_sizelist_cmd
9665 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009666" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009667 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009668" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009669
Bram Moolenaara6878372014-03-22 21:02:50 +01009670 " report on missing file or directory messages
9671 if search('[Nn]o such file or directory\|Failed to change directory')
9672 let mesg= getline(".")
9673 if exists("w:netrw_bannercnt")
9674 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009675 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +01009676 setl noma
9677 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009678 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009679 call netrw#ErrorMsg(s:WARNING,mesg,96)
9680" call Dret("s:NetrwRemoteListing : -1")
9681 return -1
9682 endif
9683
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009684 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 +00009685 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009686" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009687 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009688
9689 " cleanup
9690 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009691 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
9692 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009693 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009694 sil! NetrwKeepj %s/\r$//e
9695 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009696
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009697 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +00009698 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009699 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +01009700 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009701" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009702 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009703" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009704 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009705 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009706 exe "sil! NetrwKeepj ".line1
9707 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009708
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009709" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009710 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009711" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009712 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
9713 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009714 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009715" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009716 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
9717 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
9718 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
9719 NetrwKeepj call histdel("/",-1)
9720 NetrwKeepj call histdel("/",-1)
9721 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009722 endif
9723 endif
9724
Bram Moolenaar13600302014-05-22 18:26:40 +02009725 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00009726 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009727" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009728 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009729" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009730 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009731" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
9732 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009733 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009734 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
9735 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
9736 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
9737 NetrwKeepj call histdel("/",-1)
9738 NetrwKeepj call histdel("/",-1)
9739 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009740 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009741 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
9742 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009743 endif
9744 else
9745 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009746" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009747 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00009748 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009749" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
9750 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
9751" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009752 endif
9753 endif
9754
9755 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +01009756 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009757" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009758 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
9759 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009760 endif
9761 endif
9762
9763 if w:netrw_liststyle == s:LONGLIST
9764 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009765" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009766
9767 if s:method == "ftp"
9768 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009769 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009770 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009771 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +00009772 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009773 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +00009774 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009775 sil! NetrwKeepj 1
9776 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009777 let line2= line(".")
9778 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009779 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009780 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009781 endif
9782 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009783 exe "sil! NetrwKeepj ".line1
9784 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009785 endif
9786
9787 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009788" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009789 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 +00009790 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009791" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009792 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009793 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009794 exe 'sil NetrwKeepj '.w:netrw_bannercnt
9795 NetrwKeepj call histdel("/",-1)
9796 NetrwKeepj call histdel("/",-1)
9797 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009798 endif
9799 endif
9800
9801" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009802" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009803" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01009804
9805" call Dret("s:NetrwRemoteListing 0")
9806 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009807endfun
9808
Bram Moolenaar446cb832008-06-24 21:56:24 +00009809" ---------------------------------------------------------------------
9810" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
9811fun! s:NetrwRemoteRm(usrhost,path) range
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009812 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009813
9814 let all= 0
9815 if exists("s:netrwmarkfilelist_{bufnr('%')}")
9816 " remove all marked files
9817 for fname in s:netrwmarkfilelist_{bufnr("%")}
9818 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009819 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009820 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009821 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009822 let all= 1
9823 endif
9824 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01009825 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009826
9827 else
9828 " remove files specified by range
9829
9830 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009831 let keepsol = &l:sol
9832 setl nosol
9833 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +00009834
9835 " remove multiple files and directories
9836 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009837 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009838 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009839 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009840 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009841 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009842 let all= 1
9843 endif
9844 let ctr= ctr + 1
9845 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009846 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +00009847 endif
9848
9849 " refresh the (remote) directory listing
Tom Benham64a536d2024-11-07 21:15:03 +01009850 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009851 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009852endfun
9853
9854" ---------------------------------------------------------------------
9855" s:NetrwRemoteRmFile: {{{2
9856fun! s:NetrwRemoteRmFile(path,rmfile,all)
9857" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
9858
9859 let all= a:all
9860 let ok = ""
9861
9862 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
9863 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009864" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009865 if !all
9866 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009867" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009868 call inputsave()
9869 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
9870 call inputrestore()
9871 echohl NONE
9872 if ok == ""
9873 let ok="no"
9874 endif
9875 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009876 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009877 let all= 1
9878 endif
9879 endif
9880
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009881 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009882" 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 +00009883 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009884" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009885 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009886 if path =~ '^\a\{3,}://'
9887 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009888 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009889 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009890 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
9891 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009892" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009893 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009894" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009895 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009896 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009897 let ok="q"
9898 else
MiguelBarroc46c21b2024-01-31 20:07:17 +01009899 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009900" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
9901" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
9902" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009903 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009904 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009905 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009906 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009907 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009908" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009909 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009910 if v:shell_error != 0
9911 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09009912 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 +01009913 else
9914 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
9915 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009916 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009917 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009918 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009919" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009920 endif
9921 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009922 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009923" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009924 endif
9925
9926 else
9927 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009928" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009929 if !all
9930 call inputsave()
9931 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
9932 call inputrestore()
9933 if ok == ""
9934 let ok="no"
9935 endif
9936 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009937 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009938 let all= 1
9939 endif
9940 endif
9941
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009942 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00009943 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009944 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009945 else
9946 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009947 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
9948" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00009949 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009950" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009951
9952 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009953" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
9954 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
9955" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00009956 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009957" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009958
9959 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009960 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009961 endif
9962 endif
9963 endif
9964
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009965 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009966" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009967 endif
9968 endif
9969
9970" call Dret("s:NetrwRemoteRmFile ".ok)
9971 return ok
9972endfun
9973
9974" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009975" s:NetrwRemoteRename: rename a remote file or directory {{{2
9976fun! s:NetrwRemoteRename(usrhost,path) range
Bram Moolenaar446cb832008-06-24 21:56:24 +00009977
9978 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009979 let svpos = winsaveview()
9980" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009981 let ctr = a:firstline
9982 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
9983
9984 " rename files given by the markfilelist
9985 if exists("s:netrwmarkfilelist_{bufnr('%')}")
9986 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00009987 if exists("subfrom")
9988 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009989 else
9990 call inputsave()
9991 let newname= input("Moving ".oldname." to : ",oldname)
9992 call inputrestore()
9993 if newname =~ '^s/'
9994 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
9995 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
9996 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009997 endif
9998 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009999
Bram Moolenaar446cb832008-06-24 21:56:24 +000010000 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010001 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010002 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010003 let oldname= s:ShellEscape(a:path.oldname)
10004 let newname= s:ShellEscape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010005 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010006 endif
10007
10008 endfor
10009 call s:NetrwUnMarkFile(1)
10010
10011 else
10012
10013 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010014 let keepsol= &l:sol
10015 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010016 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010017 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010018
10019 let oldname= s:NetrwGetWord()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010020
10021 call inputsave()
10022 let newname= input("Moving ".oldname." to : ",oldname)
10023 call inputrestore()
10024
10025 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10026 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10027 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010028 let oldname= s:ShellEscape(a:path.oldname)
10029 let newname= s:ShellEscape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010030 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010031 endif
10032
10033 let ctr= ctr + 1
10034 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010035 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010036 endif
10037
10038 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010039 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010040 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010041endfun
10042
Bram Moolenaar85850f32019-07-19 22:05:51 +020010043" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010044" Local Directory Browsing Support: {{{1
10045" ==========================================
10046
10047" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010048" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010049" Should accept: file://localhost/etc/fstab
10050" file:///etc/fstab
10051" file:///c:/WINDOWS/clock.avi
10052" file:///c|/WINDOWS/clock.avi
10053" file://localhost/c:/WINDOWS/clock.avi
10054" file://localhost/c|/WINDOWS/clock.avi
10055" file://c:/foo.txt
10056" file:///c:/foo.txt
10057" 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 +020010058fun! netrw#FileUrlEdit(fname)
10059" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010060 let fname = a:fname
10061 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010062" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010063 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010064" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010065 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010066 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010067 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010068" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010069 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010070" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010071 endif
10072 endif
10073 let fname2396 = netrw#RFC2396(fname)
10074 let fname2396e= fnameescape(fname2396)
10075 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010076 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010077" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010078 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010079" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010080 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10081 endif
10082 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010083
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010084" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10085" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010086 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010087 exe 'NetrwKeepj keepalt edit '.plainfname
10088 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10089
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010090" 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 +020010091" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010092 exe "sil doau BufReadPost ".fname2396e
10093endfun
10094
10095" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010096" netrw#LocalBrowseCheck: {{{2
10097fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010098 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010099 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10100 "
10101 " unfortunate interaction -- split window debugging can't be used here, must use
10102 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10103 " another call to LocalBrowseCheck() when attempts to write
10104 " to the DBG buffer are made.
10105 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010106 " The &ft == "netrw" test was installed because the BufEnter event
10107 " would hit when re-entering netrw windows, creating unexpected
10108 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010109" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010110" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010111" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +010010112 " getting E930: Cannot use :redir inside execute
10113"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010114" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10115" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010116
Bram Moolenaar97d62492012-11-15 21:28:22 +010010117 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010118 if isdirectory(s:NetrwFile(a:dirname))
10119" 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 +010010120
Bram Moolenaar97d62492012-11-15 21:28:22 +010010121 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010122" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10123" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010124 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010125
Bram Moolenaar446cb832008-06-24 21:56:24 +000010126 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010127" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010128 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010129
Bram Moolenaar5c736222010-01-06 20:54:52 +010010130 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010131" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010132 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010133 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010134 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010135" 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 +010010136" call Dret("netrw#LocalBrowseCheck")
10137 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010138 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010139
Bram Moolenaar85850f32019-07-19 22:05:51 +020010140 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010141 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10142 " AND IF the listing style is not a tree listing
10143 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010144" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010145 let ibuf = 1
10146 let buflast = bufnr("$")
10147 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010148 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10149 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010150 endif
10151 let ibuf= ibuf + 1
10152 endwhile
10153 endif
10154 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010155" 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>"))
10156" 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 +000010157 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010158" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010159endfun
10160
10161" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010162" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010163" performed any shell command. The idea is to cause all local-browsing
10164" buffers to be refreshed after a user has executed some shell command,
10165" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010166fun! s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010167 " determine which buffers currently reside in a tab
10168 if !exists("s:netrw_browselist")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010169 return
10170 endif
10171 if !exists("w:netrw_bannercnt")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010172 return
10173 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010174 if !empty(getcmdwintype())
10175 " cannot move away from cmdline window, see :h E11
10176 return
10177 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010178 if exists("s:netrw_events") && s:netrw_events == 1
10179 " s:LocalFastBrowser gets called (indirectly) from a
10180 let s:netrw_events= 2
Bram Moolenaara6878372014-03-22 21:02:50 +010010181 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010182 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010183 let itab = 1
10184 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010185 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010186 while itab <= tabpagenr("$")
10187 let buftablist = buftablist + tabpagebuflist()
10188 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010189 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010190 endwhile
Bram Moolenaar446cb832008-06-24 21:56:24 +000010191 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10192 " | refresh any netrw window
10193 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010194 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010195 let ibl = 0
10196 for ibuf in s:netrw_browselist
Bram Moolenaar446cb832008-06-24 21:56:24 +000010197 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10198 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010199 " (ibuf not shown in a current window AND
10200 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010201 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010202 call remove(s:netrw_browselist,ibl)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010203 continue
10204 elseif index(tabpagebuflist(),ibuf) != -1
10205 " refresh any netrw buffer
Bram Moolenaar446cb832008-06-24 21:56:24 +000010206 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010207 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010208 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10209 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10210 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10211 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010212 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10213 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10214 endif
Tom Benham64a536d2024-11-07 21:15:03 +010010215 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010216 endif
10217 let ibl= ibl + 1
10218 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010219 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010220 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010221endfun
10222
10223" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010224" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10225"
10226" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010227" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010228" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10229" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010230" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010231"
10232" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
10233" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010010234" (re-using a buffer may not be as accurate)
10235"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010236" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010010237" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
10238" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
10239" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
10240" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010241fun! s:LocalFastBrowser()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010242
10243 " initialize browselist, a list of buffer numbers that the local browser has used
10244 if !exists("s:netrw_browselist")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010245 let s:netrw_browselist= []
10246 endif
10247
10248 " append current buffer to fastbrowse list
10249 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaar97d62492012-11-15 21:28:22 +010010250 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010251 endif
10252
10253 " enable autocmd events to handle refreshing/removing local browser buffers
10254 " If local browse buffer is currently showing: refresh it
10255 " If local browse buffer is currently hidden : wipe it
10256 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
10257 " =1 : medium speed, re-use directory listing for remote only
10258 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010010259 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
10260 let s:netrw_events= 1
10261 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010262 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020010263 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010010264 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010265 else
Bram Moolenaara6878372014-03-22 21:02:50 +010010266 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010267 endif
10268 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010010269
10270 " user must have changed fastbrowse to its fast setting, so remove
10271 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010010272 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara6878372014-03-22 21:02:50 +010010273 unlet s:netrw_events
10274 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010275 au!
10276 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010010277 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010278 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010279endfun
10280
Tom Benham64a536d2024-11-07 21:15:03 +010010281fun! s:NetrwLocalListingList(dirname,setmaxfilenamelen)
Bram Moolenaara6878372014-03-22 21:02:50 +010010282 " get the list of files contained in the current directory
Tom Benham64a536d2024-11-07 21:15:03 +010010283 let dirname = a:dirname
10284 let dirnamelen = strlen(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010285 let filelist = s:NetrwGlob(dirname,"*",0)
10286 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara6878372014-03-22 21:02:50 +010010287
Nir Lichtman1e34b952024-05-08 19:19:34 +020010288 if g:netrw_cygwin == 0 && has("win32")
Tom Benham64a536d2024-11-07 21:15:03 +010010289 elseif index(filelist,'..') == -1 && dirname !~ '/'
Bram Moolenaara6878372014-03-22 21:02:50 +010010290 " include ../ in the glob() entry if its missing
Tom Benham64a536d2024-11-07 21:15:03 +010010291 let filelist= filelist+[s:ComposePath(dirname,"../")]
Bram Moolenaara6878372014-03-22 21:02:50 +010010292 endif
10293
Tom Benham64a536d2024-11-07 21:15:03 +010010294 if a:setmaxfilenamelen && get(g:, 'netrw_dynamic_maxfilenamelen', 0)
Bram Moolenaara6878372014-03-22 21:02:50 +010010295 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
10296 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara6878372014-03-22 21:02:50 +010010297 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010298
Tom Benham64a536d2024-11-07 21:15:03 +010010299 let resultfilelist = []
Bram Moolenaara6878372014-03-22 21:02:50 +010010300 for filename in filelist
Bram Moolenaara6878372014-03-22 21:02:50 +010010301
10302 if getftype(filename) == "link"
10303 " indicate a symbolic link
Bram Moolenaara6878372014-03-22 21:02:50 +010010304 let pfile= filename."@"
10305
10306 elseif getftype(filename) == "socket"
10307 " indicate a socket
Bram Moolenaara6878372014-03-22 21:02:50 +010010308 let pfile= filename."="
10309
10310 elseif getftype(filename) == "fifo"
10311 " indicate a fifo
Bram Moolenaara6878372014-03-22 21:02:50 +010010312 let pfile= filename."|"
10313
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010314 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010315 " indicate a directory
Bram Moolenaara6878372014-03-22 21:02:50 +010010316 let pfile= filename."/"
10317
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010318 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020010319 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010010320 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
10321 " indicate an executable
Bram Moolenaara6878372014-03-22 21:02:50 +010010322 let pfile= filename."*"
10323 else
10324 " normal file
10325 let pfile= filename
10326 endif
10327 elseif executable(filename)
10328 " indicate an executable
Bram Moolenaara6878372014-03-22 21:02:50 +010010329 let pfile= filename."*"
10330 else
10331 " normal file
10332 let pfile= filename
10333 endif
10334
10335 else
10336 " normal file
10337 let pfile= filename
10338 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010339
10340 if pfile =~ '//$'
10341 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara6878372014-03-22 21:02:50 +010010342 endif
10343 let pfile= strpart(pfile,dirnamelen)
10344 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara6878372014-03-22 21:02:50 +010010345
10346 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090010347 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
10348 let sz = getfsize(filename)
10349 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
10350 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010010351
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010352 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010353 let sz= s:NetrwHumanReadable(sz)
10354 endif
K.Takata8750e3c2023-11-22 18:20:01 +090010355 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090010356 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010357 endif
10358
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010359 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010010360 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010010361 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaara6878372014-03-22 21:02:50 +010010362 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090010363 let ft = printf("%018d",t)
Bram Moolenaara6878372014-03-22 21:02:50 +010010364 let ftpfile= ft.'/'.pfile
Tom Benham64a536d2024-11-07 21:15:03 +010010365 let resultfilelist += [ftpfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010366
10367 elseif g:netrw_sort_by =~ "^s"
10368 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaara6878372014-03-22 21:02:50 +010010369 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090010370 let fsz = printf("%018d",sz)
Bram Moolenaara6878372014-03-22 21:02:50 +010010371 let fszpfile= fsz.'/'.pfile
Tom Benham64a536d2024-11-07 21:15:03 +010010372 let resultfilelist += [fszpfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010373
10374 else
10375 " sort by name
Tom Benham64a536d2024-11-07 21:15:03 +010010376 let resultfilelist += [pfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010377 endif
Tom Benham64a536d2024-11-07 21:15:03 +010010378 endfor
10379
10380 return resultfilelist
10381endfun
10382
10383" ---------------------------------------------------------------------
10384" s:LocalListing: does the job of "ls" for local directories {{{2
10385fun! s:LocalListing()
10386
10387 let filelist = s:NetrwLocalListingList(b:netrw_curdir, 1)
10388 for filename in filelist
10389 sil! NetrwKeepj put =filename
Bram Moolenaara6878372014-03-22 21:02:50 +010010390 endfor
10391
10392 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010393 sil! NetrwKeepj g/^$/d
10394 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010010395 call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010396 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010397endfun
10398
10399" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010400" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
10401fun! s:NetrwLocalExecute(cmd)
10402" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
10403 let ykeep= @@
10404 " sanity check
10405 if !executable(a:cmd)
10406 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
10407 let @@= ykeep
10408" call Dret("s:NetrwLocalExecute")
10409 return
10410 endif
10411
10412 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010413" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010414 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010415" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010416
10417 " strip any ansi escape sequences off
10418 let result = substitute(result,"\e\\[[0-9;]*m","","g")
10419
10420 " show user the result(s)
10421 echomsg result
10422 let @@= ykeep
10423
10424" call Dret("s:NetrwLocalExecute")
10425endfun
10426
10427" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010428" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010429fun! s:NetrwLocalRename(path) range
Bram Moolenaar97d62492012-11-15 21:28:22 +010010430
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010431 if !exists("w:netrw_bannercnt")
10432 let w:netrw_bannercnt= b:netrw_bannercnt
10433 endif
10434
Bram Moolenaar97d62492012-11-15 21:28:22 +010010435 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010010436 let ykeep = @@
10437 let ctr = a:firstline
10438 let svpos = winsaveview()
10439 let all = 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010010440
10441 " rename files given by the markfilelist
10442 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10443 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar97d62492012-11-15 21:28:22 +010010444 if exists("subfrom")
10445 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaar97d62492012-11-15 21:28:22 +010010446 else
10447 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010448 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010449 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010450 if newname =~ ''
10451 " two ctrl-x's : ignore all of string preceding the ctrl-x's
10452 let newname = substitute(newname,'^.*','','')
10453 elseif newname =~ ''
10454 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
10455 let newname = substitute(newname,'[^/]*','','')
10456 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010457 if newname =~ '^s/'
10458 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10459 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaar97d62492012-11-15 21:28:22 +010010460 let newname = substitute(oldname,subfrom,subto,'')
10461 endif
10462 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010010463 if !all && filereadable(newname)
10464 call inputsave()
10465 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
10466 call inputrestore()
10467 if response == "all"
10468 let all= 1
10469 elseif response != "y" && response != "yes"
10470 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010471 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaar29634562020-01-09 21:46:04 +010010472 NetrwKeepj call winrestview(svpos)
10473 let @@= ykeep
Bram Moolenaar29634562020-01-09 21:46:04 +010010474 return
10475 endif
10476 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010477 call rename(oldname,newname)
10478 endfor
10479 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010480
Bram Moolenaar97d62492012-11-15 21:28:22 +010010481 else
10482
10483 " attempt to rename files/directories
10484 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010485 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010010486
10487 " sanity checks
10488 if line(".") < w:netrw_bannercnt
10489 let ctr= ctr + 1
10490 continue
10491 endif
10492 let curword= s:NetrwGetWord()
10493 if curword == "./" || curword == "../"
10494 let ctr= ctr + 1
10495 continue
10496 endif
10497
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010498 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010010499 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010500
10501 call inputsave()
10502 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
10503 call inputrestore()
10504
10505 call rename(oldname,newname)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010506 let ctr= ctr + 1
10507 endwhile
10508 endif
10509
10510 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010511 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010512 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010513 let @@= ykeep
Bram Moolenaar97d62492012-11-15 21:28:22 +010010514endfun
10515
10516" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010517" s:NetrwLocalRm: {{{2
10518fun! s:NetrwLocalRm(path) range
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010519 if !exists("w:netrw_bannercnt")
10520 let w:netrw_bannercnt= b:netrw_bannercnt
10521 endif
10522
Bram Moolenaar446cb832008-06-24 21:56:24 +000010523 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010010524 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010525 let ret = 0
10526 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010527 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010528
10529 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10530 " remove all marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +000010531 for fname in s:netrwmarkfilelist_{bufnr("%")}
10532 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010533 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010534 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010535 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010536 let all= 1
10537 endif
10538 endfor
10539 call s:NetrwUnMarkFile(1)
10540
10541 else
10542 " remove (multiple) files and directories
Bram Moolenaar446cb832008-06-24 21:56:24 +000010543
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010544 let keepsol= &l:sol
10545 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010546 let ctr = a:firstline
10547 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010548 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010549
10550 " sanity checks
10551 if line(".") < w:netrw_bannercnt
10552 let ctr= ctr + 1
10553 continue
10554 endif
10555 let curword= s:NetrwGetWord()
10556 if curword == "./" || curword == "../"
10557 let ctr= ctr + 1
10558 continue
10559 endif
10560 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010561 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010562 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010563 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010564 let all= 1
10565 endif
10566 let ctr= ctr + 1
10567 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010568 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010569 endif
10570
10571 " refresh the directory
Bram Moolenaar446cb832008-06-24 21:56:24 +000010572 if bufname("%") != "NetrwMessage"
Tom Benham64a536d2024-11-07 21:15:03 +010010573 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010574 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010575 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010576 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010577endfun
10578
10579" ---------------------------------------------------------------------
10580" s:NetrwLocalRmFile: remove file fname given the path {{{2
10581" Give confirmation prompt unless all==1
10582fun! s:NetrwLocalRmFile(path,fname,all)
10583" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010584
Bram Moolenaar446cb832008-06-24 21:56:24 +000010585 let all= a:all
10586 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010587 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020010588 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010589" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010590
10591 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
10592 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010593" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010594 if !all
10595 echohl Statement
10596 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020010597 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010598 call inputrestore()
10599 echohl NONE
10600 if ok == ""
10601 let ok="no"
10602 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010603" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010604 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010605" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010606 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010607 let all= 1
10608 endif
10609 endif
10610
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010611 if all || ok =~# '^y\%[es]$' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000010612 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010613" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010614 endif
10615
10616 else
10617 " attempt to remove directory
10618 if !all
10619 echohl Statement
10620 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020010621 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010622 call inputrestore()
10623 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
10624 if ok == ""
10625 let ok="no"
10626 endif
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010627 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010628 let all= 1
10629 endif
10630 endif
10631 let rmfile= substitute(rmfile,'[\/]$','','e')
10632
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010633 if all || ok =~# '^y\%[es]$' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020010634 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010010635 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010636 endif
10637 endif
10638 endif
10639
10640" call Dret("s:NetrwLocalRmFile ".ok)
10641 return ok
10642endfun
10643
Bram Moolenaar85850f32019-07-19 22:05:51 +020010644" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010645" Support Functions: {{{1
10646
Bram Moolenaar488c6512005-08-11 20:09:58 +000010647" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010648" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
10649" 0: marked file list of current buffer
10650" 1: marked file target
10651fun! netrw#Access(ilist)
10652 if a:ilist == 0
10653 if exists("s:netrwmarkfilelist_".bufnr('%'))
10654 return s:netrwmarkfilelist_{bufnr('%')}
10655 else
10656 return "no-list-buf#".bufnr('%')
10657 endif
10658 elseif a:ilist == 1
10659 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020010660 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010661endfun
10662
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010663" ---------------------------------------------------------------------
10664" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
10665fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010666 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010667endfun
10668
Bram Moolenaara6878372014-03-22 21:02:50 +010010669" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010670" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
10671" I expect this function to be used in
10672" :PChkAssert netrw#Expose("netrwmarkfilelist")
10673" for example.
10674fun! netrw#Expose(varname)
10675" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010676 if exists("s:".a:varname)
10677 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010678" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010679 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010680" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010681 if type(retval) == 3
10682 let retval = copy(retval)
10683 let i = 0
10684 while i < len(retval)
10685 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
10686 let i = i + 1
10687 endwhile
10688 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010689" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010690 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010691 else
10692" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010693 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010694 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010695" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010696 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010697 endif
10698
10699" call Dret("netrw#Expose ".string(retval))
10700 return retval
10701endfun
10702
10703" ---------------------------------------------------------------------
10704" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
10705fun! netrw#Modify(varname,newvalue)
10706" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
10707 exe "let s:".a:varname."= ".string(a:newvalue)
10708" call Dret("netrw#Modify")
10709endfun
10710
10711" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010712" netrw#RFC2396: converts %xx into characters {{{2
10713fun! netrw#RFC2396(fname)
10714" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090010715 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010010716" call Dret("netrw#RFC2396 ".fname)
10717 return fname
10718endfun
10719
10720" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010721" netrw#UserMaps: supports user-specified maps {{{2
10722" see :help function()
10723"
10724" g:Netrw_UserMaps is a List with members such as:
10725" [[keymap sequence, function reference],...]
10726"
10727" The referenced function may return a string,
10728" refresh : refresh the display
10729" -other- : this string will be executed
10730" or it may return a List of strings.
10731"
10732" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020010733" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010734" Related functions:
10735" netrw#Expose(varname) -- see s:varname variables
10736" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
10737" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
10738fun! netrw#UserMaps(islocal)
10739" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
10740" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
10741
10742 " set up usermaplist
10743 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
10744" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
10745 for umap in g:Netrw_UserMaps
10746" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
10747" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
10748 " if umap[0] is a string and umap[1] is a string holding a function name
10749 if type(umap[0]) == 1 && type(umap[1]) == 1
10750" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
10751 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
10752 else
10753 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
10754 endif
10755 endfor
10756 endif
10757" call Dret("netrw#UserMaps")
10758endfun
10759
10760" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010761" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
10762fun! netrw#WinPath(path)
10763" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010764 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010765 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010010766 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010767 " remove trailing slash (Win95)
10768 let path = substitute(path, '\(\\\|/\)$', '', 'g')
10769 " remove escaped spaces
10770 let path = substitute(path, '\ ', ' ', 'g')
10771 " convert slashes to backslashes
10772 let path = substitute(path, '/', '\', 'g')
10773 else
10774 let path= a:path
10775 endif
10776" call Dret("netrw#WinPath <".path.">")
10777 return path
10778endfun
10779
10780" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020010781" s:StripTrailingSlash: removes trailing slashes from a path {{{2
10782fun! s:StripTrailingSlash(path)
10783 " remove trailing slash
10784 return substitute(a:path, '[/\\]$', '', 'g')
10785endfun
10786
Travis Sheltone34d0e32024-07-30 21:08:56 +020010787" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010788" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
10789" cb : bl2mf=0 add marked files to buffer list
10790" cB : bl2mf=1 use bufferlist to mark files
10791" (mnemonic: cb = copy (marked files) to buffer list)
10792fun! s:NetrwBadd(islocal,bl2mf)
10793" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
10794 if a:bl2mf
10795 " cB: add buffer list to marked files
10796 redir => bufl
10797 ls
10798 redir END
10799 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
10800 for fname in bufl
10801 call s:NetrwMarkFile(a:islocal,fname)
10802 endfor
10803 else
10804 " cb: add marked files to buffer list
10805 for fname in s:netrwmarkfilelist_{bufnr("%")}
10806" " call Decho("badd ".fname,'~'.expand("<slnum>"))
10807 exe "badd ".fnameescape(fname)
10808 endfor
10809 let curbufnr = bufnr("%")
10810 let curdir = s:NetrwGetCurdir(a:islocal)
10811 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
10812 endif
10813" call Dret("s:NetrwBadd")
10814endfun
10815
10816" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000010817" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
10818fun! s:ComposePath(base,subdir)
10819" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
10820
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010821 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010822" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010823 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000010824 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010825 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000010826 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010827 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000010828 endif
10829
Bram Moolenaar85850f32019-07-19 22:05:51 +020010830 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020010831 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010832" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010833 let ret= a:subdir
10834
Nir Lichtman1e34b952024-05-08 19:19:34 +020010835 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010836" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010837 if a:base =~ '[/\\]$'
10838 let ret= a:base.a:subdir
10839 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010840 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010010841 endif
10842
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010843 elseif a:base =~ '^\a\{3,}://'
10844" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010845 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
10846 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
10847 if a:subdir == '../'
10848 if curpath =~ '[^/]/[^/]\+/$'
10849 let curpath= substitute(curpath,'[^/]\+/$','','')
10850 else
10851 let curpath=""
10852 endif
10853 let ret= urlbase.curpath
10854 else
10855 let ret= urlbase.curpath.a:subdir
10856 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010857" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
10858" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
10859" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010860
10861 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010862" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010863 let ret = substitute(a:base."/".a:subdir,"//","/","g")
10864 if a:base =~ '^//'
10865 " keeping initial '//' for the benefit of network share listing support
10866 let ret= '/'.ret
10867 endif
10868 let ret= simplify(ret)
10869 endif
10870
10871" call Dret("s:ComposePath ".ret)
10872 return ret
10873endfun
10874
10875" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010876" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
10877" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
10878fun! s:DeleteBookmark(fname)
10879" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
10880 call s:MergeBookmarks()
10881
10882 if exists("g:netrw_bookmarklist")
10883 let indx= index(g:netrw_bookmarklist,a:fname)
10884 if indx == -1
10885 let indx= 0
10886 while indx < len(g:netrw_bookmarklist)
10887 if g:netrw_bookmarklist[indx] =~ a:fname
10888 call remove(g:netrw_bookmarklist,indx)
10889 let indx= indx - 1
10890 endif
10891 let indx= indx + 1
10892 endwhile
10893 else
10894 " remove exact match
10895 call remove(g:netrw_bookmarklist,indx)
10896 endif
10897 endif
10898
10899" call Dret("s:DeleteBookmark")
10900endfun
10901
10902" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000010903" s:FileReadable: o/s independent filereadable {{{2
10904fun! s:FileReadable(fname)
10905" call Dfunc("s:FileReadable(fname<".a:fname.">)")
10906
10907 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010908 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010909 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010910 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010911 endif
10912
10913" call Dret("s:FileReadable ".ret)
10914 return ret
10915endfun
10916
10917" ---------------------------------------------------------------------
10918" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
10919" Places correct suffix on end of temporary filename,
10920" using the suffix provided with fname
10921fun! s:GetTempfile(fname)
10922" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
10923
10924 if !exists("b:netrw_tmpfile")
10925 " get a brand new temporary filename
10926 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010927" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010928
Bram Moolenaarc236c162008-07-13 17:41:49 +000010929 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010930" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010931
Bram Moolenaar9964e462007-05-05 17:54:07 +000010932 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010933 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
10934" 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 +010010935 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010936" call Dret("s:GetTempfile getcwd<".getcwd().">")
10937 return ""
10938 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010939
Bram Moolenaar9964e462007-05-05 17:54:07 +000010940 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010941 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010942" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010943
Bram Moolenaar9964e462007-05-05 17:54:07 +000010944 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000010945 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010010946 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020010947 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010948 if !exists("+shellslash") || !&ssl
10949 let tmpfile = substitute(tmpfile,'/','\','g')
10950 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010951 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010952 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000010953 endif
10954 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010955" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010956 else
10957 " re-use temporary filename
10958 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010959" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010960 endif
10961
10962 " use fname's suffix for the temporary file
10963 if a:fname != ""
10964 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010965" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010966 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000010967 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010968 elseif a:fname =~ '.txz$'
10969 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000010970 else
10971 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
10972 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010973" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010974 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010975" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010976 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010977" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010978 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
10979 endif
10980 endif
10981
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010982" 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 +000010983" call Dret("s:GetTempfile <".tmpfile.">")
10984 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000010985endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000010986
10987" ---------------------------------------------------------------------
10988" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000010989" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000010990fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010991" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020010992 if s:user == ""
10993 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
10994 else
10995 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
10996 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010997 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000010998 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000010999 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011000 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011001 else
11002 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11003 endif
11004" call Dret("s:MakeSshCmd <".sshcmd.">")
11005 return sshcmd
11006endfun
11007
11008" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011009" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11010fun! s:MakeBookmark(fname)
11011" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11012
11013 if !exists("g:netrw_bookmarklist")
11014 let g:netrw_bookmarklist= []
11015 endif
11016
11017 if index(g:netrw_bookmarklist,a:fname) == -1
11018 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011019 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011020 call add(g:netrw_bookmarklist,a:fname.'/')
11021 elseif a:fname !~ '/'
11022 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11023 else
11024 call add(g:netrw_bookmarklist,a:fname)
11025 endif
11026 call sort(g:netrw_bookmarklist)
11027 endif
11028
11029" call Dret("s:MakeBookmark")
11030endfun
11031
11032" ---------------------------------------------------------------------
11033" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11034fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011035" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011036 " get bookmarks from .netrwbook file
11037 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011038 if filereadable(s:NetrwFile(savefile))
11039" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011040 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011041" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011042 NetrwKeepj call delete(savefile)
11043 endif
11044" call Dret("s:MergeBookmarks")
11045endfun
11046
11047" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011048" s:NetrwBMShow: {{{2
11049fun! s:NetrwBMShow()
11050" call Dfunc("s:NetrwBMShow()")
11051 redir => bmshowraw
11052 menu
11053 redir END
11054 let bmshowlist = split(bmshowraw,'\n')
11055 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011056 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011057 if bmshowfuncs != []
11058 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011059 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011060 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011061 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011062 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011063 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011064" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11065endfun
11066
11067" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011068" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011069fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011070 if !exists("w:netrw_liststyle")
11071 let w:netrw_liststyle= g:netrw_liststyle
11072 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011073" 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 +020011074
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011075" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11076
Bram Moolenaaradc21822011-04-01 18:03:16 +020011077 if &ft != "netrw"
11078 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11079 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011080" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011081
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011082 elseif g:netrw_cursor == 8
11083 if w:netrw_liststyle == s:WIDELIST
11084 setl cursorline
11085 setl cursorcolumn
11086 else
11087 setl cursorline
11088 endif
11089 elseif g:netrw_cursor == 7
11090 setl cursorline
11091 elseif g:netrw_cursor == 6
11092 if w:netrw_liststyle == s:WIDELIST
11093 setl cursorline
11094 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011095 elseif g:netrw_cursor == 4
11096 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011097" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011098 setl cursorline
11099 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011100
11101 elseif g:netrw_cursor == 3
11102 " thin-long-tree: cursorline, user's cursorcolumn
11103 " wide : cursorline, cursorcolumn
11104 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011105" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011106 setl cursorline
11107 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011108 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011109" 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 +020011110 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011111 endif
11112
11113 elseif g:netrw_cursor == 2
11114 " thin-long-tree: cursorline, user's cursorcolumn
11115 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011116" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011117 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011118
11119 elseif g:netrw_cursor == 1
11120 " thin-long-tree: user's cursorline, user's cursorcolumn
11121 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011122 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011123" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011124 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011125 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011126" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011127 endif
11128
11129 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011130 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011131" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011132 let &l:cursorline = s:netrw_usercul
11133 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011134 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011135
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011136" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011137" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011138endfun
11139
11140" ---------------------------------------------------------------------
11141" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11142fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011143" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011144 if exists("s:netrw_usercul")
11145 let &l:cursorline = s:netrw_usercul
11146 endif
11147 if exists("s:netrw_usercuc")
11148 let &l:cursorcolumn = s:netrw_usercuc
11149 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011150" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011151" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11152endfun
11153
Christian Brabandt62f7b552024-06-23 20:23:40 +020011154" s:RestoreRegister: restores all registers given in the dict {{{2
11155fun! s:RestoreRegister(dict)
11156 for [key, val] in items(a:dict)
11157 if key == 'unnamed'
11158 let key = ''
11159 endif
11160 call setreg(key, val[0], val[1])
11161 endfor
11162endfun
11163
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011164" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011165" s:NetrwDelete: Deletes a file. {{{2
11166" Uses Steve Hall's idea to insure that Windows paths stay
11167" acceptable. No effect on Unix paths.
11168" Examples of use: let result= s:NetrwDelete(path)
11169fun! s:NetrwDelete(path)
11170" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11171
Bram Moolenaar5c736222010-01-06 20:54:52 +010011172 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011173 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000011174 if exists("+shellslash")
11175 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011176 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011177 let result = delete(path)
11178 let &shellslash = sskeep
11179 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011180" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011181 let result= delete(path)
11182 endif
11183 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011184" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011185 let result= delete(path)
11186 endif
11187 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011188 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011189 endif
11190
11191" call Dret("s:NetrwDelete ".result)
11192 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000011193endfun
11194
11195" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011196" s:NetrwBufRemover: removes a buffer that: {{{2s
11197" has buffer-id > 1
11198" is unlisted
11199" is unnamed
11200" does not appear in any window
11201fun! s:NetrwBufRemover(bufid)
11202" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
11203" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
11204" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
11205" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
11206" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
11207
yasuda4dbb2662023-10-04 20:50:35 +020011208 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011209" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020011210 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011211 endif
11212
11213" call Dret("s:NetrwBufRemover")
11214endfun
11215
11216" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011217" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010011218fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011219" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011220" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011221
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011222 " Clean out the last buffer:
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011223 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
11224 " If so, delete it.
11225 call s:NetrwBufRemover(bufnr("$"))
11226
Bram Moolenaar446cb832008-06-24 21:56:24 +000011227 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011228" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011229 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
11230 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
11231 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
11232 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
11233 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11234 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
11235 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
11236 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
11237 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
11238 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11239 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
11240 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
11241 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
11242 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
11243 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
11244 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
11245
Bram Moolenaar85850f32019-07-19 22:05:51 +020011246 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011247" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011248 " when tree listing uses file TreeListing... a new buffer is made.
11249 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011250 " COMBAK: this causes a problem, see P43
11251" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011252 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010011253 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011254 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011255" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020011256 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011257
Bram Moolenaar446cb832008-06-24 21:56:24 +000011258 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011259" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011260 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
11261 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
11262 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
11263 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
11264 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
11265 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
11266 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
11267 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
11268 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
11269 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
11270 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
11271 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
11272 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
11273 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
11274 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
11275 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
11276
Bram Moolenaar5c736222010-01-06 20:54:52 +010011277 if a:0 > 0
11278 let b:netrw_curdir= a:1
11279 if b:netrw_curdir =~ '/$'
11280 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011281 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010011282 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011283 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020011284 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
11285 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010011286 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011287 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010011288 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011289 endif
11290 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011291 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
11292 let &l:bexpr = "netrw#BalloonHelp()"
11293 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011294
Bram Moolenaar8d043172014-01-23 14:24:41 +010011295" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011296endfun
11297
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011298" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011299" s:NetrwExe: executes a string using "!" {{{2
11300fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011301" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Konfekt3d7e5672024-10-27 22:16:49 +010011302 if has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +020011303" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011304 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
11305 set shell& shellcmdflag& shellxquote& shellxescape&
11306 set shellquote& shellpipe& shellredir& shellslash&
Konfekt3d7e5672024-10-27 22:16:49 +010011307 try
11308 exe a:cmd
11309 finally
11310 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
11311 endtry
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011312 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011313" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011314 exe a:cmd
11315 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011316 if v:shell_error
11317 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
11318 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011319" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011320endfun
11321
11322" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011323" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
11324fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011325 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011326" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011327 let curbuf = bufnr("%")
11328 let curwin = winnr()
11329 let iwin = 1
11330 while iwin <= winnr("$")
11331 exe iwin."wincmd w"
11332 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
11333 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
11334 let winvars= w:
11335 break
11336 endif
11337 let iwin= iwin + 1
11338 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020011339 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011340 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011341" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011342 for k in keys(winvars)
11343 let w:{k}= winvars[k]
11344 endfor
11345 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011346" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011347 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011348endfun
11349
Bram Moolenaara6878372014-03-22 21:02:50 +010011350" ---------------------------------------------------------------------
11351" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020011352" Returns: 0=success
11353" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010011354fun! s:NetrwLcd(newdir)
11355" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011356" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011357
Bram Moolenaar85850f32019-07-19 22:05:51 +020011358 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011359 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011360 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010011361 catch /^Vim\%((\a\+)\)\=:E344/
11362 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
11363 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011364 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010011365 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
11366 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020011367 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010011368 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
11369 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090011370 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010011371 endif
11372 endif
11373 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020011374 let err472= 1
11375 endtry
11376
11377 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010011378 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
11379 if exists("w:netrw_prvdir")
11380 let a:newdir= w:netrw_prvdir
11381 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011382 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011383" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020011384 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011385" 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 +010011386 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010011387 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011388" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
11389 return -1
11390 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011391
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011392" call Decho("getcwd <".getcwd().">")
11393" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020011394" call Dret("s:NetrwLcd 0")
11395 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011396endfun
11397
Bram Moolenaar9964e462007-05-05 17:54:07 +000011398" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011399" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
11400" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
11401fun! s:NetrwSaveWordPosn()
11402" call Dfunc("NetrwSaveWordPosn()")
11403 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
11404" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
11405endfun
11406
11407" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011408" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
11409" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
11410fun! s:NetrwHumanReadable(sz)
11411" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
11412
11413 if g:netrw_sizestyle == 'h'
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011414 if a:sz >= 1000000000
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011415 let sz = printf("%.1f",a:sz/1000000000.0)."g"
11416 elseif a:sz >= 10000000
11417 let sz = printf("%d",a:sz/1000000)."m"
11418 elseif a:sz >= 1000000
11419 let sz = printf("%.1f",a:sz/1000000.0)."m"
11420 elseif a:sz >= 10000
11421 let sz = printf("%d",a:sz/1000)."k"
11422 elseif a:sz >= 1000
11423 let sz = printf("%.1f",a:sz/1000.0)."k"
11424 else
11425 let sz= a:sz
11426 endif
11427
11428 elseif g:netrw_sizestyle == 'H'
11429 if a:sz >= 1073741824
11430 let sz = printf("%.1f",a:sz/1073741824.0)."G"
11431 elseif a:sz >= 10485760
11432 let sz = printf("%d",a:sz/1048576)."M"
11433 elseif a:sz >= 1048576
11434 let sz = printf("%.1f",a:sz/1048576.0)."M"
11435 elseif a:sz >= 10240
11436 let sz = printf("%d",a:sz/1024)."K"
11437 elseif a:sz >= 1024
11438 let sz = printf("%.1f",a:sz/1024.0)."K"
11439 else
11440 let sz= a:sz
11441 endif
11442
11443 else
11444 let sz= a:sz
11445 endif
11446
11447" call Dret("s:NetrwHumanReadable ".sz)
11448 return sz
11449endfun
11450
11451" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011452" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
11453" changed sorting, etc. Also see s:NetrwSaveWordPosn().
11454fun! s:NetrwRestoreWordPosn()
11455" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020011456 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000011457" call Dret("NetrwRestoreWordPosn")
11458endfun
11459
11460" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011461" s:RestoreBufVars: {{{2
11462fun! s:RestoreBufVars()
11463" call Dfunc("s:RestoreBufVars()")
11464
11465 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
11466 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
11467 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
11468 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
11469 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
11470 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
11471
11472" call Dret("s:RestoreBufVars")
11473endfun
11474
11475" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011476" s:RemotePathAnalysis: {{{2
11477fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020011478" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011479
Bram Moolenaara6878372014-03-22 21:02:50 +010011480 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010011481 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011482 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010011483 let s:user = substitute(a:dirname,dirpat,'\3','')
11484 let s:machine = substitute(a:dirname,dirpat,'\4','')
11485 let s:port = substitute(a:dirname,dirpat,'\5','')
11486 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020011487 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010011488 if s:machine =~ '@'
11489 let dirpat = '^\(.*\)@\(.\{-}\)$'
11490 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
11491 let s:machine = substitute(s:machine,dirpat,'\2','')
11492 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011493
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011494" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
11495" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
11496" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
11497" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
11498" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
11499" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011500
11501" call Dret("s:RemotePathAnalysis")
11502endfun
11503
11504" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011505" s:RemoteSystem: runs a command on a remote host using ssh {{{2
11506" Returns status
11507" Runs system() on
11508" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011509" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000011510fun! s:RemoteSystem(cmd)
11511" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
11512 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011513 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 +000011514 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011515 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011516 else
11517 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
11518 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
11519 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011520 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000011521 else
11522 let cmd= cmd.' '
11523 endif
11524 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011525" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011526 let ret= system(cmd)
11527 endif
11528" call Dret("s:RemoteSystem ".ret)
11529 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000011530endfun
11531
11532" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011533" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000011534fun! s:RestoreWinVars()
11535" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000011536 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011537 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
11538 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
11539 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
11540 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
11541 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
11542 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
11543 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
11544 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
11545 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
11546 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
11547 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
11548 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000011549 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
11550 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011551 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
11552 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
11553 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
11554" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000011555endfun
11556
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011557" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011558" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
11559"
11560" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
11561" is true) and a command, :Rexplore, which call this function.
11562"
Bram Moolenaar85850f32019-07-19 22:05:51 +020011563" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011564"
11565" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000011566fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020011567 if exists("s:netrwdrag")
11568 return
11569 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011570" 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 +010011571" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
11572" 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 +010011573
11574 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011575 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011576" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011577 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011578 unlet w:netrw_rexfile
11579" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020011580 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011581" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011582" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
11583" 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 +020011584 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011585
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011586 " ---------------------------
11587 " :Rex issued while in a file
11588 " ---------------------------
11589
Bram Moolenaara6878372014-03-22 21:02:50 +010011590 " record current file so :Rex can return to it from netrw
11591 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011592" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011593
11594 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011595" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010011596 return
11597 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011598" 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 +020011599 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011600 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011601 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011602 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011603 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011604 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010011605 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020011606 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011607 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011608" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
11609 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011610" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
11611 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011612 if exists("s:rexposn_".bufnr('%'))
11613 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011614 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011615 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011616" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011617 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011618
Bram Moolenaar85850f32019-07-19 22:05:51 +020011619 if has("syntax") && exists("g:syntax_on") && g:syntax_on
11620 if exists("s:explore_match")
11621 exe "2match netrwMarkFile /".s:explore_match."/"
11622 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010011623 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011624
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011625" 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 +010011626" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011627endfun
11628
11629" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010011630" s:SaveBufVars: save selected b: variables to s: variables {{{2
11631" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000011632fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011633" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011634
11635 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
11636 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
11637 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
11638 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
11639 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
11640 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
11641
11642" call Dret("s:SaveBufVars")
11643endfun
11644
11645" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011646" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
11647fun! s:SavePosn(posndict)
11648" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
11649
Bram Moolenaar85850f32019-07-19 22:05:51 +020011650 if !exists("a:posndict[bufnr('%')]")
11651 let a:posndict[bufnr("%")]= []
11652 endif
11653" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11654 call add(a:posndict[bufnr("%")],winsaveview())
11655" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011656
11657" call Dret("s:SavePosn posndict")
11658 return a:posndict
11659endfun
11660
11661" ---------------------------------------------------------------------
11662" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
11663fun! s:RestorePosn(posndict)
11664" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020011665 if exists("a:posndict")
11666 if has_key(a:posndict,bufnr("%"))
11667" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11668 let posnlen= len(a:posndict[bufnr("%")])
11669 if posnlen > 0
11670 let posnlen= posnlen - 1
11671" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
11672 call winrestview(a:posndict[bufnr("%")][posnlen])
11673 call remove(a:posndict[bufnr("%")],posnlen)
11674" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11675 endif
11676 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011677 endif
11678" call Dret("s:RestorePosn")
11679endfun
11680
11681" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011682" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000011683fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011684" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000011685 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
11686 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
11687 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
11688 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
11689 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
11690 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
11691 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
11692 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
11693 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
11694 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
11695 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
11696 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
11697 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
11698 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
11699 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
11700 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
11701 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
11702 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
11703" call Dret("s:SaveWinVars")
11704endfun
11705
11706" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011707" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011708" To allow separate windows to have their own activities, such as
11709" Explore **/pattern, several variables have been made window-oriented.
11710" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011711" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011712" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011713fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011714" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000011715 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
11716 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
11717 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
11718 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
11719 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
11720 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
11721 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
11722 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
11723 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
11724 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
11725" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011726endfun
11727
11728" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011729" s:SetRexDir: set directory for :Rexplore {{{2
11730fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011731" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011732 let w:netrw_rexdir = a:dirname
11733 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011734 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011735" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
11736" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011737" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011738" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011739" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011740endfun
11741
11742" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011743" s:ShowLink: used to modify thin and tree listings to show links {{{2
11744fun! s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011745 if exists("b:netrw_curdir")
11746 norm! $?\a
Tom Benham64a536d2024-11-07 21:15:03 +010011747 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treetop")
11748 let basedir = s:NetrwTreePath(w:netrw_treetop)
11749 else
11750 let basedir = b:netrw_curdir.'/'
11751 endif
11752 let fname = basedir.s:NetrwGetWord()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011753 let resname = resolve(fname)
Tom Benham64a536d2024-11-07 21:15:03 +010011754 if resname =~ '^\M'.basedir
11755 let dirlen = strlen(basedir)
11756 let resname = strpart(resname,dirlen)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011757 endif
11758 let modline = getline(".")."\t --> ".resname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011759 setl noro ma
11760 call setline(".",modline)
11761 setl ro noma nomod
11762 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011763endfun
11764
11765" ---------------------------------------------------------------------
11766" s:ShowStyle: {{{2
11767fun! s:ShowStyle()
11768 if !exists("w:netrw_liststyle")
11769 let liststyle= g:netrw_liststyle
11770 else
11771 let liststyle= w:netrw_liststyle
11772 endif
11773 if liststyle == s:THINLIST
11774 return s:THINLIST.":thin"
11775 elseif liststyle == s:LONGLIST
11776 return s:LONGLIST.":long"
11777 elseif liststyle == s:WIDELIST
11778 return s:WIDELIST.":wide"
11779 elseif liststyle == s:TREELIST
11780 return s:TREELIST.":tree"
11781 else
11782 return 'n/a'
11783 endif
11784endfun
11785
11786" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010011787" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
11788" Solution from Nicolai Weibull, vim docs (:help strlen()),
11789" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000011790fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011791" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
11792
11793 if v:version >= 703 && exists("*strdisplaywidth")
11794 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011795
Bram Moolenaar8d043172014-01-23 14:24:41 +010011796 elseif type(g:Align_xstrlen) == 1
11797 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
11798 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011799
Bram Moolenaar8d043172014-01-23 14:24:41 +010011800 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000011801 " number of codepoints (Latin a + combining circumflex is two codepoints)
11802 " (comment from TM, solution from NW)
11803 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011804
Bram Moolenaar8d043172014-01-23 14:24:41 +010011805 elseif g:Align_xstrlen == 2
11806 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000011807 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
11808 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011809 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011810
Bram Moolenaar8d043172014-01-23 14:24:41 +010011811 elseif g:Align_xstrlen == 3
11812 " virtual length (counting, for instance, tabs as anything between 1 and
11813 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000011814 " preceded by lam, one otherwise, etc.)
11815 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011816 let modkeep= &l:mod
11817 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011818 call setline(line("."),a:x)
11819 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010011820 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011821 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010011822 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011823
Bram Moolenaar446cb832008-06-24 21:56:24 +000011824 else
11825 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010011826 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011827 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010011828" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011829 return ret
11830endfun
11831
11832" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011833" s:ShellEscape: shellescape(), or special windows handling {{{2
11834fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011835 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011836 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011837 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011838 let f = a:0 > 0 ? a:1 : 0
11839 return shellescape(a:s, f)
11840endfun
11841
11842" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011843" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000011844fun! s:TreeListMove(dir)
11845" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011846 let curline = getline('.')
11847 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
11848 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
11849 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
11850 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
11851 let treedepthchr = substitute(s:treedepthstring,' ','','g')
11852 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
11853" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
11854" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
11855" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
11856" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
11857" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
11858 " COMBAK : need to handle when on a directory
11859 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000011860 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011861 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011862 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011863 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011864" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011865 elseif a:dir == '[]' && nxtline != ''
11866 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011867" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011868 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
11869 if nl != 0
11870 NetrwKeepj norm! k
11871 else
11872 NetrwKeepj norm! G
11873 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011874" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011875 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011876 endif
11877
11878" call Dret("s:TreeListMove")
11879endfun
11880
11881" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011882" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
11883" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
11884" can't be called except via emenu. But due to locale, that menu line may not be called
11885" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
11886fun! s:UpdateBuffersMenu()
11887" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020011888 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000011889 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020011890 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000011891 catch /^Vim\%((\a\+)\)\=:E/
11892 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011893 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000011894 endtry
11895 endif
11896" call Dret("s:UpdateBuffersMenu")
11897endfun
11898
11899" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011900" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020011901" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011902fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000011903" call Dfunc("s:UseBufWinVars()")
11904 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011905 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
11906 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
11907 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
11908 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
11909 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
11910 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11911 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11912 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
11913 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 +000011914" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011915endfun
11916
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011917" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011918" s:UserMaps: supports user-defined UserMaps {{{2
11919" * calls a user-supplied funcref(islocal,curdir)
11920" * interprets result
11921" See netrw#UserMaps()
11922fun! s:UserMaps(islocal,funcname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011923 if !exists("b:netrw_curdir")
11924 let b:netrw_curdir= getcwd()
11925 endif
11926 let Funcref = function(a:funcname)
11927 let result = Funcref(a:islocal)
11928
11929 if type(result) == 1
11930 " if result from user's funcref is a string...
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011931 if result == "refresh"
Tom Benham64a536d2024-11-07 21:15:03 +010011932 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011933 elseif result != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011934 exe result
11935 endif
11936
11937 elseif type(result) == 3
11938 " if result from user's funcref is a List...
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011939 for action in result
11940 if action == "refresh"
Tom Benham64a536d2024-11-07 21:15:03 +010011941 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011942 elseif action != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011943 exe action
11944 endif
11945 endfor
11946 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011947endfun
11948
Bram Moolenaar85850f32019-07-19 22:05:51 +020011949" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011950" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020011951" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000011952let &cpo= s:keepcpo
11953unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000011954
Bram Moolenaar85850f32019-07-19 22:05:51 +020011955" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000011956" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020011957" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000011958" vim:ts=8 fdm=marker