blob: 89aad816f8c39c4ae35ae2931a67504a906b5afc [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)
Konfekt460799d2024-11-14 21:42:27 +010038" 2024 Nov 14 by Vim Project: small fixes to netrw#BrowseX (#16056)
Travis Sheltone34d0e32024-07-30 21:08:56 +020039" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010040" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000041" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010042" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000043" Permission is hereby granted to use and distribute this code,
44" with or without modifications, provided that this copyright
45" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000046" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000047" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000048" expressed or implied. By using this plugin, you agree that
49" in no event will the copyright holder be liable for any damages
50" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010051"
52" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
53" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
54"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020055"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000056"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000057" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000058" (James 1:22 RSV)
59" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000060" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000061if &cp || exists("g:loaded_netrw")
62 finish
63endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020064
65" Check that vim has patches that netrw requires.
66" Patches needed for v7.4: 1557, and 213.
67" (netrw will benefit from vim's having patch#656, too)
68let s:needspatches=[1557,213]
69if exists("s:needspatches")
70 for ptch in s:needspatches
71 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
72 if !exists("s:needpatch{ptch}")
73 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
74 endif
75 let s:needpatch{ptch}= 1
76 finish
77 endif
78 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020079endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020080
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010081let g:loaded_netrw = "v173"
Bram Moolenaar446cb832008-06-24 21:56:24 +000082
Bram Moolenaar1afcace2005-11-25 19:54:28 +000083let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010084setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020085"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010086"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010087"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000088
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000089" ======================
90" Netrw Variables: {{{1
91" ======================
92
Bram Moolenaar071d4272004-06-13 20:20:40 +000093" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020094" netrw#ErrorMsg: {{{2
95" 0=note = s:NOTE
96" 1=warning = s:WARNING
97" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010098" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
99" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
100" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +0100101" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200102fun! netrw#ErrorMsg(level,msg,errnum)
103" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
104
105 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200106" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200107 return
108 endif
109
110 if a:level == 1
111 let level= "**warning** (netrw) "
112 elseif a:level == 2
113 let level= "**error** (netrw) "
114 else
115 let level= "**note** (netrw) "
116 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100117" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200118
Damienb4d11642024-08-15 22:00:45 +0200119 if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200120 " use popup window
121 if type(a:msg) == 3
122 let msg = [level]+a:msg
123 else
124 let msg= level.a:msg
125 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200126 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200127 let s:popuperr_text= ""
128 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200129 " (default) netrw creates a one-line window to show error/warning
130 " messages (reliably displayed)
131
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100132 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200133 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100134" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200135
136 " getting messages out reliably is just plain difficult!
137 " This attempt splits the current window, creating a one line window.
138 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100139" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200140 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100141" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200142 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100143 if type(a:msg) == 3
144 for msg in a:msg
145 NetrwKeepj call setline(line("$")+1,level.msg)
146 endfor
147 else
148 NetrwKeepj call setline(line("$")+1,level.a:msg)
149 endif
150 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200151 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100152" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200153 bo 1split
154 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200155 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200156 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100157 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100158" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200159 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100160 if type(a:msg) == 3
161 for msg in a:msg
162 NetrwKeepj call setline(line("$")+1,level.msg)
163 endfor
164 else
165 NetrwKeepj call setline(line("$"),level.a:msg)
166 endif
167 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200168 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100169" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200170 if &fo !~ '[ta]'
171 syn clear
172 syn match netrwMesgNote "^\*\*note\*\*"
173 syn match netrwMesgWarning "^\*\*warning\*\*"
174 syn match netrwMesgError "^\*\*error\*\*"
175 hi link netrwMesgWarning WarningMsg
176 hi link netrwMesgError Error
177 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100178" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200179 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200180
181 else
182 " (optional) netrw will show messages using echomsg. Even if the
183 " message doesn't appear, at least it'll be recallable via :messages
184" redraw!
185 if a:level == s:WARNING
186 echohl WarningMsg
187 elseif a:level == s:ERROR
188 echohl Error
189 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100190
191 if type(a:msg) == 3
192 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100193 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100194 endfor
195 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100196 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100197 endif
198
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100199" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200200 echohl None
201 endif
202
203" call Dret("netrw#ErrorMsg")
204endfun
205
206" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100207" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100208" Loosely, varname = value.
209fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100210" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100211 if !exists(a:varname)
212 if type(a:value) == 0
213 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200214 elseif type(a:value) == 1 && a:value =~ '^[{[]'
215 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100216 elseif type(a:value) == 1
217 exe "let ".a:varname."="."'".a:value."'"
218 else
219 exe "let ".a:varname."=".a:value
220 endif
221 endif
222endfun
223
224" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000225" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200226call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000227if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100228 call s:NetrwInit("s:THINLIST",0)
229 call s:NetrwInit("s:LONGLIST",1)
230 call s:NetrwInit("s:WIDELIST",2)
231 call s:NetrwInit("s:TREELIST",3)
232 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000233endif
234
Damien7c754112024-08-15 21:58:57 +0200235let s:NOTE = 0
236let s:WARNING = 1
237let s:ERROR = 2
238call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
239
Bram Moolenaar9964e462007-05-05 17:54:07 +0000240" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200241" Default option values: {{{2
242let g:netrw_localcopycmdopt = ""
243let g:netrw_localcopydircmdopt = ""
244let g:netrw_localmkdiropt = ""
245let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200246
247" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000248" Default values for netrw's global protocol variables {{{2
Damienb4d11642024-08-15 22:00:45 +0200249if exists("*popup_atcursor")
250\ && has("syntax")
251\ && exists("g:syntax_on")
252\ && has("mouse")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200253 call s:NetrwInit("g:netrw_use_errorwindow",2)
254else
255 call s:NetrwInit("g:netrw_use_errorwindow",1)
256endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200257
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000258if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100259 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000260 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100261 elseif executable("curl")
262 let g:netrw_dav_cmd = "curl"
263 else
264 let g:netrw_dav_cmd = ""
265 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000266endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000267if !exists("g:netrw_fetch_cmd")
268 if executable("fetch")
269 let g:netrw_fetch_cmd = "fetch -o"
270 else
271 let g:netrw_fetch_cmd = ""
272 endif
273endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100274if !exists("g:netrw_file_cmd")
275 if executable("elinks")
276 call s:NetrwInit("g:netrw_file_cmd","elinks")
277 elseif executable("links")
278 call s:NetrwInit("g:netrw_file_cmd","links")
279 endif
280endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000281if !exists("g:netrw_ftp_cmd")
282 let g:netrw_ftp_cmd = "ftp"
283endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200284let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200285if !exists("g:netrw_ftp_options")
286 let g:netrw_ftp_options= "-i -n"
287endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000288if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100289 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100290 let g:netrw_http_cmd = "wget"
291 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100292 elseif executable("curl")
293 let g:netrw_http_cmd = "curl"
294 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200295 elseif executable("elinks")
296 let g:netrw_http_cmd = "elinks"
297 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000298 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100299 let g:netrw_http_cmd = "fetch"
300 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200301 elseif executable("links")
302 let g:netrw_http_cmd = "links"
303 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000304 else
305 let g:netrw_http_cmd = ""
306 endif
307endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100308call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100309call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100310call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
311call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200312call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200313if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200314 if executable("scp")
315 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
316 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200317 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200318 else
319 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
320 endif
321endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100322call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
323call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000324
Nir Lichtman1e34b952024-05-08 19:19:34 +0200325if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000326 \ && exists("g:netrw_use_nt_rcp")
327 \ && g:netrw_use_nt_rcp
328 \ && executable( $SystemRoot .'/system32/rcp.exe')
329 let s:netrw_has_nt_rcp = 1
330 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000331else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000332 let s:netrw_has_nt_rcp = 0
333 let s:netrw_rcpmode = ''
334endif
335
336" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000337" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000338" Cygwin Detection ------- {{{3
339if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200340 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
341 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000342 else
343 let g:netrw_cygwin= 0
344 endif
345endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000346" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100347call s:NetrwInit("g:netrw_alto" , &sb)
348call s:NetrwInit("g:netrw_altv" , &spr)
349call s:NetrwInit("g:netrw_banner" , 1)
350call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200351call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100352call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200353call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100354call s:NetrwInit("g:netrw_compress" , "gzip")
355call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200356if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
357 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
358 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000359endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200360call s:NetrwInit("g:netrw_cursor" , 2)
361let s:netrw_usercul = &cursorline
362let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200363"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100364call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000365" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200366call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200367call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200368call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100369call s:NetrwInit("g:netrw_dirhistmax" , 10)
370call s:NetrwInit("g:netrw_fastbrowse" , 1)
371call 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 +0000372if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000373 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
374 let g:netrw_ftp_list_cmd = "ls -lF"
375 let g:netrw_ftp_timelist_cmd = "ls -tlF"
376 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000377 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000378 let g:netrw_ftp_list_cmd = "dir"
379 let g:netrw_ftp_timelist_cmd = "dir"
380 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000381 endif
382endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100383call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000384" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100385call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000386if !exists("g:netrw_ignorenetrc")
387 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
388 let g:netrw_ignorenetrc= 1
389 else
390 let g:netrw_ignorenetrc= 0
391 endif
392endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100393call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000394if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000395 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100396 if exists("g:netrw_list_cmd_options")
397 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
398 else
399 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
400 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000401 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200402 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100403 if exists("g:netrw_list_cmd_options")
404 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
405 else
406 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
407 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000408 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100409" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000410 let g:netrw_list_cmd= ""
411 endif
412endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100413call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000414" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200415if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200416 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200417 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
418endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100419if !exists("g:netrw_localcmdshell")
420 let g:netrw_localcmdshell= ""
421endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000422if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200423 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000424 if g:netrw_cygwin
425 let g:netrw_localcopycmd= "cp"
426 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000427 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200428 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000429 endif
430 elseif has("unix") || has("macunix")
431 let g:netrw_localcopycmd= "cp"
432 else
433 let g:netrw_localcopycmd= ""
434 endif
435endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100436if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200437 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100438 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200439 let g:netrw_localcopydircmd = "cp"
440 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100441 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000442 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200443 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100444 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200445 elseif has("unix")
446 let g:netrw_localcopydircmd = "cp"
447 let g:netrw_localcopydircmdopt= " -R"
448 elseif has("macunix")
449 let g:netrw_localcopydircmd = "cp"
450 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100451 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200452 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100453 endif
454endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200455if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100456 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200457 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
458endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200459if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200460 if g:netrw_cygwin
461 call s:NetrwInit("g:netrw_localmkdir","mkdir")
462 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000463 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200464 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200465 endif
466else
467 call s:NetrwInit("g:netrw_localmkdir","mkdir")
468endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200469call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200470if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200471 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200472 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
473endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000474if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200475 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000476 if g:netrw_cygwin
477 let g:netrw_localmovecmd= "mv"
478 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000479 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200480 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000481 endif
482 elseif has("unix") || has("macunix")
483 let g:netrw_localmovecmd= "mv"
484 else
485 let g:netrw_localmovecmd= ""
486 endif
487endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100488" following serves as an example for how to insert a version&patch specific test
489"if v:version < 704 || (v:version == 704 && !has("patch1107"))
490"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100491call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
492" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000493if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000494 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000495endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000496if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000497 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
498endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000499" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100500call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
501call s:NetrwInit("g:netrw_maxfilenamelen", 32)
502call s:NetrwInit("g:netrw_menu" , 1)
503call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200504call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100505call s:NetrwInit("g:netrw_retmap" , 0)
506if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
507 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200508elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100509 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
510else
511 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000512endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100513call s:NetrwInit("g:netrw_preview" , 0)
514call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100515call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100516call s:NetrwInit("g:netrw_sshport" , "-p")
517call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
518call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
519call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100520call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
521" Default values - q-s ---------- {{{3
522call s:NetrwInit("g:netrw_quickhelp",0)
523let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100524 \ "(create new) %:file d:directory",
525 \ "(windows split&open) o:horz v:vert p:preview",
526 \ "i:style qf:file info O:obtain r:reverse",
527 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
528 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
529 \ "(history) qb:list u:go up U:go down",
530 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100531" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
532call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100533if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
534 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
535else
536 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
537endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100538call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
539call s:NetrwInit("g:netrw_sort_options" , "")
540call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000541if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100542 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200543 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100544 else
545 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000546 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000547endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100548call s:NetrwInit("g:netrw_special_syntax" , 0)
549call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaara6878372014-03-22 21:02:50 +0100550call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100551call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000552" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100553call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200554if !exists("g:netrw_xstrlen")
555 if exists("g:Align_xstrlen")
556 let g:netrw_xstrlen= g:Align_xstrlen
557 elseif exists("g:drawit_xstrlen")
558 let g:netrw_xstrlen= g:drawit_xstrlen
559 elseif &enc == "latin1" || !has("multi_byte")
560 let g:netrw_xstrlen= 0
561 else
562 let g:netrw_xstrlen= 1
563 endif
564endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100565call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200566call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100567call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200568if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000569" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000570" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100571call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200572if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200573 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200574else
Bram Moolenaarff034192013-04-24 18:51:19 +0200575 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200576endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200577call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100578call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
579call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100580if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100581 let s:treedepthstring= "│ "
582else
583 let s:treedepthstring= "| "
584endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200585call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000586
587" BufEnter event ignored by decho when following variable is true
588" Has a side effect that doau BufReadPost doesn't work, so
589" files read by network transfer aren't appropriately highlighted.
590"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000591
Bram Moolenaaradc21822011-04-01 18:03:16 +0200592" ======================
593" Netrw Initialization: {{{1
594" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200595if 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 +0100596" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100597 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200598" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100599 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100600 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
601 au VimEnter * let s:initbeval= &beval
602"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100603" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
604" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
605" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
606" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
607" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
608" 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 +0200609endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200610au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200611
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200612if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100613 com! -nargs=* NetrwKeepj keepj <args>
614else
615 let g:netrw_keepj= ""
616 com! -nargs=* NetrwKeepj <args>
617endif
618
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000619" ==============================
620" Netrw Utility Functions: {{{1
621" ==============================
622
Bram Moolenaaradc21822011-04-01 18:03:16 +0200623" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100624" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100625if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100626" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100627 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100628 if &ft != "netrw"
629 return ""
630 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200631 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
632 " popup error window is still showing
633 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
634 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
635 " text under mouse hasn't changed; only close window when it changes
636 call popup_close(s:popuperr_id)
637 unlet s:popuperr_text
638 else
639 let s:popuperr_text= v:beval_text
640 endif
641 let mesg= ""
642 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 +0100643 let mesg= ""
644 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
645 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
646 elseif getline(v:beval_lnum) =~ '^"\s*/'
647 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
648 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100649 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100650 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
651 let mesg = "S: edit sorting sequence"
652 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
653 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
654 elseif v:beval_text == "Quick" || v:beval_text == "Help"
655 let mesg = "Help: press <F1>"
656 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
657 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
658 else
659 let mesg= ""
660 endif
661 return mesg
662 endfun
663"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100664" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
665" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
666" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
667" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
668" 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 +0200669endif
670
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200672" netrw#Explore: launch the local browser in the directory of the current file {{{2
673" indx: == -1: Nexplore
674" == -2: Pexplore
675" == +: this is overloaded:
676" * If Nexplore/Pexplore is in use, then this refers to the
677" indx'th item in the w:netrw_explore_list[] of items which
678" matched the */pattern **/pattern *//pattern **//pattern
679" * If Hexplore or Vexplore, then this will override
680" g:netrw_winsize to specify the qty of rows or columns the
681" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100682" 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 +0200683" dosplit==1: the window will be split before running the local browser
684" style == 0: Explore style == 1: Explore!
685" == 2: Hexplore style == 3: Hexplore!
686" == 4: Vexplore style == 5: Vexplore!
687" == 6: Texplore
688fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaarff034192013-04-24 18:51:19 +0200689 if !exists("b:netrw_curdir")
690 let b:netrw_curdir= getcwd()
Bram Moolenaarff034192013-04-24 18:51:19 +0200691 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100692
693 " record current file for Rexplore's benefit
694 if &ft != "netrw"
695 let w:netrw_rexfile= expand("%:p")
696 endif
697
698 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200699 let curdir = simplify(b:netrw_curdir)
700 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200701 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200702 let curdir= substitute(curdir,'\','/','g')
703 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100704
705 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
706 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
707 " try Explore again.
708 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100709 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200710 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
711 if a1 != a:1
712 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
713 return
714 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100715 endif
716 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200717
718 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200719 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100720" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100721 sil! let keepregstar = @*
722 sil! let keepregplus = @+
723 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200724 sil! let keepregslash= @/
725
Bram Moolenaar8d043172014-01-23 14:24:41 +0100726 " if dosplit
727 " -or- file has been modified AND file not hidden when abandoned
728 " -or- Texplore used
729 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaarff034192013-04-24 18:51:19 +0200730 call s:SaveWinVars()
731 let winsz= g:netrw_winsize
732 if a:indx > 0
733 let winsz= a:indx
734 endif
735
736 if a:style == 0 " Explore, Sexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200737 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200738 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200739 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200740
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200741 elseif a:style == 1 " Explore!, Sexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200742 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200743 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200744 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200745
746 elseif a:style == 2 " Hexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200747 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200748 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200749 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200750
751 elseif a:style == 3 " Hexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200752 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200753 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200754 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200755
756 elseif a:style == 4 " Vexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200757 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200758 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200759 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200760
761 elseif a:style == 5 " Vexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200762 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200763 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200764 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200765
766 elseif a:style == 6 " Texplore
767 call s:SaveBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200768 exe "keepalt tabnew ".fnameescape(curdir)
769 call s:RestoreBufVars()
770 endif
771 call s:RestoreWinVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200772 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100773 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200774
775 if a:0 > 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200776 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaarff034192013-04-24 18:51:19 +0200777 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaarff034192013-04-24 18:51:19 +0200778 elseif a:1 == '.'
Bram Moolenaarff034192013-04-24 18:51:19 +0200779 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
780 if dirname !~ '/$'
781 let dirname= dirname."/"
782 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200783 elseif a:1 =~ '\$'
Bram Moolenaarff034192013-04-24 18:51:19 +0200784 let dirname= simplify(expand(a:1))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200785 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaarff034192013-04-24 18:51:19 +0200786 let dirname= simplify(a:1)
Bram Moolenaarff034192013-04-24 18:51:19 +0200787 else
Bram Moolenaarff034192013-04-24 18:51:19 +0200788 let dirname= a:1
789 endif
790 else
791 " clear explore
Bram Moolenaarff034192013-04-24 18:51:19 +0200792 call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200793 return
794 endif
795
Bram Moolenaarff034192013-04-24 18:51:19 +0200796 if dirname =~ '\.\./\=$'
797 let dirname= simplify(fnamemodify(dirname,':p:h'))
798 elseif dirname =~ '\.\.' || dirname == '.'
799 let dirname= simplify(fnamemodify(dirname,':p'))
800 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200801
802 if dirname =~ '^\*//'
803 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200804 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
805 let starpat= 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200806 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
807
808 elseif dirname =~ '^\*\*//'
809 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200810 let pattern= substitute(dirname,'^\*\*//','','')
811 let starpat= 2
Bram Moolenaarff034192013-04-24 18:51:19 +0200812
813 elseif dirname =~ '/\*\*/'
814 " handle .../**/.../filepat
Bram Moolenaarff034192013-04-24 18:51:19 +0200815 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200816 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200817 let b:netrw_curdir = prefixdir
818 else
819 let b:netrw_curdir= getcwd().'/'.prefixdir
820 endif
821 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
822 let starpat= 4
Bram Moolenaarff034192013-04-24 18:51:19 +0200823
824 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200825 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200826 let starpat= 3
Bram Moolenaarff034192013-04-24 18:51:19 +0200827
828 elseif dirname=~ '^\*\*/'
829 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
830 let starpat= 4
Bram Moolenaarff034192013-04-24 18:51:19 +0200831
832 else
833 let starpat= 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200834 endif
835
836 if starpat == 0 && a:indx >= 0
837 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaarff034192013-04-24 18:51:19 +0200838 if dirname == ""
839 let dirname= curfiledir
Bram Moolenaarff034192013-04-24 18:51:19 +0200840 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200841 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200842 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200843 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200844 if dirname == ""
845 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200846 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100847 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100848 " depending on whether backslashes have been converted to forward slashes by earlier code).
849 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200850 let dirname= b:netrw_curdir."/".dirname
851 endif
852 elseif dirname !~ '^/'
853 let dirname= b:netrw_curdir."/".dirname
854 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200855 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200856 endif
857 if exists("w:netrw_bannercnt")
858 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
859 " If one wants to return the same place in the netrw window, use :Rex instead.
860 exe w:netrw_bannercnt
861 endif
862
Bram Moolenaarff034192013-04-24 18:51:19 +0200863
864 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
865 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
866 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
867 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
868 elseif a:indx <= 0
869 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaarff034192013-04-24 18:51:19 +0200870 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaarff034192013-04-24 18:51:19 +0200871 let s:didstarstar= 1
872 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
873 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
874 endif
875
876 if has("path_extra")
Bram Moolenaarff034192013-04-24 18:51:19 +0200877 if !exists("w:netrw_explore_indx")
878 let w:netrw_explore_indx= 0
879 endif
880
881 let indx = a:indx
Bram Moolenaarff034192013-04-24 18:51:19 +0200882
883 if indx == -1
884 " Nexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200885 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100886 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 +0200887 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100888 if @* != keepregstar | sil! let @* = keepregstar | endif
889 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100890 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200891 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200892 return
893 endif
894 let indx= w:netrw_explore_indx
895 if indx < 0 | let indx= 0 | endif
896 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
897 let curfile= w:netrw_explore_list[indx]
Bram Moolenaarff034192013-04-24 18:51:19 +0200898 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
899 let indx= indx + 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200900 endwhile
901 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200902
903 elseif indx == -2
904 " Pexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200905 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100906 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 +0200907 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100908 if @* != keepregstar | sil! let @* = keepregstar | endif
909 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100910 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200911 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200912 return
913 endif
914 let indx= w:netrw_explore_indx
915 if indx < 0 | let indx= 0 | endif
916 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
917 let curfile= w:netrw_explore_list[indx]
Bram Moolenaarff034192013-04-24 18:51:19 +0200918 while indx >= 0 && curfile == w:netrw_explore_list[indx]
919 let indx= indx - 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200920 endwhile
921 if indx < 0 | let indx= 0 | endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200922
923 else
924 " Explore -- initialize
925 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100926 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200927 let w:netrw_explore_indx= 0
928 if !exists("b:netrw_curdir")
929 let b:netrw_curdir= getcwd()
930 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200931
932 " switch on starpat to build the w:netrw_explore_list of files
933 if starpat == 1
934 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200935 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100936 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200937 catch /^Vim\%((\a\+)\)\=:E480/
938 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +0200939 return
940 endtry
941 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
942 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
943
944 elseif starpat == 2
945 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200946 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100947 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200948 catch /^Vim\%((\a\+)\)\=:E480/
949 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
950 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200951 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100952 if @* != keepregstar | sil! let @* = keepregstar | endif
953 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100954 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200955 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200956 return
957 endtry
958 let s:netrw_curdir = b:netrw_curdir
959 let w:netrw_explore_list = getqflist()
960 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
961 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
962
963 elseif starpat == 3
964 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200965 let filepat= substitute(dirname,'^\*/','','')
966 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaarff034192013-04-24 18:51:19 +0200967 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
968 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
969
970 elseif starpat == 4
971 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200972 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
973 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
974 endif " switch on starpat to build w:netrw_explore_list
975
976 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaarff034192013-04-24 18:51:19 +0200977
978 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100979 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200980 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100981 if @* != keepregstar | sil! let @* = keepregstar | endif
982 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100983 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200984 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200985 return
986 endif
987 endif " if indx ... endif
988
989 " NetrwStatusLine support - for exploring support
990 let w:netrw_explore_indx= indx
Bram Moolenaarff034192013-04-24 18:51:19 +0200991
992 " wrap the indx around, but issue a note
993 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200994 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
995 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100996 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +0200997 endif
998
999 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaarff034192013-04-24 18:51:19 +02001000 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaarff034192013-04-24 18:51:19 +02001001
Bram Moolenaarff034192013-04-24 18:51:19 +02001002 call netrw#LocalBrowseCheck(newdir)
1003 if !exists("w:netrw_liststyle")
1004 let w:netrw_liststyle= g:netrw_liststyle
1005 endif
1006 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001007 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001008 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001009 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001010 endif
1011 let w:netrw_explore_mtchcnt = indx + 1
1012 let w:netrw_explore_bufnr = bufnr("%")
1013 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001014 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaarff034192013-04-24 18:51:19 +02001015
1016 else
Bram Moolenaarff034192013-04-24 18:51:19 +02001017 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001018 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 +02001019 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001020 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001021 if @* != keepregstar | sil! let @* = keepregstar | endif
1022 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001023 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001024 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +02001025 return
1026 endif
1027
1028 else
Bram Moolenaarff034192013-04-24 18:51:19 +02001029 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1030 sil! unlet w:netrw_treedict
1031 sil! unlet w:netrw_treetop
1032 endif
1033 let newdir= dirname
1034 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001035 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001036 else
Tom Benham64a536d2024-11-07 21:15:03 +01001037 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir,0))
Bram Moolenaarff034192013-04-24 18:51:19 +02001038 endif
1039 endif
1040
1041 " visual display of **/ **// */ Exploration files
Bram Moolenaarff034192013-04-24 18:51:19 +02001042 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaarff034192013-04-24 18:51:19 +02001043 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001044 " only update match list when current directory isn't the same as before
Bram Moolenaarff034192013-04-24 18:51:19 +02001045 let s:explore_prvdir = b:netrw_curdir
1046 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001047 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001048 if b:netrw_curdir !~ '/$'
1049 let dirlen= dirlen + 1
1050 endif
1051 let prvfname= ""
1052 for fname in w:netrw_explore_list
Bram Moolenaarff034192013-04-24 18:51:19 +02001053 if fname =~ '^'.b:netrw_curdir
1054 if s:explore_match == ""
1055 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1056 else
1057 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1058 endif
1059 elseif fname !~ '^/' && fname != prvfname
1060 if s:explore_match == ""
1061 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1062 else
1063 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1064 endif
1065 endif
1066 let prvfname= fname
1067 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02001068 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1069 exe "2match netrwMarkFile /".s:explore_match."/"
1070 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001071 endif
1072 echo "<s-up>==Pexplore <s-down>==Nexplore"
1073 else
1074 2match none
1075 if exists("s:explore_match") | unlet s:explore_match | endif
1076 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001077 endif
1078
Bram Moolenaara6878372014-03-22 21:02:50 +01001079 " since Explore may be used to initialize netrw's browser,
1080 " there's no danger of a late FocusGained event on initialization.
1081 " Consequently, set s:netrw_events to 2.
1082 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001083 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001084 if @* != keepregstar | sil! let @* = keepregstar | endif
1085 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001086 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001087 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +02001088endfun
1089
1090" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001091" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001092" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1093" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1094" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1095" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1096" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001097fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001098" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001099 let curwin= winnr()
1100
Bram Moolenaara6878372014-03-22 21:02:50 +01001101 if a:0 > 0 && a:1 != ""
1102 " if a netrw window is already on the left-side of the tab
1103 " and a directory has been specified, explore with that
1104 " directory.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001105 let a1 = expand(a:1)
Bram Moolenaara6878372014-03-22 21:02:50 +01001106 exe "1wincmd w"
1107 if &ft == "netrw"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001108 exe "Explore ".fnameescape(a1)
1109 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001110 let s:lexplore_win= curwin
1111 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001112 if exists("t:netrw_lexposn")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001113 unlet t:netrw_lexposn
1114 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001115 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001116 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001117 exe curwin."wincmd w"
1118 else
1119 let a1= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01001120 endif
1121
Bram Moolenaar8d043172014-01-23 14:24:41 +01001122 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001123 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001124 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001125 else
1126 let lexwinnr= 0
1127 endif
1128
1129 if lexwinnr > 0
1130 " close down netrw explorer window
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001131 exe lexwinnr."wincmd w"
1132 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001133 let t:netrw_lexposn = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001134 close
1135 if lexwinnr < curwin
1136 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001137 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001138 if lexwinnr != curwin
1139 exe curwin."wincmd w"
1140 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001141 unlet t:netrw_lexbufnr
1142
1143 else
1144 " open netrw explorer window
1145 exe "1wincmd w"
1146 let keep_altv = g:netrw_altv
1147 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001148 if a:count != 0
1149 let netrw_winsize = g:netrw_winsize
1150 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001151 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001152 let curfile= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001153 exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
1154 if a:0 > 0 && a1 != ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001155 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001156 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001157 elseif curfile =~ '^\a\{3,}://'
Bram Moolenaar85850f32019-07-19 22:05:51 +02001158 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001159 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02001160 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001161 endif
1162 if a:count != 0
1163 let g:netrw_winsize = netrw_winsize
1164 endif
1165 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001166 let g:netrw_altv = keep_altv
1167 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001168 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1169 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001170 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001171 set bh=wipe
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001172 if exists("t:netrw_lexposn")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001173 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001174 unlet t:netrw_lexposn
1175 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001176 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001177
1178 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001179 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001180 if a:rightside
1181 let g:netrw_chgwin= 1
1182 else
1183 let g:netrw_chgwin= 2
1184 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001185 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001186
Bram Moolenaar8d043172014-01-23 14:24:41 +01001187endfun
1188
1189" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001190" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001191" supports :NetrwClean -- remove netrw from first directory on runtimepath
1192" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001193fun! netrw#Clean(sys)
1194" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001195
1196 if a:sys
1197 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1198 else
1199 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1200 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001201" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001202 let diddel= 0
1203 let diddir= ""
1204
1205 if choice == 1
1206 for dir in split(&rtp,',')
1207 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001208" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001209 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1210 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1211 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1212 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1213 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1214 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 +00001215 let diddir= dir
1216 let diddel= diddel + 1
1217 if !a:sys|break|endif
1218 endif
1219 endfor
1220 endif
1221
1222 echohl WarningMsg
1223 if diddel == 0
1224 echomsg "netrw is either not installed or not removable"
1225 elseif diddel == 1
1226 echomsg "removed one copy of netrw from <".diddir.">"
1227 else
1228 echomsg "removed ".diddel." copies of netrw"
1229 endif
1230 echohl None
1231
Bram Moolenaara6878372014-03-22 21:02:50 +01001232" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001233endfun
1234
Bram Moolenaar5c736222010-01-06 20:54:52 +01001235" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001236" netrw#MakeTgt: make a target out of the directory name provided {{{2
1237fun! netrw#MakeTgt(dname)
1238" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1239 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001240 let svpos = winsaveview()
1241" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001242 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1243" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001244 if s:netrwmftgt_islocal
1245 let netrwmftgt= simplify(a:dname)
1246 else
1247 let netrwmftgt= a:dname
1248 endif
1249 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1250 " re-selected target, so just clear it
1251 unlet s:netrwmftgt s:netrwmftgt_islocal
1252 else
1253 let s:netrwmftgt= netrwmftgt
1254 endif
1255 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001256 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001257 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001258" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1259 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001260" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001261endfun
1262
Bram Moolenaara6878372014-03-22 21:02:50 +01001263" ---------------------------------------------------------------------
1264" netrw#Obtain: {{{2
1265" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001266" islocal=0 obtain from remote source
1267" =1 obtain from local source
1268" fname : a filename or a list of filenames
1269" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001270fun! netrw#Obtain(islocal,fname,...)
1271" 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 +02001272 " NetrwStatusLine support - for obtaining support
1273
1274 if type(a:fname) == 1
1275 let fnamelist= [ a:fname ]
1276 elseif type(a:fname) == 3
1277 let fnamelist= a:fname
1278 else
1279 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 +01001280" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001281 return
1282 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001283" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001284 if a:0 > 0
1285 let tgtdir= a:1
1286 else
1287 let tgtdir= getcwd()
1288 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001289" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001290
1291 if exists("b:netrw_islocal") && b:netrw_islocal
1292 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001293" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001294 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1295 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001296 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001297 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001298" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001299 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001300" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001301 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001302 if v:shell_error != 0
1303 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 +01001304" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001305 return
1306 endif
1307 endfor
1308 else
1309 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001310" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1311 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1312" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001313 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001314 if v:shell_error != 0
1315 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 +01001316" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001317 return
1318 endif
1319 endif
1320 elseif !exists("b:netrw_curdir")
1321 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1322 else
1323 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1324 endif
1325
1326 else
1327 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001328" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001329 if type(a:fname) == 1
1330 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1331 endif
1332 call s:NetrwMethod(b:netrw_curdir)
1333
1334 if b:netrw_method == 4
1335 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001336" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001337 if exists("g:netrw_port") && g:netrw_port != ""
1338 let useport= " ".g:netrw_scpport." ".g:netrw_port
1339 else
1340 let useport= ""
1341 endif
1342 if b:netrw_fname =~ '/'
1343 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1344 else
1345 let path= ""
1346 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001347 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001348 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 +02001349
1350 elseif b:netrw_method == 2
1351 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001352" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001353 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001354 let tmpbufnr= bufnr("%")
1355 setl ff=unix
1356 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001357 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001358" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001359 endif
1360
1361 if exists("b:netrw_fname") && b:netrw_fname != ""
1362 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001363" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001364 endif
1365
1366 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001367 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001368" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001369 endif
1370 for fname in fnamelist
1371 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001372" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001373 endfor
1374 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001375 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 +02001376 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001377 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001378 endif
1379 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1380 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1381 let debugkeep= &debug
1382 setl debug=msg
1383 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1384 let &debug= debugkeep
1385 endif
1386
1387 elseif b:netrw_method == 3
1388 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001389" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001390 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001391 let tmpbufnr= bufnr("%")
1392 setl ff=unix
1393
1394 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001395 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001396" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001397 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001398 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001399" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001400 endif
1401
1402 if exists("g:netrw_uid") && g:netrw_uid != ""
1403 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001404 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001405" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001406 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001407 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001408 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001409" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001410 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001411 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001412" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001413 endif
1414 endif
1415
1416 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001417 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001418" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001419 endif
1420
1421 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001422 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001423" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001424 endif
1425
1426 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001427 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001428" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001429 endif
1430
1431 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001432 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001433" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001434 endif
1435 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001436 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001437 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001438" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001439
1440 " perform ftp:
1441 " -i : turns off interactive prompting from ftp
1442 " -n unix : DON'T use <.netrc>, even though it exists
1443 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001444 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1445 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001446 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001447 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1448 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001449" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001450 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001451 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001452 endif
1453 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001454
1455 elseif b:netrw_method == 9
1456 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001457" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001458 if a:fname =~ '/'
1459 let localfile= substitute(a:fname,'^.*/','','')
1460 else
1461 let localfile= a:fname
1462 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001463 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 +02001464
Bram Moolenaarff034192013-04-24 18:51:19 +02001465 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001466 " probably a badly formed url; protocol not recognized
1467" call Dret("netrw#Obtain : unsupported method")
1468 return
1469
1470 else
1471 " protocol recognized but not supported for Obtain (yet?)
1472 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001473 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001474 endif
1475" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001476 return
1477 endif
1478
1479 " restore status line
1480 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001481 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001482 endif
1483
1484 endif
1485
1486 " cleanup
1487 if exists("tmpbufnr")
1488 if bufnr("%") != tmpbufnr
1489 exe tmpbufnr."bw!"
1490 else
1491 q!
1492 endif
1493 endif
1494
Bram Moolenaara6878372014-03-22 21:02:50 +01001495" call Dret("netrw#Obtain")
1496endfun
1497
1498" ---------------------------------------------------------------------
1499" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1500fun! netrw#Nread(mode,fname)
1501" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001502 let svpos= winsaveview()
1503" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001504 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001505" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1506 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001507
1508 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1509 if exists("w:netrw_bannercnt")
1510 " start with cursor just after the banner
1511 exe w:netrw_bannercnt
1512 endif
1513 endif
1514" call Dret("netrw#Nread")
1515endfun
1516
1517" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001518" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1519" Options get restored by s:NetrwOptionsRestore()
1520"
1521" Option handling:
1522" * save user's options (s:NetrwOptionsSave)
1523" * set netrw-safe options (s:NetrwOptionsSafe)
1524" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1525" * restore user's options (s:netrwOPtionsRestore)
1526" - restore a user option when != safe option (s:NetrwRestoreSetting)
1527" vt: (variable type) normally its either "w:" or "s:"
1528fun! s:NetrwOptionsSave(vt)
1529" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1530" 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 +02001531" 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>"))
1532" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001533
1534 if !exists("{a:vt}netrw_optionsave")
1535 let {a:vt}netrw_optionsave= 1
1536 else
1537" call Dret("s:NetrwOptionsSave : options already saved")
1538 return
1539 endif
1540" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1541
1542 " Save current settings and current directory
1543" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1544 let s:yykeep = @@
1545 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1546 let {a:vt}netrw_aikeep = &l:ai
1547 let {a:vt}netrw_awkeep = &l:aw
1548 let {a:vt}netrw_bhkeep = &l:bh
1549 let {a:vt}netrw_blkeep = &l:bl
1550 let {a:vt}netrw_btkeep = &l:bt
1551 let {a:vt}netrw_bombkeep = &l:bomb
1552 let {a:vt}netrw_cedit = &cedit
1553 let {a:vt}netrw_cikeep = &l:ci
1554 let {a:vt}netrw_cinkeep = &l:cin
1555 let {a:vt}netrw_cinokeep = &l:cino
1556 let {a:vt}netrw_comkeep = &l:com
1557 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001558 let {a:vt}netrw_cuckeep = &l:cuc
1559 let {a:vt}netrw_culkeep = &l:cul
1560" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001561 let {a:vt}netrw_diffkeep = &l:diff
1562 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001563 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1564 let {a:vt}netrw_ffkeep = &l:ff
1565 endif
1566 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1567 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001568 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001569 let {a:vt}netrw_hidkeep = &l:hidden
1570 let {a:vt}netrw_imkeep = &l:im
1571 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001572 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001573 let {a:vt}netrw_lskeep = &l:ls
1574 let {a:vt}netrw_makeep = &l:ma
1575 let {a:vt}netrw_magickeep = &l:magic
1576 let {a:vt}netrw_modkeep = &l:mod
1577 let {a:vt}netrw_nukeep = &l:nu
1578 let {a:vt}netrw_rnukeep = &l:rnu
1579 let {a:vt}netrw_repkeep = &l:report
1580 let {a:vt}netrw_rokeep = &l:ro
1581 let {a:vt}netrw_selkeep = &l:sel
1582 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001583 if !g:netrw_use_noswf
1584 let {a:vt}netrw_swfkeep = &l:swf
1585 endif
1586 let {a:vt}netrw_tskeep = &l:ts
1587 let {a:vt}netrw_twkeep = &l:tw " textwidth
1588 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1589 let {a:vt}netrw_wrapkeep = &l:wrap
1590 let {a:vt}netrw_writekeep = &l:write
1591
1592 " save a few selected netrw-related variables
1593" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1594 if g:netrw_keepdir
1595 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001596" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001597 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001598 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001599 sil! let {a:vt}netrw_starkeep = @*
1600 sil! let {a:vt}netrw_pluskeep = @+
1601 endif
1602 sil! let {a:vt}netrw_slashkeep= @/
1603
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001604" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001605" 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>"))
1606" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1607endfun
1608
1609" ---------------------------------------------------------------------
1610" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1611" Use s:NetrwSaveOptions() to save user settings
1612" Use s:NetrwOptionsRestore() to restore user settings
1613fun! s:NetrwOptionsSafe(islocal)
1614" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1615" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1616" 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>"))
1617 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1618 call s:NetrwSetSafeSetting("&l:ai",0)
1619 call s:NetrwSetSafeSetting("&l:aw",0)
1620 call s:NetrwSetSafeSetting("&l:bl",0)
1621 call s:NetrwSetSafeSetting("&l:bomb",0)
1622 if a:islocal
1623 call s:NetrwSetSafeSetting("&l:bt","nofile")
1624 else
1625 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1626 endif
1627 call s:NetrwSetSafeSetting("&l:ci",0)
1628 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001629 if g:netrw_fastbrowse > a:islocal
1630 call s:NetrwSetSafeSetting("&l:bh","hide")
1631 else
1632 call s:NetrwSetSafeSetting("&l:bh","delete")
1633 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001634 call s:NetrwSetSafeSetting("&l:cino","")
1635 call s:NetrwSetSafeSetting("&l:com","")
1636 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1637 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1638 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001639 if &go =~ 'a' | set go-=a | endif
1640 if &go =~ 'A' | set go-=A | endif
1641 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001642 call s:NetrwSetSafeSetting("&l:hid",0)
1643 call s:NetrwSetSafeSetting("&l:im",0)
1644 setl isk+=@ isk+=* isk+=/
1645 call s:NetrwSetSafeSetting("&l:magic",1)
1646 if g:netrw_use_noswf
1647 call s:NetrwSetSafeSetting("swf",0)
1648 endif
1649 call s:NetrwSetSafeSetting("&l:report",10000)
1650 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1651 call s:NetrwSetSafeSetting("&l:spell",0)
1652 call s:NetrwSetSafeSetting("&l:tw",0)
1653 call s:NetrwSetSafeSetting("&l:wig","")
1654 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001655
1656 " set up cuc and cul based on g:netrw_cursor and listing style
1657 " COMBAK -- cuc cul related
1658 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001659
1660 " allow the user to override safe options
1661" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1662 if &ft == "netrw"
1663" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1664 keepalt NetrwKeepj doau FileType netrw
1665 endif
1666
1667" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1668" 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>"))
1669" call Dret("s:NetrwOptionsSafe")
1670endfun
1671
1672" ---------------------------------------------------------------------
1673" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1674fun! s:NetrwOptionsRestore(vt)
Bram Moolenaara6878372014-03-22 21:02:50 +01001675 if !exists("{a:vt}netrw_optionsave")
Christian Brabandtaa2ce6f2024-10-30 18:27:03 +01001676 " filereadable() returns zero for remote files (e.g. scp://user@localhost//etc/fstab)
1677 " Note: @ may not be in 'isfname', so '^\w\+://\f\+/' may not match
1678 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+'
Bram Moolenaar71badf92023-04-22 22:40:14 +01001679 filetype detect
Bram Moolenaar71badf92023-04-22 22:40:14 +01001680 else
1681 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001682 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001683 return
1684 endif
1685 unlet {a:vt}netrw_optionsave
1686
1687 if exists("+acd")
1688 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara6878372014-03-22 21:02:50 +01001689 let curdir = getcwd()
1690 let &l:acd = {a:vt}netrw_acdkeep
1691 unlet {a:vt}netrw_acdkeep
1692 if &l:acd
1693 call s:NetrwLcd(curdir)
1694 endif
1695 endif
1696 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001697 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1698 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1699 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1700 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1701 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
1702 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1703 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1704 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1705 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1706 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
1707 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1708 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1709 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1710 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1711 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001712 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001713 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1714 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001715 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001716 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001717 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1718 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001719 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001720 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1721 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001722 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001723 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1724 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001725 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1726 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1727 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1728 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001729 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001730 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1731 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1732 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001733 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
1734 call s:NetrwRestoreSetting("s:yykeep","@@")
1735 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1736 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1737 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1738 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1739
Bram Moolenaara6878372014-03-22 21:02:50 +01001740 if exists("{a:vt}netrw_swfkeep")
1741 if &directory == ""
1742 " user hasn't specified a swapfile directory;
1743 " netrw will temporarily set the swapfile directory
1744 " to the current directory as returned by getcwd().
1745 let &l:directory= getcwd()
1746 sil! let &l:swf = {a:vt}netrw_swfkeep
1747 setl directory=
1748 unlet {a:vt}netrw_swfkeep
1749 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001750 if !g:netrw_use_noswf
1751 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1752 sil! let &l:swf= {a:vt}netrw_swfkeep
1753 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001754 unlet {a:vt}netrw_swfkeep
1755 endif
1756 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001757 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001758 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1759 if exists("{a:vt}netrw_dirkeep")
1760 call s:NetrwLcd(dirkeep)
1761 unlet {a:vt}netrw_dirkeep
1762 endif
1763 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001764 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001765 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1766 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001767 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001768 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001769
Bram Moolenaara6878372014-03-22 21:02:50 +01001770 " Moved the filetype detect here from NetrwGetFile() because remote files
1771 " were having their filetype detect-generated settings overwritten by
1772 " NetrwOptionRestore.
1773 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001774 filetype detect
Bram Moolenaara6878372014-03-22 21:02:50 +01001775 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001776endfun
1777
1778" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001779" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1780" but only when the options' value and the safe setting differ
1781" Doing this means that netrw will not come up as having changed a
1782" setting last when it really didn't actually change it.
1783"
1784" Called from s:NetrwOptionsSafe
1785" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1786fun! s:NetrwSetSafeSetting(setting,safesetting)
1787" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001788
Bram Moolenaar85850f32019-07-19 22:05:51 +02001789 if a:setting =~ '^&'
1790" call Decho("fyi: a:setting starts with &")
1791 exe "let settingval= ".a:setting
1792" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001793
Bram Moolenaar85850f32019-07-19 22:05:51 +02001794 if settingval != a:safesetting
1795" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1796 if type(a:safesetting) == 0
1797 exe "let ".a:setting."=".a:safesetting
1798 elseif type(a:safesetting) == 1
1799 exe "let ".a:setting."= '".a:safesetting."'"
1800 else
1801 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1802 endif
1803 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001804 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001805
Bram Moolenaar85850f32019-07-19 22:05:51 +02001806" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001807endfun
1808
1809" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001810" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1811" but only if the setting value differs from the associated keepvar.
1812" Doing this means that netrw will not come up as having changed a
1813" setting last when it really didn't actually change it.
1814"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001815" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001816" keepvars are set up by s:NetrwOptionsSave
1817fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001818""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001819
Bram Moolenaar85850f32019-07-19 22:05:51 +02001820 " typically called from s:NetrwOptionsRestore
1821 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1822 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001823 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001824 if exists(a:keepvar)
1825 exe "let keepvarval= ".a:keepvar
1826 exe "let setting= ".a:setting
1827
1828"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1829"" call Decho("fyi: keepvarval=".keepvarval)
1830"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1831
1832 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001833"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001834 if type(a:setting) == 0
1835 exe "let ".a:setting."= ".keepvarval
1836 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001837 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001838 else
1839 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1840 endif
1841 endif
1842
1843 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001844 endif
1845
Bram Moolenaar85850f32019-07-19 22:05:51 +02001846"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001847endfun
1848
1849" ---------------------------------------------------------------------
1850" NetrwStatusLine: {{{2
1851fun! NetrwStatusLine()
1852
1853" vvv NetrwStatusLine() debugging vvv
1854" let g:stlmsg=""
1855" if !exists("w:netrw_explore_bufnr")
1856" let g:stlmsg="!X<explore_bufnr>"
1857" elseif w:netrw_explore_bufnr != bufnr("%")
1858" let g:stlmsg="explore_bufnr!=".bufnr("%")
1859" endif
1860" if !exists("w:netrw_explore_line")
1861" let g:stlmsg=" !X<explore_line>"
1862" elseif w:netrw_explore_line != line(".")
1863" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
1864" endif
1865" if !exists("w:netrw_explore_list")
1866" let g:stlmsg=" !X<explore_list>"
1867" endif
1868" ^^^ NetrwStatusLine() debugging ^^^
1869
1870 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")
1871 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09001872 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02001873 let &laststatus = s:netrw_users_ls
1874 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
1875 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
1876 return ""
1877 else
1878 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
1879 endif
1880endfun
1881
Bram Moolenaar85850f32019-07-19 22:05:51 +02001882" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001883" Netrw Transfer Functions: {{{1
1884" ===============================
1885
Bram Moolenaar071d4272004-06-13 20:20:40 +00001886" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001887" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001888" mode: =0 read remote file and insert before current line
1889" =1 read remote file and insert after current line
1890" =2 replace with remote file
1891" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001892fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02001893" 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 +00001894
Bram Moolenaar5c736222010-01-06 20:54:52 +01001895 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02001896 call s:NetrwOptionsSave("w:")
1897 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001898 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001899 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
1900 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
1901 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02001902" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001903
Bram Moolenaar5c736222010-01-06 20:54:52 +01001904 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001905 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001906 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001907 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001908 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001909 elseif a:mode == 2 " replace with remote file
1910 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00001911 elseif a:mode == 3 " skip read of file (leave as temporary)
1912 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001913 else
1914 exe a:mode
1915 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001916 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001917 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001918" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001919
Bram Moolenaar5c736222010-01-06 20:54:52 +01001920 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00001921 let tmpfile= s:GetTempfile("")
1922 if tmpfile == ""
1923" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001924 return
1925 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001926
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001927 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001928
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001929 " attempt to repeat with previous host-file-etc
1930 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001931" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001932 let choice = b:netrw_lastfile
1933 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001934
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001935 else
1936 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001937" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001938
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001939 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001940 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001941 echomsg 'NetRead Usage:'
1942 echomsg ':Nread machine:path uses rcp'
1943 echomsg ':Nread "machine path" uses ftp with <.netrc>'
1944 echomsg ':Nread "machine id password path" uses ftp'
1945 echomsg ':Nread dav://machine[:port]/path uses cadaver'
1946 echomsg ':Nread fetch://machine/path uses fetch'
1947 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
1948 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001949 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01001950 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001951 echomsg ':Nread rcp://[user@]machine/path uses rcp'
1952 echomsg ':Nread rsync://machine[:port]/path uses rsync'
1953 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
1954 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00001955 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001956 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001957
Bram Moolenaar9964e462007-05-05 17:54:07 +00001958 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001959 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001960" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00001961 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001962 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02001963 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001964 else
1965 " case "... ... ..."
1966 let choice = strpart(choice,1,strlen(choice)-1)
1967 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001968
Bram Moolenaar9964e462007-05-05 17:54:07 +00001969 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001970 let wholechoice = wholechoice . " " . choice
1971 let ichoice = ichoice + 1
1972 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09001973 if !exists("g:netrw_quiet")
1974 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
1975 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00001976" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001977 return
1978 endif
1979 let choice= a:{ichoice}
1980 endwhile
1981 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
1982 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001983 endif
1984 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001985
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001986" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001987 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001988
Bram Moolenaar5c736222010-01-06 20:54:52 +01001989 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00001990 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01001991 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001992" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001993 return
1994 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00001995 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001996
Bram Moolenaar8d043172014-01-23 14:24:41 +01001997 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001998" 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 +02001999 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002000" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002001 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002002" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002003 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002004 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002005
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002006 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002007 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002008 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002009 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2010 echo "(netrw) Processing your read request..."
2011 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002012
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002013 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002014 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002015 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002016" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002017 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002018 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002019 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002020 " ER: the tmpfile is full path: rcp sees C:\... as host C
2021 if s:netrw_has_nt_rcp == 1
2022 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2023 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2024 else
2025 " Any way needed it machine contains a '.'
2026 let uid_machine = g:netrw_machine .'.'. $USERNAME
2027 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002028 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002029 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2030 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2031 else
2032 let uid_machine = g:netrw_machine
2033 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002034 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002035 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 +00002036 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002037 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002038
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002039 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002040 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002041 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002042" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002043 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002044 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002045 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002046 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002047 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002048" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002049 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002050 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002051" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002052 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002053 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002054" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002055 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002056 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 +00002057 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002058 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002059 endif
2060 " 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 +00002061 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002062 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002063 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002064 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002065 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002066 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002067 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002068 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002069 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2070 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002071 q!
2072 endif
2073 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002074 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002075 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002076
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002077 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002078 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002079 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2080 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002081" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002082 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002083 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002084 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002085 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002086 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002087 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002088" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002089 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002090 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002091" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002092 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002093
Bram Moolenaar97d62492012-11-15 21:28:22 +01002094 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002095 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002096 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002097" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002098 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002099 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002100 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002101" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002102 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002103 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002104" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002105 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002106 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002107
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002108 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002109 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002110" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002111 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002112 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002113 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002114" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002115 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002116 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002117" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002118
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002119 " perform ftp:
2120 " -i : turns off interactive prompting from ftp
2121 " -n unix : DON'T use <.netrc>, even though it exists
2122 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002123 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002124 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002125 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2126 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002127" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002128 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002129 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002130 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002131 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002132 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002133 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002134 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002135
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002136 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002137 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002138 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002139" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002140 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002141 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002142 else
2143 let useport= ""
2144 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002145 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2146 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002147 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002148 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2149 else
2150 let tmpfile_get = tmpfile
2151 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002152 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 +00002153 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002154 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002155
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002156 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002157 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002158 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002159" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002160 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002161 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002162 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002163 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002164" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002165 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002166 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002167
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002168 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2169 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002170" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002171 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002172 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 +00002173 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002174 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 +00002175 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002176 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002177
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002178 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002179 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002180" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002181 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2182 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002183" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2184" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2185 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 +00002186 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002187" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002188 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002189 endif
2190 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002191" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002192 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002193
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002194 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002195 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002196 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002197" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002198
Bram Moolenaar5c736222010-01-06 20:54:52 +01002199 if !executable(g:netrw_dav_cmd)
2200 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2201" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2202 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002203 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002204 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002205 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 +01002206 else
2207 " Construct execution string (four lines) which will be passed through filter
2208 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2209 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002210 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002211 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002212 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002213 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002214 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002215 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002216 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002217 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002218 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002219 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2220 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002221
Bram Moolenaar5c736222010-01-06 20:54:52 +01002222 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002223 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002224 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002225 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002226 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002227 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002228 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002229
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002230 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002231 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002232 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002233" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002234 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 +00002235 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002236 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002237
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002238 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002239 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002240 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002241 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002242" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002243 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002244 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002245 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002246 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002247" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002248 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002249 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002250 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002251 let netrw_option= "http"
2252 else
2253 let netrw_option= "ftp"
2254 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002255" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002256
Bram Moolenaar446cb832008-06-24 21:56:24 +00002257 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002258 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 +00002259 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002260 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 +00002261 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002262
Bram Moolenaar446cb832008-06-24 21:56:24 +00002263 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002264 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002265" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002266 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002267
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002268 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002269 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002270 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002271" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2272 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 +00002273 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002274 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002275
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002276 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002277 " NetRead: (file) NetRead Method #10 {{{3
2278 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002279" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2280 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002281 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2282 let b:netrw_lastfile = choice
2283
2284 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002285 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002286 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002287 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002288 endif
2289 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002290
Bram Moolenaar5c736222010-01-06 20:54:52 +01002291 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002292 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002293" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002294 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002295 unlet b:netrw_fname
2296 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002297 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 +01002298" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002299 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002300 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002301 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002302
Bram Moolenaar9964e462007-05-05 17:54:07 +00002303" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002304endfun
2305
2306" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002307" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002308fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002309" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002310
Bram Moolenaar5c736222010-01-06 20:54:52 +01002311 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002312 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002313 call s:NetrwOptionsSave("w:")
2314 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002315
Bram Moolenaar5c736222010-01-06 20:54:52 +01002316 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002317 let tmpfile= s:GetTempfile("")
2318 if tmpfile == ""
2319" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002320 return
2321 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002322
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002323 if a:0 == 0
2324 let ichoice = 0
2325 else
2326 let ichoice = 1
2327 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002328
Bram Moolenaar9964e462007-05-05 17:54:07 +00002329 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002330" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002331 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002332 " For binary writes, always write entire file.
2333 " (line numbers don't really make sense for that).
2334 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002335" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002336 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002337 elseif g:netrw_cygwin
2338 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002339 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002340" 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 +01002341 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002342 else
2343 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002344" 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 +01002345 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002346 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002347
Bram Moolenaar9964e462007-05-05 17:54:07 +00002348 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002349 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002350 " on the temporary file's name. Deletion of the temporary file during
2351 " cleanup then causes an error message.
2352 0file!
2353 endif
2354
Bram Moolenaar5c736222010-01-06 20:54:52 +01002355 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002356 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002357
Bram Moolenaar9964e462007-05-05 17:54:07 +00002358 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002359 " attempt to repeat with previous host-file-etc
2360 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002361" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002362 let choice = b:netrw_lastfile
2363 let ichoice= ichoice + 1
2364 else
2365 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002366
Bram Moolenaar8d043172014-01-23 14:24:41 +01002367 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002368 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002369 echomsg 'NetWrite Usage:"'
2370 echomsg ':Nwrite machine:path uses rcp'
2371 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2372 echomsg ':Nwrite "machine id password path" uses ftp'
2373 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2374 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2375 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2376 echomsg ':Nwrite rcp://machine/path uses rcp'
2377 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2378 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2379 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002380 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002381 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002382
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002383 elseif match(choice,"^\"") != -1
2384 if match(choice,"\"$") != -1
2385 " case "..."
2386 let choice=strpart(choice,1,strlen(choice)-2)
2387 else
2388 " case "... ... ..."
2389 let choice = strpart(choice,1,strlen(choice)-1)
2390 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002391
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002392 while match(choice,"\"$") == -1
2393 let wholechoice= wholechoice . " " . choice
2394 let ichoice = ichoice + 1
2395 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002396 if !exists("g:netrw_quiet")
2397 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2398 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002399" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002400 return
2401 endif
2402 let choice= a:{ichoice}
2403 endwhile
2404 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2405 endif
2406 endif
2407 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002408 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002409" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002410
Bram Moolenaar9964e462007-05-05 17:54:07 +00002411 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002412 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002413 if !exists("b:netrw_method") || b:netrw_method < 0
2414" call Dfunc("netrw#NetWrite : unsupported method")
2415 return
2416 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002417
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002418 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002419 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002420 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002421 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2422 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002423" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002424 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002425
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002426 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002427 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002428 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002429" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002430 if s:netrw_has_nt_rcp == 1
2431 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2432 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2433 else
2434 let uid_machine = g:netrw_machine .'.'. $USERNAME
2435 endif
2436 else
2437 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2438 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2439 else
2440 let uid_machine = g:netrw_machine
2441 endif
2442 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002443 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 +00002444 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002445
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002446 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002447 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002448 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002449" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002450 let netrw_fname = b:netrw_fname
2451
2452 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2453 let bhkeep = &l:bh
2454 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002455 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002456 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002457
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002458" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002459 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002460 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002461" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002462 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002463 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002464" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002465 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002466 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002467" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002468 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002469 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 +00002470 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002471" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2472 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002473 endif
2474 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2475 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002476 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002477 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002478 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002479 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002480 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002481
2482 " remove enew buffer (quietly)
2483 let filtbuf= bufnr("%")
2484 exe curbuf."b!"
2485 let &l:bh = bhkeep
2486 exe filtbuf."bw!"
2487
Bram Moolenaar071d4272004-06-13 20:20:40 +00002488 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002489
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002490 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002491 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002492 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002493 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002494" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002495 let netrw_fname = b:netrw_fname
2496 let bhkeep = &l:bh
2497
2498 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2499 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002500 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002501 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002502 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002503
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002504 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002505 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002506" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002507 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002508 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002509" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002510 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002511 if exists("g:netrw_uid") && g:netrw_uid != ""
2512 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002513 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002514" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002515 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002516 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002517 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002518" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002519 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002520 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002521" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002522 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002523 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002524 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002525" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002526 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002527 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002528" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002529 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002530 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002531" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002532 " save choice/id/password for future use
2533 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002534
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002535 " perform ftp:
2536 " -i : turns off interactive prompting from ftp
2537 " -n unix : DON'T use <.netrc>, even though it exists
2538 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002539 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002540 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002541 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2542 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002543 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002544 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002545 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002546 let mod=1
2547 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002548
2549 " remove enew buffer (quietly)
2550 let filtbuf= bufnr("%")
2551 exe curbuf."b!"
2552 let &l:bh= bhkeep
2553 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002554
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002555 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002556 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002557 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002558" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002559 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002560 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002561 else
2562 let useport= ""
2563 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002564 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 +00002565 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002566
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002567 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002568 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002569 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002570" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002571 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2572 if executable(curl)
2573 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002574 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 +01002575 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002576 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002577 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002578
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002579 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002580 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002581 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002582" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002583
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002584 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002585 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2586 let bhkeep = &l:bh
2587
2588 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2589 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002590 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002591 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002592
Bram Moolenaarff034192013-04-24 18:51:19 +02002593 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002594 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002595 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002596 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002597 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002598 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002599 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002600 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002601 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002602 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002603
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002604 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002605 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002606 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002607
2608 " remove enew buffer (quietly)
2609 let filtbuf= bufnr("%")
2610 exe curbuf."b!"
2611 let &l:bh = bhkeep
2612 exe filtbuf."bw!"
2613
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002614 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002615
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002616 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002617 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002618 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002619" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002620 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 +00002621 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002622
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002623 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002624 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002625 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002626" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002627 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002628 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2629 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2630 else
2631 let uid_machine = g:netrw_machine
2632 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002633
2634 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2635 let bhkeep = &l:bh
2636 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002637 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002638 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002639
Bram Moolenaarff034192013-04-24 18:51:19 +02002640 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002641 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002642" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002643 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002644 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002645 let filtbuf= bufnr("%")
2646 exe curbuf."b!"
2647 let &l:bh = bhkeep
2648 exe filtbuf."bw!"
2649 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002650
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002651 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002652 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002653 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002654 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002655 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002656 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002657 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002658
Bram Moolenaar5c736222010-01-06 20:54:52 +01002659 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002660" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002661 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002662" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002663 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002664 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002665 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002666
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002667 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002668 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002669 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002670" 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 +02002671 elseif !exists("leavemod")
2672 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002673" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002674 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002675" 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 +00002676 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002677
Bram Moolenaar9964e462007-05-05 17:54:07 +00002678" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002679endfun
2680
2681" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002682" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002683" uses NetRead to get a copy of the file into a temporarily file,
2684" then sources that file,
2685" then removes that file.
2686fun! netrw#NetSource(...)
2687" call Dfunc("netrw#NetSource() a:0=".a:0)
2688 if a:0 > 0 && a:1 == '?'
2689 " give help
2690 echomsg 'NetSource Usage:'
2691 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2692 echomsg ':Nsource fetch://machine/path uses fetch'
2693 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002694 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002695 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2696 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2697 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2698 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2699 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002700 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002701 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002702 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002703 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002704" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002705 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002706" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002707 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002708" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002709 if delete(s:netrw_tmpfile)
2710 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2711 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002712 unlet s:netrw_tmpfile
2713 else
2714 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2715 endif
2716 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002717 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002718 endif
2719" call Dret("netrw#NetSource")
2720endfun
2721
Bram Moolenaar8d043172014-01-23 14:24:41 +01002722" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002723" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2724" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002725fun! netrw#SetTreetop(iscmd,...)
Bram Moolenaara6878372014-03-22 21:02:50 +01002726
Bram Moolenaar85850f32019-07-19 22:05:51 +02002727 " iscmd==0: netrw#SetTreetop called using gn mapping
2728 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
Bram Moolenaar8d043172014-01-23 14:24:41 +01002729 " clear out the current tree
2730 if exists("w:netrw_treetop")
2731 let inittreetop= w:netrw_treetop
2732 unlet w:netrw_treetop
2733 endif
2734 if exists("w:netrw_treedict")
2735 unlet w:netrw_treedict
2736 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002737
Bram Moolenaar85850f32019-07-19 22:05:51 +02002738 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002739 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaar8d043172014-01-23 14:24:41 +01002740 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002741 if isdirectory(s:NetrwFile(a:1))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002742 let treedir = a:1
2743 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002744 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002745 let treedir = b:netrw_curdir."/".a:1
2746 let s:netrw_treetop = treedir
Bram Moolenaar8d043172014-01-23 14:24:41 +01002747 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002748 " normally the cursor is left in the message window.
2749 " However, here this results in the directory being listed in the message window, which is not wanted.
2750 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002751 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002752 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002753 let treedir = "."
2754 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002755 endif
2756 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002757
2758 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002759 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar85850f32019-07-19 22:05:51 +02002760
2761 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002762 if islocal
Tom Benham64a536d2024-11-07 21:15:03 +01002763 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir,0))
Bram Moolenaara6878372014-03-22 21:02:50 +01002764 else
Tom Benham64a536d2024-11-07 21:15:03 +01002765 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir,0))
Bram Moolenaara6878372014-03-22 21:02:50 +01002766 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002767
Bram Moolenaar8d043172014-01-23 14:24:41 +01002768endfun
2769
Bram Moolenaar9964e462007-05-05 17:54:07 +00002770" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002771" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002772" readcmd == %r : replace buffer with newly read file
2773" == 0r : read file at top of buffer
2774" == r : read file after current line
2775" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002776fun! s:NetrwGetFile(readcmd, tfile, method)
2777" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002778
2779 " readcmd=='t': simply do nothing
2780 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002781" 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 +01002782" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002783 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002784 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002785
Bram Moolenaar9964e462007-05-05 17:54:07 +00002786 " get name of remote filename (ie. url and all)
2787 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002788" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002789
Bram Moolenaar9964e462007-05-05 17:54:07 +00002790 if exists("*NetReadFixup")
2791 " for the use of NetReadFixup (not otherwise used internally)
2792 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002793 endif
2794
Bram Moolenaar9964e462007-05-05 17:54:07 +00002795 if a:readcmd[0] == '%'
2796 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002797" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002798
2799 " rename the current buffer to the temp file (ie. tfile)
2800 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002801 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002802 else
2803 let tfile= a:tfile
2804 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002805 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002806
2807 " edit temporary file (ie. read the temporary file in)
2808 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002809" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002810 call zip#Browse(tfile)
2811 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002812" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002813 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002814 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002815" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002816 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002817 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002818" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002819 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002820 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002821" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002822 call tar#Browse(tfile)
2823 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002824" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002825 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002826 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002827" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002828 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002829 endif
2830
2831 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002832 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002833
Bram Moolenaar71badf92023-04-22 22:40:14 +01002834 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002835 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002836 " Note that isk must not include a "/" for scripts.vim
2837 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002838" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2839" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002840" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002841" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
2842 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01002843 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01002844 filetype detect
2845" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09002846 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02002847" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002848 let line1 = 1
2849 let line2 = line("$")
2850
Bram Moolenaar8d043172014-01-23 14:24:41 +01002851 elseif !&ma
2852 " 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 +01002853 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002854" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002855 return
2856
Bram Moolenaar9964e462007-05-05 17:54:07 +00002857 elseif s:FileReadable(a:tfile)
2858 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002859" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002860 let curline = line(".")
2861 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002862" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002863 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002864 let line1= curline + 1
2865 let line2= line("$") - lastline + 1
2866
2867 else
2868 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002869" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
2870" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002871 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002872" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002873 return
2874 endif
2875
2876 " User-provided (ie. optional) fix-it-up command
2877 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002878" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002879 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002880" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002881" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002882 endif
2883
Bram Moolenaaradc21822011-04-01 18:03:16 +02002884 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00002885 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002886 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00002887 endif
2888
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002889" 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 +00002890
2891 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00002892" redraw!
2893
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002894" 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 +00002895" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002896endfun
2897
Bram Moolenaar9964e462007-05-05 17:54:07 +00002898" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002899" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01002900" Input:
2901" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
2902" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002903" b:netrw_method= 1: rcp
2904" 2: ftp + <.netrc>
2905" 3: ftp + machine, id, password, and [path]filename
2906" 4: scp
2907" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002908" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002909" 7: rsync
2910" 8: fetch
2911" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002912" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01002913" g:netrw_machine= hostname
2914" b:netrw_fname = filename
2915" g:netrw_port = optional port number (for ftp)
2916" g:netrw_choice = copy of input url (choice)
2917fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002918" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002919
Bram Moolenaar251e1912011-06-19 05:09:16 +02002920 " sanity check: choice should have at least three slashes in it
2921 if strlen(substitute(a:choice,'[^/]','','g')) < 3
2922 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
2923 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02002924" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02002925 return
2926 endif
2927
Bram Moolenaar5c736222010-01-06 20:54:52 +01002928 " record current g:netrw_machine, if any
2929 " curmachine used if protocol == ftp and no .netrc
2930 if exists("g:netrw_machine")
2931 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002932" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002933 else
2934 let curmachine= "N O T A HOST"
2935 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002936 if exists("g:netrw_port")
2937 let netrw_port= g:netrw_port
2938 endif
2939
2940 " insure that netrw_ftp_cmd starts off every method determination
2941 " with the current g:netrw_ftp_cmd
2942 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01002943
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002944 " initialization
2945 let b:netrw_method = 0
2946 let g:netrw_machine = ""
2947 let b:netrw_fname = ""
2948 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002949 let g:netrw_choice = a:choice
2950
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002951 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002952 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00002953 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
2954 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002955 " rcpurm : rcp://[user@]host/filename Use rcp
2956 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002957 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02002958 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01002959 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002960 " rsyncurm : rsync://host[:port]/path Use rsync
2961 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
2962 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002963 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002964 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
2965 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02002966 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
2967 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002968 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002969 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02002970 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00002971 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002972 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02002973 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002974 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002975 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002976
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002977" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002978 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02002979 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002980 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002981" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00002982 let b:netrw_method = 1
2983 let userid = substitute(a:choice,rcpurm,'\1',"")
2984 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
2985 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002986 if userid != ""
2987 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002989
Bram Moolenaaradc21822011-04-01 18:03:16 +02002990 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002991 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002992" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002993 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00002994 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
2995 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
2996 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002997
Bram Moolenaar15146672011-10-20 22:22:38 +02002998 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002999 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003000" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003001 let b:netrw_method = 5
3002 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3003 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003004 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003005
Bram Moolenaaradc21822011-04-01 18:03:16 +02003006 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003007 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003008" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003009 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003010 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003011 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3012 else
3013 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3014 endif
3015 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003016
Bram Moolenaaradc21822011-04-01 18:03:16 +02003017 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003018 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003019" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003020 let b:netrw_method = 7
3021 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3022 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003023
Bram Moolenaaradc21822011-04-01 18:03:16 +02003024 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003025 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003026" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003027 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003028 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3029 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3030 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003031" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003032 if userid != ""
3033 let g:netrw_uid= userid
3034 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003035
Bram Moolenaaradc21822011-04-01 18:03:16 +02003036 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003037 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003038 call NetUserPass("ftp:".g:netrw_machine)
3039 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003040 " if there's a change in hostname, require password re-entry
3041 unlet s:netrw_passwd
3042 endif
3043 if exists("netrw_port")
3044 unlet netrw_port
3045 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003046 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003047
Bram Moolenaar446cb832008-06-24 21:56:24 +00003048 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003049 let b:netrw_method = 3
3050 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003051 let host= substitute(g:netrw_machine,'\..*$','','')
3052 if exists("s:netrw_hup[host]")
3053 call NetUserPass("ftp:".host)
3054
Nir Lichtman1e34b952024-05-08 19:19:34 +02003055 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003056" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3057" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003058 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003059 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003060" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003061 endif
3062 let b:netrw_method= 2
3063 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003064" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003065 let b:netrw_method= 2
3066 else
3067 if !exists("g:netrw_uid") || g:netrw_uid == ""
3068 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003069 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003070 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003071 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003072 endif
3073 let b:netrw_method= 3
3074 endif
3075 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003076
Bram Moolenaaradc21822011-04-01 18:03:16 +02003077 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003078 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003079" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003080 let b:netrw_method = 8
3081 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3082 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3083 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3084 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003085
Bram Moolenaaradc21822011-04-01 18:03:16 +02003086 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003087 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003088" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003089 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003090 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3091 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003092 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003093 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003094 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003095
Bram Moolenaaradc21822011-04-01 18:03:16 +02003096 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003097 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003098" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003099 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003100 let b:netrw_method = 3
3101 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3102 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003103
Bram Moolenaar9964e462007-05-05 17:54:07 +00003104 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003105 let b:netrw_method = 2
3106 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3107 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3108 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003109
Bram Moolenaaradc21822011-04-01 18:03:16 +02003110 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003111 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003112" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003113 let b:netrw_method = 9
3114 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3115 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003116
Bram Moolenaaradc21822011-04-01 18:03:16 +02003117 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003118 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003119" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003120 let b:netrw_method = 1
3121 let userid = substitute(a:choice,rcphf,'\2',"")
3122 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3123 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003124" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3125" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3126" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3127" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003128 if userid != ""
3129 let g:netrw_uid= userid
3130 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003131
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003132 " Method#10: file://user@hostname/...path-to-file {{{3
3133 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003134" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003135 let b:netrw_method = 10
3136 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003137" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003138
Bram Moolenaaradc21822011-04-01 18:03:16 +02003139 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003140 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003141 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003142 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003143 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003144 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003146 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003147
Bram Moolenaar81695252004-12-29 20:58:21 +00003148 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003149 " remove any leading [:#] from port number
3150 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3151 elseif exists("netrw_port")
3152 " retain port number as implicit for subsequent ftp operations
3153 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003154 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003155
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003156" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3157" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3158" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3159" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003160" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003161" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003162" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003163" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003164" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003165" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003166" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003167" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003168endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169
Bram Moolenaar9964e462007-05-05 17:54:07 +00003170" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003171" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003172" Usage: :call NetUserPass() -- will prompt for userid and password
3173" :call NetUserPass("uid") -- will prompt for password
3174" :call NetUserPass("uid","password") -- sets global userid and password
3175" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3176" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177fun! NetUserPass(...)
3178
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003179" call Dfunc("NetUserPass() a:0=".a:0)
3180
3181 if !exists('s:netrw_hup')
3182 let s:netrw_hup= {}
3183 endif
3184
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003186 " case: no input arguments
3187
3188 " change host and username if not previously entered; get new password
3189 if !exists("g:netrw_machine")
3190 let g:netrw_machine= input('Enter hostname: ')
3191 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003192 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003193 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194 let g:netrw_uid= input('Enter username: ')
3195 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003196 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003197 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003198
3199 " set up hup database
3200 let host = substitute(g:netrw_machine,'\..*$','','')
3201 if !exists('s:netrw_hup[host]')
3202 let s:netrw_hup[host]= {}
3203 endif
3204 let s:netrw_hup[host].uid = g:netrw_uid
3205 let s:netrw_hup[host].passwd = s:netrw_passwd
3206
3207 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003208 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003209
3210 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003211 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003212 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003213" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003214 let host = substitute(a:1,'^ftp:','','')
3215 let host = substitute(host,'\..*','','')
3216 if exists("s:netrw_hup[host]")
3217 let g:netrw_uid = s:netrw_hup[host].uid
3218 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003219" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3220" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003221 else
3222 let g:netrw_uid = input("Enter UserId: ")
3223 let s:netrw_passwd = inputsecret("Enter Password: ")
3224 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003225
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003226 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003227 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003228" 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 +02003229 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003230 if g:netrw_machine =~ '[0-9.]\+'
3231 let host= g:netrw_machine
3232 else
3233 let host= substitute(g:netrw_machine,'\..*$','','')
3234 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003235 else
3236 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003237 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003238 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003239" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003240 if exists("g:netrw_passwd")
3241 " ask for password if one not previously entered
3242 let s:netrw_passwd= g:netrw_passwd
3243 else
3244 let s:netrw_passwd = inputsecret("Enter Password: ")
3245 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003246 endif
3247
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003248" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003249 if exists("host")
3250 if !exists('s:netrw_hup[host]')
3251 let s:netrw_hup[host]= {}
3252 endif
3253 let s:netrw_hup[host].uid = g:netrw_uid
3254 let s:netrw_hup[host].passwd = s:netrw_passwd
3255 endif
3256
3257 elseif a:0 == 2
3258 let g:netrw_uid = a:1
3259 let s:netrw_passwd = a:2
3260
3261 elseif a:0 == 3
3262 " enter hostname, user-id, and password into the hup dictionary
3263 let host = substitute(a:1,'^\a\+:','','')
3264 let host = substitute(host,'\..*$','','')
3265 if !exists('s:netrw_hup[host]')
3266 let s:netrw_hup[host]= {}
3267 endif
3268 let s:netrw_hup[host].uid = a:2
3269 let s:netrw_hup[host].passwd = a:3
3270 let g:netrw_uid = s:netrw_hup[host].uid
3271 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003272" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3273" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003274 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003275
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003276" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003277endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003278
Bram Moolenaar85850f32019-07-19 22:05:51 +02003279" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003280" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003281" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003282
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003283" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003284" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3285fun! s:ExplorePatHls(pattern)
3286" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3287 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003288" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003289 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003290" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003291 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3292" call Dret("s:ExplorePatHls repat<".repat.">")
3293 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003294endfun
3295
3296" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003297" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003298" 0: (user: <mb>) bookmark current directory
3299" 1: (user: <gb>) change to the bookmarked directory
3300" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003301" 3: (browsing) records current directory history
3302" 4: (user: <u>) go up (previous) directory, using history
3303" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003304" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003305fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003306" 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 +02003307 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3308" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3309 return
3310 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003311
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003312 let ykeep = @@
3313 let curbufnr = bufnr("%")
3314
Bram Moolenaar9964e462007-05-05 17:54:07 +00003315 if a:chg == 0
3316 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003317" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003318 if exists("s:netrwmarkfilelist_{curbufnr}")
3319 call s:NetrwBookmark(0)
3320 echo "bookmarked marked files"
3321 else
3322 call s:MakeBookmark(a:curdir)
3323 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003324 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003325
KSR-Yasudaf4498252023-10-06 03:34:17 +09003326 try
3327 call s:NetrwBookHistSave()
3328 catch
3329 endtry
3330
Bram Moolenaar9964e462007-05-05 17:54:07 +00003331 elseif a:chg == 1
3332 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003333" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003334 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003335" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003336 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003337 else
3338 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3339 endif
3340
3341 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003342" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003343 let didwork= 0
3344 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003345" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003346 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003347" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003348 let cnt= 1
3349 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003350" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003351 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003352 let didwork = 1
3353 let cnt = cnt + 1
3354 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003355 endif
3356
3357 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003358 " Note: history is saved only when PerformListing is done;
3359 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3360 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003361 let first = 1
3362 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003363 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003364 while ( first || cnt != g:netrw_dirhistcnt )
3365" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003366 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003367" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003368 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003369 let didwork= 1
3370 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003371 let histcnt = histcnt + 1
3372 let first = 0
3373 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003374 if cnt < 0
3375 let cnt= cnt + g:netrw_dirhistmax
3376 endif
3377 endwhile
3378 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003379 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003380 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003381 if didwork
3382 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3383 endif
3384
3385 elseif a:chg == 3
3386 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003387" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003388 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 +02003389 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003390 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3391 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003392 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003393" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003394 endif
3395
3396 elseif a:chg == 4
3397 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003398" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003399 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003400 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3401 if g:netrw_dirhistcnt < 0
3402 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003403 endif
3404 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003405 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003406 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003407 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3408" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003409 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003410 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003411" call Decho("setl ma noro",'~'.expand("<slnum>"))
3412 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003413 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003414" call Decho("setl nomod",'~'.expand("<slnum>"))
3415" 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 +00003416 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003417" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3418 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003419 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003420 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003421 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003422 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003423 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003424 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003425 echo "Sorry, no predecessor directory exists yet"
3426 endif
3427
3428 elseif a:chg == 5
3429 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003430" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003431 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003432 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3433 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3434" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003435 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003436" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003437 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003438 sil! NetrwKeepj %d _
3439" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3440" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003441 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003442" 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 +02003443 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003444" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3445 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003446 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003447 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3448 if g:netrw_dirhistcnt < 0
3449 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003450 endif
3451 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003452 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003453 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003454 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003455 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003456 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003457
3458 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003459" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003460 if exists("s:netrwmarkfilelist_{curbufnr}")
3461 call s:NetrwBookmark(1)
3462 echo "removed marked files from bookmarks"
3463 else
3464 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003465 let iremove = v:count
3466 let dremove = g:netrw_bookmarklist[iremove - 1]
3467" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003468 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003469" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3470 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3471 echo "removed ".dremove." from g:netrw_bookmarklist"
3472" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003473 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003474" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003475
3476 try
3477 call s:NetrwBookHistSave()
3478 catch
3479 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003480 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003481 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003482 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003483 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003484" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003485endfun
3486
3487" ---------------------------------------------------------------------
3488" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003489" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003490" Sister function: s:NetrwBookHistSave()
3491fun! s:NetrwBookHistRead()
3492" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003493 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003494" 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 +02003495 return
3496 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003497 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003498
3499 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003500 if !exists("s:netrw_initbookhist")
3501 let home = s:NetrwHome()
3502 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003503 if filereadable(s:NetrwFile(savefile))
3504" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003505 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003506 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003507
3508 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003509 if g:netrw_dirhistmax > 0
3510 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003511 if filereadable(s:NetrwFile(savefile))
3512" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003513 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003514 endif
3515 let s:netrw_initbookhist= 1
3516 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003517 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003518 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003519
Bram Moolenaar97d62492012-11-15 21:28:22 +01003520 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003521" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3522" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003523" call Dret("s:NetrwBookHistRead")
3524endfun
3525
3526" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003527" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003528" Sister function: s:NetrwBookHistRead()
3529" I used to do this via viminfo but that appears to
3530" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003531" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3532" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003533" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003534fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003535" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003536 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003537" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003538 return
3539 endif
3540
Bram Moolenaar5c736222010-01-06 20:54:52 +01003541 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003542" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003543 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003544
3545 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003546 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003547" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003548 if g:netrw_use_noswf
3549 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3550 else
3551 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3552 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003553 setl nocin noai noci magic nospell nohid wig= noaw
3554 setl ma noro write
3555 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003556 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003557
Bram Moolenaar85850f32019-07-19 22:05:51 +02003558 " rename enew'd file: .netrwhist -- no attempt to merge
3559 " record dirhistmax and current dirhistcnt
3560 " save history
3561" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003562 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003563 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003564 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3565 if g:netrw_dirhistmax > 0
3566 let lastline = line("$")
3567 let cnt = g:netrw_dirhistcnt
3568 let first = 1
3569 while ( first || cnt != g:netrw_dirhistcnt )
3570 let lastline= lastline + 1
3571 if exists("g:netrw_dirhist_{cnt}")
3572 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3573" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3574 endif
3575 let first = 0
3576 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3577 if cnt < 0
3578 let cnt= cnt + g:netrw_dirhistmax
3579 endif
3580 endwhile
3581 exe "sil! w! ".savefile
3582" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3583 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003584
Bram Moolenaar85850f32019-07-19 22:05:51 +02003585 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003586 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003587 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003588" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003589 " merge and write .netrwbook
3590 let savefile= s:NetrwHome()."/.netrwbook"
3591
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003592 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003593 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003594 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003595 for bdm in booklist
3596 if index(g:netrw_bookmarklist,bdm) == -1
3597 call add(g:netrw_bookmarklist,bdm)
3598 endif
3599 endfor
3600 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003601 endif
3602
3603 " construct and save .netrwbook
3604 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003605 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003606" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003607 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003608
3609 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003610 let bgone= bufnr("%")
3611 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003612 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003613
3614" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003615endfun
3616
3617" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003618" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3619" list of the contents of a local or remote directory. It is assumed that the
3620" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3621" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003622" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003623fun! s:NetrwBrowse(islocal,dirname)
3624 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaara6878372014-03-22 21:02:50 +01003625
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003626 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3627 " This is useful when one edits a local file, then :e ., then :Rex
3628 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3629 let w:netrw_rexfile= bufname("#")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003630 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003631
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003632 " s:NetrwBrowse : initialize history {{{3
3633 if !exists("s:netrw_initbookhist")
3634 NetrwKeepj call s:NetrwBookHistRead()
3635 endif
3636
3637 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003638 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003639 let dirname= simplify(a:dirname)
3640 else
3641 let dirname= a:dirname
3642 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003643
Bram Moolenaar85850f32019-07-19 22:05:51 +02003644 " repoint t:netrw_lexbufnr if appropriate
3645 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02003646 let repointlexbufnr= 1
3647 endif
3648
3649 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003650 if exists("s:netrw_skipbrowse")
3651 unlet s:netrw_skipbrowse
Bram Moolenaar446cb832008-06-24 21:56:24 +00003652 return
3653 endif
3654 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003655 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003656 return
3657 endif
3658 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003659 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003660 return
3661 endif
3662
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003663 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003664 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003665
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003666 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003667 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3668 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaar85850f32019-07-19 22:05:51 +02003669 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3670 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003671 endif
3672
3673 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003674 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003675 if s:NetrwLcd(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003676 return
3677 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003678
Bram Moolenaar5c736222010-01-06 20:54:52 +01003679 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003680 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003681 if bufname(dirname) != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003682 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003683 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003684 " attempt transfer of remote regular file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003685
3686 " remove any filetype indicator from end of dirname, except for the
3687 " "this is a directory" indicator (/).
3688 " There shouldn't be one of those here, anyway.
3689 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003690 call s:RemotePathAnalysis(dirname)
3691
3692 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3693 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003694 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003695 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003696 let b:netrw_curdir = dirname
3697 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003698 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003699 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3700 sil call netrw#NetRead(2,url)
3701 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003702 if s:path =~ '.bz2'
3703 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3704 elseif s:path =~ '.gz'
3705 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3706 elseif s:path =~ '.gz'
3707 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3708 else
3709 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3710 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003711 endif
3712
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003713 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003714 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003715 call s:NetrwOptionsRestore("w:")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003716 setl ma nomod noro
Bram Moolenaar446cb832008-06-24 21:56:24 +00003717 return
3718 endif
3719
Bram Moolenaaradc21822011-04-01 18:03:16 +02003720 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003721 call s:UseBufWinVars()
3722
3723 " set up some variables {{{3
3724 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003725 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003726 let s:last_sort_by = g:netrw_sort_by
3727
3728 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003729 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003730
Bram Moolenaar97d62492012-11-15 21:28:22 +01003731 " get/set-up buffer {{{3
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003732 let svpos = winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01003733
3734 " NetrwGetBuffer might change buffers but s:rexposn_X was set for the
3735 " previous buffer
3736 let prevbufnr = bufnr('%')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003737 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Tom Benham64a536d2024-11-07 21:15:03 +01003738 if exists("s:rexposn_".prevbufnr)
3739 let s:rexposn_{bufnr('%')} = s:rexposn_{prevbufnr}
3740 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003741
Bram Moolenaar446cb832008-06-24 21:56:24 +00003742 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003743 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3744 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02003745 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3746 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003747 2match none
3748 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003749 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003750 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003751 call s:NetrwOptionsRestore("w:")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003752 setl noma nomod nowrap
Bram Moolenaar446cb832008-06-24 21:56:24 +00003753 return
3754 endif
3755
3756 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003757 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003758 if b:netrw_curdir =~ '[/\\]$'
3759 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3760 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003761 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003762 let b:netrw_curdir= b:netrw_curdir."/"
3763 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003764 if b:netrw_curdir == ''
3765 if has("amiga")
3766 " On the Amiga, the empty string connotes the current directory
3767 let b:netrw_curdir= getcwd()
3768 else
3769 " under unix, when the root directory is encountered, the result
3770 " from the preceding substitute is an empty string.
3771 let b:netrw_curdir= '/'
3772 endif
3773 endif
3774 if !a:islocal && b:netrw_curdir !~ '/$'
3775 let b:netrw_curdir= b:netrw_curdir.'/'
3776 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003777
3778 " ------------
3779 " (local only) {{{3
3780 " ------------
3781 if a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00003782 " Set up ShellCmdPost handling. Append current buffer to browselist
3783 call s:LocalFastBrowser()
3784
3785 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3786 if !g:netrw_keepdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003787 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003788 if s:NetrwLcd(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003789 return
3790 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003791 endif
3792 endif
3793
3794 " --------------------------------
3795 " remote handling: {{{3
3796 " --------------------------------
3797 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00003798
Bram Moolenaar97d62492012-11-15 21:28:22 +01003799 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003800 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003801 let dirname= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003802 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3803 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3804 if dirname !~ '/$'
3805 let dirname= dirname.'/'
3806 endif
3807 let b:netrw_curdir = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003808 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003809 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003810 endif
3811
3812 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
3813 if dirname !~ dirpat
3814 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003815 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003816 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003817 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003818 setl noma nomod nowrap
Bram Moolenaar446cb832008-06-24 21:56:24 +00003819 return
3820 endif
3821 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003822 endif " (additional remote handling)
3823
Bram Moolenaar85850f32019-07-19 22:05:51 +02003824 " -------------------------------
3825 " Perform Directory Listing: {{{3
3826 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003827 NetrwKeepj call s:NetrwMaps(a:islocal)
3828 NetrwKeepj call s:NetrwCommands(a:islocal)
3829 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003830
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003831 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003832 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003833
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003834 " If there is a rexposn: restore position with rexposn
3835 " Otherwise : set rexposn
3836 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003837 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
3838 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
3839 NetrwKeepj exe w:netrw_bannercnt
3840 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003841 else
3842 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
3843 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02003844 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01003845 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara6878372014-03-22 21:02:50 +01003846 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02003847 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003848
Bram Moolenaar85850f32019-07-19 22:05:51 +02003849 " repoint t:netrw_lexbufnr if appropriate
3850 if exists("repointlexbufnr")
3851 let t:netrw_lexbufnr= bufnr("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02003852 endif
3853
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003854 " restore position
3855 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003856 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003857 endif
3858
Bram Moolenaara6878372014-03-22 21:02:50 +01003859 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003860 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
3861 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaar446cb832008-06-24 21:56:24 +00003862 return
3863endfun
3864
3865" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003866" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
3867" may not apply correctly; ie. netrw's idea of the current directory may
3868" differ from vim's. This function insures that netrw's idea of the current
3869" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003870" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003871fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003872" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
3873" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
3874" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
3875" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
3876" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003877
3878 " clean up any leading treedepthstring
3879 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
3880 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02003881" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003882 else
3883 let fname= a:fname
3884 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003885
3886 if g:netrw_keepdir
3887 " vim's idea of the current directory possibly may differ from netrw's
3888 if !exists("b:netrw_curdir")
3889 let b:netrw_curdir= getcwd()
3890 endif
3891
Nir Lichtman1e34b952024-05-08 19:19:34 +02003892 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003893 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003894 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003895 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003896" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003897 else
3898 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003899 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003900" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003901 endif
3902
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003903 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003904 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003905 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003906" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003907 else
3908 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003909 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003910" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003911 endif
3912 else
3913 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003914 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003915" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
3916" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
3917" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003918 endif
3919
Bram Moolenaar85850f32019-07-19 22:05:51 +02003920" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003921 return ret
3922endfun
3923
3924" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003925" s:NetrwFileInfo: supports qf (query for file information) {{{2
3926fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01003927" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01003928 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00003929 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003930 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003931 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003932 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003933 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003934 let lsopt= "-lsadh --si"
3935 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02003936" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003937 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003938
3939 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003940 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003941" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003942
Bram Moolenaara6878372014-03-22 21:02:50 +01003943 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003944 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003945" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003946
3947 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003948 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003949" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003950
Bram Moolenaar446cb832008-06-24 21:56:24 +00003951 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003952" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003953 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003954" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003955 endif
3956 else
3957 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003958" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
3959 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003960 let fname= substitute(a:fname,".$","","")
3961 else
3962 let fname= a:fname
3963 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003964 let t = getftime(s:NetrwFile(fname))
3965 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003966 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003967 let sz= s:NetrwHumanReadable(sz)
3968 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003969 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
3970" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003971 endif
3972 else
3973 echo "sorry, \"qf\" not supported yet for remote files"
3974 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003975 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00003976" call Dret("s:NetrwFileInfo")
3977endfun
3978
3979" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003980" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
3981fun! s:NetrwFullPath(filename)
3982" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
3983 let filename= a:filename
3984 if filename !~ '^/'
3985 let filename= resolve(getcwd().'/'.filename)
3986 endif
3987 if filename != "/" && filename =~ '/$'
3988 let filename= substitute(filename,'/$','','')
3989 endif
3990" " call Dret("s:NetrwFullPath <".filename.">")
3991 return filename
3992endfun
3993
3994" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003995" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003996" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003997" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02003998" 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 +00003999fun! s:NetrwGetBuffer(islocal,dirname)
4000" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004001" 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 +02004002" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4003" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004004 let dirname= a:dirname
4005
4006 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004007" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004008 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004009" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004010 let s:netrwbuf= {}
4011 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004012" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4013" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4014
4015 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4016 let bufnum = -1
4017
4018 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4019 if has_key(s:netrwbuf,"NetrwTreeListing")
4020 let bufnum= s:netrwbuf["NetrwTreeListing"]
4021 else
4022 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4023 endif
4024" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4025 if !bufexists(bufnum)
Peter Aronoffbe551da2024-09-22 11:29:40 +02004026 call remove(s:netrwbuf,"NetrwTreeListing")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004027 let bufnum= -1
4028 endif
4029 elseif bufnr("NetrwTreeListing") != -1
4030 let bufnum= bufnr("NetrwTreeListing")
4031" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4032 else
4033" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4034 let bufnum= -1
4035 endif
4036
4037 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004038 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004039" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004040 if !bufexists(bufnum)
4041 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4042 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004043 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004044
Bram Moolenaar446cb832008-06-24 21:56:24 +00004045 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004046" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004047 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004048 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004049" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4050
Bram Moolenaar71badf92023-04-22 22:40:14 +01004051 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004052 " IF the buffer already has the desired name
4053 " AND it is empty
4054 let curbuf = bufname("%")
4055 if curbuf == '.'
4056 let curbuf = getcwd()
4057 endif
4058" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004059" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004060" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4061" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4062" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4063" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4064 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004065" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4066 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004067 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004068" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004069 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004070 " 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 +00004071
4072 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004073 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004074" 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 +00004075 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004076" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004077 " name the buffer
4078 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4079 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004080" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004081 let w:netrw_treebufnr = bufnr("%")
4082 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004083 if g:netrw_use_noswf
4084 setl nobl bt=nofile noswf
4085 else
4086 setl nobl bt=nofile
4087 endif
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>
4091 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004092" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004093 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004094 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004095 " enter the new buffer into the s:netrwbuf dictionary
4096 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4097" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4098" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004099 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004100" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004101
4102 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004103" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004104 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004105 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004106 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004107
4108 if &ft == "netrw"
4109" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4110 exe "sil! NetrwKeepj noswapfile b ".bufnum
4111" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004112 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004113" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4114 call s:NetrwEditBuf(bufnum)
4115" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004116 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004117" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004118 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004119 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004120 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004121
4122 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004123 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004124
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004125 if line("$") <= 1 && getline(1) == ""
4126 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004127 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004128" 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>"))
4129" 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 +01004130" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4131 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004132
Bram Moolenaar97d62492012-11-15 21:28:22 +01004133 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004134" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004135 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004136 sil NetrwKeepj %d _
4137" 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>"))
4138" 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 +01004139" 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 +00004140 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004141
Bram Moolenaar446cb832008-06-24 21:56:24 +00004142 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004143" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4144" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004145 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004146 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004147 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004148" 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>"))
4149" 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 +01004150" 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 +00004151 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004152
Bram Moolenaar446cb832008-06-24 21:56:24 +00004153 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004154" 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>"))
4155" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4156" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004157 return 1
4158 endif
4159 endif
4160
4161 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4162 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4163 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4164 " med 1 D H
4165 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004166" 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 +00004167 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004168 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004169 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004170
4171 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004172" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4173" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4174 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004175
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004176" 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>"))
4177" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4178" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004179 return 0
4180endfun
4181
4182" ---------------------------------------------------------------------
4183" s:NetrwGetcwd: get the current directory. {{{2
4184" Change backslashes to forward slashes, if any.
4185" If doesc is true, escape certain troublesome characters
4186fun! s:NetrwGetcwd(doesc)
4187" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4188 let curdir= substitute(getcwd(),'\\','/','ge')
4189 if curdir !~ '[\/]$'
4190 let curdir= curdir.'/'
4191 endif
4192 if a:doesc
4193 let curdir= fnameescape(curdir)
4194 endif
4195" call Dret("NetrwGetcwd <".curdir.">")
4196 return curdir
4197endfun
4198
4199" ---------------------------------------------------------------------
4200" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4201fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004202" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4203" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4204 let keepsol= &l:sol
4205 setl nosol
4206
Bram Moolenaar446cb832008-06-24 21:56:24 +00004207 call s:UseBufWinVars()
4208
4209 " insure that w:netrw_liststyle is set up
4210 if !exists("w:netrw_liststyle")
4211 if exists("g:netrw_liststyle")
4212 let w:netrw_liststyle= g:netrw_liststyle
4213 else
4214 let w:netrw_liststyle= s:THINLIST
4215 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004216" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004217 endif
4218
4219 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4220 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004221" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004222 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004223 let dirname= "./"
4224 let curline= getline('.')
4225
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004226 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004227 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004228 let s:netrw_skipbrowse= 1
4229 echo 'Pressing "s" also works'
4230
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004231 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004232 let s:netrw_skipbrowse= 1
4233 echo 'Press "S" to edit sorting sequence'
4234
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004235 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004236 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004237 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004238
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004239 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004240 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004241 let s:netrw_skipbrowse= 1
4242 echo 'Pressing "a" also works'
4243
4244 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004245 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004246 endif
4247
4248 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004249" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004250 NetrwKeepj norm! 0
4251 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004252
4253 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004254" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004255 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004256 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4257
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004258 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004259" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004260 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004261 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004262
4263 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004264" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004265 let dirname= getline('.')
4266
4267 if !exists("b:netrw_cpf")
4268 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004269 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 +01004270 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004271" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004272 endif
4273
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004274" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004275 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004276" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4277" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004278 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004279 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004280 else
4281 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004282 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004283 endif
Enno3146d632024-07-04 19:44:42 +02004284
4285 let dict={}
4286 " save the unnamed register and register 0-9 and a
4287 let dict.a=[getreg('a'), getregtype('a')]
4288 for i in range(0, 9)
4289 let dict[i] = [getreg(i), getregtype(i)]
4290 endfor
4291 let dict.unnamed = [getreg(''), getregtype('')]
4292
Bram Moolenaarc236c162008-07-13 17:41:49 +00004293 let eofname= filestart + b:netrw_cpf + 1
4294 if eofname <= col("$")
4295 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004296 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004297 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004298 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004299 endif
Enno3146d632024-07-04 19:44:42 +02004300
Bram Moolenaar446cb832008-06-24 21:56:24 +00004301 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004302 call s:RestoreRegister(dict)
4303
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004304" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004305 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004306" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004307 endif
4308
4309 " symlinks are indicated by a trailing "@". Remove it before further processing.
4310 let dirname= substitute(dirname,"@$","","")
4311
4312 " executables are indicated by a trailing "*". Remove it before further processing.
4313 let dirname= substitute(dirname,"\*$","","")
4314
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004315 let &l:sol= keepsol
4316
Bram Moolenaar446cb832008-06-24 21:56:24 +00004317" call Dret("s:NetrwGetWord <".dirname.">")
4318 return dirname
4319endfun
4320
4321" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004322" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4323" g:netrw_bufsettings will be used after the listing is produced.
4324" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004325fun! s:NetrwListSettings(islocal)
4326" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004327" 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 +00004328 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004329" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4330 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4331 setl bt=nofile nobl ma nonu nowrap noro nornu
4332 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004333 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004334 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004335 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004336" call Dredir("ls!","s:NetrwListSettings")
4337" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004338 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004339 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004340 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004341 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004342 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004343 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004344 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004345" 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 +00004346" call Dret("s:NetrwListSettings")
4347endfun
4348
4349" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004350" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004351" islocal=0: remote browsing
4352" =1: local browsing
4353fun! s:NetrwListStyle(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004354 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004355 let fname = s:NetrwGetWord()
4356 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004357 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004358 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00004359
Bram Moolenaar85850f32019-07-19 22:05:51 +02004360 " repoint t:netrw_lexbufnr if appropriate
4361 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02004362 let repointlexbufnr= 1
4363 endif
4364
Bram Moolenaar446cb832008-06-24 21:56:24 +00004365 if w:netrw_liststyle == s:THINLIST
4366 " use one column listing
Bram Moolenaar446cb832008-06-24 21:56:24 +00004367 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4368
4369 elseif w:netrw_liststyle == s:LONGLIST
4370 " use long list
Bram Moolenaar446cb832008-06-24 21:56:24 +00004371 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4372
4373 elseif w:netrw_liststyle == s:WIDELIST
4374 " give wide list
Bram Moolenaar446cb832008-06-24 21:56:24 +00004375 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4376
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004377 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00004378 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4379
4380 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004381 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004382 let g:netrw_liststyle = s:THINLIST
4383 let w:netrw_liststyle = g:netrw_liststyle
4384 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4385 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004386 setl ma noro
Bram Moolenaar446cb832008-06-24 21:56:24 +00004387
4388 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004389 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004390 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004391 setl nomod
Bram Moolenaar446cb832008-06-24 21:56:24 +00004392
4393 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01004394 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004395 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004396
Bram Moolenaar85850f32019-07-19 22:05:51 +02004397 " repoint t:netrw_lexbufnr if appropriate
4398 if exists("repointlexbufnr")
4399 let t:netrw_lexbufnr= bufnr("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004400 endif
4401
Bram Moolenaar13600302014-05-22 18:26:40 +02004402 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004403" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4404 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004405 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004406
Bram Moolenaar446cb832008-06-24 21:56:24 +00004407endfun
4408
4409" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004410" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4411fun! s:NetrwBannerCtrl(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004412 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004413 " toggle the banner (enable/suppress)
4414 let g:netrw_banner= !g:netrw_banner
4415
4416 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004417 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01004418 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004419
4420 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004421 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4422 let fname= s:NetrwGetWord()
4423 sil NetrwKeepj $
4424 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4425" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4426 if result <= 0 && exists("w:netrw_bannercnt")
4427 exe "NetrwKeepj ".w:netrw_bannercnt
4428 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004429 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004430 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004431" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4432endfun
4433
4434" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004435" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4436"
4437" No bang: enters files/directories into Netrw's bookmark system
4438" No argument and in netrw buffer:
4439" if there are marked files: bookmark marked files
4440" otherwise : bookmark file/directory under cursor
4441" No argument and not in netrw buffer: bookmarks current open file
4442" Has arguments: globs them individually and bookmarks them
4443"
4444" With bang: deletes files/directories from Netrw's bookmark system
4445fun! s:NetrwBookmark(del,...)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004446 if a:0 == 0
4447 if &ft == "netrw"
4448 let curbufnr = bufnr("%")
4449
4450 if exists("s:netrwmarkfilelist_{curbufnr}")
4451 " for every filename in the marked list
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004452 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004453 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004454 for fname in s:netrwmarkfilelist_{curbufnr}
4455 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4456 endfor
4457 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4458 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01004459 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004460 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004461 else
4462 let fname= s:NetrwGetWord()
4463 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4464 endif
4465
4466 else
4467 " bookmark currently open file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004468 let fname= expand("%")
4469 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4470 endif
4471
4472 else
4473 " bookmark specified files
4474 " attempts to infer if working remote or local
4475 " by deciding if the current file begins with an url
4476 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004477 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004478 let i = 1
4479 while i <= a:0
4480 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004481 if v:version > 704 || (v:version == 704 && has("patch656"))
4482 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004483 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004484 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004485 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004486 else
4487 let mbfiles= [a:{i}]
4488 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004489 for mbfile in mbfiles
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004490 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4491 endfor
4492 let i= i + 1
4493 endwhile
4494 endif
4495
4496 " update the menu
4497 call s:NetrwBookmarkMenu()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004498endfun
4499
4500" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004501" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4502" .2.[cnt] for bookmarks, and
4503" .3.[cnt] for history
4504" (see s:NetrwMenu())
4505fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004506 if !exists("s:netrw_menucnt")
4507 return
4508 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004509" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004510
4511 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004512 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004513 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004514" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004515 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4516 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004517 endif
4518 if !exists("s:netrw_initbookhist")
4519 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004520 endif
4521
4522 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004523 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004524 let cnt= 1
4525 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004526" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004527 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004528
4529 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004530 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004531
4532 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004533 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 +01004534 let cnt= cnt + 1
4535 endfor
4536
4537 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004538
4539 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004540 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004541 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004542 let first = 1
4543 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004544 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004545 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004546 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004547 if exists("g:netrw_dirhist_{cnt}")
4548 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004549" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004550 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4551 endif
4552 let first = 0
4553 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4554 if cnt < 0
4555 let cnt= cnt + g:netrw_dirhistmax
4556 endif
4557 endwhile
4558 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004559
Bram Moolenaar9964e462007-05-05 17:54:07 +00004560 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004561" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004562endfun
4563
4564" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004565" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4566" directory and a new directory name. Also, if the
4567" "new directory name" is actually a file,
4568" NetrwBrowseChgDir() edits the file.
Tom Benham64a536d2024-11-07 21:15:03 +01004569" cursor=0: newdir is relative to b:netrw_curdir
4570" =1: newdir is relative to the path to the word under the cursor in
4571" tree view
4572fun! s:NetrwBrowseChgDir(islocal,newdir,cursor,...)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004573 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004574 if !exists("b:netrw_curdir")
4575 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4576 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004577 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004578 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004579 endif
4580
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004581 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02004582 call s:SavePosn(s:netrw_posn)
4583 NetrwKeepj call s:NetrwOptionsSave("s:")
4584 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Tom Benham64a536d2024-11-07 21:15:03 +01004585
4586 let newdir = a:newdir
4587 if a:cursor && exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treetop")
4588 " dirname is the path to the word under the cursor
4589 let dirname = s:NetrwTreePath(w:netrw_treetop)
Christian Brabandt5b63b232024-11-10 20:22:34 +01004590 " newdir resolves to a directory and points to a directory in dirname
4591 " /tmp/test/folder_symlink/ -> /tmp/test/original_folder/
4592 if a:islocal && fnamemodify(dirname, ':t') == newdir && isdirectory(resolve(dirname)) && resolve(dirname) == resolve(newdir)
4593 let dirname = fnamemodify(resolve(dirname), ':p:h:h')
4594 let newdir = fnamemodify(resolve(newdir), ':t')
4595 endif
Tom Benham64a536d2024-11-07 21:15:03 +01004596 " Remove trailing "/"
4597 let dirname = substitute(dirname, "/$", "", "")
4598
4599 " If the word under the cursor is a directory (except for ../), NetrwTreePath
4600 " returns the full path, including the word under the cursor, remove it
4601 if newdir =~ "/$" && newdir != "../"
4602 let dirname = fnamemodify(dirname, ":h")
4603 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004604 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004605 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004606 endif
Tom Benham64a536d2024-11-07 21:15:03 +01004607 if has("win32")
4608 let dirname = substitute(dirname,'\\','/','ge')
4609 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004610 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004611 let dorestore = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01004612
4613 " ignore <cr>s when done in the banner
4614 if g:netrw_banner
Bram Moolenaara6878372014-03-22 21:02:50 +01004615 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004616 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +01004617 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaar13600302014-05-22 18:26:40 +02004618 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004619 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004620 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004621 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara6878372014-03-22 21:02:50 +01004622 endif
4623 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004624 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004625
Bram Moolenaar446cb832008-06-24 21:56:24 +00004626 " set up o/s-dependent directory recognition pattern
4627 if has("amiga")
4628 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004629 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004630 let dirpat= '[\/]$'
4631 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004632
4633 if dirname !~ dirpat
4634 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004635 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004636 let dirname= dirname.'/'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004637 endif
4638
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004639 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004640 " ------------------------------
4641 " NetrwBrowseChgDir: edit a file {{{3
4642 " ------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004643
Bram Moolenaar97d62492012-11-15 21:28:22 +01004644 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004645 let s:rexposn_{bufnr("%")}= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01004646
Bram Moolenaar446cb832008-06-24 21:56:24 +00004647 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004648 if dirname =~ '/$'
4649 let dirname= dirname.newdir
4650 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004651 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004652 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004653 elseif newdir =~ '^\(/\|\a:\)'
4654 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004655 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004656 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004657 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004658 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004659 if a:0 < 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004660 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004661 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004662 if !exists("s:didsplit")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004663 if type(g:netrw_browse_split) == 3
4664 " open file in server
4665 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004666 call s:NetrwServerEdit(a:islocal,dirname)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004667 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004668
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004669 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004670 " horizontally splitting the window first
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004671 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4672 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004673 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004674 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004675 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004676 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004677
Bram Moolenaar446cb832008-06-24 21:56:24 +00004678 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004679 " vertically splitting the window first
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004680 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4681 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004682 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004683 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004684 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004685 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004686
Bram Moolenaar446cb832008-06-24 21:56:24 +00004687 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004688 " open file in new tab
Bram Moolenaarff034192013-04-24 18:51:19 +02004689 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004690 if !exists("b:netrw_curdir")
4691 let b:netrw_curdir= getcwd()
4692 endif
4693 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004694
Bram Moolenaar446cb832008-06-24 21:56:24 +00004695 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004696 " act like "P" (ie. open previous window)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004697 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004698 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004699 return
4700 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004701 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004702
Bram Moolenaar9964e462007-05-05 17:54:07 +00004703 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004704 " handling a file, didn't split, so remove menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00004705 call s:NetrwMenu(0)
4706 " optional change to window
4707 if g:netrw_chgwin >= 1
Bram Moolenaar13600302014-05-22 18:26:40 +02004708 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004709 " if g:netrw_chgwin is set to one more than the last window, then
4710 " vertically split the last window to make that window available.
4711 let curwin= winnr()
4712 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4713 vs
4714 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004715 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004716 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004717 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004718 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004719 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004720
Bram Moolenaar9964e462007-05-05 17:54:07 +00004721 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004722
Bram Moolenaar446cb832008-06-24 21:56:24 +00004723 " the point where netrw actually edits the (local) file
4724 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004725 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004726 if !&mod
4727 " if e the new file would fail due to &mod, then don't change any of the flags
4728 let dolockout= 1
4729 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004730 if a:islocal
Bram Moolenaar8d043172014-01-23 14:24:41 +01004731 " some like c-^ to return to the last edited file
4732 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004733 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4734 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01004735 call s:NetrwEditFile("e","",dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004736 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02004737 if &hidden || &bufhidden == "hide"
4738 " file came from vim's hidden storage. Don't "restore" options with it.
4739 let dorestore= 0
4740 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004741 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00004742 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004743
4744 " handle g:Netrw_funcref -- call external-to-netrw functions
4745 " This code will handle g:Netrw_funcref as an individual function reference
4746 " or as a list of function references. It will ignore anything that's not
4747 " a function reference. See :help Funcref for information about function references.
4748 if exists("g:Netrw_funcref")
4749 if type(g:Netrw_funcref) == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004750 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004751 elseif type(g:Netrw_funcref) == 3
4752 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004753 if type(Fncref) == 2
4754 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004755 endif
4756 endfor
4757 endif
4758 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004759 endif
4760
4761 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004762 " ----------------------------------------------------
4763 " NetrwBrowseChgDir: just go to the new directory spec {{{3
4764 " ----------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004765 let dirname = newdir
4766 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004767 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004768 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004769
4770 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004771 " ---------------------------------------------
4772 " NetrwBrowseChgDir: refresh the directory list {{{3
4773 " ---------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004774 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004775 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004776
4777 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004778 " --------------------------------------
4779 " NetrwBrowseChgDir: go up one directory {{{3
4780 " --------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004781
4782 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
4783 " force a refresh
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004784 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004785 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004786 endif
4787
4788 if has("amiga")
4789 " amiga
Bram Moolenaar446cb832008-06-24 21:56:24 +00004790 if a:islocal
4791 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
4792 let dirname= substitute(dirname,'/$','','')
4793 else
4794 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
4795 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004796
Nir Lichtman1e34b952024-05-08 19:19:34 +02004797 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004798 " windows
4799 if a:islocal
4800 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4801 if dirname == ""
4802 let dirname= '/'
4803 endif
4804 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004805 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01004806 endif
4807 if dirname =~ '^\a:$'
4808 let dirname= dirname.'/'
4809 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01004810
Bram Moolenaar446cb832008-06-24 21:56:24 +00004811 else
4812 " unix or cygwin
Bram Moolenaar446cb832008-06-24 21:56:24 +00004813 if a:islocal
4814 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4815 if dirname == ""
4816 let dirname= '/'
4817 endif
4818 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004819 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004820 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004821 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004822 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004823 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004824
4825 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004826 " --------------------------------------
4827 " NetrwBrowseChgDir: Handle Tree Listing {{{3
4828 " --------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004829 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004830 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004831 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004832 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004833 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004834 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004835 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004836 let haskey = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004837
4838 " search treedict for tree dir as-is
4839 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004840 let haskey= 1
4841 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004842 endif
4843
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004844 " search treedict for treedir with a [/@] appended
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004845 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004846 if has_key(w:netrw_treedict,treedir."/")
4847 let treedir= treedir."/"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004848 let haskey = 1
4849 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004850 endif
4851 endif
4852
4853 " search treedict for treedir with any trailing / elided
4854 if !haskey && treedir =~ '/$'
4855 let treedir= substitute(treedir,'/$','','')
4856 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004857 let haskey = 1
4858 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004859 endif
4860 endif
4861
4862 if haskey
4863 " close tree listing for selected subdirectory
Bram Moolenaar446cb832008-06-24 21:56:24 +00004864 call remove(w:netrw_treedict,treedir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004865 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00004866 else
4867 " go down one directory
4868 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004869 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004870 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004871 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004872
4873 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01004874 " ----------------------------------------
4875 " NetrwBrowseChgDir: Go down one directory {{{3
4876 " ----------------------------------------
4877 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004878 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004879 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00004880 endif
4881
Bram Moolenaar97d62492012-11-15 21:28:22 +01004882 " --------------------------------------
4883 " NetrwBrowseChgDir: Restore and Cleanup {{{3
4884 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02004885 if dorestore
4886 " dorestore is zero'd when a local file was hidden or bufhidden;
4887 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004888 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02004889 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02004890 if dolockout && dorestore
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004891 if filewritable(dirname)
Bram Moolenaar13600302014-05-22 18:26:40 +02004892 setl ma noro nomod
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004893 else
Bram Moolenaar13600302014-05-22 18:26:40 +02004894 setl ma ro nomod
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004895 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004896 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004897 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004898 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004899
Bram Moolenaar446cb832008-06-24 21:56:24 +00004900 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00004901endfun
4902
4903" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004904" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
4905" for thin, long, and wide: cursor placed just after banner
4906" for tree, keeps cursor on current filename
4907fun! s:NetrwBrowseUpDir(islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004908 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
4909 " this test needed because occasionally this function seems to be incorrectly called
4910 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004911 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004912 " directories.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004913 return
4914 endif
4915
Bram Moolenaara6878372014-03-22 21:02:50 +01004916 norm! 0
4917 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara6878372014-03-22 21:02:50 +01004918 let curline= getline(".")
4919 let swwline= winline() - 1
4920 if exists("w:netrw_treetop")
4921 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02004922 elseif exists("b:netrw_curdir")
4923 let w:netrw_treetop= b:netrw_curdir
4924 else
4925 let w:netrw_treetop= getcwd()
4926 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01004927 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004928 let curfile = getline(".")
4929 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01004930 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01004931 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004932 else
Tom Benham64a536d2024-11-07 21:15:03 +01004933 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004934 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004935 if w:netrw_treetop == '/'
4936 keepj call search('^\M'.curfile,"w")
4937 elseif curfile == '../'
4938 keepj call search('^\M'.curfile,"wb")
4939 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004940 while 1
4941 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
4942 let treepath= s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004943 if treepath == curpath
4944 break
4945 endif
4946 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01004947 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004948
Bram Moolenaara6878372014-03-22 21:02:50 +01004949 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004950 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004951 if exists("b:netrw_curdir")
4952 let curdir= b:netrw_curdir
4953 else
4954 let curdir= expand(getcwd())
4955 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004956 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01004957 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004958 else
Tom Benham64a536d2024-11-07 21:15:03 +01004959 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004960 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004961 call s:RestorePosn(s:netrw_posn)
4962 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01004963 let curdir= '\<'. escape(curdir, '~'). '/'
4964 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01004965 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004966endfun
4967
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01004968func s:redir()
4969 " set up redirection (avoids browser messages)
4970 " by default if not set, g:netrw_suppress_gx_mesg is true
4971 if get(g:, 'netrw_suppress_gx_mesg', 1)
4972 if &srr =~# "%s"
4973 return printf(&srr, has("win32") ? "nul" : "/dev/null")
4974 else
4975 return &srr .. (has("win32") ? "nul" : "/dev/null")
4976 endif
4977 endif
4978 return ''
4979endfunc
4980
4981if has('unix')
4982 if has('win32unix')
4983 " Cygwin provides cygstart
4984 if executable('cygstart')
4985 fun! netrw#Launch(args)
4986 exe 'silent ! cygstart --hide' a:args s:redir() | redraw!
4987 endfun
4988 elseif !empty($MSYSTEM) && executable('start')
4989 " MSYS2/Git Bash comes by default without cygstart; see
4990 " https://www.msys2.org/wiki/How-does-MSYS2-differ-from-Cygwin
4991 " Instead it provides /usr/bin/start script running `cmd.exe //c start`
4992 " Adding "" //b` sets void title, hides cmd window and blocks path conversion
4993 " of /b to \b\ " by MSYS2; see https://www.msys2.org/docs/filesystem-paths/
4994 fun! netrw#Launch(args)
4995 exe 'silent !start "" //b' a:args s:redir() | redraw!
4996 endfun
4997 else
4998 " imitate /usr/bin/start script for other environments and hope for the best
4999 fun! netrw#Launch(args)
5000 exe 'silent !cmd //c start "" //b' a:args s:redir() | redraw!
5001 endfun
5002 endif
5003 elseif exists('$WSL_DISTRO_NAME') " use cmd.exe to start GUI apps in WSL
5004 fun! netrw#Launch(args)
5005 let args = a:args
5006 exe 'silent !' ..
5007 \ ((args =~? '\v<\f+\.(exe|com|bat|cmd)>') ?
Konfekt460799d2024-11-14 21:42:27 +01005008 \ 'cmd.exe /c start /b ' .. args :
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005009 \ 'nohup ' .. args .. ' ' .. s:redir() .. ' &')
5010 \ | redraw!
5011 endfun
5012 else
5013 fun! netrw#Launch(args)
5014 exe ':silent ! nohup' a:args s:redir() '&' | redraw!
5015 endfun
5016 endif
5017elseif has('win32')
5018 fun! netrw#Launch(args)
5019 exe 'silent !' .. (&shell =~? '\<cmd\.exe\>' ? '' : 'cmd.exe /c')
5020 \ 'start "" /b' a:args s:redir() | redraw!
5021 endfun
5022else
5023 fun! netrw#Launch(dummy)
5024 echom 'No common launcher found'
5025 endfun
5026endif
5027
5028" Git Bash
5029if has('win32unix')
5030 " (cyg)start suffices
5031 let s:os_viewer = ''
5032" Windows / WSL
5033elseif executable('explorer.exe')
5034 let s:os_viewer = 'explorer.exe'
5035" Linux / BSD
5036elseif executable('xdg-open')
5037 let s:os_viewer = 'xdg-open'
5038" MacOS
5039elseif executable('open')
5040 let s:os_viewer = 'open'
5041endif
5042
5043fun! s:viewer()
5044 if exists('g:netrw_browsex_viewer') && executable(g:netrw_browsex_viewer)
5045 " extract any viewing options. Assumes that they're set apart by spaces.
5046 " call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
5047 if g:netrw_browsex_viewer =~ '\s'
5048 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5049 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5050 let oviewer = ''
5051 let cnt = 1
5052 while !executable(viewer) && viewer != oviewer
5053 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5054 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5055 let cnt = cnt + 1
5056 let oviewer = viewer
5057 " call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
5058 endwhile
5059 else
5060 let viewer = g:netrw_browsex_viewer
5061 let viewopt = ""
5062 endif
5063 " call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
5064 return viewer .. ' ' .. viewopt
5065 else
5066 if !exists('s:os_viewer')
5067 call netrw#ErrorMsg(s:ERROR,"No program to open this path found. See :help Open for more information.",106)
5068 else
5069 return s:os_viewer
5070 endif
5071 endif
5072endfun
5073
5074fun! netrw#Open(file) abort
5075 call netrw#Launch(s:viewer() .. ' ' .. shellescape(a:file, 1))
5076endf
5077
5078if !exists('g:netrw_regex_url')
5079 let g:netrw_regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}'
5080endif
5081
Bram Moolenaara6878372014-03-22 21:02:50 +01005082" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005083" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005084" given filename; typically this means given their extension.
5085" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005086fun! netrw#BrowseX(fname,remote)
Konfekt460799d2024-11-14 21:42:27 +01005087 if a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
Bram Moolenaar91359012019-11-30 17:57:03 +01005088 " remote directory, not a webpage access, looks like an attempt to do a directory listing
Bram Moolenaar91359012019-11-30 17:57:03 +01005089 norm! gf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005090 endif
5091
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005092 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5093 let remote = a:remote
5094 else
5095 let remote = 0
5096 endif
5097
Bram Moolenaar97d62492012-11-15 21:28:22 +01005098 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005099 let screenposn = winsaveview()
Bram Moolenaar97d62492012-11-15 21:28:22 +01005100
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005101 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5102 let awkeep = &aw
5103 set noaw
5104
Bram Moolenaar5c736222010-01-06 20:54:52 +01005105 " special core dump handler
5106 if a:fname =~ '/core\(\.\d\+\)\=$'
5107 if exists("g:Netrw_corehandler")
5108 if type(g:Netrw_corehandler) == 2
5109 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005110 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005111 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005112 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005113 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005114 if type(Fncref) == 2
5115 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005116 endif
5117 endfor
5118 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005119 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005120 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005121 let &aw= awkeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005122 return
5123 endif
5124 endif
5125
Bram Moolenaar446cb832008-06-24 21:56:24 +00005126 " set up the filename
5127 " (lower case the extension, make a local copy of a remote file)
5128 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005129 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005130 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005131 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005132 if exten =~ "[\\/]"
5133 let exten= ""
5134 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005135
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005136 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005137 " create a local copy
Bram Moolenaarff034192013-04-24 18:51:19 +02005138 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005139 call netrw#NetRead(3,a:fname)
5140 " attempt to rename tempfile
5141 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005142 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02005143 if s:netrw_tmpfile != newname && newname != ""
5144 if rename(s:netrw_tmpfile,newname) == 0
5145 " renaming succeeded
Bram Moolenaar85850f32019-07-19 22:05:51 +02005146 let fname= newname
5147 else
5148 " renaming failed
Bram Moolenaar85850f32019-07-19 22:05:51 +02005149 let fname= s:netrw_tmpfile
5150 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005151 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005152 let fname= s:netrw_tmpfile
5153 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005154 else
5155 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005156 " special ~ handler for local
5157 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005158 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005159 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005160 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005161
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005162 " although shellescape(..., 1) is used in netrw#Open(), it's insufficient
5163 call netrw#Open(escape(fname, '#%'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005164
Bram Moolenaar446cb832008-06-24 21:56:24 +00005165 " cleanup: remove temporary file,
5166 " delete current buffer if success with handler,
5167 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005168 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005169 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005170" if remote == 1 && fname != a:fname
Bram Moolenaarc236c162008-07-13 17:41:49 +00005171" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005172" endif
5173
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005174 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005175 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005176 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005177 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005178 endif
Christian Brabandt9f320692024-10-30 18:36:20 +01005179 exe "sil! NetrwKeepj norm! \<c-o>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005180 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005181 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005182 let @@ = ykeep
5183 let &aw= awkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005184endfun
5185
5186" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005187" netrw#GX: gets word under cursor for gx support {{{2
5188" See also: netrw#BrowseXVis
5189" netrw#BrowseX
5190fun! netrw#GX()
5191" call Dfunc("netrw#GX()")
5192 if &ft == "netrw"
5193 let fname= s:NetrwGetWord()
5194 else
Konfekt3d7e5672024-10-27 22:16:49 +01005195 let fname= exists("g:netrw_gx")? expand(g:netrw_gx) : s:GetURL()
Bram Moolenaar85850f32019-07-19 22:05:51 +02005196 endif
5197" call Dret("netrw#GX <".fname.">")
5198 return fname
5199endfun
5200
Konfekt3d7e5672024-10-27 22:16:49 +01005201fun! s:GetURL() abort
5202 let URL = ''
5203 if exists('*Netrw_get_URL_' .. &filetype)
5204 let URL = call('Netrw_get_URL_' .. &filetype, [])
5205 endif
5206 if !empty(URL) | return URL | endif
5207 " URLs end in letter, digit or forward slash
5208 let URL = matchstr(expand("<cWORD>"), '\<' .. g:netrw_regex_url .. '\ze[^A-Za-z0-9/]*$')
5209 if !empty(URL) | return URL | endif
5210
5211 " Is it a file in the current work dir ...
5212 let file = expand("<cfile>")
5213 if filereadable(file) | return file | endif
5214 " ... or in that of the current buffer?
5215 let path = fnamemodify(expand('%'), ':p')
5216 if isdirectory(path)
5217 let dir = path
5218 elseif filereadable(path)
5219 let dir = fnamemodify(path, ':h')
5220 endif
5221 if exists('dir') && filereadable(dir..'/'..file) | return dir..'/'..file | endif
5222
5223 return ''
5224endf
5225
Bram Moolenaar85850f32019-07-19 22:05:51 +02005226" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005227" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5228fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005229 let dict={}
5230 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005231 norm! gv"ay
5232 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005233 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005234 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005235endfun
5236
5237" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005238" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5239" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5240" to become an unlisted buffer, so in that case don't bwipe it.
5241fun! s:NetrwBufRename(newname)
5242" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5243" call Dredir("ls!","s:NetrwBufRename (before rename)")
5244 let oldbufname= bufname(bufnr("%"))
5245" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5246
5247 if oldbufname != a:newname
5248" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5249 let b:junk= 1
5250" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5251 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005252" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005253 let oldbufnr= bufnr(oldbufname)
5254" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5255" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5256 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5257" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5258 exe "bwipe! ".oldbufnr
5259" else " Decho
5260" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005261" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5262" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5263" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005264 endif
5265" call Dredir("ls!","s:NetrwBufRename (after rename)")
5266" else " Decho
5267" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5268 endif
5269
5270" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5271endfun
5272
5273" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005274" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005275fun! netrw#CheckIfRemote(...)
5276" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5277 if a:0 > 0
5278 let curfile= a:1
5279 else
5280 let curfile= expand("%")
5281 endif
5282" call Decho("curfile<".curfile.">")
5283 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005284" call Dret("netrw#CheckIfRemote 1")
5285 return 1
5286 else
5287" call Dret("netrw#CheckIfRemote 0")
5288 return 0
5289 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005290endfun
5291
5292" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005293" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5294fun! s:NetrwChgPerm(islocal,curdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005295 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005296 call inputsave()
5297 let newperm= input("Enter new permission: ")
5298 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005299 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5300 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005301 call system(chgperm)
5302 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005303 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005304 endif
5305 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01005306 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005307 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005308 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005309endfun
5310
5311" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005312" s:CheckIfKde: checks if kdeinit is running {{{2
5313" Returns 0: kdeinit not running
5314" 1: kdeinit is running
5315fun! s:CheckIfKde()
5316" call Dfunc("s:CheckIfKde()")
5317 " seems kde systems often have gnome-open due to dependencies, even though
5318 " gnome-open's subsidiary display tools are largely absent. Kde systems
5319 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5320 if !exists("s:haskdeinit")
5321 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005322 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005323 if v:shell_error
5324 let s:haskdeinit = 0
5325 endif
5326 else
5327 let s:haskdeinit= 0
5328 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005329" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005330 endif
5331
5332" call Dret("s:CheckIfKde ".s:haskdeinit)
5333 return s:haskdeinit
5334endfun
5335
5336" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005337" s:NetrwClearExplore: clear explore variables (if any) {{{2
5338fun! s:NetrwClearExplore()
5339" call Dfunc("s:NetrwClearExplore()")
5340 2match none
5341 if exists("s:explore_match") |unlet s:explore_match |endif
5342 if exists("s:explore_indx") |unlet s:explore_indx |endif
5343 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5344 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5345 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5346 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5347 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5348 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5349 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5350" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005351" call Dret("s:NetrwClearExplore")
5352endfun
5353
5354" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005355" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5356fun! s:NetrwEditBuf(bufnum)
5357" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5358 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5359" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5360 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5361 else
5362" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005363 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005364 endif
5365" call Dret("s:NetrwEditBuf")
5366endfun
5367
5368" ---------------------------------------------------------------------
5369" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5370" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5371fun! s:NetrwEditFile(cmd,opt,fname)
5372" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5373 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5374" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5375 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5376 else
5377" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005378 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5379 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5380 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005381 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5382 endif
5383" call Dret("s:NetrwEditFile")
5384endfun
5385
5386" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005387" s:NetrwExploreListUniq: {{{2
5388fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005389 " this assumes that the list is already sorted
5390 let newexplist= []
5391 for member in a:explist
5392 if !exists("uniqmember") || member != uniqmember
5393 let uniqmember = member
5394 let newexplist = newexplist + [ member ]
5395 endif
5396 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01005397 return newexplist
5398endfun
5399
5400" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005401" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5402fun! s:NetrwForceChgDir(islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005403 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005404 if a:newdir !~ '/$'
5405 " ok, looks like force is needed to get directory-style treatment
5406 if a:newdir =~ '@$'
5407 let newdir= substitute(a:newdir,'@$','/','')
5408 elseif a:newdir =~ '[*=|\\]$'
5409 let newdir= substitute(a:newdir,'.$','/','')
5410 else
5411 let newdir= a:newdir.'/'
5412 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005413 else
5414 " should already be getting treatment as a directory
5415 let newdir= a:newdir
5416 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005417 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir,0)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005418 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005419 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005420endfun
5421
5422" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005423" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005424" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5425" expr : this is the expression to follow the directory. Will use s:ComposePath()
5426" pare =1: remove the current directory from the resulting glob() filelist
5427" =0: leave the current directory in the resulting glob() filelist
5428fun! s:NetrwGlob(direntry,expr,pare)
5429" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005430 if netrw#CheckIfRemote()
5431 keepalt 1sp
5432 keepalt enew
5433 let keep_liststyle = w:netrw_liststyle
5434 let w:netrw_liststyle = s:THINLIST
5435 if s:NetrwRemoteListing() == 0
5436 keepj keepalt %s@/@@
5437 let filelist= getline(1,$)
5438 q!
5439 else
5440 " remote listing error -- leave treedict unchanged
5441 let filelist= w:netrw_treedict[a:direntry]
5442 endif
5443 let w:netrw_liststyle= keep_liststyle
5444 else
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005445 let path= s:ComposePath(fnameescape(a:direntry), a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005446 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005447 " escape [ so it is not detected as wildcard character, see :h wildcard
5448 let path= substitute(path, '[', '[[]', 'g')
5449 endif
5450 if v:version > 704 || (v:version == 704 && has("patch656"))
5451 let filelist= glob(path,0,1,1)
5452 else
5453 let filelist= glob(path,0,1)
5454 endif
5455 if a:pare
5456 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5457 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005458 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005459 return filelist
5460endfun
5461
5462" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005463" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5464fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005465 if a:newfile =~ '[/@*=|\\]$'
5466 let newfile= substitute(a:newfile,'.$','','')
5467 else
5468 let newfile= a:newfile
5469 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005470 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01005471 call s:NetrwBrowseChgDir(a:islocal,newfile,0)
Bram Moolenaarff034192013-04-24 18:51:19 +02005472 else
Tom Benham64a536d2024-11-07 21:15:03 +01005473 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile,0))
Bram Moolenaarff034192013-04-24 18:51:19 +02005474 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005475endfun
5476
5477" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005478" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5479" and switches the hiding mode. The actual hiding is done by
5480" s:NetrwListHide().
5481" g:netrw_hide= 0: show all
5482" 1: show not-hidden files
5483" 2: show hidden files only
5484fun! s:NetrwHide(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005485 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005486 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005487
5488 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005489
5490 " hide the files in the markfile list
5491 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00005492 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5493 " remove fname from hiding list
5494 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5495 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5496 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005497 else
5498 " append fname to hiding list
5499 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5500 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5501 else
5502 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5503 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005504 endif
5505 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005506 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005507 let g:netrw_hide= 1
5508
5509 else
5510
5511 " switch between show-all/show-not-hidden/show-hidden
5512 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005513 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005514 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005515 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005516 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005517 return
5518 endif
5519 endif
5520
Tom Benham64a536d2024-11-07 21:15:03 +01005521 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005522 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005523 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005524endfun
5525
5526" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005527" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5528fun! s:NetrwHideEdit(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005529 let ykeep= @@
5530 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005531 let svpos= winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005532
5533 " get new hiding list from user
5534 call inputsave()
5535 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5536 call inputrestore()
5537 let g:netrw_list_hide= newhide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005538
5539 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01005540 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./",0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005541
5542 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005543 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005544 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005545endfun
5546
5547" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005548" s:NetrwHidden: invoked by "gh" {{{2
5549fun! s:NetrwHidden(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005550 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005551 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005552 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005553
5554 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005555 " remove .file pattern from hiding list
Bram Moolenaar446cb832008-06-24 21:56:24 +00005556 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005557 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005558 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5559 else
5560 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5561 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005562 if g:netrw_list_hide =~ '^,'
5563 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5564 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005565
5566 " refresh screen and return to saved position
Tom Benham64a536d2024-11-07 21:15:03 +01005567 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005568 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005569 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005570endfun
5571
5572" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005573" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5574fun! s:NetrwHome()
5575 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005576 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005577 else
5578 " go to vim plugin home
5579 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005580 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005581 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005582 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005583 let home= basehome."/.vim"
5584 break
5585 endif
5586 endfor
5587 if home == ""
5588 " just pick the first directory
5589 let home= substitute(&rtp,',.*$','','')
5590 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005591 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005592 let home= substitute(home,'/','\\','g')
5593 endif
5594 endif
5595 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005596 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005597" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005598 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005599" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005600 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005601 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005602" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005603 call mkdir(home)
5604 endif
5605 endif
5606 let g:netrw_home= home
5607 return home
5608endfun
5609
5610" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005611" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5612fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005613 if exists("s:netrwdrag")
5614 return
5615 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005616 if &ft != "netrw"
5617 return
5618 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005619
Bram Moolenaar97d62492012-11-15 21:28:22 +01005620 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005621 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005622 while getchar(0) != 0
5623 "clear the input stream
5624 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005625 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005626 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005627 let mouse_lnum = v:mouse_lnum
5628 let wlastline = line('w$')
5629 let lastline = line('$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005630 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5631 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005632 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005633 return
5634 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005635 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005636 " 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 +01005637 " without this test when its disabled.
5638 " 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 +01005639 if v:mouse_col > virtcol('.')
5640 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005641 return
5642 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005643
Bram Moolenaar446cb832008-06-24 21:56:24 +00005644 if a:islocal
5645 if exists("b:netrw_curdir")
Tom Benham64a536d2024-11-07 21:15:03 +01005646 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005647 endif
5648 else
5649 if exists("b:netrw_curdir")
Tom Benham64a536d2024-11-07 21:15:03 +01005650 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005651 endif
5652 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005653 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005654endfun
5655
5656" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005657" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
5658fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005659 if &ft != "netrw"
5660 return
5661 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005662 call s:NetrwMarkFileTgt(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005663endfun
5664
5665" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005666" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
5667" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02005668" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005669" a:islocal=2 : <c-r> used, remote
5670" a:islocal=3 : <c-r> used, local
5671fun! s:NetrwServerEdit(islocal,fname)
5672" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
5673 let islocal = a:islocal%2 " =0: remote =1: local
5674 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
5675
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005676 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005677 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005678 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005679 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005680 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005681 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5682 unlet s:netrw_browse_split_{winnr()}
5683 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005684 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname,0))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005685 return
5686 endif
5687
5688 if has("clientserver") && executable("gvim")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005689
5690 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005691 let srvrname = g:netrw_browse_split[0]
5692 let tabnum = g:netrw_browse_split[1]
5693 let winnum = g:netrw_browse_split[2]
5694
5695 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005696 if !ctrlr
5697 " user must have closed the server window and the user did not use <c-r>, but
5698 " used something like <cr>.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005699 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09005700 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005701 endif
5702 let g:netrw_browse_split= 0
5703 if exists("s:netrw_browse_split_".winnr())
5704 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5705 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005706 call s:NetrwBrowseChgDir(islocal,a:fname,0)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005707 return
5708
5709 elseif has("win32") && executable("start")
5710 " start up remote netrw server under windows
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005711 call system("start gvim --servername ".srvrname)
5712
5713 else
5714 " start up remote netrw server under linux
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005715 call system("gvim --servername ".srvrname)
5716 endif
5717 endif
5718
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005719 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
5720 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005721 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005722 else
5723
5724 if serverlist() !~ '\<'.g:netrw_servername.'\>'
5725
5726 if !ctrlr
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005727 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09005728 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005729 endif
5730 let g:netrw_browse_split= 0
Tom Benham64a536d2024-11-07 21:15:03 +01005731 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname,0))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005732 return
5733
5734 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005735 if has("win32") && executable("start")
5736 " start up remote netrw server under windows
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005737 call system("start gvim --servername ".g:netrw_servername)
5738 else
5739 " start up remote netrw server under linux
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005740 call system("gvim --servername ".g:netrw_servername)
5741 endif
5742 endif
5743 endif
5744
5745 while 1
5746 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005747 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005748 break
5749 catch /^Vim\%((\a\+)\)\=:E241/
5750 sleep 200m
5751 endtry
5752 endwhile
5753
5754 if exists("g:netrw_browse_split")
5755 if type(g:netrw_browse_split) != 3
5756 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
5757 endif
5758 unlet g:netrw_browse_split
5759 endif
5760 let g:netrw_browse_split= [g:netrw_servername,1,1]
5761 endif
5762
5763 else
5764 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
5765 endif
5766
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005767endfun
5768
5769" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005770" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
5771fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005772 if &ft != "netrw"
5773 return
5774 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005775" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005776
Bram Moolenaar8d043172014-01-23 14:24:41 +01005777 let s:ngw= s:NetrwGetWord()
5778 call s:NetrwMarkFile(a:islocal,s:ngw)
5779
5780" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02005781endfun
5782
5783" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005784" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
5785" Used to mark multiple files.
5786fun! s:NetrwSLeftdrag(islocal)
5787" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
5788 if !exists("s:netrwdrag")
5789 let s:netrwdrag = winnr()
5790 if a:islocal
5791 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005792 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01005793 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005794 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005795 endif
5796 let ngw = s:NetrwGetWord()
5797 if !exists("s:ngw") || s:ngw != ngw
5798 call s:NetrwMarkFile(a:islocal,ngw)
5799 endif
5800 let s:ngw= ngw
5801" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5802endfun
5803
5804" ---------------------------------------------------------------------
5805" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
5806fun! s:NetrwSLeftrelease(islocal)
5807" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5808 if exists("s:netrwdrag")
5809 nunmap <s-leftrelease>
5810 let ngw = s:NetrwGetWord()
5811 if !exists("s:ngw") || s:ngw != ngw
5812 call s:NetrwMarkFile(a:islocal,ngw)
5813 endif
5814 if exists("s:ngw")
5815 unlet s:ngw
5816 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005817 unlet s:netrwdrag
5818 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005819" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02005820endfun
5821
5822" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01005823" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
5824" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00005825fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005826" 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 +02005827" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005828 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005829
5830 " 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 +02005831 " How-it-works: take the hiding command, convert it into a range.
5832 " Duplicate characters don't matter.
5833 " Remove all such characters from the '/~@#...890' string.
5834 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005835" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005836 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01005837 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005838" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005839
5840 while listhide != ""
5841 if listhide =~ ','
5842 let hide = substitute(listhide,',.*$','','e')
5843 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
5844 else
5845 let hide = listhide
5846 let listhide = ""
5847 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005848" 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 +01005849 if g:netrw_sort_by =~ '^[ts]'
5850 if hide =~ '^\^'
5851" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
5852 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
5853 elseif hide =~ '^\\(\^'
5854 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
5855 endif
5856" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
5857 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005858
5859 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005860" 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 +00005861 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005862" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005863 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005864 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005865" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005866 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005867 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005868" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005869 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02005870
Bram Moolenaar446cb832008-06-24 21:56:24 +00005871 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005872 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005873" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005874 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005875" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005876 endif
5877
Bram Moolenaaradc21822011-04-01 18:03:16 +02005878 " remove any blank lines that have somehow remained.
5879 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005880 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02005881
Bram Moolenaar97d62492012-11-15 21:28:22 +01005882 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005883" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005884endfun
5885
5886" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005887" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005888" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005889fun! s:NetrwMakeDir(usrhost)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005890
Bram Moolenaar97d62492012-11-15 21:28:22 +01005891 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005892 " get name of new directory from user. A bare <CR> will skip.
5893 " if its currently a directory, also request will be skipped, but with
5894 " a message.
5895 call inputsave()
5896 let newdirname= input("Please give directory name: ")
5897 call inputrestore()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005898
5899 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01005900 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005901 return
5902 endif
5903
5904 if a:usrhost == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005905
5906 " Local mkdir:
5907 " sanity checks
5908 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005909 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005910 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005911 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005912 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005913 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005914 return
5915 endif
5916 if s:FileReadable(fullnewdir)
5917 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005918 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005919 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005920 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005921 return
5922 endif
5923
5924 " requested new local directory is neither a pre-existing file or
5925 " directory, so make it!
5926 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005927 if has("unix")
5928 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
5929 else
5930 call mkdir(fullnewdir,"p")
5931 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005932 else
5933 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005934 if s:NetrwLcd(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005935 return
5936 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005937 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005938 if v:shell_error != 0
5939 let @@= ykeep
5940 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 +01005941 return
5942 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005943 if !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02005944 if s:NetrwLcd(netrw_origdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005945 return
5946 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005947 endif
5948 endif
5949
5950 if v:shell_error == 0
5951 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005952 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01005953 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005954 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005955 elseif !exists("g:netrw_quiet")
5956 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
5957 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005958
5959 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01005960 " Remote mkdir: using ssh
Bram Moolenaar446cb832008-06-24 21:56:24 +00005961 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
5962 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005963 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005964 if v:shell_error == 0
5965 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005966 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01005967 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005968 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005969 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005970 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005971 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005972
5973 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01005974 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005975 let svpos= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01005976 if exists("b:netrw_fname")
Bram Moolenaara6878372014-03-22 21:02:50 +01005977 let remotepath= b:netrw_fname
5978 else
5979 let remotepath= ""
5980 endif
5981 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Tom Benham64a536d2024-11-07 21:15:03 +01005982 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005983 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01005984
Bram Moolenaar446cb832008-06-24 21:56:24 +00005985 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01005986 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005987 let svpos= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01005988 if exists("b:netrw_fname")
Bram Moolenaara6878372014-03-22 21:02:50 +01005989 let remotepath= b:netrw_fname
5990 else
5991 let remotepath= ""
5992 endif
5993 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Tom Benham64a536d2024-11-07 21:15:03 +01005994 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005995 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005996 endif
5997
Bram Moolenaar97d62492012-11-15 21:28:22 +01005998 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01005999endfun
6000
6001" ---------------------------------------------------------------------
6002" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6003fun! s:TreeSqueezeDir(islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01006004 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6005 " its a tree-listing style
6006 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006007 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006008 let depth = strchars(substitute(curdepth,' ','','g'))
6009 let srch = -1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006010 if depth >= 2
6011 NetrwKeepj norm! 0
6012 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6013 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006014 elseif depth == 1
6015 NetrwKeepj norm! 0
6016 let treedepthchr= substitute(s:treedepthstring,' ','','')
6017 let srch = search('^[^'.treedepthchr.']','bW',stopline)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006018 endif
6019 if srch > 0
Tom Benham64a536d2024-11-07 21:15:03 +01006020 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord(),1))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006021 exe srch
6022 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006023 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006024endfun
6025
6026" ---------------------------------------------------------------------
6027" s:NetrwMaps: {{{2
6028fun! s:NetrwMaps(islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01006029
Bram Moolenaar85850f32019-07-19 22:05:51 +02006030 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006031 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006032" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006033 if !hasmapto("<Plug>NetrwReturn")
6034 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006035 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6036 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006037 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6038 endif
6039 endif
6040 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006041 endif
6042
Bram Moolenaar85850f32019-07-19 22:05:51 +02006043 " generate default <Plug> maps {{{3
6044 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006045 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006046 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6047 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6048 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6049 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6050 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6051 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6052 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6053 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6054 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6055 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006056
Bram Moolenaara6878372014-03-22 21:02:50 +01006057 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02006058 " local normal-mode maps {{{3
6059 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6060 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6061 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6062 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6063 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6064 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6065 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006066 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006067 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6068 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6069 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6070" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006071 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6072 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6073 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006074 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006075 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006076 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6077 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6078 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6079 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006080 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6081 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6082 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6083 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6084 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6085 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6086 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6087 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6088 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6089 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6090 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6091 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6092 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006093 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006094 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006095 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6096 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6097 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6098 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6099 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006100 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006101 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006102 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 +01006103 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006104 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6105 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6106 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006107 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006108 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006109 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6110 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006111 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006112 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006113 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6114 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6115 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006116 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 +01006117 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006118
Tom Benham64a536d2024-11-07 21:15:03 +01006119 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 +01006120 if !hasmapto('<Plug>NetrwHideEdit')
6121 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006122 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006123 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006124 if !hasmapto('<Plug>NetrwRefresh')
6125 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006126 endif
Tom Benham64a536d2024-11-07 21:15:03 +01006127 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 +01006128 if s:didstarstar || !mapcheck("<s-down>","n")
6129 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006130 endif
6131 if s:didstarstar || !mapcheck("<s-up>","n")
6132 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006133 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006134 if !hasmapto('<Plug>NetrwTreeSqueeze')
6135 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006136 endif
6137 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006138 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6139 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006140 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6141 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6142 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6143 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6144 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6145 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6146 imap <buffer> <leftmouse> <Plug>ILeftmouse
6147 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006148 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6149 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6150 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6151 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6152 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006153 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006154 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6155 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006156 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006157 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6158 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6159 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6160 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6161 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6162 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6163 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006164 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6165
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006166 " support user-specified maps
6167 call netrw#UserMaps(1)
6168
Bram Moolenaar85850f32019-07-19 22:05:51 +02006169 else
6170 " remote normal-mode maps {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006171 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006172 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6173 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6174 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6175 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6176 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6177 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6178 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006179 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./',0))<cr>
6180 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 +02006181 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6182 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6183" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006184 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6185 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6186 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6187 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6188 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6189 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6190 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6191 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006192 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006193 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006194 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6195 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6196 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6197 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6198 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6199 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6200 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6201 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6202 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6203 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6204 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006205 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006206 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006207 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6208 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6209 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6210 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6211 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006212 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6213 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006214 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 +01006215 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006216 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006217 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6218 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006219 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006220 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 +01006221 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6222 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6223 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6224 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6225 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6226 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6227 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6228 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006229 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord(),1),1)<cr>
Konfekt3d7e5672024-10-27 22:16:49 +01006230 nmap <buffer> <nowait> gx x
Bram Moolenaara6878372014-03-22 21:02:50 +01006231 if !hasmapto('<Plug>NetrwHideEdit')
6232 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006233 endif
6234 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6235 if !hasmapto('<Plug>NetrwRefresh')
6236 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006237 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006238 if !hasmapto('<Plug>NetrwTreeSqueeze')
6239 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006240 endif
6241 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006242
6243 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006244 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006245
Tom Benham64a536d2024-11-07 21:15:03 +01006246 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./',0))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006247 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006248 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006249 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006250 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006251 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006252 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006253 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006254 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006255 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006256 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006257 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006258 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6259 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6260 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006261 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006262 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006263 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6264 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006265 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006266 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6267 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6268 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6269 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6270 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6271 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6272 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006273 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006274
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006275 " support user-specified maps
6276 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006277 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006278endfun
6279
6280" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006281" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006282" If -buffer, the command is only available from within netrw buffers
6283" Otherwise, the command is available from any window, so long as netrw
6284" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006285fun! s:NetrwCommands(islocal)
6286" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6287
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006288 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6289 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006290 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 +01006291 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006292 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006293 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006294 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006295 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006296 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006297
6298" call Dret("s:NetrwCommands")
6299endfun
6300
6301" ---------------------------------------------------------------------
6302" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6303" glob()ing only works with local files
6304fun! s:NetrwMarkFiles(islocal,...)
6305" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006306 let curdir = s:NetrwGetCurdir(a:islocal)
6307 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006308 while i <= a:0
6309 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006310 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006311 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006312 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006313 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006314 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006315 else
6316 let mffiles= [a:{i}]
6317 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006318" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006319 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006320" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006321 call s:NetrwMarkFile(a:islocal,mffile)
6322 endfor
6323 let i= i + 1
6324 endwhile
6325" call Dret("s:NetrwMarkFiles")
6326endfun
6327
6328" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006329" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006330fun! s:NetrwMarkTarget(...)
Bram Moolenaara6878372014-03-22 21:02:50 +01006331 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006332 let curdir = s:NetrwGetCurdir(1)
6333 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006334 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006335 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6336 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006337 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006338 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006339 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6340 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006341 let svpos = winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01006342 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006343 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006344endfun
6345
6346" ---------------------------------------------------------------------
6347" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6348" mark and unmark files. If a markfile list exists,
6349" then the rename and delete functions will use it instead
6350" of whatever may happen to be under the cursor at that
6351" moment. When the mouse and gui are available,
6352" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006353"
6354" Creates two lists
6355" s:netrwmarkfilelist -- holds complete paths to all marked files
6356" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6357"
6358" Creates a marked file match string
6359" s:netrwmarfilemtch_# -- used with 2match to display marked files
6360"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006361" Creates a buffer version of islocal
6362" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006363fun! s:NetrwMarkFile(islocal,fname)
6364" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006365" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006366
6367 " sanity check
6368 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006369" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006370 return
6371 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006372 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006373
Bram Moolenaar97d62492012-11-15 21:28:22 +01006374 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006375 let curbufnr= bufnr("%")
yasudac18a9d52024-09-19 18:09:51 +02006376 let leader= '\%(^\|\s\)\zs'
Bram Moolenaara6878372014-03-22 21:02:50 +01006377 if a:fname =~ '\a$'
6378 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6379 else
6380 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6381 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006382
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006383 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006384 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006385" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6386" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6387" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006388 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006389
6390 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006391 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006392" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006393 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006394 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006395
6396 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006397 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006398" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006399 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6400 if s:netrwmarkfilelist_{curbufnr} == []
6401 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006402" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006403 call s:NetrwUnmarkList(curbufnr,curdir)
6404 else
6405 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006406" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006407 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006408 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006409 for fname in s:netrwmarkfilelist_{curbufnr}
6410 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006411 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006412 else
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 endif
6415 let first= 0
6416 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006417" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006418 endif
6419 endif
6420
6421 else
6422 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006423" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006424
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006425" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006426 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006427 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6428" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006429
6430 " build initial markfile matching pattern
6431 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006432 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006433 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006434 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006435 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006436" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006437 endif
6438
6439 " handle global markfilelist
6440 if exists("s:netrwmarkfilelist")
6441 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6442 if index(s:netrwmarkfilelist,dname) == -1
6443 " append new filename to global markfilelist
6444 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006445" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006446 else
6447 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006448" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6449" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006450 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006451" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006452 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006453" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006454 unlet s:netrwmarkfilelist
6455 endif
6456 endif
6457 else
6458 " initialize new global-directory markfilelist
6459 let s:netrwmarkfilelist= []
6460 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006461" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006462 endif
6463
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006464 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006465 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6466 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6467" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6468 if exists("g:did_drchip_netrwlist_syntax")
6469 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6470 endif
6471 else
6472" " call Decho("2match none",'~'.expand("<slnum>"))
6473 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006474 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006475 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006476 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006477" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6478" 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 +00006479endfun
6480
6481" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006482" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6483" mA: move the argument list to marked file list (tomflist=1)
6484" Uses the global marked file list
6485fun! s:NetrwMarkFileArgList(islocal,tomflist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006486 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006487 let curdir = s:NetrwGetCurdir(a:islocal)
6488 let curbufnr = bufnr("%")
6489
6490 if a:tomflist
6491 " mA: move argument list to marked file list
6492 while argc()
6493 let fname= argv(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006494 exe "argdel ".fnameescape(fname)
6495 call s:NetrwMarkFile(a:islocal,fname)
6496 endwhile
6497
6498 else
6499 " ma: move marked file list to argument list
6500 if exists("s:netrwmarkfilelist")
6501
6502 " for every filename in the marked list
6503 for fname in s:netrwmarkfilelist
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006504 exe "argadd ".fnameescape(fname)
6505 endfor " for every file in the marked list
6506
6507 " unmark list and refresh
6508 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01006509 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006510 NetrwKeepj call winrestview(svpos)
6511 endif
6512 endif
6513
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006514endfun
6515
6516" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006517" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
6518" compress/decompress files using the programs
6519" in g:netrw_compress and g:netrw_uncompress,
6520" using g:netrw_compress_suffix to know which to
6521" do. By default:
6522" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006523" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00006524fun! s:NetrwMarkFileCompress(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006525 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006526 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006527 let curbufnr = bufnr("%")
6528
Bram Moolenaarff034192013-04-24 18:51:19 +02006529 " sanity check
6530 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006531 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006532 return
6533 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006534
Bram Moolenaar446cb832008-06-24 21:56:24 +00006535 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02006536
6537 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00006538 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02006539 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02006540 if exists("g:netrw_decompress['".sfx."']")
6541 " fname has a suffix indicating that its compressed; apply associated decompression routine
6542 let exe= g:netrw_decompress[sfx]
Bram Moolenaarff034192013-04-24 18:51:19 +02006543 let exe= netrw#WinPath(exe)
6544 if a:islocal
6545 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006546 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006547 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006548 call system(exe." ".fname)
6549 if v:shell_error
6550 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01006551 endif
6552 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006553 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
6554 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01006555 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006556
Bram Moolenaarff034192013-04-24 18:51:19 +02006557 endif
6558 unlet sfx
6559
Bram Moolenaar446cb832008-06-24 21:56:24 +00006560 if exists("exe")
6561 unlet exe
6562 elseif a:islocal
6563 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006564 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006565 if v:shell_error
6566 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
6567 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006568 else
6569 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006570 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006571 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006572 endfor " for every file in the marked list
6573
Bram Moolenaar446cb832008-06-24 21:56:24 +00006574 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01006575 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006576 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006577 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006578endfun
6579
6580" ---------------------------------------------------------------------
6581" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
6582" If no marked files, then set up directory as the
6583" target. Currently does not support copying entire
6584" directories. Uses the local-buffer marked file list.
6585" Returns 1=success (used by NetrwMarkFileMove())
6586" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006587fun! s:NetrwMarkFileCopy(islocal,...)
6588" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
6589
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006590 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006591 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006592 if b:netrw_curdir !~ '/$'
6593 if !exists("b:netrw_curdir")
6594 let b:netrw_curdir= curdir
6595 endif
6596 let b:netrw_curdir= b:netrw_curdir."/"
6597 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006598
Bram Moolenaarff034192013-04-24 18:51:19 +02006599 " sanity check
6600 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006601 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006602" call Dret("s:NetrwMarkFileCopy")
6603 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006604 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006605" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006606
Bram Moolenaar446cb832008-06-24 21:56:24 +00006607 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006608 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006609" call Dret("s:NetrwMarkFileCopy 0")
6610 return 0
6611 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006612" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006613
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006614 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006615 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006616" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006617 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006618 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
6619" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
6620 return
6621 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006622
6623 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02006624 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006625 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
6626 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006627" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006628 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006629 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
6630 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006631" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006632 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006633 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006634 let oldname = a:1
6635 else
6636 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006637" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006638 let s:recursive= 1
6639 for oldname in s:netrwmarkfilelist_{bufnr("%")}
6640 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
6641 if ret == 0
6642 break
6643 endif
6644 endfor
6645 unlet s:recursive
6646 call s:NetrwUnmarkList(curbufnr,curdir)
6647" call Dret("s:NetrwMarkFileCopy ".ret)
6648 return ret
6649 endif
6650
6651 call inputsave()
6652 let newname= input("Copy ".oldname." to : ",oldname,"file")
6653 call inputrestore()
6654 if newname == ""
6655" call Dret("s:NetrwMarkFileCopy 0")
6656 return 0
6657 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006658 let args= s:ShellEscape(oldname)
6659 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006660 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006661 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
6662 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006663 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02006664 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02006665 let args= substitute(args,'/','\\','g')
6666 let tgt = substitute(tgt, '/','\\','g')
6667 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006668 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
6669 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
6670 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
6671 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
6672" call Decho("args <".args.">",'~'.expand("<slnum>"))
6673" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006674 if isdirectory(s:NetrwFile(args))
6675" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006676 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006677" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02006678 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006679 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
6680 " contents to a target. One must append the source directory name to the target to get xcopy to
6681 " do the right thing.
6682 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006683" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006684 endif
6685 else
6686 let copycmd= g:netrw_localcopycmd
6687 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006688 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006689 let copycmd = substitute(copycmd,'\s.*$','','')
6690 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02006691 let copycmd = netrw#WinPath(copycmd).copycmdargs
6692 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006693 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02006694 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006695" call Decho("args <".args.">",'~'.expand("<slnum>"))
6696" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
6697" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
6698" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006699 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01006700 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02006701 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02006702 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 +01006703 else
6704 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
6705 endif
6706" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006707 return 0
6708 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006709
6710 elseif a:islocal && !s:netrwmftgt_islocal
6711 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006712" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006713 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006714
6715 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006716 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006717" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006718 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006719
6720 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006721 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006722" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006723 let curdir = getcwd()
6724 let tmpdir = s:GetTempfile("")
6725 if tmpdir !~ '/'
6726 let tmpdir= curdir."/".tmpdir
6727 endif
6728 if exists("*mkdir")
6729 call mkdir(tmpdir)
6730 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006731 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006732 if v:shell_error != 0
6733 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 +01006734" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01006735 return
6736 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006737 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006738 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006739 if s:NetrwLcd(tmpdir)
6740" call Dret("s:NetrwMarkFileCopy : lcd failure")
6741 return
6742 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006743 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006744 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006745 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006746 if getcwd() == tmpdir
6747 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006748 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006749 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02006750 if s:NetrwLcd(curdir)
6751" call Dret("s:NetrwMarkFileCopy : lcd failure")
6752 return
6753 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01006754 if delete(tmpdir,"d")
6755 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006756 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006757 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006758 if s:NetrwLcd(curdir)
6759" call Dret("s:NetrwMarkFileCopy : lcd failure")
6760 return
6761 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006762 endif
6763 endif
6764 endif
6765
6766 " -------
6767 " cleanup
6768 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006769" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006770 " remove markings from local buffer
6771 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006772" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
6773" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
6774" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
6775" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
6776" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
6777" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
6778 if exists("s:recursive")
6779" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
6780 else
6781" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006782 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006783 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01006784 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006785 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006786 else
6787 " refresh local and targets for fast browsing
6788 if !exists("s:recursive")
6789 " remove markings from local buffer
6790" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
6791 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
6792 endif
6793
6794 " refresh buffers
6795 if s:netrwmftgt_islocal
6796" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
6797 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
6798 endif
6799 if a:islocal && s:netrwmftgt != curdir
6800" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
6801 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
6802 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01006803 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006804
Bram Moolenaar446cb832008-06-24 21:56:24 +00006805" call Dret("s:NetrwMarkFileCopy 1")
6806 return 1
6807endfun
6808
6809" ---------------------------------------------------------------------
6810" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
6811" invoke vim's diff mode on the marked files.
6812" Either two or three files can be so handled.
6813" Uses the global marked file list.
6814fun! s:NetrwMarkFileDiff(islocal)
6815" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6816 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006817
Bram Moolenaarff034192013-04-24 18:51:19 +02006818 " sanity check
6819 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006820 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006821" call Dret("s:NetrwMarkFileDiff")
6822 return
6823 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006824 let curdir= s:NetrwGetCurdir(a:islocal)
6825" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006826
Bram Moolenaara6878372014-03-22 21:02:50 +01006827 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006828 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00006829 for fname in s:netrwmarkfilelist
6830 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006831 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006832" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006833 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006834 diffthis
6835 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09006836 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006837" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006838 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006839 diffthis
6840 else
6841 break
6842 endif
6843 endfor
6844 call s:NetrwUnmarkList(curbufnr,curdir)
6845 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006846
Bram Moolenaar446cb832008-06-24 21:56:24 +00006847" call Dret("s:NetrwMarkFileDiff")
6848endfun
6849
6850" ---------------------------------------------------------------------
6851" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
6852" Uses global markfilelist
6853fun! s:NetrwMarkFileEdit(islocal)
6854" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
6855
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006856 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006857 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02006858
6859 " sanity check
6860 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006861 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006862" call Dret("s:NetrwMarkFileEdit")
6863 return
6864 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006865" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006866
Bram Moolenaar446cb832008-06-24 21:56:24 +00006867 if exists("s:netrwmarkfilelist_{curbufnr}")
6868 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006869 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006870 " unmark markedfile list
6871" call s:NetrwUnmarkList(curbufnr,curdir)
6872 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006873" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02006874 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00006875 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006876 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006877
Bram Moolenaar446cb832008-06-24 21:56:24 +00006878" call Dret("s:NetrwMarkFileEdit")
6879endfun
6880
6881" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006882" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02006883fun! s:NetrwMarkFileQFEL(islocal,qfel)
6884" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
6885 call s:NetrwUnmarkAll()
6886 let curbufnr= bufnr("%")
6887
6888 if !empty(a:qfel)
6889 for entry in a:qfel
6890 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006891" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006892 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006893" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006894 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
6895 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
6896 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
6897 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006898" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006899 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
6900 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006901" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006902 endif
6903 endfor
6904 echo "(use me to edit marked files)"
6905 else
6906 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
6907 endif
6908
6909" call Dret("s:NetrwMarkFileQFEL")
6910endfun
6911
6912" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006913" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
6914" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
6915" mX enbloc=1: Uses the global marked-file list, applies command to entire list
6916fun! s:NetrwMarkFileExe(islocal,enbloc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006917 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006918 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006919 let curbufnr = bufnr("%")
6920
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006921 if a:enbloc == 0
6922 " individually apply command to files, one at a time
6923 " sanity check
6924 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6925 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006926 return
6927 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006928
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006929 if exists("s:netrwmarkfilelist_{curbufnr}")
6930 " get the command
6931 call inputsave()
6932 let cmd= input("Enter command: ","","file")
6933 call inputrestore()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006934 if cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006935 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006936 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006937
6938 " apply command to marked files, individually. Substitute: filename -> %
6939 " If no %, then append a space and the filename to the command
6940 for fname in s:netrwmarkfilelist_{curbufnr}
6941 if a:islocal
6942 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09006943 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006944 endif
6945 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006946 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006947 endif
6948 if cmd =~ '%'
6949 let xcmd= substitute(cmd,'%',fname,'g')
6950 else
6951 let xcmd= cmd.' '.fname
6952 endif
6953 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006954 let ret= system(xcmd)
6955 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006956 let ret= s:RemoteSystem(xcmd)
6957 endif
6958 if v:shell_error < 0
6959 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
6960 break
6961 else
yasudac75dad02024-08-22 21:06:32 +02006962 if ret !=# ''
6963 echo "\n"
6964 " skip trailing new line
6965 echo ret[0:-2]
6966 else
6967 echo ret
6968 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006969 endif
6970 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00006971
6972 " unmark marked file list
6973 call s:NetrwUnmarkList(curbufnr,curdir)
6974
6975 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01006976 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006977 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006978 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006979 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006980 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006981
6982 else " apply command to global list of files, en bloc
6983
6984 call inputsave()
6985 let cmd= input("Enter command: ","","file")
6986 call inputrestore()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006987 if cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006988 return
6989 endif
6990 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006991 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006992 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006993 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006994 endif
6995 if a:islocal
6996 call system(cmd)
6997 if v:shell_error < 0
6998 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
6999 endif
7000 else
7001 let ret= s:RemoteSystem(cmd)
7002 endif
7003 call s:NetrwUnmarkAll()
7004
7005 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007006 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007007 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007008
7009 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007010endfun
7011
7012" ---------------------------------------------------------------------
7013" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7014" as the marked file(s) (toggles suffix presence)
7015" Uses the local marked file list.
7016fun! s:NetrwMarkHideSfx(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007017 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007018 let curbufnr = bufnr("%")
7019
7020 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7021 if exists("s:netrwmarkfilelist_{curbufnr}")
7022
7023 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007024 " construct suffix pattern
7025 if fname =~ '\.'
7026 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7027 else
7028 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7029 endif
7030 " determine if its in the hiding list or not
7031 let inhidelist= 0
7032 if g:netrw_list_hide != ""
7033 let itemnum = 0
7034 let hidelist= split(g:netrw_list_hide,',')
7035 for hidepat in hidelist
7036 if sfxpat == hidepat
7037 let inhidelist= 1
7038 break
7039 endif
7040 let itemnum= itemnum + 1
7041 endfor
7042 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007043 if inhidelist
7044 " remove sfxpat from list
7045 call remove(hidelist,itemnum)
7046 let g:netrw_list_hide= join(hidelist,",")
7047 elseif g:netrw_list_hide != ""
7048 " append sfxpat to non-empty list
7049 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7050 else
7051 " set hiding list to sfxpat
7052 let g:netrw_list_hide= sfxpat
7053 endif
7054 endfor
7055
7056 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007057 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007058 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007059 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007060 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007061 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007062endfun
7063
7064" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007065" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007066" Uses the local marked-file list.
7067fun! s:NetrwMarkFileVimCmd(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007068 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007069 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007070 let curbufnr = bufnr("%")
7071
Bram Moolenaarff034192013-04-24 18:51:19 +02007072 " sanity check
7073 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007074 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007075 return
7076 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007077
Bram Moolenaar15146672011-10-20 22:22:38 +02007078 if exists("s:netrwmarkfilelist_{curbufnr}")
7079 " get the command
7080 call inputsave()
7081 let cmd= input("Enter vim command: ","","file")
7082 call inputrestore()
Bram Moolenaar15146672011-10-20 22:22:38 +02007083 if cmd == ""
Bram Moolenaar15146672011-10-20 22:22:38 +02007084 return
7085 endif
7086
7087 " apply command to marked files. Substitute: filename -> %
7088 " If no %, then append a space and the filename to the command
7089 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar15146672011-10-20 22:22:38 +02007090 if a:islocal
7091 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007092 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaar15146672011-10-20 22:22:38 +02007093 exe cmd
7094 exe "sil! keepalt wq!"
7095 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007096 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007097 endif
7098 endfor
7099
7100 " unmark marked file list
7101 call s:NetrwUnmarkList(curbufnr,curdir)
7102
7103 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007104 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007105 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007106 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007107 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007108 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007109endfun
7110
7111" ---------------------------------------------------------------------
7112" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7113" as the marked file(s) (toggles suffix presence)
7114" Uses the local marked file list.
7115fun! s:NetrwMarkHideSfx(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007116 let svpos = winsaveview()
Bram Moolenaar15146672011-10-20 22:22:38 +02007117 let curbufnr = bufnr("%")
7118
7119 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7120 if exists("s:netrwmarkfilelist_{curbufnr}")
7121
7122 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar15146672011-10-20 22:22:38 +02007123 " construct suffix pattern
7124 if fname =~ '\.'
7125 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7126 else
7127 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7128 endif
7129 " determine if its in the hiding list or not
7130 let inhidelist= 0
7131 if g:netrw_list_hide != ""
7132 let itemnum = 0
7133 let hidelist= split(g:netrw_list_hide,',')
7134 for hidepat in hidelist
7135 if sfxpat == hidepat
7136 let inhidelist= 1
7137 break
7138 endif
7139 let itemnum= itemnum + 1
7140 endfor
7141 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007142 if inhidelist
7143 " remove sfxpat from list
7144 call remove(hidelist,itemnum)
7145 let g:netrw_list_hide= join(hidelist,",")
7146 elseif g:netrw_list_hide != ""
7147 " append sfxpat to non-empty list
7148 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7149 else
7150 " set hiding list to sfxpat
7151 let g:netrw_list_hide= sfxpat
7152 endif
7153 endfor
7154
7155 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007156 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007157 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007158 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007159 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007160 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007161endfun
7162
7163" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007164" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7165" Uses the global markfilelist
7166fun! s:NetrwMarkFileGrep(islocal)
7167" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007168 let svpos = winsaveview()
7169" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007170 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007171 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007172
7173 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007174" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007175 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007176" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007177 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007178 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007179" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007180 let netrwmarkfilelist= "*"
7181 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007182
Bram Moolenaarff034192013-04-24 18:51:19 +02007183 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007184" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007185 call inputsave()
7186 let pat= input("Enter pattern: ","")
7187 call inputrestore()
7188 let patbang = ""
7189 if pat =~ '^!'
7190 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007191 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007192 endif
7193 if pat =~ '^\i'
7194 let pat = escape(pat,'/')
7195 let pat = '/'.pat.'/'
7196 else
7197 let nonisi = pat[0]
7198 endif
7199
7200 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007201" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007202 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007203 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007204 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007205 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007206" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7207 return
7208 endtry
7209 echo "(use :cn, :cp to navigate, :Rex to return)"
7210
7211 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007212" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7213 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007214
7215 if exists("nonisi")
7216 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007217" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007218 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007219 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007220 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007221 endif
7222
7223" call Dret("s:NetrwMarkFileGrep")
7224endfun
7225
7226" ---------------------------------------------------------------------
7227" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7228" uses the global marked file list
7229" s:netrwmfloc= 0: target directory is remote
7230" = 1: target directory is local
7231fun! s:NetrwMarkFileMove(islocal)
7232" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007233 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007234 let curbufnr = bufnr("%")
7235
7236 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007237 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007238 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007239" call Dret("s:NetrwMarkFileMove")
7240 return
7241 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007242" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007243
Bram Moolenaar446cb832008-06-24 21:56:24 +00007244 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007245 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007246" call Dret("s:NetrwMarkFileCopy 0")
7247 return 0
7248 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007249" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007250
7251 if a:islocal && s:netrwmftgt_islocal
7252 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007253" call Decho("move from local to local",'~'.expand("<slnum>"))
7254" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007255 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007256 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7257" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7258 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007259 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007260 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007261" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007262 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007263 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007264" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007265 if g:netrw_localmovecmd =~ '\s'
7266 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7267 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7268 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007269" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007270 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007271 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007272" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007273 endif
7274 else
7275 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007276" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007277 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007278 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007279 if g:netrw_keepdir
7280 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7281 let fname= b:netrw_curdir."/".fname
7282 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007283 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007284 let fname= substitute(fname,'/','\\','g')
7285 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007286" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007287 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007288 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007289 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007290 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 +01007291 else
7292 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7293 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007294 break
7295 endif
7296 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007297
7298 elseif a:islocal && !s:netrwmftgt_islocal
7299 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007300" call Decho("move from local to remote",'~'.expand("<slnum>"))
7301" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007302 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007303 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007304" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007305 for fname in mflist
7306 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7307 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7308 endfor
7309 unlet mflist
7310
7311 elseif !a:islocal && s:netrwmftgt_islocal
7312 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007313" call Decho("move from remote to local",'~'.expand("<slnum>"))
7314" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007315 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007316 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007317" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007318 for fname in mflist
7319 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7320 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7321 endfor
7322 unlet mflist
7323
7324 elseif !a:islocal && !s:netrwmftgt_islocal
7325 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007326" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7327" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007328 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007329 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007330" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007331 for fname in mflist
7332 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7333 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7334 endfor
7335 unlet mflist
7336 endif
7337
7338 " -------
7339 " cleanup
7340 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007341" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007342
7343 " remove markings from local buffer
7344 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7345
7346 " refresh buffers
7347 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007348" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007349 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007350 endif
7351 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007352" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007353 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007354 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007355 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007356" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007357 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007358 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007359
Bram Moolenaar446cb832008-06-24 21:56:24 +00007360" call Dret("s:NetrwMarkFileMove")
7361endfun
7362
7363" ---------------------------------------------------------------------
7364" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7365" using the hardcopy command. Local marked-file list only.
7366fun! s:NetrwMarkFilePrint(islocal)
7367" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7368 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007369
7370 " sanity check
7371 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007372 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007373" call Dret("s:NetrwMarkFilePrint")
7374 return
7375 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007376" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7377 let curdir= s:NetrwGetCurdir(a:islocal)
7378
Bram Moolenaar446cb832008-06-24 21:56:24 +00007379 if exists("s:netrwmarkfilelist_{curbufnr}")
7380 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007381 call s:NetrwUnmarkList(curbufnr,curdir)
7382 for fname in netrwmarkfilelist
7383 if a:islocal
7384 if g:netrw_keepdir
7385 let fname= s:ComposePath(curdir,fname)
7386 endif
7387 else
7388 let fname= curdir.fname
7389 endif
7390 1split
7391 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007392" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007393 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007394" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007395 hardcopy
7396 q
7397 endfor
7398 2match none
7399 endif
7400" call Dret("s:NetrwMarkFilePrint")
7401endfun
7402
7403" ---------------------------------------------------------------------
7404" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7405" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007406" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007407fun! s:NetrwMarkFileRegexp(islocal)
7408" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7409
7410 " get the regular expression
7411 call inputsave()
7412 let regexp= input("Enter regexp: ","","file")
7413 call inputrestore()
7414
7415 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007416 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007417" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007418 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007419" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007420 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007421 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007422 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007423 else
7424 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007425 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007426 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007427" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007428
7429 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007430 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007431 if fname =~ '^'.fnameescape(curdir)
7432" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7433 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7434 else
7435" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7436 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7437 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007438 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007439
7440 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007441" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007442
7443 " convert displayed listing into a filelist
7444 let eikeep = &ei
7445 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007446 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007447 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007448" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007449 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007450 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02007451 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007452 sil NetrwKeepj norm! "ap
7453 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007454 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007455 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007456 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007457 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007458 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007459 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007460 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007461 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007462 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007463 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007464 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7465 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007466 call histdel("/",-1)
7467 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007468 endif
7469 " convert regexp into the more usual glob-style format
7470 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007471" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007472 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01007473 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007474 let filelist= getline(1,line("$"))
7475 q!
7476 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007477 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007478 endfor
7479 unlet filelist
7480 let @a = areg
7481 let &ei = eikeep
7482 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007483 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007484
7485" call Dret("s:NetrwMarkFileRegexp")
7486endfun
7487
7488" ---------------------------------------------------------------------
7489" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
7490" Uses the local marked file list.
7491fun! s:NetrwMarkFileSource(islocal)
7492" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
7493 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007494
7495 " sanity check
7496 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007497 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007498" call Dret("s:NetrwMarkFileSource")
7499 return
7500 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007501" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7502 let curdir= s:NetrwGetCurdir(a:islocal)
7503
Bram Moolenaar446cb832008-06-24 21:56:24 +00007504 if exists("s:netrwmarkfilelist_{curbufnr}")
7505 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007506 call s:NetrwUnmarkList(curbufnr,curdir)
7507 for fname in netrwmarkfilelist
7508 if a:islocal
7509 if g:netrw_keepdir
7510 let fname= s:ComposePath(curdir,fname)
7511 endif
7512 else
7513 let fname= curdir.fname
7514 endif
7515 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007516" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007517 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007518 endfor
7519 2match none
7520 endif
7521" call Dret("s:NetrwMarkFileSource")
7522endfun
7523
7524" ---------------------------------------------------------------------
7525" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
7526" Uses the global markfilelist
7527fun! s:NetrwMarkFileTag(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007528 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007529 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007530 let curbufnr = bufnr("%")
7531
Bram Moolenaarff034192013-04-24 18:51:19 +02007532 " sanity check
7533 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007534 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007535 return
7536 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007537
Bram Moolenaar446cb832008-06-24 21:56:24 +00007538 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007539 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007540 call s:NetrwUnmarkAll()
7541
7542 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02007543
Bram Moolenaar85850f32019-07-19 22:05:51 +02007544 call system(g:netrw_ctags." ".netrwmarkfilelist)
7545 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00007546 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
7547 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007548
Bram Moolenaar446cb832008-06-24 21:56:24 +00007549 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00007550 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01007551 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007552 let curdir= b:netrw_curdir
7553 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007554 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00007555 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007556 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01007557 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007558 wq!
7559 endif
7560 2match none
Tom Benham64a536d2024-11-07 21:15:03 +01007561 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007562 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007563 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007564endfun
7565
7566" ---------------------------------------------------------------------
7567" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007568" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02007569" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00007570" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02007571" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00007572fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007573 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007574 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007575 let hadtgt = exists("s:netrwmftgt")
7576 if !exists("w:netrw_bannercnt")
7577 let w:netrw_bannercnt= b:netrw_bannercnt
7578 endif
7579
7580 " set up target
7581 if line(".") < w:netrw_bannercnt
Bram Moolenaarff034192013-04-24 18:51:19 +02007582 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
7583 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaarff034192013-04-24 18:51:19 +02007584 unlet s:netrwmftgt s:netrwmftgt_islocal
7585 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007586 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02007587 endif
Tom Benham64a536d2024-11-07 21:15:03 +01007588 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007589 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007590 return
7591 else
7592 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaarff034192013-04-24 18:51:19 +02007593 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007594
7595 else
7596 " get word under cursor.
7597 " * If directory, use it for the target.
7598 " * If file, use b:netrw_curdir for the target
7599 let curword= s:NetrwGetWord()
7600 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007601 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007602 let s:netrwmftgt = tgtdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007603 elseif !a:islocal && tgtdir =~ '/$'
7604 let s:netrwmftgt = tgtdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007605 else
7606 let s:netrwmftgt = curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007607 endif
7608 endif
7609 if a:islocal
7610 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
7611 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007612 endif
7613 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007614 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007615 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
7616 endif
7617 let s:netrwmftgt_islocal= a:islocal
7618
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007619 " need to do refresh so that the banner will be updated
7620 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01007621 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007622 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007623 endif
Tom Benham64a536d2024-11-07 21:15:03 +01007624" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007625 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Tom Benham64a536d2024-11-07 21:15:03 +01007626 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop,0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007627 else
Tom Benham64a536d2024-11-07 21:15:03 +01007628 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007629 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007630 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007631 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007632 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00007633 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007634endfun
7635
7636" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007637" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
7638fun! s:NetrwGetCurdir(islocal)
7639" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
7640
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007641 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007642 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
7643" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
7644 elseif !exists("b:netrw_curdir")
7645 let b:netrw_curdir= getcwd()
7646" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
7647 endif
7648
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007649" 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 +01007650 if b:netrw_curdir !~ '\<\a\{3,}://'
7651 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007652" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007653 if g:netrw_keepdir == 0
7654 call s:NetrwLcd(curdir)
7655 endif
7656 endif
7657
7658" call Dret("s:NetrwGetCurdir <".curdir.">")
7659 return b:netrw_curdir
7660endfun
7661
7662" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00007663" s:NetrwOpenFile: query user for a filename and open it {{{2
7664fun! s:NetrwOpenFile(islocal)
7665" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007666 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00007667 call inputsave()
7668 let fname= input("Enter filename: ")
7669 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02007670" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
7671
7672 " determine if Lexplore is in use
7673 if exists("t:netrw_lexbufnr")
7674 " check if t:netrw_lexbufnr refers to a netrw window
7675" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
7676 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
7677 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
7678" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
7679 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
7680 exe "NetrwKeepj e ".fnameescape(fname)
7681 let @@= ykeep
7682" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
7683 endif
7684 endif
7685
7686 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00007687 if fname !~ '[/\\]'
7688 if exists("b:netrw_curdir")
7689 if exists("g:netrw_quiet")
7690 let netrw_quiet_keep = g:netrw_quiet
7691 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007692 let g:netrw_quiet = 1
7693 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007694 let s:rexposn_{bufnr("%")}= winsaveview()
7695" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007696 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007697 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007698 else
7699 exe "e ".fnameescape(b:netrw_curdir."/".fname)
7700 endif
7701 if exists("netrw_quiet_keep")
7702 let g:netrw_quiet= netrw_quiet_keep
7703 else
7704 unlet g:netrw_quiet
7705 endif
7706 endif
7707 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007708 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007709 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007710 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00007711" call Dret("s:NetrwOpenFile")
7712endfun
7713
7714" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007715" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
7716" For the mapping to this function be made via
7717" netrwPlugin, you'll need to have had
7718" g:netrw_usetab set to non-zero.
7719fun! netrw#Shrink()
7720" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
7721 let curwin = winnr()
7722 let wiwkeep = &wiw
7723 set wiw=1
7724
7725 if &ft == "netrw"
7726 if winwidth(0) > g:netrw_wiw
7727 let t:netrw_winwidth= winwidth(0)
7728 exe "vert resize ".g:netrw_wiw
7729 wincmd l
7730 if winnr() == curwin
7731 wincmd h
7732 endif
7733" call Decho("vert resize 0",'~'.expand("<slnum>"))
7734 else
7735 exe "vert resize ".t:netrw_winwidth
7736" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
7737 endif
7738
7739 elseif exists("t:netrw_lexbufnr")
7740 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
7741 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
7742 let t:netrw_winwidth= winwidth(0)
7743 exe "vert resize ".g:netrw_wiw
7744 wincmd l
7745 if winnr() == curwin
7746 wincmd h
7747 endif
7748" call Decho("vert resize 0",'~'.expand("<slnum>"))
7749 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
7750 exe "vert resize ".t:netrw_winwidth
7751" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01007752 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007753 call netrw#Lexplore(0,0)
7754 endif
7755
7756 else
7757 call netrw#Lexplore(0,0)
7758 endif
7759 let wiw= wiwkeep
7760
7761" call Dret("netrw#Shrink")
7762endfun
7763
7764" ---------------------------------------------------------------------
7765" s:NetSortSequence: allows user to edit the sorting sequence {{{2
7766fun! s:NetSortSequence(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007767 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007768 let svpos= winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007769 call inputsave()
7770 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
7771 call inputrestore()
7772
7773 " refresh the listing
7774 let g:netrw_sort_sequence= newsortseq
Tom Benham64a536d2024-11-07 21:15:03 +01007775 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007776 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007777 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007778endfun
7779
7780" ---------------------------------------------------------------------
7781" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
7782" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02007783" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00007784fun! s:NetrwUnmarkList(curbufnr,curdir)
7785" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
7786
7787 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007788 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007789 for mfile in s:netrwmarkfilelist_{a:curbufnr}
7790 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
7791 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
7792 call remove(s:netrwmarkfilelist,idx) " remove from global list
7793 endfor
7794 if s:netrwmarkfilelist == []
7795 unlet s:netrwmarkfilelist
7796 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007797
Bram Moolenaar446cb832008-06-24 21:56:24 +00007798 " getting rid of the local marked-file lists is easy
7799 unlet s:netrwmarkfilelist_{a:curbufnr}
7800 endif
7801 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
7802 unlet s:netrwmarkfilemtch_{a:curbufnr}
7803 endif
7804 2match none
7805" call Dret("s:NetrwUnmarkList")
7806endfun
7807
7808" ---------------------------------------------------------------------
7809" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
7810fun! s:NetrwUnmarkAll()
7811" call Dfunc("s:NetrwUnmarkAll()")
7812 if exists("s:netrwmarkfilelist")
7813 unlet s:netrwmarkfilelist
7814 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02007815 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007816 2match none
7817" call Dret("s:NetrwUnmarkAll")
7818endfun
7819
7820" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02007821" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007822fun! s:NetrwUnmarkAll2()
7823" call Dfunc("s:NetrwUnmarkAll2()")
7824 redir => netrwmarkfilelist_let
7825 let
7826 redir END
7827 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007828 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00007829 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
7830 for flist in netrwmarkfilelist_list
7831 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
7832 unlet s:netrwmarkfilelist_{curbufnr}
7833 unlet s:netrwmarkfilemtch_{curbufnr}
7834 endfor
7835" call Dret("s:NetrwUnmarkAll2")
7836endfun
7837
7838" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007839" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
7840"
7841" Marked files are in two types of lists:
7842" s:netrwmarkfilelist -- holds complete paths to all marked files
7843" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
7844"
7845" Marked files suitable for use with 2match are in:
7846" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00007847fun! s:NetrwUnMarkFile(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007848 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007849 let curbufnr = bufnr("%")
7850
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007851 " unmark marked file list
7852 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
7853 if exists("s:netrwmarkfilelist")
7854" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007855 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007856 endif
7857
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007858 let ibuf= 1
7859 while ibuf < bufnr("$")
7860 if exists("s:netrwmarkfilelist_".ibuf)
7861 unlet s:netrwmarkfilelist_{ibuf}
7862 unlet s:netrwmarkfilemtch_{ibuf}
7863 endif
7864 let ibuf = ibuf + 1
7865 endwhile
7866 2match none
7867
Tom Benham64a536d2024-11-07 21:15:03 +01007868" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007869call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007870endfun
7871
7872" ---------------------------------------------------------------------
7873" s:NetrwMenu: generates the menu for gvim and netrw {{{2
7874fun! s:NetrwMenu(domenu)
7875
7876 if !exists("g:NetrwMenuPriority")
7877 let g:NetrwMenuPriority= 80
7878 endif
7879
Bram Moolenaaradc21822011-04-01 18:03:16 +02007880 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00007881" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
7882
7883 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007884" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007885 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02007886 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
7887 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
7888 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
7889 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
7890 if g:netrw_dirhistmax > 0
7891 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
7892 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
7893 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
7894 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
7895 else
7896 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
7897 endif
7898 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
7899 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
7900 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
7901 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
7902 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
7903 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
7904 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
7905 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
7906 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
7907 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
7908 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
7909 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
7910 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
7911 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
7912 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 +01007913 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 +02007914 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
7915 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
7916 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
7917 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
7918 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
7919 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
7920 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
7921 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
7922 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
7923 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
7924 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
7925 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
7926 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
7927 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
7928 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
7929 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
7930 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
7931 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
7932 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
7933 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
7934 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
7935 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
7936 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
7937 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
7938 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
7939 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
7940 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
7941 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
7942 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
7943 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>'
7944 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>'
7945 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>'
7946 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
7947 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>'
7948 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>'
7949 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 +01007950 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 +02007951 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
7952 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00007953 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02007954 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
7955 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00007956
7957 elseif !a:domenu
7958 let s:netrwcnt = 0
7959 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007960 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007961 exe curwin."wincmd w"
7962
7963 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007964" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007965 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007966" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007967 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00007968 endif
7969 endif
7970" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007971 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007972 endif
7973
7974endfun
7975
7976" ---------------------------------------------------------------------
7977" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
7978" Used by the O maps (as <SID>NetrwObtain())
7979fun! s:NetrwObtain(islocal)
7980" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
7981
Bram Moolenaar97d62492012-11-15 21:28:22 +01007982 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00007983 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007984 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01007985 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00007986 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
7987 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007988 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007989 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007990 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00007991
7992" call Dret("NetrwObtain")
7993endfun
7994
7995" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007996" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
7997" If there's only one window, then the window will first be split.
7998" Returns:
7999" choice = 0 : didn't have to choose
8000" choice = 1 : saved modified file in window first
8001" choice = 2 : didn't save modified file, opened window
8002" choice = 3 : cancel open
8003fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008004 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008005 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008006 let curdir = b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008007
8008 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008009 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008010 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008011 let curword = s:NetrwGetWord()
8012 let choice = 0
8013 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 +01008014 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01008015 let curdir = s:treedir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008016
Bram Moolenaar8d043172014-01-23 14:24:41 +01008017 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008018 if lastwinnr == 1
8019 " if only one window, open a new one first
Bram Moolenaar85850f32019-07-19 22:05:51 +02008020 " g:netrw_preview=0: preview window shown in a horizontally split window
8021 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008022 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008023 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008024 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar15146672011-10-20 22:22:38 +02008025 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008026 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008027 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008028 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar15146672011-10-20 22:22:38 +02008029 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008030 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008031 let didsplit = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00008032
8033 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008034 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008035 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01008036 setl ei=all
Bram Moolenaar446cb832008-06-24 21:56:24 +00008037 wincmd p
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01008038
Bram Moolenaar71badf92023-04-22 22:40:14 +01008039 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8040 " whoops -- user trying to open file in the Lexplore window.
8041 " Use Lexplore's opening-file window instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01008042" exe g:netrw_chgwin."wincmd w"
8043 wincmd p
Tom Benham64a536d2024-11-07 21:15:03 +01008044 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008045 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008046
8047 " prevwinnr: the window number of the "prev" window
8048 " prevbufnr: the buffer number of the buffer in the "prev" window
8049 " bnrcnt : the qty of windows open on the "prev" buffer
8050 let prevwinnr = winnr()
8051 let prevbufnr = bufnr("%")
8052 let prevbufname = bufname("%")
8053 let prevmod = &mod
8054 let bnrcnt = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008055 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008056
8057 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008058 " and it doesn't appear in any other extant window, then ask the
8059 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008060 if prevmod
Bram Moolenaar8d043172014-01-23 14:24:41 +01008061 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008062 exe prevwinnr."wincmd w"
8063
8064 if bnrcnt == 1 && &hidden == 0
8065 " only one copy of the modified buffer in a window, and
8066 " hidden not set, so overwriting will lose the modified file. Ask first...
8067 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008068 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008069
8070 if choice == 1
8071 " Yes -- write file & then browse
8072 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008073 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008074 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008075 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008076 exe origwin."wincmd w"
8077 let &ei = eikeep
8078 let @@ = ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008079 return choice
8080 endif
8081
8082 elseif choice == 2
8083 " No -- don't worry about changed file, just browse anyway
Bram Moolenaar8d043172014-01-23 14:24:41 +01008084 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008085
8086 else
8087 " Cancel -- don't do this
Bram Moolenaar8d043172014-01-23 14:24:41 +01008088 exe origwin."wincmd w"
8089 let &ei= eikeep
8090 let @@ = ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008091 return choice
8092 endif
8093 endif
8094 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008095 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008096 endif
8097
8098 " restore b:netrw_curdir (window split/enew may have lost it)
8099 let b:netrw_curdir= curdir
8100 if a:islocal < 2
8101 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01008102 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword,0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008103 else
Tom Benham64a536d2024-11-07 21:15:03 +01008104 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword,0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008105 endif
8106 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008107 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008108 return choice
8109endfun
8110
8111" ---------------------------------------------------------------------
8112" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8113" Always assumed to be local -> remote
8114" call s:NetrwUpload(filename, target)
8115" call s:NetrwUpload(filename, target, fromdirectory)
8116fun! s:NetrwUpload(fname,tgt,...)
8117" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8118
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008119 if a:tgt =~ '^\a\{3,}://'
8120 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008121 else
8122 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8123 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008124" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008125
8126 if a:0 > 0
8127 let fromdir= a:1
8128 else
8129 let fromdir= getcwd()
8130 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008131" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008132
8133 if type(a:fname) == 1
8134 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008135" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008136 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008137" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8138 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8139" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008140 if a:tgt =~ '/$'
8141 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008142" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008143 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008144 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008145" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008146 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008147" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008148 endif
8149 q!
8150
8151 elseif type(a:fname) == 3
8152 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008153" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008154 let curdir= getcwd()
8155 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008156 if s:NetrwLcd(fromdir)
8157" call Dret("s:NetrwUpload : lcd failure")
8158 return
8159 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008160 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008161 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008162 if exists("g:netrw_port") && g:netrw_port != ""
8163 let useport= " ".g:netrw_scpport." ".g:netrw_port
8164 else
8165 let useport= ""
8166 endif
8167 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8168 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008169 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 +02008170 if s:NetrwLcd(curdir)
8171" call Dret("s:NetrwUpload : lcd failure")
8172 return
8173 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008174
8175 elseif a:tgt =~ '^ftp:'
8176 call s:NetrwMethod(a:tgt)
8177
8178 if b:netrw_method == 2
8179 " handle uploading a list of files via ftp+.netrc
8180 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008181 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008182" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008183
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008184 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008185" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008186
8187 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008188 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008189" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008190 endif
8191
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008192 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008193" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008194
Bram Moolenaaradc21822011-04-01 18:03:16 +02008195 if tgtdir == ""
8196 let tgtdir= '/'
8197 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008198 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008199" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008200
8201 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008202 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8203" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008204 endfor
8205
8206 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008207 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 +00008208 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008209" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8210 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008211 endif
8212 " 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 +01008213 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008214 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008215 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8216 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8217 else
8218 bw!|q
8219 endif
8220
8221 elseif b:netrw_method == 3
8222 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8223 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008224 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008225 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008226 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008227
8228 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008229 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008230" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008231 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008232 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008233" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008234 endif
8235
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008236 if exists("g:netrw_uid") && g:netrw_uid != ""
8237 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008238 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008239" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008240 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008241 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008242 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008243" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008244 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008245 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008246" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008247 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008248 endif
8249
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008250 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008251" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008252
8253 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008254 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008255" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008256 endif
8257
8258 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008259 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008260" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008261 endif
8262
8263 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008264 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008265" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008266 endfor
8267
8268 " perform ftp:
8269 " -i : turns off interactive prompting from ftp
8270 " -n unix : DON'T use <.netrc>, even though it exists
8271 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008272 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008273 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008274 " 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 +01008275 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008276 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008277 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8278 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008279 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008280 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8281 let &debug = debugkeep
8282 let mod = 1
8283 else
8284 bw!|q
8285 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008286 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008287" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008288 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008289 endif
8290 else
8291 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8292 endif
8293 endif
8294
8295" call Dret("s:NetrwUpload")
8296endfun
8297
8298" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008299" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008300fun! s:NetrwPreview(path) range
8301" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008302" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8303" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008304 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008305 NetrwKeepj call s:NetrwOptionsSave("s:")
8306 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8307 NetrwKeepj call s:NetrwOptionsSafe(1)
8308 else
8309 NetrwKeepj call s:NetrwOptionsSafe(0)
8310 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008311 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008312" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008313 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008314" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8315 if g:netrw_preview
8316 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008317 let pvhkeep = &pvh
8318 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8319 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008320" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8321 else
8322 " horizontal split
8323 let pvhkeep = &pvh
8324 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8325 let &pvh = winheight(0) - winsz
8326" 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 +02008327 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008328 " g:netrw_preview g:netrw_alto
8329 " 1 : vert 1: top -- preview window is vertically split off and on the left
8330 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8331 " 0 : 1: top -- preview window is horizontally split off and on the top
8332 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8333 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008334 " 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 +02008335 " the BufEnter event set up in netrwPlugin.vim
8336" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8337 let eikeep = &ei
8338 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008339 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008340 let &ei= eikeep
8341" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008342 if exists("pvhkeep")
8343 let &pvh= pvhkeep
8344 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008345 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008346 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008347 endif
8348 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008349 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 +00008350 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008351 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008352 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008353" call Dret("NetrwPreview")
8354endfun
8355
8356" ---------------------------------------------------------------------
8357" s:NetrwRefresh: {{{2
8358fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008359" 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 +00008360 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008361 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008362" call Decho("setl ma noro",'~'.expand("<slnum>"))
8363" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008364 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008365 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8366 if !exists("w:netrw_treetop")
8367 if exists("b:netrw_curdir")
8368 let w:netrw_treetop= b:netrw_curdir
8369 else
8370 let w:netrw_treetop= getcwd()
8371 endif
8372 endif
8373 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
8374 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008375
8376 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008377 let screenposn = winsaveview()
8378" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008379
8380" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
8381" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
8382 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008383 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008384 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008385 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008386 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008387 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008388
8389 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008390" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
8391 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008392
8393 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02008394 if has("syntax") && exists("g:syntax_on") && g:syntax_on
8395 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8396" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
8397 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8398 else
8399" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
8400 2match none
8401 endif
8402 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008403
Bram Moolenaar97d62492012-11-15 21:28:22 +01008404" restore
8405 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008406" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008407endfun
8408
8409" ---------------------------------------------------------------------
8410" s:NetrwRefreshDir: refreshes a directory by name {{{2
8411" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008412" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008413fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008414 if g:netrw_fastbrowse == 0
8415 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008416 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008417
8418 if tgtwin > 0
8419 " tgtwin is being displayed, so refresh it
8420 let curwin= winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008421 exe tgtwin."wincmd w"
Tom Benham64a536d2024-11-07 21:15:03 +01008422 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008423 exe curwin."wincmd w"
8424
8425 elseif bufnr(a:dirname) > 0
8426 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008427 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00008428 endif
8429
8430 elseif g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008431 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008432 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008433endfun
8434
8435" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02008436" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
8437" window number to do its editing in.
8438" Supports [count]C where the count, if present, is used to specify
8439" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008440fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02008441" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008442 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008443" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008444 if a:1 == "" " :NetrwC win#
8445 let g:netrw_chgwin= winnr()
8446 else " :NetrwC
8447 let g:netrw_chgwin= a:1
8448 endif
8449 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02008450 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008451 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02008452 let g:netrw_chgwin= winnr()
8453 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008454 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008455" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02008456endfun
8457
8458" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008459" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
8460" What this function does is to compute a priority for the patterns
8461" in the g:netrw_sort_sequence. It applies a substitute to any
8462" "files" that satisfy each pattern, putting the priority / in
8463" front. An "*" pattern handles the default priority.
8464fun! s:NetrwSetSort()
8465" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008466 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008467 if w:netrw_liststyle == s:LONGLIST
8468 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
8469 else
8470 let seqlist = g:netrw_sort_sequence
8471 endif
8472 " sanity check -- insure that * appears somewhere
8473 if seqlist == ""
8474 let seqlist= '*'
8475 elseif seqlist !~ '\*'
8476 let seqlist= seqlist.',*'
8477 endif
8478 let priority = 1
8479 while seqlist != ""
8480 if seqlist =~ ','
8481 let seq = substitute(seqlist,',.*$','','e')
8482 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
8483 else
8484 let seq = seqlist
8485 let seqlist = ""
8486 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008487 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01008488 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008489 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01008490 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008491 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01008492 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008493 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008494" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008495
8496 " sanity check
8497 if w:netrw_bannercnt > line("$")
8498 " apparently no files were left after a Hiding pattern was used
8499" call Dret("SetSort : no files left after hiding")
8500 return
8501 endif
8502 if seq == '*'
8503 let starpriority= spriority
8504 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008505 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008506 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008507 " sometimes multiple sorting patterns will match the same file or directory.
8508 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008509 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
8510 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008511 endif
8512 let priority = priority + 1
8513 endwhile
8514 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008515 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
8516 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008517 endif
8518
8519 " Following line associated with priority -- items that satisfy a priority
8520 " pattern get prefixed by ###/ which permits easy sorting by priority.
8521 " Sometimes files can satisfy multiple priority patterns -- only the latest
8522 " priority pattern needs to be retained. So, at this point, these excess
8523 " priority prefixes need to be removed, but not directories that happen to
8524 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008525 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
8526 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008527 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008528
8529" call Dret("SetSort")
8530endfun
8531
Bram Moolenaarff034192013-04-24 18:51:19 +02008532" ---------------------------------------------------------------------
8533" s:NetrwSetTgt: sets the target to the specified choice index {{{2
8534" Implements [count]Tb (bookhist<b>)
8535" [count]Th (bookhist<h>)
8536" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008537fun! s:NetrwSetTgt(islocal,bookhist,choice)
8538" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02008539
8540 if a:bookhist == 'b'
8541 " supports choosing a bookmark as a target using a qb-generated list
8542 let choice= a:choice - 1
8543 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01008544 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02008545 else
8546 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
8547 endif
8548
8549 elseif a:bookhist == 'h'
8550 " supports choosing a history stack entry as a target using a qb-generated list
8551 let choice= (a:choice % g:netrw_dirhistmax) + 1
8552 if exists("g:netrw_dirhist_".choice)
8553 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01008554 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02008555 else
8556 echomsg "Sorry, history#".a:choice." not available!"
8557 endif
8558 endif
8559
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008560 " refresh the display
8561 if !exists("b:netrw_curdir")
8562 let b:netrw_curdir= getcwd()
8563 endif
8564 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
8565
Bram Moolenaarff034192013-04-24 18:51:19 +02008566" call Dret("s:NetrwSetTgt")
8567endfun
8568
Bram Moolenaar446cb832008-06-24 21:56:24 +00008569" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02008570" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008571fun! s:NetrwSortStyle(islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008572 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008573 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008574
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008575 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 +01008576 NetrwKeepj norm! 0
Tom Benham64a536d2024-11-07 21:15:03 +01008577 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008578 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008579endfun
8580
8581" ---------------------------------------------------------------------
8582" s:NetrwSplit: mode {{{2
8583" =0 : net and o
8584" =1 : net and t
8585" =2 : net and v
8586" =3 : local and o
8587" =4 : local and t
8588" =5 : local and v
8589fun! s:NetrwSplit(mode)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008590
Bram Moolenaar97d62492012-11-15 21:28:22 +01008591 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008592 call s:SaveWinVars()
8593
8594 if a:mode == 0
8595 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02008596 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008597 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008598 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008599 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008600 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008601 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008602 unlet s:didsplit
8603
8604 elseif a:mode == 1
8605 " remote and t
Tom Benham64a536d2024-11-07 21:15:03 +01008606 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008607 tabnew
8608 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008609 NetrwKeepj call s:RestoreWinVars()
8610 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008611 unlet s:didsplit
8612
8613 elseif a:mode == 2
8614 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02008615 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008616 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008617 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008618 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008619 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008620 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008621 unlet s:didsplit
8622
8623 elseif a:mode == 3
8624 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02008625 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008626 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008627 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008628 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008629 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008630 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008631 unlet s:didsplit
8632
8633 elseif a:mode == 4
8634 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00008635 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008636 let eikeep = &ei
8637 let netrw_winnr = winnr()
8638 let netrw_line = line(".")
8639 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008640 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01008641 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01008642 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008643 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
8644 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008645 let &ei = eikeep
8646 let netrw_curdir = s:NetrwTreeDir(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008647 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01008648 let b:netrw_curdir = netrw_curdir
8649 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008650 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008651 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword,0))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008652 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01008653 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008654 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
8655 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01008656 let &ei= eikeep
8657 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008658 unlet s:didsplit
8659
8660 elseif a:mode == 5
8661 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02008662 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008663 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008664 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008665 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008666 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008667 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008668 unlet s:didsplit
8669
8670 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008671 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008672 endif
8673
Bram Moolenaar97d62492012-11-15 21:28:22 +01008674 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008675endfun
8676
8677" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008678" s:NetrwTgtMenu: {{{2
8679fun! s:NetrwTgtMenu()
8680 if !exists("s:netrw_menucnt")
8681 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008682 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008683" call Dfunc("s:NetrwTgtMenu()")
8684
8685 " the following test assures that gvim is running, has menus available, and has menus enabled.
8686 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
8687 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008688" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008689 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
8690 endif
8691 if !exists("s:netrw_initbookhist")
8692 call s:NetrwBookHistRead()
8693 endif
8694
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008695 " try to cull duplicate entries
8696 let tgtdict={}
8697
Bram Moolenaarff034192013-04-24 18:51:19 +02008698 " target bookmarked places
8699 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008700" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008701 let cnt= 1
8702 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008703 if has_key(tgtdict,bmd)
8704 let cnt= cnt + 1
8705 continue
8706 endif
8707 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02008708 let ebmd= escape(bmd,g:netrw_menu_escape)
8709 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008710" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008711 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 +02008712 let cnt= cnt + 1
8713 endfor
8714 endif
8715
8716 " target directory browsing history
8717 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008718" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008719 let histcnt = 1
8720 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02008721 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02008722 if exists("g:netrw_dirhist_{histcnt}")
8723 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008724 if has_key(tgtdict,histentry)
8725 let histcnt = histcnt + 1
8726 continue
8727 endif
8728 let tgtdict[histentry] = histcnt
8729 let ehistentry = escape(histentry,g:netrw_menu_escape)
8730" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008731 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 +02008732 endif
8733 let histcnt = histcnt + 1
8734 endwhile
8735 endif
8736 endif
8737" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008738endfun
8739
8740" ---------------------------------------------------------------------
8741" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
8742" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008743fun! s:NetrwTreeDir(islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008744
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008745 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008746 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
8747 let treedir= s:treedir
8748 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008749 unlet s:prevwinopen
Bram Moolenaar8d043172014-01-23 14:24:41 +01008750 return treedir
8751 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008752 if exists("s:prevwinopen")
8753 unlet s:prevwinopen
8754 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008755
Bram Moolenaar8d043172014-01-23 14:24:41 +01008756 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
8757 let b:netrw_curdir= getcwd()
8758 endif
8759 let treedir = b:netrw_curdir
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008760 let s:treecurpos= winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008761
8762 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar5c736222010-01-06 20:54:52 +01008763
8764 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008765 let curline= substitute(getline('.'),"\t -->.*$",'','')
8766 if curline =~ '/$'
Bram Moolenaar8d043172014-01-23 14:24:41 +01008767 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008768 elseif curline =~ '@$'
Tom Benham64a536d2024-11-07 21:15:03 +01008769 let potentialdir= resolve(s:NetrwTreePath(w:netrw_treetop))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008770 else
8771 let treedir= ""
8772 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008773
8774 " detect user attempting to close treeroot
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008775 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008776 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008777 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008778 return b:netrw_curdir
8779 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008780
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008781 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
8782" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
8783" let newdir = w:netrw_treetop.'/'.potentialdir
Christian Brabandt56b7da32024-02-29 17:48:14 +01008784 if a:islocal && curline =~ '@$'
8785 if isdirectory(s:NetrwFile(potentialdir))
Tom Benham64a536d2024-11-07 21:15:03 +01008786 let treedir = potentialdir
Christian Brabandt56b7da32024-02-29 17:48:14 +01008787 let w:netrw_treetop = treedir
8788 endif
8789 else
8790 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
8791 let treedir = s:NetrwTreePath(w:netrw_treetop)
8792 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008793 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008794
8795 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00008796 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008797 return treedir
8798endfun
8799
8800" ---------------------------------------------------------------------
8801" s:NetrwTreeDisplay: recursive tree display {{{2
8802fun! s:NetrwTreeDisplay(dir,depth)
Tom Benham64a536d2024-11-07 21:15:03 +01008803 " ensure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02008804 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00008805
8806 " install ../ and shortdir
8807 if a:depth == ""
8808 call setline(line("$")+1,'../')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008809 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008810 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008811 if a:dir == w:netrw_treetop
8812 let shortdir= a:dir
8813 else
8814 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
8815 endif
8816 call setline(line("$")+1,a:depth.shortdir)
8817 else
8818 let shortdir= substitute(a:dir,'^.*/','','e')
8819 call setline(line("$")+1,a:depth.shortdir.'/')
8820 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008821 " append a / to dir if its missing one
8822 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008823
8824 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008825 let depth= s:treedepthstring.a:depth
Bram Moolenaar446cb832008-06-24 21:56:24 +00008826
Bram Moolenaar85850f32019-07-19 22:05:51 +02008827 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
8828 if g:netrw_hide == 1
8829 " hide given patterns
8830 let listhide= split(g:netrw_list_hide,',')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008831 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02008832 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008833 endfor
8834
8835 elseif g:netrw_hide == 2
8836 " show given patterns (only)
8837 let listhide= split(g:netrw_list_hide,',')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008838 let entries=[]
8839 for entry in w:netrw_treedict[dir]
8840 for pat in listhide
8841 if entry =~ pat
8842 call add(entries,entry)
8843 break
8844 endif
8845 endfor
8846 endfor
8847 let w:netrw_treedict[dir]= entries
8848 endif
8849 if depth != ""
8850 " always remove "." and ".." entries when there's depth
8851 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
Tom Benham64a536d2024-11-07 21:15:03 +01008852 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\./$"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008853 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 endif
8856
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008857 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008858 if dir =~ '/$'
8859 let direntry= substitute(dir.entry,'[@/]$','','e')
8860 else
8861 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
8862 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008863 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008864 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008865 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008866 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
8867 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
Tom Benham64a536d2024-11-07 21:15:03 +01008868 NetrwKeepj call s:NetrwTreeDisplay(direntry.'@',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008869 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008870 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008871 endif
8872 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008873endfun
8874
8875" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008876" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
8877fun! s:NetrwRefreshTreeDict(dir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008878 if !exists("w:netrw_treedict")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008879 return
8880 endif
8881
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008882 for entry in w:netrw_treedict[a:dir]
8883 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008884
8885 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008886 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Tom Benham64a536d2024-11-07 21:15:03 +01008887 let filelist = s:NetrwLocalListingList(direntry,0)
8888 let w:netrw_treedict[direntry] = sort(filelist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008889
8890 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008891 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Tom Benham64a536d2024-11-07 21:15:03 +01008892 let filelist = s:NetrwLocalListingList(direntry.'/',0)
8893 let w:netrw_treedict[direntry] = sort(filelist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008894
8895 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008896 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008897 let liststar = s:NetrwGlob(direntry.'/','*',1)
8898 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008899
8900 else
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008901 endif
8902 endfor
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008903endfun
8904
8905" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008906" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008907" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008908fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008909 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00008910
8911 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00008912 if !exists("w:netrw_treetop")
8913 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008914 let s:netrw_treetop= w:netrw_treetop
Tom Benham4d618002024-10-31 10:47:23 +01008915 " use \V in case the directory contains specials chars like '$' or '~'
8916 elseif (w:netrw_treetop =~ ('^'.'\V'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop))
8917 \ || a:dirname !~ ('^'.'\V'.w:netrw_treetop)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008918 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008919 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00008920 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008921 if exists("w:netrw_treetop")
8922 let s:netrw_treetop= w:netrw_treetop
8923 else
8924 let w:netrw_treetop= getcwd()
8925 let s:netrw_treetop= w:netrw_treetop
8926 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008927
Bram Moolenaar446cb832008-06-24 21:56:24 +00008928 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008929 " insure that we have a treedict, albeit empty
Bram Moolenaar446cb832008-06-24 21:56:24 +00008930 let w:netrw_treedict= {}
8931 endif
8932
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008933 " update the dictionary for the current directory
Christian Brabandta063b222024-11-07 14:30:30 +01008934 exe "sil! NetrwKeepj keepp ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008935 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008936 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008937
8938 " if past banner, record word
8939 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
8940 let fname= expand("<cword>")
8941 else
8942 let fname= ""
8943 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008944
8945 " display from treetop on down
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008946 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008947
8948 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
8949 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaar8d043172014-01-23 14:24:41 +01008950 1d
8951 endwhile
8952
Bram Moolenaar13600302014-05-22 18:26:40 +02008953 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00008954
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008955 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008956 endif
8957endfun
8958
8959" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008960" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01008961" Normally, treetop is w:netrw_treetop, but a
8962" user of the function ( netrw#SetTreetop() )
8963" wipes that out prior to calling this function
8964fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008965" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
8966 if line(".") < w:netrw_bannercnt + 2
8967 let treedir= a:treetop
8968 if treedir !~ '/$'
8969 let treedir= treedir.'/'
8970 endif
8971" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
8972 return treedir
8973 endif
8974
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008975 let svpos = winsaveview()
8976" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008977 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008978" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008979 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008980" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
8981 let curline= getline('.')
8982" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
8983 if curline =~ '/$'
8984" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
8985 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
8986" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
8987 elseif curline =~ '@\s\+-->'
8988" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
8989 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
8990 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
8991" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008992 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008993" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008994 let treedir= ""
8995 endif
8996 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008997" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
8998" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008999 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9000 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9001 let treedir= dirname.treedir
9002 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009003" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009004 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009005" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009006 if a:treetop =~ '/$'
9007 let treedir= a:treetop.treedir
9008 else
9009 let treedir= a:treetop.'/'.treedir
9010 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009011" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009012 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009013" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009014" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9015 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009016" call Dret("s:NetrwTreePath <".treedir.">")
9017 return treedir
9018endfun
9019
9020" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009021" s:NetrwWideListing: {{{2
9022fun! s:NetrwWideListing()
9023
9024 if w:netrw_liststyle == s:WIDELIST
9025" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9026 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009027 " cpf: characters per filename
9028 " fpl: filenames per line
9029 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009030 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009031 let dict={}
9032 " save the unnamed register and register 0-9 and a
9033 let dict.a=[getreg('a'), getregtype('a')]
9034 for i in range(0, 9)
9035 let dict[i] = [getreg(i), getregtype(i)]
9036 endfor
9037 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009038" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009039 let b:netrw_cpf= 0
9040 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009041 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009042 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9043 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009044 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009045 " restore stored registers
9046 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009047" call Dret("NetrwWideListing")
9048 return
9049 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009050 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009051 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009052" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009053
9054 " determine qty files per line (fpl)
9055 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9056 if w:netrw_fpl <= 0
9057 let w:netrw_fpl= 1
9058 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009059" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009060
9061 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009062 " fpc: files per column of wide listing
9063 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009064 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009065 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9066 let newcolstart = w:netrw_bannercnt + fpc
9067 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009068" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009069 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009070" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009071 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009072 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009073 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009074 while line("$") >= newcolstart
9075 if newcolend > line("$") | let newcolend= line("$") | endif
9076 let newcolqty= newcolend - newcolstart
9077 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009078 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009079 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009080 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009081 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009082 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009083 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009084 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009085 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009086 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009087 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009088" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009089 if @* != keepregstar | sil! let @* = keepregstar | endif
9090 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009091 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009092 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9093 NetrwKeepj call histdel("/",-1)
9094 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9095 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009096" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009097 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009098 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009099" 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 +00009100" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009101 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009102 else
9103 if hasmapto("w","n")
9104 sil! nunmap <buffer> w
9105 endif
9106 if hasmapto("b","n")
9107 sil! nunmap <buffer> b
9108 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009109 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009110endfun
9111
9112" ---------------------------------------------------------------------
9113" s:PerformListing: {{{2
9114fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009115" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9116" 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 +02009117" 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>"))
9118 sil! NetrwKeepj %d _
9119" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009120
Bram Moolenaar15146672011-10-20 22:22:38 +02009121 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009122" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009123 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009124
Bram Moolenaar85850f32019-07-19 22:05:51 +02009125 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009126 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009127" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009128
9129" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009130" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009131" endif " Decho
9132
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009133" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009134 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9135 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009136" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9137 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009138 endif
9139
9140 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009141 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009142
9143 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009144 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009145" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009146 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009147 if exists("g:netrw_pchk")
9148 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9149 " failure detections.
9150 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009151 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009152 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9153 endif
9154 if exists("g:netrw_pchk")
9155 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9156 else
9157 let curdir= b:netrw_curdir
9158 endif
9159 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9160 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9161 else
9162 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009163 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009164 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009165 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009166 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009167" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009168 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009169 let w:netrw_bannercnt= 1
9170 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009171" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9172" 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 +00009173
Bram Moolenaar85850f32019-07-19 22:05:51 +02009174 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009175 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009176 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009177 let sortby= sortby." reversed"
9178 endif
9179
9180 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009181 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009182" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009183 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009184" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009185 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009186 NetrwKeepj put ='\" Sorted by '.sortby
9187 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009188 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9189 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009190" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009191 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009192 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009193 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9194 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009195 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009196" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009197" 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 +00009198 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009199
Bram Moolenaar85850f32019-07-19 22:05:51 +02009200 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009201 if g:netrw_banner
9202 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009203" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009204 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009205 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009206 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009207 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009208 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009209 endif
9210 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009211 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009212" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009213 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009214 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009215 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009216
9217 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009218 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009219" 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 +01009220 if g:netrw_list_hide != "" && g:netrw_hide
9221 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009222 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009223 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009224 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009225 endif
9226 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009227 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009228 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009229
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009230" 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 +01009231 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009232" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009233 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009234" 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 +01009235 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009236 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009237" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009238" 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 +00009239 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009240
9241 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009242 if g:netrw_banner
9243 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009244 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009245" 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 +01009246" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009247" 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 +01009248 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009249
Bram Moolenaar446cb832008-06-24 21:56:24 +00009250 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009251" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009252 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009253 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009254 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009255 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009256 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009257" 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 +01009258" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9259 return
9260 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009261 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009262
9263 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009264 if !exists("w:netrw_bannercnt")
9265 let w:netrw_bannercnt= 0
9266 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009267" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
9268" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
9269" 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 +01009270
Bram Moolenaar5c736222010-01-06 20:54:52 +01009271 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009272" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009273" 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 +00009274 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009275 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009276 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009277 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009278" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009279
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009280 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009281 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +02009282" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009283 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009284
Bram Moolenaar5c736222010-01-06 20:54:52 +01009285 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009286" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009287 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +02009288 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009289 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009290 else
9291 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009292 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009293 endif
9294 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009295
Bram Moolenaar446cb832008-06-24 21:56:24 +00009296 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009297" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009298 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
9299 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009300
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009301 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +02009302 " exten: sort by extension
9303 " The histdel(...,-1) calls remove the last search from the search history
9304" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009305 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
9306 NetrwKeepj call histdel("/",-1)
9307 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
9308 NetrwKeepj call histdel("/",-1)
9309 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
9310 NetrwKeepj call histdel("/",-1)
9311 if !g:netrw_banner || w:netrw_bannercnt < line("$")
9312" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009313 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009314 " normal direction sorting
9315 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
9316 else
9317 " reverse direction sorting
9318 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
9319 endif
9320 endif
9321 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
9322 NetrwKeepj call histdel("/",-1)
9323
Bram Moolenaar446cb832008-06-24 21:56:24 +00009324 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01009325 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009326" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009327 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009328" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009329 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009330 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009331" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009332 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009333 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009334" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009335 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
9336 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009337 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009338 endif
9339
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009340 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009341" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009342 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009343 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009344 call histdel("/",-1)
9345 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009346 endif
9347 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009348" 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 +00009349
9350 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009351" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
9352" 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 +01009353 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009354" 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 +01009355 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
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#3)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009357
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009358 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009359 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009360" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Christian Brabandta063b222024-11-07 14:30:30 +01009361 sil! keepp g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009362 endif
9363
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009364 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009365 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009366" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
9367 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009368 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009369" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
9370 else
9371" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
9372" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
9373" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
9374" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009375 endif
9376
9377 " record previous current directory
9378 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009379" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009380
9381 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009382" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
9383" 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 +01009384 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009385" 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 +02009386 NetrwKeepj call s:NetrwOptionsRestore("w:")
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#6)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009388
9389 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009390" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02009391 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009392" 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 +01009393 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009394" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009395 exe "setl ts=".(g:netrw_maxfilenamelen+1)
9396 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009397" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009398" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009399
Bram Moolenaar8d043172014-01-23 14:24:41 +01009400 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009401" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
9402" 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 +01009403" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
9404 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009405 unlet s:treecurpos
9406 endif
9407
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009408" 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>"))
9409" 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 +00009410" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
9411endfun
9412
9413" ---------------------------------------------------------------------
9414" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00009415fun! s:SetupNetrwStatusLine(statline)
9416" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
9417
9418 if !exists("s:netrw_setup_statline")
9419 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009420" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00009421
9422 if !exists("s:netrw_users_stl")
9423 let s:netrw_users_stl= &stl
9424 endif
9425 if !exists("s:netrw_users_ls")
9426 let s:netrw_users_ls= &laststatus
9427 endif
9428
9429 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +02009430 let dict={}
9431 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +00009432 redir @a
9433 try
9434 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009435 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +00009436 if &bg == "dark"
9437 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
9438 else
9439 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
9440 endif
9441 endtry
9442 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +02009443 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +00009444 endif
9445
9446 " set up status line (may use User9 highlighting)
9447 " insure that windows have a statusline
9448 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +09009449 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +02009450 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009451" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009452 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +00009453
9454" call Dret("SetupNetrwStatusLine : stl=".&stl)
9455endfun
9456
Bram Moolenaar85850f32019-07-19 22:05:51 +02009457" =========================================
9458" Remote Directory Browsing Support: {{{1
9459" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00009460
9461" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01009462" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
9463" This function assumes that a long listing will be received. Size, time,
9464" and reverse sorts will be requested of the server but not otherwise
9465" enforced here.
9466fun! s:NetrwRemoteFtpCmd(path,listcmd)
9467" 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 +01009468" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009469 " sanity check: {{{3
9470 if !exists("w:netrw_method")
9471 if exists("b:netrw_method")
9472 let w:netrw_method= b:netrw_method
9473 else
9474 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
9475" call Dret("NetrwRemoteFtpCmd")
9476 return
9477 endif
9478 endif
9479
9480 " WinXX ftp uses unix style input, so set ff to unix " {{{3
9481 let ffkeep= &ff
9482 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009483" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009484
9485 " clear off any older non-banner lines " {{{3
9486 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009487" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
9488 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +01009489
9490 ".........................................
9491 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
9492 " ftp + <.netrc>: Method #2
9493 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009494 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009495 endif
9496 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009497 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009498" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009499 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009500 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009501" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +01009502 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009503" 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>"))
9504 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 +01009505 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009506" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
9507 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 +01009508 endif
9509
9510 ".........................................
9511 elseif w:netrw_method == 3 " {{{3
9512 " ftp + machine,id,passwd,filename: Method #3
9513 setl ff=unix
9514 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009515 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +01009516 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009517 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +01009518 endif
9519
9520 " handle userid and password
9521 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009522" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009523 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
9524 call NetUserPass("ftp:".host)
9525 endif
9526 if exists("g:netrw_uid") && g:netrw_uid != ""
9527 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009528 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +01009529 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009530 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009531 endif
9532 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009533 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009534 endif
9535 endif
9536
9537 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009538 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009539 endif
9540 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009541 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009542" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009543 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009544 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +01009545
9546 " perform ftp:
9547 " -i : turns off interactive prompting from ftp
9548 " -n unix : DON'T use <.netrc>, even though it exists
9549 " -n win32: quit being obnoxious about password
9550 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009551" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009552 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +01009553" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009554" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
9555" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009556 endif
9557
9558 ".........................................
9559 elseif w:netrw_method == 9 " {{{3
9560 " sftp username@machine: Method #9
9561 " s:netrw_sftp_cmd
9562 setl ff=unix
9563
9564 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +09009565 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +01009566" call Dret("NetrwRemoteFtpCmd")
9567 return
9568
9569 ".........................................
9570 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009571 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +01009572 endif
9573
9574 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +02009575 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009576 sil! NetrwKeepj %s/\r$//e
9577 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009578 endif
9579 if a:listcmd == "dir"
9580 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009581 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
9582 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
9583 NetrwKeepj call histdel("/",-1)
9584 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009585 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 +01009586 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
9587 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009588 endif
9589 endif
9590
9591 " ftp's listing doesn't seem to include ./ or ../ " {{{3
9592 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009593 exe 'NetrwKeepj '.w:netrw_bannercnt
9594 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +01009595 endif
9596 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009597 exe 'NetrwKeepj '.w:netrw_bannercnt
9598 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +01009599 endif
9600
9601 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +09009602 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +01009603" call Dret("NetrwRemoteFtpCmd")
9604endfun
9605
9606" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009607" s:NetrwRemoteListing: {{{2
9608fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009609" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00009610
Bram Moolenaara6878372014-03-22 21:02:50 +01009611 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
9612 let w:netrw_bannercnt= s:bannercnt
9613 endif
9614 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +09009615 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009616 endif
9617
Bram Moolenaar446cb832008-06-24 21:56:24 +00009618 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009619
Bram Moolenaar446cb832008-06-24 21:56:24 +00009620 " sanity check:
9621 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009622" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009623 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009624" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009625 if !exists("g:netrw_quiet")
9626 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
9627 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009628 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009629" call Dret("s:NetrwRemoteListing -1")
9630 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00009631 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009632
Bram Moolenaar8d043172014-01-23 14:24:41 +01009633 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009634" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009635 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009636 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009637 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 +00009638 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009639 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 +00009640 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009641 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009642
Bram Moolenaar85850f32019-07-19 22:05:51 +02009643 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009644" call Dret("s:NetrwRemoteListing -1")
9645 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009646 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009647" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009648
Bram Moolenaar446cb832008-06-24 21:56:24 +00009649 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009650" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009651 let w:netrw_method= b:netrw_method
9652 endif
9653
Bram Moolenaar13600302014-05-22 18:26:40 +02009654 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +02009655 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009656" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009657 let s:method = "ftp"
9658 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009659 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009660 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009661 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009662 let listcmd= g:netrw_ftp_sizelist_cmd
9663 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009664" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009665 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009666" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009667
Bram Moolenaara6878372014-03-22 21:02:50 +01009668 " report on missing file or directory messages
9669 if search('[Nn]o such file or directory\|Failed to change directory')
9670 let mesg= getline(".")
9671 if exists("w:netrw_bannercnt")
9672 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009673 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +01009674 setl noma
9675 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009676 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009677 call netrw#ErrorMsg(s:WARNING,mesg,96)
9678" call Dret("s:NetrwRemoteListing : -1")
9679 return -1
9680 endif
9681
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009682 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 +00009683 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009684" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009685 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009686
9687 " cleanup
9688 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009689 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
9690 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009691 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009692 sil! NetrwKeepj %s/\r$//e
9693 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009694
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009695 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +00009696 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009697 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +01009698 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009699" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009700 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009701" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009702 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009703 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009704 exe "sil! NetrwKeepj ".line1
9705 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009706
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009707" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009708 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009709" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009710 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
9711 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009712 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009713" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009714 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
9715 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
9716 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
9717 NetrwKeepj call histdel("/",-1)
9718 NetrwKeepj call histdel("/",-1)
9719 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009720 endif
9721 endif
9722
Bram Moolenaar13600302014-05-22 18:26:40 +02009723 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00009724 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009725" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009726 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009727" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009728 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009729" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
9730 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009731 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009732 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
9733 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
9734 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
9735 NetrwKeepj call histdel("/",-1)
9736 NetrwKeepj call histdel("/",-1)
9737 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009738 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009739 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
9740 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009741 endif
9742 else
9743 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009744" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009745 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00009746 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009747" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
9748 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
9749" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009750 endif
9751 endif
9752
9753 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +01009754 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009755" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009756 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
9757 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009758 endif
9759 endif
9760
9761 if w:netrw_liststyle == s:LONGLIST
9762 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009763" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009764
9765 if s:method == "ftp"
9766 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009767 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009768 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009769 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +00009770 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009771 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +00009772 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009773 sil! NetrwKeepj 1
9774 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009775 let line2= line(".")
9776 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009777 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009778 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009779 endif
9780 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009781 exe "sil! NetrwKeepj ".line1
9782 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009783 endif
9784
9785 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009786" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009787 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 +00009788 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009789" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009790 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009791 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009792 exe 'sil NetrwKeepj '.w:netrw_bannercnt
9793 NetrwKeepj call histdel("/",-1)
9794 NetrwKeepj call histdel("/",-1)
9795 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009796 endif
9797 endif
9798
9799" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009800" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009801" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01009802
9803" call Dret("s:NetrwRemoteListing 0")
9804 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009805endfun
9806
Bram Moolenaar446cb832008-06-24 21:56:24 +00009807" ---------------------------------------------------------------------
9808" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
9809fun! s:NetrwRemoteRm(usrhost,path) range
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009810 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009811
9812 let all= 0
9813 if exists("s:netrwmarkfilelist_{bufnr('%')}")
9814 " remove all marked files
9815 for fname in s:netrwmarkfilelist_{bufnr("%")}
9816 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009817 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009818 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009819 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009820 let all= 1
9821 endif
9822 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01009823 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009824
9825 else
9826 " remove files specified by range
9827
9828 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009829 let keepsol = &l:sol
9830 setl nosol
9831 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +00009832
9833 " remove multiple files and directories
9834 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009835 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009836 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009837 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009838 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009839 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009840 let all= 1
9841 endif
9842 let ctr= ctr + 1
9843 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009844 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +00009845 endif
9846
9847 " refresh the (remote) directory listing
Tom Benham64a536d2024-11-07 21:15:03 +01009848 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009849 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009850endfun
9851
9852" ---------------------------------------------------------------------
9853" s:NetrwRemoteRmFile: {{{2
9854fun! s:NetrwRemoteRmFile(path,rmfile,all)
9855" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
9856
9857 let all= a:all
9858 let ok = ""
9859
9860 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
9861 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009862" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009863 if !all
9864 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009865" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009866 call inputsave()
9867 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
9868 call inputrestore()
9869 echohl NONE
9870 if ok == ""
9871 let ok="no"
9872 endif
9873 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009874 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009875 let all= 1
9876 endif
9877 endif
9878
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009879 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009880" 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 +00009881 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009882" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009883 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009884 if path =~ '^\a\{3,}://'
9885 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009886 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009887 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009888 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
9889 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009890" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009891 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009892" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009893 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009894 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009895 let ok="q"
9896 else
MiguelBarroc46c21b2024-01-31 20:07:17 +01009897 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009898" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
9899" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
9900" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009901 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009902 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009903 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009904 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009905 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009906" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009907 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009908 if v:shell_error != 0
9909 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09009910 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 +01009911 else
9912 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
9913 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009914 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009915 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009916 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009917" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009918 endif
9919 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009920 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009921" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009922 endif
9923
9924 else
9925 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009926" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009927 if !all
9928 call inputsave()
9929 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
9930 call inputrestore()
9931 if ok == ""
9932 let ok="no"
9933 endif
9934 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009935 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009936 let all= 1
9937 endif
9938 endif
9939
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009940 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00009941 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009942 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009943 else
9944 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009945 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
9946" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00009947 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009948" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009949
9950 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009951" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
9952 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
9953" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00009954 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009955" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009956
9957 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009958 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009959 endif
9960 endif
9961 endif
9962
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009963 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009964" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009965 endif
9966 endif
9967
9968" call Dret("s:NetrwRemoteRmFile ".ok)
9969 return ok
9970endfun
9971
9972" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009973" s:NetrwRemoteRename: rename a remote file or directory {{{2
9974fun! s:NetrwRemoteRename(usrhost,path) range
Bram Moolenaar446cb832008-06-24 21:56:24 +00009975
9976 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009977 let svpos = winsaveview()
9978" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009979 let ctr = a:firstline
9980 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
9981
9982 " rename files given by the markfilelist
9983 if exists("s:netrwmarkfilelist_{bufnr('%')}")
9984 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00009985 if exists("subfrom")
9986 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009987 else
9988 call inputsave()
9989 let newname= input("Moving ".oldname." to : ",oldname)
9990 call inputrestore()
9991 if newname =~ '^s/'
9992 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
9993 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
9994 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009995 endif
9996 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009997
Bram Moolenaar446cb832008-06-24 21:56:24 +00009998 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009999 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010000 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010001 let oldname= s:ShellEscape(a:path.oldname)
10002 let newname= s:ShellEscape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010003 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010004 endif
10005
10006 endfor
10007 call s:NetrwUnMarkFile(1)
10008
10009 else
10010
10011 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010012 let keepsol= &l:sol
10013 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010014 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010015 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010016
10017 let oldname= s:NetrwGetWord()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010018
10019 call inputsave()
10020 let newname= input("Moving ".oldname." to : ",oldname)
10021 call inputrestore()
10022
10023 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10024 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10025 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010026 let oldname= s:ShellEscape(a:path.oldname)
10027 let newname= s:ShellEscape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010028 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010029 endif
10030
10031 let ctr= ctr + 1
10032 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010033 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010034 endif
10035
10036 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010037 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010038 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010039endfun
10040
Bram Moolenaar85850f32019-07-19 22:05:51 +020010041" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010042" Local Directory Browsing Support: {{{1
10043" ==========================================
10044
10045" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010046" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010047" Should accept: file://localhost/etc/fstab
10048" file:///etc/fstab
10049" file:///c:/WINDOWS/clock.avi
10050" file:///c|/WINDOWS/clock.avi
10051" file://localhost/c:/WINDOWS/clock.avi
10052" file://localhost/c|/WINDOWS/clock.avi
10053" file://c:/foo.txt
10054" file:///c:/foo.txt
10055" 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 +020010056fun! netrw#FileUrlEdit(fname)
10057" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010058 let fname = a:fname
10059 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010060" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010061 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010062" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010063 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010064 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010065 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010066" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010067 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010068" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010069 endif
10070 endif
10071 let fname2396 = netrw#RFC2396(fname)
10072 let fname2396e= fnameescape(fname2396)
10073 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010074 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010075" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010076 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010077" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010078 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10079 endif
10080 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010081
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010082" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10083" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010084 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010085 exe 'NetrwKeepj keepalt edit '.plainfname
10086 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10087
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010088" 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 +020010089" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010090 exe "sil doau BufReadPost ".fname2396e
10091endfun
10092
10093" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010094" netrw#LocalBrowseCheck: {{{2
10095fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010096 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010097 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10098 "
10099 " unfortunate interaction -- split window debugging can't be used here, must use
10100 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10101 " another call to LocalBrowseCheck() when attempts to write
10102 " to the DBG buffer are made.
10103 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010104 " The &ft == "netrw" test was installed because the BufEnter event
10105 " would hit when re-entering netrw windows, creating unexpected
10106 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010107" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010108" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010109" 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 +010010110 " getting E930: Cannot use :redir inside execute
10111"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010112" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10113" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010114
Bram Moolenaar97d62492012-11-15 21:28:22 +010010115 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010116 if isdirectory(s:NetrwFile(a:dirname))
10117" 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 +010010118
Bram Moolenaar97d62492012-11-15 21:28:22 +010010119 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010120" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10121" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010122 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010123
Bram Moolenaar446cb832008-06-24 21:56:24 +000010124 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010125" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010126 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010127
Bram Moolenaar5c736222010-01-06 20:54:52 +010010128 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010129" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010130 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010131 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010132 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010133" 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 +010010134" call Dret("netrw#LocalBrowseCheck")
10135 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010136 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010137
Bram Moolenaar85850f32019-07-19 22:05:51 +020010138 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010139 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10140 " AND IF the listing style is not a tree listing
10141 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010142" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010143 let ibuf = 1
10144 let buflast = bufnr("$")
10145 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010146 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10147 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010148 endif
10149 let ibuf= ibuf + 1
10150 endwhile
10151 endif
10152 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010153" 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>"))
10154" 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 +000010155 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010156" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010157endfun
10158
10159" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010160" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010161" performed any shell command. The idea is to cause all local-browsing
10162" buffers to be refreshed after a user has executed some shell command,
10163" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010164fun! s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010165 " determine which buffers currently reside in a tab
10166 if !exists("s:netrw_browselist")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010167 return
10168 endif
10169 if !exists("w:netrw_bannercnt")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010170 return
10171 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010172 if !empty(getcmdwintype())
10173 " cannot move away from cmdline window, see :h E11
10174 return
10175 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010176 if exists("s:netrw_events") && s:netrw_events == 1
10177 " s:LocalFastBrowser gets called (indirectly) from a
10178 let s:netrw_events= 2
Bram Moolenaara6878372014-03-22 21:02:50 +010010179 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010180 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010181 let itab = 1
10182 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010183 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010184 while itab <= tabpagenr("$")
10185 let buftablist = buftablist + tabpagebuflist()
10186 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010187 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010188 endwhile
Bram Moolenaar446cb832008-06-24 21:56:24 +000010189 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10190 " | refresh any netrw window
10191 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010192 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010193 let ibl = 0
10194 for ibuf in s:netrw_browselist
Bram Moolenaar446cb832008-06-24 21:56:24 +000010195 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10196 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010197 " (ibuf not shown in a current window AND
10198 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010199 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010200 call remove(s:netrw_browselist,ibl)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010201 continue
10202 elseif index(tabpagebuflist(),ibuf) != -1
10203 " refresh any netrw buffer
Bram Moolenaar446cb832008-06-24 21:56:24 +000010204 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010205 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010206 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10207 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10208 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10209 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010210 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10211 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10212 endif
Tom Benham64a536d2024-11-07 21:15:03 +010010213 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010214 endif
10215 let ibl= ibl + 1
10216 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010217 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010218 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010219endfun
10220
10221" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010222" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10223"
10224" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010225" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010226" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10227" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010228" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010229"
10230" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
10231" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010010232" (re-using a buffer may not be as accurate)
10233"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010234" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010010235" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
10236" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
10237" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
10238" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010239fun! s:LocalFastBrowser()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010240
10241 " initialize browselist, a list of buffer numbers that the local browser has used
10242 if !exists("s:netrw_browselist")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010243 let s:netrw_browselist= []
10244 endif
10245
10246 " append current buffer to fastbrowse list
10247 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaar97d62492012-11-15 21:28:22 +010010248 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010249 endif
10250
10251 " enable autocmd events to handle refreshing/removing local browser buffers
10252 " If local browse buffer is currently showing: refresh it
10253 " If local browse buffer is currently hidden : wipe it
10254 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
10255 " =1 : medium speed, re-use directory listing for remote only
10256 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010010257 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
10258 let s:netrw_events= 1
10259 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010260 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020010261 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010010262 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010263 else
Bram Moolenaara6878372014-03-22 21:02:50 +010010264 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010265 endif
10266 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010010267
10268 " user must have changed fastbrowse to its fast setting, so remove
10269 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010010270 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara6878372014-03-22 21:02:50 +010010271 unlet s:netrw_events
10272 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010273 au!
10274 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010010275 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010276 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010277endfun
10278
Tom Benham64a536d2024-11-07 21:15:03 +010010279fun! s:NetrwLocalListingList(dirname,setmaxfilenamelen)
Bram Moolenaara6878372014-03-22 21:02:50 +010010280 " get the list of files contained in the current directory
Tom Benham64a536d2024-11-07 21:15:03 +010010281 let dirname = a:dirname
10282 let dirnamelen = strlen(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010283 let filelist = s:NetrwGlob(dirname,"*",0)
10284 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara6878372014-03-22 21:02:50 +010010285
Nir Lichtman1e34b952024-05-08 19:19:34 +020010286 if g:netrw_cygwin == 0 && has("win32")
Tom Benham64a536d2024-11-07 21:15:03 +010010287 elseif index(filelist,'..') == -1 && dirname !~ '/'
Bram Moolenaara6878372014-03-22 21:02:50 +010010288 " include ../ in the glob() entry if its missing
Tom Benham64a536d2024-11-07 21:15:03 +010010289 let filelist= filelist+[s:ComposePath(dirname,"../")]
Bram Moolenaara6878372014-03-22 21:02:50 +010010290 endif
10291
Tom Benham64a536d2024-11-07 21:15:03 +010010292 if a:setmaxfilenamelen && get(g:, 'netrw_dynamic_maxfilenamelen', 0)
Bram Moolenaara6878372014-03-22 21:02:50 +010010293 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
10294 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara6878372014-03-22 21:02:50 +010010295 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010296
Tom Benham64a536d2024-11-07 21:15:03 +010010297 let resultfilelist = []
Bram Moolenaara6878372014-03-22 21:02:50 +010010298 for filename in filelist
Bram Moolenaara6878372014-03-22 21:02:50 +010010299
10300 if getftype(filename) == "link"
10301 " indicate a symbolic link
Bram Moolenaara6878372014-03-22 21:02:50 +010010302 let pfile= filename."@"
10303
10304 elseif getftype(filename) == "socket"
10305 " indicate a socket
Bram Moolenaara6878372014-03-22 21:02:50 +010010306 let pfile= filename."="
10307
10308 elseif getftype(filename) == "fifo"
10309 " indicate a fifo
Bram Moolenaara6878372014-03-22 21:02:50 +010010310 let pfile= filename."|"
10311
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010312 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010313 " indicate a directory
Bram Moolenaara6878372014-03-22 21:02:50 +010010314 let pfile= filename."/"
10315
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010316 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020010317 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010010318 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
10319 " indicate an executable
Bram Moolenaara6878372014-03-22 21:02:50 +010010320 let pfile= filename."*"
10321 else
10322 " normal file
10323 let pfile= filename
10324 endif
10325 elseif executable(filename)
10326 " indicate an executable
Bram Moolenaara6878372014-03-22 21:02:50 +010010327 let pfile= filename."*"
10328 else
10329 " normal file
10330 let pfile= filename
10331 endif
10332
10333 else
10334 " normal file
10335 let pfile= filename
10336 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010337
10338 if pfile =~ '//$'
10339 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara6878372014-03-22 21:02:50 +010010340 endif
10341 let pfile= strpart(pfile,dirnamelen)
10342 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara6878372014-03-22 21:02:50 +010010343
10344 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090010345 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
10346 let sz = getfsize(filename)
10347 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
10348 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010010349
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010350 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010351 let sz= s:NetrwHumanReadable(sz)
10352 endif
K.Takata8750e3c2023-11-22 18:20:01 +090010353 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090010354 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010355 endif
10356
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010357 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010010358 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010010359 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaara6878372014-03-22 21:02:50 +010010360 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090010361 let ft = printf("%018d",t)
Bram Moolenaara6878372014-03-22 21:02:50 +010010362 let ftpfile= ft.'/'.pfile
Tom Benham64a536d2024-11-07 21:15:03 +010010363 let resultfilelist += [ftpfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010364
10365 elseif g:netrw_sort_by =~ "^s"
10366 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaara6878372014-03-22 21:02:50 +010010367 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090010368 let fsz = printf("%018d",sz)
Bram Moolenaara6878372014-03-22 21:02:50 +010010369 let fszpfile= fsz.'/'.pfile
Tom Benham64a536d2024-11-07 21:15:03 +010010370 let resultfilelist += [fszpfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010371
10372 else
10373 " sort by name
Tom Benham64a536d2024-11-07 21:15:03 +010010374 let resultfilelist += [pfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010375 endif
Tom Benham64a536d2024-11-07 21:15:03 +010010376 endfor
10377
10378 return resultfilelist
10379endfun
10380
10381" ---------------------------------------------------------------------
10382" s:LocalListing: does the job of "ls" for local directories {{{2
10383fun! s:LocalListing()
10384
10385 let filelist = s:NetrwLocalListingList(b:netrw_curdir, 1)
10386 for filename in filelist
10387 sil! NetrwKeepj put =filename
Bram Moolenaara6878372014-03-22 21:02:50 +010010388 endfor
10389
10390 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010391 sil! NetrwKeepj g/^$/d
10392 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010010393 call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010394 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010395endfun
10396
10397" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010398" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
10399fun! s:NetrwLocalExecute(cmd)
10400" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
10401 let ykeep= @@
10402 " sanity check
10403 if !executable(a:cmd)
10404 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
10405 let @@= ykeep
10406" call Dret("s:NetrwLocalExecute")
10407 return
10408 endif
10409
10410 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010411" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010412 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010413" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010414
10415 " strip any ansi escape sequences off
10416 let result = substitute(result,"\e\\[[0-9;]*m","","g")
10417
10418 " show user the result(s)
10419 echomsg result
10420 let @@= ykeep
10421
10422" call Dret("s:NetrwLocalExecute")
10423endfun
10424
10425" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010426" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010427fun! s:NetrwLocalRename(path) range
Bram Moolenaar97d62492012-11-15 21:28:22 +010010428
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010429 if !exists("w:netrw_bannercnt")
10430 let w:netrw_bannercnt= b:netrw_bannercnt
10431 endif
10432
Bram Moolenaar97d62492012-11-15 21:28:22 +010010433 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010010434 let ykeep = @@
10435 let ctr = a:firstline
10436 let svpos = winsaveview()
10437 let all = 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010010438
10439 " rename files given by the markfilelist
10440 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10441 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar97d62492012-11-15 21:28:22 +010010442 if exists("subfrom")
10443 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaar97d62492012-11-15 21:28:22 +010010444 else
10445 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010446 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010447 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010448 if newname =~ ''
10449 " two ctrl-x's : ignore all of string preceding the ctrl-x's
10450 let newname = substitute(newname,'^.*','','')
10451 elseif newname =~ ''
10452 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
10453 let newname = substitute(newname,'[^/]*','','')
10454 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010455 if newname =~ '^s/'
10456 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10457 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaar97d62492012-11-15 21:28:22 +010010458 let newname = substitute(oldname,subfrom,subto,'')
10459 endif
10460 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010010461 if !all && filereadable(newname)
10462 call inputsave()
10463 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
10464 call inputrestore()
10465 if response == "all"
10466 let all= 1
10467 elseif response != "y" && response != "yes"
10468 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010469 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaar29634562020-01-09 21:46:04 +010010470 NetrwKeepj call winrestview(svpos)
10471 let @@= ykeep
Bram Moolenaar29634562020-01-09 21:46:04 +010010472 return
10473 endif
10474 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010475 call rename(oldname,newname)
10476 endfor
10477 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010478
Bram Moolenaar97d62492012-11-15 21:28:22 +010010479 else
10480
10481 " attempt to rename files/directories
10482 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010483 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010010484
10485 " sanity checks
10486 if line(".") < w:netrw_bannercnt
10487 let ctr= ctr + 1
10488 continue
10489 endif
10490 let curword= s:NetrwGetWord()
10491 if curword == "./" || curword == "../"
10492 let ctr= ctr + 1
10493 continue
10494 endif
10495
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010496 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010010497 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010498
10499 call inputsave()
10500 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
10501 call inputrestore()
10502
10503 call rename(oldname,newname)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010504 let ctr= ctr + 1
10505 endwhile
10506 endif
10507
10508 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010509 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010510 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010511 let @@= ykeep
Bram Moolenaar97d62492012-11-15 21:28:22 +010010512endfun
10513
10514" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010515" s:NetrwLocalRm: {{{2
10516fun! s:NetrwLocalRm(path) range
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010517 if !exists("w:netrw_bannercnt")
10518 let w:netrw_bannercnt= b:netrw_bannercnt
10519 endif
10520
Bram Moolenaar446cb832008-06-24 21:56:24 +000010521 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010010522 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010523 let ret = 0
10524 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010525 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010526
10527 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10528 " remove all marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +000010529 for fname in s:netrwmarkfilelist_{bufnr("%")}
10530 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010531 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010532 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010533 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010534 let all= 1
10535 endif
10536 endfor
10537 call s:NetrwUnMarkFile(1)
10538
10539 else
10540 " remove (multiple) files and directories
Bram Moolenaar446cb832008-06-24 21:56:24 +000010541
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010542 let keepsol= &l:sol
10543 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010544 let ctr = a:firstline
10545 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010546 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010547
10548 " sanity checks
10549 if line(".") < w:netrw_bannercnt
10550 let ctr= ctr + 1
10551 continue
10552 endif
10553 let curword= s:NetrwGetWord()
10554 if curword == "./" || curword == "../"
10555 let ctr= ctr + 1
10556 continue
10557 endif
10558 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010559 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010560 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010561 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010562 let all= 1
10563 endif
10564 let ctr= ctr + 1
10565 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010566 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010567 endif
10568
10569 " refresh the directory
Bram Moolenaar446cb832008-06-24 21:56:24 +000010570 if bufname("%") != "NetrwMessage"
Tom Benham64a536d2024-11-07 21:15:03 +010010571 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010572 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010573 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010574 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010575endfun
10576
10577" ---------------------------------------------------------------------
10578" s:NetrwLocalRmFile: remove file fname given the path {{{2
10579" Give confirmation prompt unless all==1
10580fun! s:NetrwLocalRmFile(path,fname,all)
10581" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010582
Bram Moolenaar446cb832008-06-24 21:56:24 +000010583 let all= a:all
10584 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010585 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020010586 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010587" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010588
10589 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
10590 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010591" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010592 if !all
10593 echohl Statement
10594 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020010595 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010596 call inputrestore()
10597 echohl NONE
10598 if ok == ""
10599 let ok="no"
10600 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010601" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010602 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010603" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010604 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010605 let all= 1
10606 endif
10607 endif
10608
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010609 if all || ok =~# '^y\%[es]$' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000010610 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010611" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010612 endif
10613
10614 else
10615 " attempt to remove directory
10616 if !all
10617 echohl Statement
10618 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020010619 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010620 call inputrestore()
10621 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
10622 if ok == ""
10623 let ok="no"
10624 endif
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010625 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010626 let all= 1
10627 endif
10628 endif
10629 let rmfile= substitute(rmfile,'[\/]$','','e')
10630
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010631 if all || ok =~# '^y\%[es]$' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020010632 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010010633 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010634 endif
10635 endif
10636 endif
10637
10638" call Dret("s:NetrwLocalRmFile ".ok)
10639 return ok
10640endfun
10641
Bram Moolenaar85850f32019-07-19 22:05:51 +020010642" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010643" Support Functions: {{{1
10644
Bram Moolenaar488c6512005-08-11 20:09:58 +000010645" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010646" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
10647" 0: marked file list of current buffer
10648" 1: marked file target
10649fun! netrw#Access(ilist)
10650 if a:ilist == 0
10651 if exists("s:netrwmarkfilelist_".bufnr('%'))
10652 return s:netrwmarkfilelist_{bufnr('%')}
10653 else
10654 return "no-list-buf#".bufnr('%')
10655 endif
10656 elseif a:ilist == 1
10657 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020010658 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010659endfun
10660
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010661" ---------------------------------------------------------------------
10662" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
10663fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010664 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010665endfun
10666
Bram Moolenaara6878372014-03-22 21:02:50 +010010667" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010668" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
10669" I expect this function to be used in
10670" :PChkAssert netrw#Expose("netrwmarkfilelist")
10671" for example.
10672fun! netrw#Expose(varname)
10673" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010674 if exists("s:".a:varname)
10675 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010676" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010677 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010678" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010679 if type(retval) == 3
10680 let retval = copy(retval)
10681 let i = 0
10682 while i < len(retval)
10683 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
10684 let i = i + 1
10685 endwhile
10686 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010687" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010688 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010689 else
10690" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010691 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010692 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010693" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010694 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010695 endif
10696
10697" call Dret("netrw#Expose ".string(retval))
10698 return retval
10699endfun
10700
10701" ---------------------------------------------------------------------
10702" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
10703fun! netrw#Modify(varname,newvalue)
10704" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
10705 exe "let s:".a:varname."= ".string(a:newvalue)
10706" call Dret("netrw#Modify")
10707endfun
10708
10709" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010710" netrw#RFC2396: converts %xx into characters {{{2
10711fun! netrw#RFC2396(fname)
10712" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090010713 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010010714" call Dret("netrw#RFC2396 ".fname)
10715 return fname
10716endfun
10717
10718" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010719" netrw#UserMaps: supports user-specified maps {{{2
10720" see :help function()
10721"
10722" g:Netrw_UserMaps is a List with members such as:
10723" [[keymap sequence, function reference],...]
10724"
10725" The referenced function may return a string,
10726" refresh : refresh the display
10727" -other- : this string will be executed
10728" or it may return a List of strings.
10729"
10730" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020010731" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010732" Related functions:
10733" netrw#Expose(varname) -- see s:varname variables
10734" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
10735" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
10736fun! netrw#UserMaps(islocal)
10737" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
10738" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
10739
10740 " set up usermaplist
10741 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
10742" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
10743 for umap in g:Netrw_UserMaps
10744" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
10745" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
10746 " if umap[0] is a string and umap[1] is a string holding a function name
10747 if type(umap[0]) == 1 && type(umap[1]) == 1
10748" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
10749 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
10750 else
10751 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
10752 endif
10753 endfor
10754 endif
10755" call Dret("netrw#UserMaps")
10756endfun
10757
10758" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010759" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
10760fun! netrw#WinPath(path)
10761" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010762 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010763 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010010764 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010765 " remove trailing slash (Win95)
10766 let path = substitute(path, '\(\\\|/\)$', '', 'g')
10767 " remove escaped spaces
10768 let path = substitute(path, '\ ', ' ', 'g')
10769 " convert slashes to backslashes
10770 let path = substitute(path, '/', '\', 'g')
10771 else
10772 let path= a:path
10773 endif
10774" call Dret("netrw#WinPath <".path.">")
10775 return path
10776endfun
10777
10778" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020010779" s:StripTrailingSlash: removes trailing slashes from a path {{{2
10780fun! s:StripTrailingSlash(path)
10781 " remove trailing slash
10782 return substitute(a:path, '[/\\]$', '', 'g')
10783endfun
10784
Travis Sheltone34d0e32024-07-30 21:08:56 +020010785" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010786" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
10787" cb : bl2mf=0 add marked files to buffer list
10788" cB : bl2mf=1 use bufferlist to mark files
10789" (mnemonic: cb = copy (marked files) to buffer list)
10790fun! s:NetrwBadd(islocal,bl2mf)
10791" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
10792 if a:bl2mf
10793 " cB: add buffer list to marked files
10794 redir => bufl
10795 ls
10796 redir END
10797 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
10798 for fname in bufl
10799 call s:NetrwMarkFile(a:islocal,fname)
10800 endfor
10801 else
10802 " cb: add marked files to buffer list
10803 for fname in s:netrwmarkfilelist_{bufnr("%")}
10804" " call Decho("badd ".fname,'~'.expand("<slnum>"))
10805 exe "badd ".fnameescape(fname)
10806 endfor
10807 let curbufnr = bufnr("%")
10808 let curdir = s:NetrwGetCurdir(a:islocal)
10809 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
10810 endif
10811" call Dret("s:NetrwBadd")
10812endfun
10813
10814" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000010815" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
10816fun! s:ComposePath(base,subdir)
10817" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
10818
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010819 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010820" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010821 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000010822 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010823 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000010824 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010825 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000010826 endif
10827
Bram Moolenaar85850f32019-07-19 22:05:51 +020010828 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020010829 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010830" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010831 let ret= a:subdir
10832
Nir Lichtman1e34b952024-05-08 19:19:34 +020010833 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010834" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010835 if a:base =~ '[/\\]$'
10836 let ret= a:base.a:subdir
10837 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010838 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010010839 endif
10840
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010841 elseif a:base =~ '^\a\{3,}://'
10842" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010843 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
10844 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
10845 if a:subdir == '../'
10846 if curpath =~ '[^/]/[^/]\+/$'
10847 let curpath= substitute(curpath,'[^/]\+/$','','')
10848 else
10849 let curpath=""
10850 endif
10851 let ret= urlbase.curpath
10852 else
10853 let ret= urlbase.curpath.a:subdir
10854 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010855" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
10856" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
10857" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010858
10859 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010860" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010861 let ret = substitute(a:base."/".a:subdir,"//","/","g")
10862 if a:base =~ '^//'
10863 " keeping initial '//' for the benefit of network share listing support
10864 let ret= '/'.ret
10865 endif
10866 let ret= simplify(ret)
10867 endif
10868
10869" call Dret("s:ComposePath ".ret)
10870 return ret
10871endfun
10872
10873" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010874" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
10875" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
10876fun! s:DeleteBookmark(fname)
10877" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
10878 call s:MergeBookmarks()
10879
10880 if exists("g:netrw_bookmarklist")
10881 let indx= index(g:netrw_bookmarklist,a:fname)
10882 if indx == -1
10883 let indx= 0
10884 while indx < len(g:netrw_bookmarklist)
10885 if g:netrw_bookmarklist[indx] =~ a:fname
10886 call remove(g:netrw_bookmarklist,indx)
10887 let indx= indx - 1
10888 endif
10889 let indx= indx + 1
10890 endwhile
10891 else
10892 " remove exact match
10893 call remove(g:netrw_bookmarklist,indx)
10894 endif
10895 endif
10896
10897" call Dret("s:DeleteBookmark")
10898endfun
10899
10900" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000010901" s:FileReadable: o/s independent filereadable {{{2
10902fun! s:FileReadable(fname)
10903" call Dfunc("s:FileReadable(fname<".a:fname.">)")
10904
10905 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010906 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010907 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010908 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010909 endif
10910
10911" call Dret("s:FileReadable ".ret)
10912 return ret
10913endfun
10914
10915" ---------------------------------------------------------------------
10916" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
10917" Places correct suffix on end of temporary filename,
10918" using the suffix provided with fname
10919fun! s:GetTempfile(fname)
10920" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
10921
10922 if !exists("b:netrw_tmpfile")
10923 " get a brand new temporary filename
10924 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010925" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010926
Bram Moolenaarc236c162008-07-13 17:41:49 +000010927 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010928" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010929
Bram Moolenaar9964e462007-05-05 17:54:07 +000010930 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010931 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
10932" 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 +010010933 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010934" call Dret("s:GetTempfile getcwd<".getcwd().">")
10935 return ""
10936 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010937
Bram Moolenaar9964e462007-05-05 17:54:07 +000010938 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010939 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010940" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010941
Bram Moolenaar9964e462007-05-05 17:54:07 +000010942 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000010943 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010010944 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020010945 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010946 if !exists("+shellslash") || !&ssl
10947 let tmpfile = substitute(tmpfile,'/','\','g')
10948 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010949 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010950 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000010951 endif
10952 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010953" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010954 else
10955 " re-use temporary filename
10956 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010957" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010958 endif
10959
10960 " use fname's suffix for the temporary file
10961 if a:fname != ""
10962 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010963" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010964 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000010965 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010966 elseif a:fname =~ '.txz$'
10967 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000010968 else
10969 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
10970 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010971" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010972 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010973" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010974 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010975" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010976 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
10977 endif
10978 endif
10979
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010980" 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 +000010981" call Dret("s:GetTempfile <".tmpfile.">")
10982 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000010983endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000010984
10985" ---------------------------------------------------------------------
10986" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000010987" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000010988fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010989" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020010990 if s:user == ""
10991 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
10992 else
10993 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
10994 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010995 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000010996 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000010997 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000010998 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000010999 else
11000 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11001 endif
11002" call Dret("s:MakeSshCmd <".sshcmd.">")
11003 return sshcmd
11004endfun
11005
11006" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011007" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11008fun! s:MakeBookmark(fname)
11009" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11010
11011 if !exists("g:netrw_bookmarklist")
11012 let g:netrw_bookmarklist= []
11013 endif
11014
11015 if index(g:netrw_bookmarklist,a:fname) == -1
11016 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011017 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011018 call add(g:netrw_bookmarklist,a:fname.'/')
11019 elseif a:fname !~ '/'
11020 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11021 else
11022 call add(g:netrw_bookmarklist,a:fname)
11023 endif
11024 call sort(g:netrw_bookmarklist)
11025 endif
11026
11027" call Dret("s:MakeBookmark")
11028endfun
11029
11030" ---------------------------------------------------------------------
11031" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11032fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011033" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011034 " get bookmarks from .netrwbook file
11035 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011036 if filereadable(s:NetrwFile(savefile))
11037" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011038 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011039" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011040 NetrwKeepj call delete(savefile)
11041 endif
11042" call Dret("s:MergeBookmarks")
11043endfun
11044
11045" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011046" s:NetrwBMShow: {{{2
11047fun! s:NetrwBMShow()
11048" call Dfunc("s:NetrwBMShow()")
11049 redir => bmshowraw
11050 menu
11051 redir END
11052 let bmshowlist = split(bmshowraw,'\n')
11053 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011054 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011055 if bmshowfuncs != []
11056 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011057 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011058 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011059 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011060 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011061 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011062" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11063endfun
11064
11065" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011066" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011067fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011068 if !exists("w:netrw_liststyle")
11069 let w:netrw_liststyle= g:netrw_liststyle
11070 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011071" 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 +020011072
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011073" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11074
Bram Moolenaaradc21822011-04-01 18:03:16 +020011075 if &ft != "netrw"
11076 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11077 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011078" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011079
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011080 elseif g:netrw_cursor == 8
11081 if w:netrw_liststyle == s:WIDELIST
11082 setl cursorline
11083 setl cursorcolumn
11084 else
11085 setl cursorline
11086 endif
11087 elseif g:netrw_cursor == 7
11088 setl cursorline
11089 elseif g:netrw_cursor == 6
11090 if w:netrw_liststyle == s:WIDELIST
11091 setl cursorline
11092 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011093 elseif g:netrw_cursor == 4
11094 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011095" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011096 setl cursorline
11097 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011098
11099 elseif g:netrw_cursor == 3
11100 " thin-long-tree: cursorline, user's cursorcolumn
11101 " wide : cursorline, cursorcolumn
11102 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011103" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011104 setl cursorline
11105 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011106 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011107" 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 +020011108 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011109 endif
11110
11111 elseif g:netrw_cursor == 2
11112 " thin-long-tree: cursorline, user's cursorcolumn
11113 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011114" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011115 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011116
11117 elseif g:netrw_cursor == 1
11118 " thin-long-tree: user's cursorline, user's cursorcolumn
11119 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011120 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011121" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011122 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011123 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011124" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011125 endif
11126
11127 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011128 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011129" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011130 let &l:cursorline = s:netrw_usercul
11131 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011132 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011133
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011134" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011135" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011136endfun
11137
11138" ---------------------------------------------------------------------
11139" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11140fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011141" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011142 if exists("s:netrw_usercul")
11143 let &l:cursorline = s:netrw_usercul
11144 endif
11145 if exists("s:netrw_usercuc")
11146 let &l:cursorcolumn = s:netrw_usercuc
11147 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011148" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011149" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11150endfun
11151
Christian Brabandt62f7b552024-06-23 20:23:40 +020011152" s:RestoreRegister: restores all registers given in the dict {{{2
11153fun! s:RestoreRegister(dict)
11154 for [key, val] in items(a:dict)
11155 if key == 'unnamed'
11156 let key = ''
11157 endif
11158 call setreg(key, val[0], val[1])
11159 endfor
11160endfun
11161
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011162" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011163" s:NetrwDelete: Deletes a file. {{{2
11164" Uses Steve Hall's idea to insure that Windows paths stay
11165" acceptable. No effect on Unix paths.
11166" Examples of use: let result= s:NetrwDelete(path)
11167fun! s:NetrwDelete(path)
11168" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11169
Bram Moolenaar5c736222010-01-06 20:54:52 +010011170 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011171 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000011172 if exists("+shellslash")
11173 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011174 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011175 let result = delete(path)
11176 let &shellslash = sskeep
11177 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011178" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011179 let result= delete(path)
11180 endif
11181 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011182" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011183 let result= delete(path)
11184 endif
11185 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011186 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011187 endif
11188
11189" call Dret("s:NetrwDelete ".result)
11190 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000011191endfun
11192
11193" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011194" s:NetrwBufRemover: removes a buffer that: {{{2s
11195" has buffer-id > 1
11196" is unlisted
11197" is unnamed
11198" does not appear in any window
11199fun! s:NetrwBufRemover(bufid)
11200" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
11201" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
11202" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
11203" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
11204" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
11205
yasuda4dbb2662023-10-04 20:50:35 +020011206 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011207" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020011208 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011209 endif
11210
11211" call Dret("s:NetrwBufRemover")
11212endfun
11213
11214" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011215" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010011216fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011217" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011218" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011219
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011220 " Clean out the last buffer:
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011221 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
11222 " If so, delete it.
11223 call s:NetrwBufRemover(bufnr("$"))
11224
Bram Moolenaar446cb832008-06-24 21:56:24 +000011225 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011226" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011227 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
11228 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
11229 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
11230 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
11231 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11232 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
11233 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
11234 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
11235 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
11236 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11237 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
11238 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
11239 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
11240 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
11241 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
11242 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
11243
Bram Moolenaar85850f32019-07-19 22:05:51 +020011244 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011245" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011246 " when tree listing uses file TreeListing... a new buffer is made.
11247 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011248 " COMBAK: this causes a problem, see P43
11249" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011250 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010011251 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011252 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011253" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020011254 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011255
Bram Moolenaar446cb832008-06-24 21:56:24 +000011256 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011257" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011258 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
11259 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
11260 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
11261 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
11262 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
11263 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
11264 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
11265 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
11266 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
11267 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
11268 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
11269 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
11270 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
11271 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
11272 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
11273 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
11274
Bram Moolenaar5c736222010-01-06 20:54:52 +010011275 if a:0 > 0
11276 let b:netrw_curdir= a:1
11277 if b:netrw_curdir =~ '/$'
11278 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011279 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010011280 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011281 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020011282 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
11283 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010011284 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011285 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010011286 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011287 endif
11288 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011289 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
11290 let &l:bexpr = "netrw#BalloonHelp()"
11291 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011292
Bram Moolenaar8d043172014-01-23 14:24:41 +010011293" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011294endfun
11295
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011296" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011297" s:NetrwExe: executes a string using "!" {{{2
11298fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011299" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Konfekt3d7e5672024-10-27 22:16:49 +010011300 if has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +020011301" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011302 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
11303 set shell& shellcmdflag& shellxquote& shellxescape&
11304 set shellquote& shellpipe& shellredir& shellslash&
Konfekt3d7e5672024-10-27 22:16:49 +010011305 try
11306 exe a:cmd
11307 finally
11308 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
11309 endtry
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011310 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011311" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011312 exe a:cmd
11313 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011314 if v:shell_error
11315 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
11316 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011317" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011318endfun
11319
11320" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011321" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
11322fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011323 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011324" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011325 let curbuf = bufnr("%")
11326 let curwin = winnr()
11327 let iwin = 1
11328 while iwin <= winnr("$")
11329 exe iwin."wincmd w"
11330 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
11331 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
11332 let winvars= w:
11333 break
11334 endif
11335 let iwin= iwin + 1
11336 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020011337 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011338 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011339" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011340 for k in keys(winvars)
11341 let w:{k}= winvars[k]
11342 endfor
11343 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011344" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011345 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011346endfun
11347
Bram Moolenaara6878372014-03-22 21:02:50 +010011348" ---------------------------------------------------------------------
11349" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020011350" Returns: 0=success
11351" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010011352fun! s:NetrwLcd(newdir)
11353" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011354" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011355
Bram Moolenaar85850f32019-07-19 22:05:51 +020011356 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011357 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011358 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010011359 catch /^Vim\%((\a\+)\)\=:E344/
11360 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
11361 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011362 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010011363 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
11364 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020011365 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010011366 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
11367 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090011368 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010011369 endif
11370 endif
11371 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020011372 let err472= 1
11373 endtry
11374
11375 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010011376 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
11377 if exists("w:netrw_prvdir")
11378 let a:newdir= w:netrw_prvdir
11379 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011380 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011381" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020011382 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011383" 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 +010011384 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010011385 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011386" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
11387 return -1
11388 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011389
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011390" call Decho("getcwd <".getcwd().">")
11391" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020011392" call Dret("s:NetrwLcd 0")
11393 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011394endfun
11395
Bram Moolenaar9964e462007-05-05 17:54:07 +000011396" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011397" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
11398" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
11399fun! s:NetrwSaveWordPosn()
11400" call Dfunc("NetrwSaveWordPosn()")
11401 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
11402" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
11403endfun
11404
11405" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011406" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
11407" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
11408fun! s:NetrwHumanReadable(sz)
11409" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
11410
11411 if g:netrw_sizestyle == 'h'
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011412 if a:sz >= 1000000000
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011413 let sz = printf("%.1f",a:sz/1000000000.0)."g"
11414 elseif a:sz >= 10000000
11415 let sz = printf("%d",a:sz/1000000)."m"
11416 elseif a:sz >= 1000000
11417 let sz = printf("%.1f",a:sz/1000000.0)."m"
11418 elseif a:sz >= 10000
11419 let sz = printf("%d",a:sz/1000)."k"
11420 elseif a:sz >= 1000
11421 let sz = printf("%.1f",a:sz/1000.0)."k"
11422 else
11423 let sz= a:sz
11424 endif
11425
11426 elseif g:netrw_sizestyle == 'H'
11427 if a:sz >= 1073741824
11428 let sz = printf("%.1f",a:sz/1073741824.0)."G"
11429 elseif a:sz >= 10485760
11430 let sz = printf("%d",a:sz/1048576)."M"
11431 elseif a:sz >= 1048576
11432 let sz = printf("%.1f",a:sz/1048576.0)."M"
11433 elseif a:sz >= 10240
11434 let sz = printf("%d",a:sz/1024)."K"
11435 elseif a:sz >= 1024
11436 let sz = printf("%.1f",a:sz/1024.0)."K"
11437 else
11438 let sz= a:sz
11439 endif
11440
11441 else
11442 let sz= a:sz
11443 endif
11444
11445" call Dret("s:NetrwHumanReadable ".sz)
11446 return sz
11447endfun
11448
11449" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011450" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
11451" changed sorting, etc. Also see s:NetrwSaveWordPosn().
11452fun! s:NetrwRestoreWordPosn()
11453" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020011454 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000011455" call Dret("NetrwRestoreWordPosn")
11456endfun
11457
11458" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011459" s:RestoreBufVars: {{{2
11460fun! s:RestoreBufVars()
11461" call Dfunc("s:RestoreBufVars()")
11462
11463 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
11464 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
11465 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
11466 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
11467 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
11468 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
11469
11470" call Dret("s:RestoreBufVars")
11471endfun
11472
11473" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011474" s:RemotePathAnalysis: {{{2
11475fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020011476" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011477
Bram Moolenaara6878372014-03-22 21:02:50 +010011478 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010011479 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011480 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010011481 let s:user = substitute(a:dirname,dirpat,'\3','')
11482 let s:machine = substitute(a:dirname,dirpat,'\4','')
11483 let s:port = substitute(a:dirname,dirpat,'\5','')
11484 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020011485 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010011486 if s:machine =~ '@'
11487 let dirpat = '^\(.*\)@\(.\{-}\)$'
11488 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
11489 let s:machine = substitute(s:machine,dirpat,'\2','')
11490 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011491
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011492" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
11493" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
11494" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
11495" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
11496" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
11497" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011498
11499" call Dret("s:RemotePathAnalysis")
11500endfun
11501
11502" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011503" s:RemoteSystem: runs a command on a remote host using ssh {{{2
11504" Returns status
11505" Runs system() on
11506" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011507" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000011508fun! s:RemoteSystem(cmd)
11509" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
11510 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011511 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 +000011512 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011513 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011514 else
11515 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
11516 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
11517 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011518 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000011519 else
11520 let cmd= cmd.' '
11521 endif
11522 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011523" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011524 let ret= system(cmd)
11525 endif
11526" call Dret("s:RemoteSystem ".ret)
11527 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000011528endfun
11529
11530" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011531" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000011532fun! s:RestoreWinVars()
11533" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000011534 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011535 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
11536 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
11537 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
11538 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
11539 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
11540 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
11541 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
11542 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
11543 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
11544 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
11545 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
11546 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000011547 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
11548 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011549 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
11550 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
11551 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
11552" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000011553endfun
11554
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011555" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011556" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
11557"
11558" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
11559" is true) and a command, :Rexplore, which call this function.
11560"
Bram Moolenaar85850f32019-07-19 22:05:51 +020011561" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011562"
11563" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000011564fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020011565 if exists("s:netrwdrag")
11566 return
11567 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011568" 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 +010011569" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
11570" 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 +010011571
11572 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011573 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011574" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011575 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011576 unlet w:netrw_rexfile
11577" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020011578 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011579" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011580" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
11581" 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 +020011582 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011583
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011584 " ---------------------------
11585 " :Rex issued while in a file
11586 " ---------------------------
11587
Bram Moolenaara6878372014-03-22 21:02:50 +010011588 " record current file so :Rex can return to it from netrw
11589 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011590" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011591
11592 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011593" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010011594 return
11595 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011596" 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 +020011597 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011598 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011599 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011600 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011601 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011602 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010011603 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020011604 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011605 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011606" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
11607 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011608" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
11609 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011610 if exists("s:rexposn_".bufnr('%'))
11611 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011612 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011613 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011614" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011615 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011616
Bram Moolenaar85850f32019-07-19 22:05:51 +020011617 if has("syntax") && exists("g:syntax_on") && g:syntax_on
11618 if exists("s:explore_match")
11619 exe "2match netrwMarkFile /".s:explore_match."/"
11620 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010011621 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011622
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011623" 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 +010011624" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011625endfun
11626
11627" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010011628" s:SaveBufVars: save selected b: variables to s: variables {{{2
11629" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000011630fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011631" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011632
11633 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
11634 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
11635 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
11636 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
11637 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
11638 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
11639
11640" call Dret("s:SaveBufVars")
11641endfun
11642
11643" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011644" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
11645fun! s:SavePosn(posndict)
11646" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
11647
Bram Moolenaar85850f32019-07-19 22:05:51 +020011648 if !exists("a:posndict[bufnr('%')]")
11649 let a:posndict[bufnr("%")]= []
11650 endif
11651" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11652 call add(a:posndict[bufnr("%")],winsaveview())
11653" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011654
11655" call Dret("s:SavePosn posndict")
11656 return a:posndict
11657endfun
11658
11659" ---------------------------------------------------------------------
11660" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
11661fun! s:RestorePosn(posndict)
11662" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020011663 if exists("a:posndict")
11664 if has_key(a:posndict,bufnr("%"))
11665" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11666 let posnlen= len(a:posndict[bufnr("%")])
11667 if posnlen > 0
11668 let posnlen= posnlen - 1
11669" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
11670 call winrestview(a:posndict[bufnr("%")][posnlen])
11671 call remove(a:posndict[bufnr("%")],posnlen)
11672" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11673 endif
11674 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011675 endif
11676" call Dret("s:RestorePosn")
11677endfun
11678
11679" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011680" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000011681fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011682" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000011683 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
11684 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
11685 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
11686 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
11687 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
11688 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
11689 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
11690 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
11691 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
11692 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
11693 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
11694 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
11695 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
11696 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
11697 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
11698 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
11699 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
11700 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
11701" call Dret("s:SaveWinVars")
11702endfun
11703
11704" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011705" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011706" To allow separate windows to have their own activities, such as
11707" Explore **/pattern, several variables have been made window-oriented.
11708" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011709" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011710" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011711fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011712" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000011713 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
11714 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
11715 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
11716 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
11717 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
11718 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
11719 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
11720 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
11721 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
11722 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
11723" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011724endfun
11725
11726" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011727" s:SetRexDir: set directory for :Rexplore {{{2
11728fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011729" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011730 let w:netrw_rexdir = a:dirname
11731 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011732 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011733" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
11734" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011735" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011736" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011737" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011738endfun
11739
11740" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011741" s:ShowLink: used to modify thin and tree listings to show links {{{2
11742fun! s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011743 if exists("b:netrw_curdir")
11744 norm! $?\a
Tom Benham64a536d2024-11-07 21:15:03 +010011745 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treetop")
11746 let basedir = s:NetrwTreePath(w:netrw_treetop)
11747 else
11748 let basedir = b:netrw_curdir.'/'
11749 endif
11750 let fname = basedir.s:NetrwGetWord()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011751 let resname = resolve(fname)
Tom Benham64a536d2024-11-07 21:15:03 +010011752 if resname =~ '^\M'.basedir
11753 let dirlen = strlen(basedir)
11754 let resname = strpart(resname,dirlen)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011755 endif
11756 let modline = getline(".")."\t --> ".resname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011757 setl noro ma
11758 call setline(".",modline)
11759 setl ro noma nomod
11760 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011761endfun
11762
11763" ---------------------------------------------------------------------
11764" s:ShowStyle: {{{2
11765fun! s:ShowStyle()
11766 if !exists("w:netrw_liststyle")
11767 let liststyle= g:netrw_liststyle
11768 else
11769 let liststyle= w:netrw_liststyle
11770 endif
11771 if liststyle == s:THINLIST
11772 return s:THINLIST.":thin"
11773 elseif liststyle == s:LONGLIST
11774 return s:LONGLIST.":long"
11775 elseif liststyle == s:WIDELIST
11776 return s:WIDELIST.":wide"
11777 elseif liststyle == s:TREELIST
11778 return s:TREELIST.":tree"
11779 else
11780 return 'n/a'
11781 endif
11782endfun
11783
11784" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010011785" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
11786" Solution from Nicolai Weibull, vim docs (:help strlen()),
11787" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000011788fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011789" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
11790
11791 if v:version >= 703 && exists("*strdisplaywidth")
11792 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011793
Bram Moolenaar8d043172014-01-23 14:24:41 +010011794 elseif type(g:Align_xstrlen) == 1
11795 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
11796 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011797
Bram Moolenaar8d043172014-01-23 14:24:41 +010011798 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000011799 " number of codepoints (Latin a + combining circumflex is two codepoints)
11800 " (comment from TM, solution from NW)
11801 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011802
Bram Moolenaar8d043172014-01-23 14:24:41 +010011803 elseif g:Align_xstrlen == 2
11804 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000011805 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
11806 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011807 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011808
Bram Moolenaar8d043172014-01-23 14:24:41 +010011809 elseif g:Align_xstrlen == 3
11810 " virtual length (counting, for instance, tabs as anything between 1 and
11811 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000011812 " preceded by lam, one otherwise, etc.)
11813 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011814 let modkeep= &l:mod
11815 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011816 call setline(line("."),a:x)
11817 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010011818 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011819 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010011820 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011821
Bram Moolenaar446cb832008-06-24 21:56:24 +000011822 else
11823 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010011824 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011825 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010011826" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011827 return ret
11828endfun
11829
11830" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011831" s:ShellEscape: shellescape(), or special windows handling {{{2
11832fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011833 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011834 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011835 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011836 let f = a:0 > 0 ? a:1 : 0
11837 return shellescape(a:s, f)
11838endfun
11839
11840" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011841" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000011842fun! s:TreeListMove(dir)
11843" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011844 let curline = getline('.')
11845 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
11846 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
11847 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
11848 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
11849 let treedepthchr = substitute(s:treedepthstring,' ','','g')
11850 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
11851" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
11852" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
11853" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
11854" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
11855" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
11856 " COMBAK : need to handle when on a directory
11857 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000011858 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011859 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011860 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011861 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011862" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011863 elseif a:dir == '[]' && nxtline != ''
11864 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011865" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011866 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
11867 if nl != 0
11868 NetrwKeepj norm! k
11869 else
11870 NetrwKeepj norm! G
11871 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011872" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011873 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011874 endif
11875
11876" call Dret("s:TreeListMove")
11877endfun
11878
11879" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011880" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
11881" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
11882" can't be called except via emenu. But due to locale, that menu line may not be called
11883" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
11884fun! s:UpdateBuffersMenu()
11885" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020011886 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000011887 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020011888 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000011889 catch /^Vim\%((\a\+)\)\=:E/
11890 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011891 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000011892 endtry
11893 endif
11894" call Dret("s:UpdateBuffersMenu")
11895endfun
11896
11897" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011898" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020011899" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011900fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000011901" call Dfunc("s:UseBufWinVars()")
11902 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011903 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
11904 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
11905 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
11906 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
11907 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
11908 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11909 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11910 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
11911 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 +000011912" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011913endfun
11914
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011915" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011916" s:UserMaps: supports user-defined UserMaps {{{2
11917" * calls a user-supplied funcref(islocal,curdir)
11918" * interprets result
11919" See netrw#UserMaps()
11920fun! s:UserMaps(islocal,funcname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011921 if !exists("b:netrw_curdir")
11922 let b:netrw_curdir= getcwd()
11923 endif
11924 let Funcref = function(a:funcname)
11925 let result = Funcref(a:islocal)
11926
11927 if type(result) == 1
11928 " if result from user's funcref is a string...
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011929 if result == "refresh"
Tom Benham64a536d2024-11-07 21:15:03 +010011930 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011931 elseif result != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011932 exe result
11933 endif
11934
11935 elseif type(result) == 3
11936 " if result from user's funcref is a List...
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011937 for action in result
11938 if action == "refresh"
Tom Benham64a536d2024-11-07 21:15:03 +010011939 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011940 elseif action != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011941 exe action
11942 endif
11943 endfor
11944 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011945endfun
11946
Bram Moolenaar85850f32019-07-19 22:05:51 +020011947" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011948" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020011949" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000011950let &cpo= s:keepcpo
11951unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000011952
Bram Moolenaar85850f32019-07-19 22:05:51 +020011953" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000011954" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020011955" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000011956" vim:ts=8 fdm=marker