blob: 3e9bd34b1909522a100a06c7ada3fa246f637ae0 [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" netrw.vim: Handles file transfer and remote directory listing across
2" AUTOLOAD SECTION
Bram Moolenaar97d62492012-11-15 21:28:22 +01003" Date: Oct 25, 2012
4" Version: 146
Bram Moolenaar9964e462007-05-05 17:54:07 +00005" Maintainer: Charles E Campbell, Jr <NdrOchip@ScampbellPfamily.AbizM-NOSPAM>
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00006" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaar97d62492012-11-15 21:28:22 +01007" Copyright: Copyright (C) 1999-2012 Charles E. Campbell, Jr. {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +00008" Permission is hereby granted to use and distribute this code,
9" with or without modifications, provided that this copyright
10" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000012" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000013" expressed or implied. By using this plugin, you agree that
14" in no event will the copyright holder be liable for any damages
15" resulting from the use of this software.
Bram Moolenaar446cb832008-06-24 21:56:24 +000016"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000017"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000018" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000019" (James 1:22 RSV)
20" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000021" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000022if &cp || exists("g:loaded_netrw")
23 finish
24endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010025let g:loaded_netrw = "v146"
Bram Moolenaar5c736222010-01-06 20:54:52 +010026if v:version < 702
27 echohl WarningMsg
28 echo "***warning*** this version of netrw needs vim 7.2"
29 echohl Normal
30 finish
31endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000032if !exists("s:NOTE")
33 let s:NOTE = 0
34 let s:WARNING = 1
35 let s:ERROR = 2
36endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000037
38" sanity checks
Bram Moolenaar578b49e2005-09-10 19:22:57 +000039if v:version < 700
Bram Moolenaar9964e462007-05-05 17:54:07 +000040 call netrw#ErrorMsg(s:WARNING,"you need vim version 7.0 or later for version ".g:loaded_netrw." of netrw",1)
Bram Moolenaar578b49e2005-09-10 19:22:57 +000041 finish
42endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000043
Bram Moolenaar1afcace2005-11-25 19:54:28 +000044let s:keepcpo= &cpo
Bram Moolenaar5b435d62012-04-05 17:33:26 +020045set cpo&vim
Bram Moolenaar9964e462007-05-05 17:54:07 +000046"DechoTabOn
47"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw)
Bram Moolenaar071d4272004-06-13 20:20:40 +000048
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000049" ======================
50" Netrw Variables: {{{1
51" ======================
52
Bram Moolenaar071d4272004-06-13 20:20:40 +000053" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020054" netrw#ErrorMsg: {{{2
55" 0=note = s:NOTE
56" 1=warning = s:WARNING
57" 2=error = s:ERROR
Bram Moolenaar97d62492012-11-15 21:28:22 +010058" Oct 24, 2012 : max errnum currently is 91
Bram Moolenaar5b435d62012-04-05 17:33:26 +020059fun! netrw#ErrorMsg(level,msg,errnum)
60" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
61
62 if a:level < g:netrw_errorlvl
Bram Moolenaar97d62492012-11-15 21:28:22 +010063" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g;netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020064 return
65 endif
66
67 if a:level == 1
68 let level= "**warning** (netrw) "
69 elseif a:level == 2
70 let level= "**error** (netrw) "
71 else
72 let level= "**note** (netrw) "
73 endif
74" call Decho("level=".level)
75
76 if g:netrw_use_errorwindow
77 " (default) netrw creates a one-line window to show error/warning
78 " messages (reliably displayed)
79
80 " record current window number for NetrwRestorePosn()'s benefit
81 let s:winBeforeErr= winnr()
82" call Decho("s:winBeforeErr=".s:winBeforeErr)
83
84 " getting messages out reliably is just plain difficult!
85 " This attempt splits the current window, creating a one line window.
86 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
87" call Decho("write to NetrwMessage buffer")
88 exe bufwinnr("NetrwMessage")."wincmd w"
89" call Decho("setl ma noro")
90 setl ma noro
91 keepj call setline(line("$")+1,level.a:msg)
92 keepj $
93 else
94" call Decho("create a NetrwMessage buffer window")
95 bo 1split
96 sil! call s:NetrwEnew()
97 sil! keepj call s:NetrwSafeOptions()
98 setl bt=nofile
99 keepj file NetrwMessage
100" call Decho("setlocal ma noro")
101 setl ma noro
102 call setline(line("$"),level.a:msg)
103 endif
104" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr())
105 if &fo !~ '[ta]'
106 syn clear
107 syn match netrwMesgNote "^\*\*note\*\*"
108 syn match netrwMesgWarning "^\*\*warning\*\*"
109 syn match netrwMesgError "^\*\*error\*\*"
110 hi link netrwMesgWarning WarningMsg
111 hi link netrwMesgError Error
112 endif
113" call Decho("(ErrorMsg) setl noma ro bh=wipe")
114 setl noma ro bh=wipe
115
116 else
117 " (optional) netrw will show messages using echomsg. Even if the
118 " message doesn't appear, at least it'll be recallable via :messages
119" redraw!
120 if a:level == s:WARNING
121 echohl WarningMsg
122 elseif a:level == s:ERROR
123 echohl Error
124 endif
125 echomsg level.a:msg
126" call Decho("echomsg ***netrw*** ".a:msg)
127 echohl None
128 endif
129
130" call Dret("netrw#ErrorMsg")
131endfun
132
133" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +0100134" NetrwInit: initializes variables if they haven't been defined {{{2
135" Loosely, varname = value.
136fun s:NetrwInit(varname,value)
137 if !exists(a:varname)
138 if type(a:value) == 0
139 exe "let ".a:varname."=".a:value
140 elseif type(a:value) == 1
141 exe "let ".a:varname."="."'".a:value."'"
142 else
143 exe "let ".a:varname."=".a:value
144 endif
145 endif
146endfun
147
148" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000149" Netrw Constants: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100150call s:NetrwInit("g:netrw_dirhist_cnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000151if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100152 call s:NetrwInit("s:THINLIST",0)
153 call s:NetrwInit("s:LONGLIST",1)
154 call s:NetrwInit("s:WIDELIST",2)
155 call s:NetrwInit("s:TREELIST",3)
156 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000157endif
158
159" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000160" Default values for netrw's global protocol variables {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +0200161call s:NetrwInit("g:netrw_use_errorwindow",1)
162
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000163if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100164 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000165 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100166 elseif executable("curl")
167 let g:netrw_dav_cmd = "curl"
168 else
169 let g:netrw_dav_cmd = ""
170 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000171endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000172if !exists("g:netrw_fetch_cmd")
173 if executable("fetch")
174 let g:netrw_fetch_cmd = "fetch -o"
175 else
176 let g:netrw_fetch_cmd = ""
177 endif
178endif
179if !exists("g:netrw_ftp_cmd")
180 let g:netrw_ftp_cmd = "ftp"
181endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200182let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200183if !exists("g:netrw_ftp_options")
184 let g:netrw_ftp_options= "-i -n"
185endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000186if !exists("g:netrw_http_cmd")
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000187 if executable("elinks")
188 let g:netrw_http_cmd = "elinks"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100189 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000190 elseif executable("links")
191 let g:netrw_http_cmd = "links"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100192 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000193 elseif executable("curl")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100194 let g:netrw_http_cmd = "curl"
195 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000196 elseif executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100197 let g:netrw_http_cmd = "wget"
198 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000199 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100200 let g:netrw_http_cmd = "fetch"
201 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000202 else
203 let g:netrw_http_cmd = ""
204 endif
205endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100206call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
207call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
208call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
209call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
210call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000211
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000212if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000213 \ && exists("g:netrw_use_nt_rcp")
214 \ && g:netrw_use_nt_rcp
215 \ && executable( $SystemRoot .'/system32/rcp.exe')
216 let s:netrw_has_nt_rcp = 1
217 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000218else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000219 let s:netrw_has_nt_rcp = 0
220 let s:netrw_rcpmode = ''
221endif
222
223" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000224" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000225" Cygwin Detection ------- {{{3
226if !exists("g:netrw_cygwin")
227 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100228 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000229 let g:netrw_cygwin= 1
230 else
231 let g:netrw_cygwin= 0
232 endif
233 else
234 let g:netrw_cygwin= 0
235 endif
236endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000237" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100238call s:NetrwInit("g:netrw_alto" , &sb)
239call s:NetrwInit("g:netrw_altv" , &spr)
240call s:NetrwInit("g:netrw_banner" , 1)
241call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200242call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100243call s:NetrwInit("g:netrw_chgwin" , -1)
244call s:NetrwInit("g:netrw_compress" , "gzip")
245call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200246if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
247 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
248 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000249endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200250call s:NetrwInit("g:netrw_cursor" , 2)
251let s:netrw_usercul = &cursorline
252let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar446cb832008-06-24 21:56:24 +0000253" Default values - d-g ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100254call s:NetrwInit("g:netrw_dirhist_cnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200255call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100256call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200257call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100258call s:NetrwInit("g:netrw_fastbrowse" , 1)
259call 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 +0000260if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000261 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
262 let g:netrw_ftp_list_cmd = "ls -lF"
263 let g:netrw_ftp_timelist_cmd = "ls -tlF"
264 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000265 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000266 let g:netrw_ftp_list_cmd = "dir"
267 let g:netrw_ftp_timelist_cmd = "dir"
268 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000269 endif
270endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100271call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000272" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100273call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000274if !exists("g:netrw_ignorenetrc")
275 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
276 let g:netrw_ignorenetrc= 1
277 else
278 let g:netrw_ignorenetrc= 0
279 endif
280endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100281call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000282if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000283 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
284 " provide a 'pscp' listing command
285 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable("c:\\private.ppk")
286 let g:netrw_scp_cmd ="pscp -i C:\\private.ppk"
287 endif
288 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
289 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000290 " provide a default listing command
Bram Moolenaar9964e462007-05-05 17:54:07 +0000291 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000292 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000293" call Decho(g:netrw_ssh_cmd." is not executable")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000294 let g:netrw_list_cmd= ""
295 endif
296endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100297call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000298" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200299if exists("g:netrw_local_copycmd")
300 let g:netrw_localcopycmd= g:netrw_local_copycmd"
301 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
302endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100303if !exists("g:netrw_localcmdshell")
304 let g:netrw_localcmdshell= ""
305endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000306if !exists("g:netrw_localcopycmd")
307 if has("win32") || has("win95") || has("win64") || has("win16")
308 if g:netrw_cygwin
309 let g:netrw_localcopycmd= "cp"
310 else
Bram Moolenaar97d62492012-11-15 21:28:22 +0100311 let g:netrw_localcopycmd= "cmd /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000312 endif
313 elseif has("unix") || has("macunix")
314 let g:netrw_localcopycmd= "cp"
315 else
316 let g:netrw_localcopycmd= ""
317 endif
318endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200319if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100320 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200321 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
322endif
323call s:NetrwInit("g:netrw_localmkdir","mkdir")
Bram Moolenaar15146672011-10-20 22:22:38 +0200324call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200325if exists("g:netrw_local_movecmd")
326 let g:netrw_localmovecmd= g:netrw_local_movecmd"
327 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
328endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000329if !exists("g:netrw_localmovecmd")
330 if has("win32") || has("win95") || has("win64") || has("win16")
331 if g:netrw_cygwin
332 let g:netrw_localmovecmd= "mv"
333 else
Bram Moolenaar97d62492012-11-15 21:28:22 +0100334 let g:netrw_localmovecmd= "cmd /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000335 endif
336 elseif has("unix") || has("macunix")
337 let g:netrw_localmovecmd= "mv"
338 else
339 let g:netrw_localmovecmd= ""
340 endif
341endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200342call s:NetrwInit("g:netrw_localrmdir", "rmdir")
343if exists("g:netrw_local_rmdir")
344 let g:netrw_localrmdir= g:netrw_local_rmdir"
345 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_rmdir is deprecated in favor of g:netrw_localrmdir",86)
346endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100347call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
348" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000349if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000350 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000351endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000352if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000353 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
354endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000355" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100356call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
357call s:NetrwInit("g:netrw_maxfilenamelen", 32)
358call s:NetrwInit("g:netrw_menu" , 1)
359call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
360call s:NetrwInit("g:netrw_mousemaps" , (exists("&mouse") && &mouse =~ '[anh]'))
361call s:NetrwInit("g:netrw_retmap" , 0)
362if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
363 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
364elseif has("win32") || has("win95") || has("win64") || has("win16")
365 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
366else
367 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000368endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100369call s:NetrwInit("g:netrw_preview" , 0)
370call s:NetrwInit("g:netrw_scpport" , "-P")
371call s:NetrwInit("g:netrw_sshport" , "-p")
372call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
373call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
374call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
375call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000376" Default values - s ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100377" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
378call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200379call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100380call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
381call s:NetrwInit("g:netrw_sort_options" , "")
382call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000383if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100384 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200385 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100386 else
387 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000388 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000389endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100390call s:NetrwInit("g:netrw_special_syntax" , 0)
391call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
392call s:NetrwInit("g:netrw_use_noswf" , 0)
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000393" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100394call s:NetrwInit("g:netrw_timefmt","%c")
395call s:NetrwInit("g:netrw_xstrlen",0)
396call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100397call s:NetrwInit("g:netrw_win95ftp",1)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200398call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200399if g:netrw_winsize == 0|let g:netrw_winsize= -1|endif
400if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000401" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000402" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100403call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200404if has("win32") || has("win95") || has("win64") || has("win16")
405 call s:NetrwInit("g:netrw_glob_escape",'[]*?`{$')
406else
407 call s:NetrwInit("g:netrw_glob_escape",'[]*?`{~$\')
408endif
409call s:NetrwInit("g:netrw_menu_escape",'./&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100410call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
411call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaar8299df92004-07-10 09:47:34 +0000412
413" BufEnter event ignored by decho when following variable is true
414" Has a side effect that doau BufReadPost doesn't work, so
415" files read by network transfer aren't appropriately highlighted.
416"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000417
Bram Moolenaaradc21822011-04-01 18:03:16 +0200418" ======================
419" Netrw Initialization: {{{1
420" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200421if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
422 let s:initbeval = &beval
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200423" let s:initbexpr = &l:bexpr
Bram Moolenaar15146672011-10-20 22:22:38 +0200424 let &l:bexpr = "netrw#NetrwBalloonHelp()"
Bram Moolenaaradc21822011-04-01 18:03:16 +0200425 set beval
Bram Moolenaar15146672011-10-20 22:22:38 +0200426 au BufWinEnter,WinEnter * if &ft == "netrw"|set beval|else|let &beval= s:initbeval|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200427endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200428au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200429
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000430" ==============================
431" Netrw Utility Functions: {{{1
432" ==============================
433
Bram Moolenaaradc21822011-04-01 18:03:16 +0200434" ---------------------------------------------------------------------
435" netrw#NetrwBalloonHelp: {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +0200436if v:version >= 700 && has("balloon_eval") && &beval == 1 && has("syntax") && exists("g:syntax_on")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200437 fun! netrw#NetrwBalloonHelp()
Bram Moolenaar15146672011-10-20 22:22:38 +0200438 if !exists("w:netrw_bannercnt") || v:beval_lnum >= w:netrw_bannercnt || (exists("g:netrw_nobeval") && g:netrw_nobeval)
Bram Moolenaaradc21822011-04-01 18:03:16 +0200439 let mesg= ""
440 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
Bram Moolenaar15146672011-10-20 22:22:38 +0200441 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
Bram Moolenaaradc21822011-04-01 18:03:16 +0200442 elseif getline(v:beval_lnum) =~ '^"\s*/'
443 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
444 elseif v:beval_text == "Sorted" || v:beval_text == "by"
445 let mesg = 's: sort by name, time, or file size r: reverse sorting order mt: mark target'
446 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
447 let mesg = "S: edit sorting sequence"
448 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
449 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
450 elseif v:beval_text == "Quick" || v:beval_text == "Help"
451 let mesg = "Help: press <F1>"
452 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
453 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
454 else
455 let mesg= ""
456 endif
457 return mesg
458 endfun
459endif
460
Bram Moolenaar071d4272004-06-13 20:20:40 +0000461" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +0000462" s:NetrwOptionSave: save options and set to "standard" form {{{2
463" 06/08/07 : removed call to NetrwSafeOptions(), either placed
464" immediately after NetrwOptionSave() calls in NetRead
465" and NetWrite, or after the s:NetrwEnew() call in
466" NetrwBrowse.
467" vt: normally its "w:" or "s:" (a variable type)
468fun! s:NetrwOptionSave(vt)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100469" call Dfunc("s:NetrwOptionSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$"))
Bram Moolenaar446cb832008-06-24 21:56:24 +0000470" call Decho(a:vt."netrw_optionsave".(exists("{a:vt}netrw_optionsave")? ("=".{a:vt}netrw_optionsave) : " doesn't exist"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200471
Bram Moolenaar446cb832008-06-24 21:56:24 +0000472 if !exists("{a:vt}netrw_optionsave")
473 let {a:vt}netrw_optionsave= 1
Bram Moolenaar9964e462007-05-05 17:54:07 +0000474 else
Bram Moolenaar446cb832008-06-24 21:56:24 +0000475" call Dret("s:NetrwOptionSave : options already saved")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000476 return
477 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200478" call Decho("fo=".&fo.(exists("&acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000479
480 " Save current settings and current directory
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200481" call Decho("saving current settings and current directory")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000482 let s:yykeep = @@
Bram Moolenaar15146672011-10-20 22:22:38 +0200483 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000484 let {a:vt}netrw_aikeep = &l:ai
485 let {a:vt}netrw_awkeep = &l:aw
Bram Moolenaar15146672011-10-20 22:22:38 +0200486 let {a:vt}netrw_bhkeep = &l:bh
487 let {a:vt}netrw_blkeep = &l:bl
488 let {a:vt}netrw_btkeep = &l:bt
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200489 let {a:vt}netrw_bombkeep = &l:bomb
Bram Moolenaar446cb832008-06-24 21:56:24 +0000490 let {a:vt}netrw_cikeep = &l:ci
491 let {a:vt}netrw_cinkeep = &l:cin
492 let {a:vt}netrw_cinokeep = &l:cino
493 let {a:vt}netrw_comkeep = &l:com
494 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200495 let {a:vt}netrw_diffkeep = &l:diff
Bram Moolenaar15146672011-10-20 22:22:38 +0200496 let {a:vt}netrw_fenkeep = &l:fen
497 let {a:vt}netrw_ffkeep = &l:ff
Bram Moolenaar446cb832008-06-24 21:56:24 +0000498 let {a:vt}netrw_fokeep = &l:fo " formatoptions
499 let {a:vt}netrw_gdkeep = &l:gd " gdefault
500 let {a:vt}netrw_hidkeep = &l:hidden
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200501 let {a:vt}netrw_imkeep = &l:im
Bram Moolenaar15146672011-10-20 22:22:38 +0200502 let {a:vt}netrw_iskkeep = &l:isk
503 let {a:vt}netrw_lskeep = &l:ls
504 let {a:vt}netrw_makeep = &l:ma
Bram Moolenaar446cb832008-06-24 21:56:24 +0000505 let {a:vt}netrw_magickeep = &l:magic
Bram Moolenaar15146672011-10-20 22:22:38 +0200506 let {a:vt}netrw_modkeep = &l:mod
507 let {a:vt}netrw_nukeep = &l:nu
Bram Moolenaar446cb832008-06-24 21:56:24 +0000508 let {a:vt}netrw_repkeep = &l:report
Bram Moolenaar15146672011-10-20 22:22:38 +0200509 let {a:vt}netrw_rokeep = &l:ro
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200510 let {a:vt}netrw_selkeep = &l:sel
Bram Moolenaar446cb832008-06-24 21:56:24 +0000511 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar15146672011-10-20 22:22:38 +0200512 let {a:vt}netrw_tskeep = &l:ts
Bram Moolenaar446cb832008-06-24 21:56:24 +0000513 let {a:vt}netrw_twkeep = &l:tw " textwidth
514 let {a:vt}netrw_wigkeep = &l:wig " wildignore
Bram Moolenaar15146672011-10-20 22:22:38 +0200515 let {a:vt}netrw_wrapkeep = &l:wrap
516 let {a:vt}netrw_writekeep = &l:write
517 if g:netrw_use_noswf && has("win32") && !has("win95")
518 let {a:vt}netrw_swfkeep = &l:swf
519 endif
520
521 " save a few selected netrw-related variables
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200522" call Decho("saving a few selected netrw-related variables")
Bram Moolenaar15146672011-10-20 22:22:38 +0200523 if g:netrw_keepdir
524 let {a:vt}netrw_dirkeep = getcwd()
525 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000526 if has("win32") && !has("win95")
Bram Moolenaarc236c162008-07-13 17:41:49 +0000527 let {a:vt}netrw_swfkeep = &l:swf " swapfile
Bram Moolenaar9964e462007-05-05 17:54:07 +0000528 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200529 if &go =~# 'a' | sil! let {a:vt}netrw_regstar = @* | endif
530 sil! let {a:vt}netrw_regslash= @/
Bram Moolenaar9964e462007-05-05 17:54:07 +0000531
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200532" call Dret("s:NetrwOptionSave : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")." modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000533endfun
534
535" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +0000536" s:NetrwOptionRestore: restore options {{{2
537fun! s:NetrwOptionRestore(vt)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200538" call Dfunc("s:NetrwOptionRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar446cb832008-06-24 21:56:24 +0000539 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar15146672011-10-20 22:22:38 +0200540 if exists("s:nbcd_curpos_{bufnr('%')}")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200541" call Decho("(NetrwOptionRestore) restoring previous position (s:nbcd_curpos_".bufnr('%')." exists)")
Bram Moolenaar15146672011-10-20 22:22:38 +0200542 keepj call netrw#NetrwRestorePosn(s:nbcd_curpos_{bufnr('%')})
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200543" call Decho("(NetrwOptionRestore) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
544" call Decho("(NetrwOptionRestore) unlet s:nbcd_curpos_".bufnr('%'))
545 unlet s:nbcd_curpos_{bufnr('%')}
Bram Moolenaar15146672011-10-20 22:22:38 +0200546 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200547" call Decho("(NetrwOptionRestore) no previous position")
Bram Moolenaar15146672011-10-20 22:22:38 +0200548 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200549" call Decho("(NetrwOptionRestore) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000550" call Dret("s:NetrwOptionRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000551 return
552 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000553 unlet {a:vt}netrw_optionsave
Bram Moolenaar9964e462007-05-05 17:54:07 +0000554
555 if exists("&acd")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000556 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200557" call Decho("(NetrwOptionRestore) g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd)
Bram Moolenaar446cb832008-06-24 21:56:24 +0000558 let curdir = getcwd()
559 let &l:acd = {a:vt}netrw_acdkeep
560 unlet {a:vt}netrw_acdkeep
561 if &l:acd
Bram Moolenaar15146672011-10-20 22:22:38 +0200562" call Decho("exe keepj lcd ".fnameescape(curdir)) " NOTE: was g:netrw_fname_escape for some reason
Bram Moolenaar446cb832008-06-24 21:56:24 +0000563 try
564 if !exists("&l:acd") && !&l:acd
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200565 exe 'keepj lcd '.fnameescape(curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +0000566 endif
567 catch /^Vim\%((\a\+)\)\=:E472/
568 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".curdir."> (permissions?)",61)
569 endtry
570 endif
571 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000572 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000573 if exists("{a:vt}netrw_aikeep") |let &l:ai = {a:vt}netrw_aikeep |unlet {a:vt}netrw_aikeep |endif
574 if exists("{a:vt}netrw_awkeep") |let &l:aw = {a:vt}netrw_awkeep |unlet {a:vt}netrw_awkeep |endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200575 if exists("{a:vt}netrw_bhkeep") |let &l:bh = {a:vt}netrw_bhkeep |unlet {a:vt}netrw_bhkeep |endif
576 if exists("{a:vt}netrw_blkeep") |let &l:bl = {a:vt}netrw_blkeep |unlet {a:vt}netrw_blkeep |endif
577 if exists("{a:vt}netrw_btkeep") |let &l:bt = {a:vt}netrw_btkeep |unlet {a:vt}netrw_btkeep |endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200578 if exists("{a:vt}netrw_bombkeep") |let &l:bomb = {a:vt}netrw_bombkeep |unlet {a:vt}netrw_bombkeep |endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000579 if exists("{a:vt}netrw_cikeep") |let &l:ci = {a:vt}netrw_cikeep |unlet {a:vt}netrw_cikeep |endif
580 if exists("{a:vt}netrw_cinkeep") |let &l:cin = {a:vt}netrw_cinkeep |unlet {a:vt}netrw_cinkeep |endif
581 if exists("{a:vt}netrw_cinokeep") |let &l:cino = {a:vt}netrw_cinokeep |unlet {a:vt}netrw_cinokeep |endif
582 if exists("{a:vt}netrw_comkeep") |let &l:com = {a:vt}netrw_comkeep |unlet {a:vt}netrw_comkeep |endif
583 if exists("{a:vt}netrw_cpokeep") |let &l:cpo = {a:vt}netrw_cpokeep |unlet {a:vt}netrw_cpokeep |endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200584 if exists("{a:vt}netrw_diffkeep") |let &l:diff = {a:vt}netrw_diffkeep |unlet {a:vt}netrw_diffkeep |endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200585 if exists("{a:vt}netrw_fenkeep") |let &l:fen = {a:vt}netrw_fenkeep |unlet {a:vt}netrw_fenkeep |endif
586 if exists("{a:vt}netrw_ffkeep") |let &l:ff = {a:vt}netrw_ffkeep |unlet {a:vt}netrw_ffkeep |endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000587 if exists("{a:vt}netrw_fokeep") |let &l:fo = {a:vt}netrw_fokeep |unlet {a:vt}netrw_fokeep |endif
588 if exists("{a:vt}netrw_gdkeep") |let &l:gd = {a:vt}netrw_gdkeep |unlet {a:vt}netrw_gdkeep |endif
589 if exists("{a:vt}netrw_hidkeep") |let &l:hidden = {a:vt}netrw_hidkeep |unlet {a:vt}netrw_hidkeep |endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200590 if exists("{a:vt}netrw_imkeep") |let &l:im = {a:vt}netrw_imkeep |unlet {a:vt}netrw_imkeep |endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200591 if exists("{a:vt}netrw_iskkeep") |let &l:isk = {a:vt}netrw_iskkeep |unlet {a:vt}netrw_iskkeep |endif
592 if exists("{a:vt}netrw_lskeep") |let &l:ls = {a:vt}netrw_lskeep |unlet {a:vt}netrw_lskeep |endif
593 if exists("{a:vt}netrw_makeep") |let &l:ma = {a:vt}netrw_makeep |unlet {a:vt}netrw_makeep |endif
594 if exists("{a:vt}netrw_magickeep")|let &l:magic = {a:vt}netrw_magickeep |unlet {a:vt}netrw_magickeep|endif
595 if exists("{a:vt}netrw_modkeep") |let &l:mod = {a:vt}netrw_modkeep |unlet {a:vt}netrw_modkeep |endif
596 if exists("{a:vt}netrw_nukeep") |let &l:nu = {a:vt}netrw_nukeep |unlet {a:vt}netrw_nukeep |endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000597 if exists("{a:vt}netrw_repkeep") |let &l:report = {a:vt}netrw_repkeep |unlet {a:vt}netrw_repkeep |endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200598 if exists("{a:vt}netrw_rokeep") |let &l:ro = {a:vt}netrw_rokeep |unlet {a:vt}netrw_rokeep |endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200599 if exists("{a:vt}netrw_selkeep") |let &l:sel = {a:vt}netrw_selkeep |unlet {a:vt}netrw_selkeep |endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000600 if exists("{a:vt}netrw_spellkeep")|let &l:spell = {a:vt}netrw_spellkeep |unlet {a:vt}netrw_spellkeep|endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100601 " Problem: start with liststyle=0; press <i> : result, following line resets l:ts.
602" if exists("{a:vt}netrw_tskeep") |let &l:ts = {a:vt}netrw_tskeep |unlet {a:vt}netrw_tskeep |endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000603 if exists("{a:vt}netrw_twkeep") |let &l:tw = {a:vt}netrw_twkeep |unlet {a:vt}netrw_twkeep |endif
604 if exists("{a:vt}netrw_wigkeep") |let &l:wig = {a:vt}netrw_wigkeep |unlet {a:vt}netrw_wigkeep |endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200605 if exists("{a:vt}netrw_wrapkeep") |let &l:wrap = {a:vt}netrw_wrapkeep |unlet {a:vt}netrw_wrapkeep |endif
606 if exists("{a:vt}netrw_writekeep")|let &l:write = {a:vt}netrw_writekeep |unlet {a:vt}netrw_writekeep|endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000607 if exists("s:yykeep") |let @@ = s:yykeep |unlet s:yykeep |endif
608 if exists("{a:vt}netrw_swfkeep")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000609 if &directory == ""
610 " user hasn't specified a swapfile directory;
611 " netrw will temporarily set the swapfile directory
612 " to the current directory as returned by getcwd().
613 let &l:directory = getcwd()
Bram Moolenaaradc21822011-04-01 18:03:16 +0200614 sil! let &l:swf = {a:vt}netrw_swfkeep
Bram Moolenaar9964e462007-05-05 17:54:07 +0000615 setlocal directory=
Bram Moolenaar446cb832008-06-24 21:56:24 +0000616 unlet {a:vt}netrw_swfkeep
617 elseif &l:swf != {a:vt}netrw_swfkeep
618 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
Bram Moolenaaradc21822011-04-01 18:03:16 +0200619 sil! let &l:swf= {a:vt}netrw_swfkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +0000620 unlet {a:vt}netrw_swfkeep
Bram Moolenaar9964e462007-05-05 17:54:07 +0000621 endif
622 endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200623 if exists("{a:vt}netrw_dirkeep") && isdirectory({a:vt}netrw_dirkeep) && g:netrw_keepdir
624 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
625 if exists("{a:vt}netrw_dirkeep") |exe "keepj lcd ".fnameescape(dirkeep)|unlet {a:vt}netrw_dirkeep |endif
626 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200627 if exists("{a:vt}netrw_regstar") |sil! let @*= {a:vt}netrw_regstar |unlet {a:vt}netrw_regstar |endif
628 if exists("{a:vt}netrw_regslash")|sil! let @/= {a:vt}netrw_regslash|unlet {a:vt}netrw_regslash|endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200629 if exists("s:nbcd_curpos_{bufnr('%')}")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200630" call Decho("(NetrwOptionRestore) restoring previous position (s:nbcd_curpos_".bufnr('%')." exists)")
Bram Moolenaar15146672011-10-20 22:22:38 +0200631 keepj call netrw#NetrwRestorePosn(s:nbcd_curpos_{bufnr('%')})
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200632" call Decho("(NetrwOptionRestore) unlet s:nbcd_curpos_".bufnr('%'))
633 unlet s:nbcd_curpos_{bufnr('%')}
Bram Moolenaar15146672011-10-20 22:22:38 +0200634 else
635" call Decho("no previous position")
636 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000637
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200638" call Decho("(NetrwOptionRestore) g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd)
639" call Decho("(NetrwOptionRestore) fo=".&fo.(exists("&acd")? " acd=".&acd : " acd doesn't exist"))
640" call Decho("(NetrwOptionRestore) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
641" call Decho("(NetrwOptionRestore) diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"))
Bram Moolenaar97d62492012-11-15 21:28:22 +0100642" call Decho("(NetrwOptionRestore) ts=".&l:ts)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200643" call Dret("s:NetrwOptionRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000644endfun
645
646" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +0000647" s:NetrwSafeOptions: sets options to help netrw do its job {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +0000648fun! s:NetrwSafeOptions()
Bram Moolenaar5c736222010-01-06 20:54:52 +0100649" call Dfunc("s:NetrwSafeOptions() win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
650" call Decho("win#".winnr()."'s ft=".&ft)
Bram Moolenaar15146672011-10-20 22:22:38 +0200651 if exists("&acd") | setlocal noacd | endif
652 setlocal noai
653 setlocal noaw
654 setlocal nobomb
655 setlocal noci
656 setlocal nocin
Bram Moolenaar9964e462007-05-05 17:54:07 +0000657 setlocal cino=
658 setlocal com=
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200659 setlocal cpo-=a
660 setlocal cpo-=A
Bram Moolenaar446cb832008-06-24 21:56:24 +0000661 setlocal fo=nroql2
Bram Moolenaar15146672011-10-20 22:22:38 +0200662 setlocal nohid
663 setlocal noim
Bram Moolenaar5c736222010-01-06 20:54:52 +0100664 setlocal isk+=@ isk+=* isk+=/
Bram Moolenaar15146672011-10-20 22:22:38 +0200665 setlocal magic
666 setlocal report=10000
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200667 setlocal sel=inclusive
Bram Moolenaar15146672011-10-20 22:22:38 +0200668 setlocal nospell
669 setlocal tw=0
670 setlocal wig=
Bram Moolenaar9964e462007-05-05 17:54:07 +0000671 if g:netrw_use_noswf && has("win32") && !has("win95")
672 setlocal noswf
673 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200674 call s:NetrwCursor()
Bram Moolenaar5c736222010-01-06 20:54:52 +0100675
676 " allow the user to override safe options
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200677" call Decho("ft<".&ft."> ei=".&ei)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100678 if &ft == "netrw"
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200679" call Decho("do any netrw FileType autocmds")
Bram Moolenaar15146672011-10-20 22:22:38 +0200680 sil! keepalt keepj doau FileType netrw
Bram Moolenaar5c736222010-01-06 20:54:52 +0100681 endif
682
Bram Moolenaar446cb832008-06-24 21:56:24 +0000683" call Decho("fo=".&fo.(exists("&acd")? " acd=".&acd : " acd doesn't exist"))
Bram Moolenaar9964e462007-05-05 17:54:07 +0000684" call Dret("s:NetrwSafeOptions")
685endfun
686
Bram Moolenaar446cb832008-06-24 21:56:24 +0000687" ---------------------------------------------------------------------
688" netrw#NetrwClean: remove netrw {{{2
689" supports :NetrwClean -- remove netrw from first directory on runtimepath
690" :NetrwClean! -- remove netrw from all directories on runtimepath
691fun! netrw#NetrwClean(sys)
692" call Dfunc("netrw#NetrwClean(sys=".a:sys.")")
693
694 if a:sys
695 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
696 else
697 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
698 endif
699" call Decho("choice=".choice)
700 let diddel= 0
701 let diddir= ""
702
703 if choice == 1
704 for dir in split(&rtp,',')
705 if filereadable(dir."/plugin/netrwPlugin.vim")
706" call Decho("removing netrw-related files from ".dir)
Bram Moolenaarc236c162008-07-13 17:41:49 +0000707 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
708 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
709 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
710 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
711 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
712 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 +0000713 let diddir= dir
714 let diddel= diddel + 1
715 if !a:sys|break|endif
716 endif
717 endfor
718 endif
719
720 echohl WarningMsg
721 if diddel == 0
722 echomsg "netrw is either not installed or not removable"
723 elseif diddel == 1
724 echomsg "removed one copy of netrw from <".diddir.">"
725 else
726 echomsg "removed ".diddel." copies of netrw"
727 endif
728 echohl None
729
730" call Dret("netrw#NetrwClean")
731endfun
732
Bram Moolenaar5c736222010-01-06 20:54:52 +0100733" ---------------------------------------------------------------------
734" netrw#Nread: {{{2
735fun! netrw#Nread(mode,fname)
736" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
737 call netrw#NetrwSavePosn()
738 call netrw#NetRead(a:mode,a:fname)
739 call netrw#NetrwRestorePosn()
740" call Dret("netrw#Nread")
741endfun
742
Bram Moolenaar9964e462007-05-05 17:54:07 +0000743" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000744" Netrw Transfer Functions: {{{1
745" ===============================
746
Bram Moolenaar071d4272004-06-13 20:20:40 +0000747" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +0000748" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +0000749" mode: =0 read remote file and insert before current line
750" =1 read remote file and insert after current line
751" =2 replace with remote file
752" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000753fun! netrw#NetRead(mode,...)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000754" call Dfunc("netrw#NetRead(mode=".a:mode.",...) a:0=".a:0." ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000755
Bram Moolenaar5c736222010-01-06 20:54:52 +0100756 " NetRead: save options {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +0000757 call s:NetrwOptionSave("w:")
758 call s:NetrwSafeOptions()
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200759 call s:RestoreCursorline()
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000760
Bram Moolenaar5c736222010-01-06 20:54:52 +0100761 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000762 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000763 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000764 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000765 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000766 elseif a:mode == 2 " replace with remote file
767 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +0000768 elseif a:mode == 3 " skip read of file (leave as temporary)
769 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000770 else
771 exe a:mode
772 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000773 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000774 let ichoice = (a:0 == 0)? 0 : 1
775" call Decho("readcmd<".readcmd."> ichoice=".ichoice)
776
Bram Moolenaar5c736222010-01-06 20:54:52 +0100777 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +0000778 let tmpfile= s:GetTempfile("")
779 if tmpfile == ""
780" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000781 return
782 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000783
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000784 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000785
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000786 " attempt to repeat with previous host-file-etc
787 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000788" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000789 let choice = b:netrw_lastfile
790 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000791
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000792 else
793 exe "let choice= a:" . ichoice
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000794" call Decho("no lastfile: choice<" . choice . ">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000795
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000796 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000797 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000798 echomsg 'NetRead Usage:'
799 echomsg ':Nread machine:path uses rcp'
800 echomsg ':Nread "machine path" uses ftp with <.netrc>'
801 echomsg ':Nread "machine id password path" uses ftp'
802 echomsg ':Nread dav://machine[:port]/path uses cadaver'
803 echomsg ':Nread fetch://machine/path uses fetch'
804 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
805 echomsg ':Nread http://[user@]machine/path uses http wget'
806 echomsg ':Nread rcp://[user@]machine/path uses rcp'
807 echomsg ':Nread rsync://machine[:port]/path uses rsync'
808 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
809 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000810 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000811 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000812
Bram Moolenaar9964e462007-05-05 17:54:07 +0000813 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000814 " Reconstruct Choice if choice starts with '"'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000815" call Decho("reconstructing choice")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000816 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000817 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +0200818 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000819 else
820 " case "... ... ..."
821 let choice = strpart(choice,1,strlen(choice)-1)
822 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000823
Bram Moolenaar9964e462007-05-05 17:54:07 +0000824 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000825 let wholechoice = wholechoice . " " . choice
826 let ichoice = ichoice + 1
827 if ichoice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000828 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000829 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000830 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000831" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000832 return
833 endif
834 let choice= a:{ichoice}
835 endwhile
836 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
837 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000838 endif
839 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000840
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000841" call Decho("choice<" . choice . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000842 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000843
Bram Moolenaar5c736222010-01-06 20:54:52 +0100844 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +0000845 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100846 if !exists("b:netrw_method") || b:netrw_method < 0
847" call Dfunc("netrw#NetRead : unsupported method")
848 return
849 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000850 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000851
Bram Moolenaar446cb832008-06-24 21:56:24 +0000852 " Check if NetrwBrowse() should be handling this request
853" call Decho("checking if NetrwBrowse() should handle choice<".choice."> with netrw_list_cmd<".g:netrw_list_cmd.">")
Bram Moolenaar15146672011-10-20 22:22:38 +0200854 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000855" call Decho("yes, choice matches '^.*[\/]$'")
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200856 keepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000857" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000858 return
Bram Moolenaar071d4272004-06-13 20:20:40 +0000859 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000860
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000861 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +0100862 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000863 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000864 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
865 echo "(netrw) Processing your read request..."
866 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000867
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000868 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +0100869 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000870 if b:netrw_method == 1 " read with rcp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000871" call Decho("read via rcp (method #1)")
Bram Moolenaard68071d2006-05-02 22:08:30 +0000872 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000873 " ER: on Win2K" rcp machine[.user]:file tmpfile
874 " ER: if machine contains '.' adding .user is required (use $USERNAME)
875 " ER: the tmpfile is full path: rcp sees C:\... as host C
876 if s:netrw_has_nt_rcp == 1
877 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
878 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
879 else
880 " Any way needed it machine contains a '.'
881 let uid_machine = g:netrw_machine .'.'. $USERNAME
882 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000883 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000884 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
885 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
886 else
887 let uid_machine = g:netrw_machine
888 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000889 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +0000890" call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".shellescape(uid_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100891 exe s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".shellescape(uid_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +0000892 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000893 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000894
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000895 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +0100896 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000897 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000898" call Decho("read via ftp+.netrc (method #2)")
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000899 let netrw_fname= b:netrw_fname
Bram Moolenaaradc21822011-04-01 18:03:16 +0200900 keepj call s:SaveBufVars()|new|keepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000901 let filtbuf= bufnr("%")
Bram Moolenaar8299df92004-07-10 09:47:34 +0000902 setlocal ff=unix
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200903 keepj put =g:netrw_ftpmode
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000904" call Decho("filter input: ".getline(line("$")))
Bram Moolenaar9964e462007-05-05 17:54:07 +0000905 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200906 keepj put =g:netrw_ftpextracmd
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000907" call Decho("filter input: ".getline(line("$")))
Bram Moolenaar9964e462007-05-05 17:54:07 +0000908 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000909 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
910" call Decho("filter input: ".getline(line("$")))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000911 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +0200912" call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
913 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000914 else
Bram Moolenaaradc21822011-04-01 18:03:16 +0200915" call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
916 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000917 endif
918 " 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 +0000919 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +0000920 let debugkeep = &debug
Bram Moolenaar9964e462007-05-05 17:54:07 +0000921 setlocal debug=msg
Bram Moolenaaradc21822011-04-01 18:03:16 +0200922 keepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +0000923 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000924 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +0000925 call s:SaveBufVars()
926 bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +0100927 if bufname("%") == "" && getline("$") == "" && line('$') == 1
928 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +0000929 q!
930 endif
931 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +0000932 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000933 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000934
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000935 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +0100936 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000937 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
938 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000939" call Decho("read via ftp+mipf (method #3)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000940 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaaradc21822011-04-01 18:03:16 +0200941 keepj call s:SaveBufVars()|new|keepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000942 let filtbuf= bufnr("%")
Bram Moolenaar8299df92004-07-10 09:47:34 +0000943 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000944 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200945 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar446cb832008-06-24 21:56:24 +0000946" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000947 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200948 keepj put ='open '.g:netrw_machine
Bram Moolenaar446cb832008-06-24 21:56:24 +0000949" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000950 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000951
Bram Moolenaar97d62492012-11-15 21:28:22 +0100952 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200953 if exists("g:netrw_ftp") && g:netrw_ftp == 1
954 keepj put =g:netrw_uid
955" call Decho("filter input: ".getline('.'))
956 if exists("s:netrw_passwd")
957 keepj put ='\"'.s:netrw_passwd.'\"'
958 endif
959" call Decho("filter input: ".getline('.'))
960 elseif exists("s:netrw_passwd")
961 keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
962" call Decho("filter input: ".getline('.'))
963 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000964 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000965
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000966 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200967 keepj put =g:netrw_ftpmode
Bram Moolenaar446cb832008-06-24 21:56:24 +0000968" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000969 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000970 if exists("g:netrw_ftpextracmd")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200971 keepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +0000972" call Decho("filter input: ".getline('.'))
Bram Moolenaar9964e462007-05-05 17:54:07 +0000973 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200974 keepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +0000975" call Decho("filter input: ".getline('.'))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000976
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000977 " perform ftp:
978 " -i : turns off interactive prompting from ftp
979 " -n unix : DON'T use <.netrc>, even though it exists
980 " -n win32: quit being obnoxious about password
Bram Moolenaaradc21822011-04-01 18:03:16 +0200981 keepj norm! 1Gdd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200982" call Decho("executing: %!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
983 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000984 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
985 if getline(1) !~ "^$"
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000986" call Decho("error<".getline(1).">")
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000987 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000988 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000989 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000990 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000991 call s:SaveBufVars()|bd!|call s:RestoreBufVars()
992 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000993 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000994
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000995 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +0100996 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000997 elseif b:netrw_method == 4 " read with scp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000998" call Decho("read via scp (method #4)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000999 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00001000 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001001 else
1002 let useport= ""
1003 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01001004" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001005 exe s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00001006 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001007 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001008
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001009 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001010 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001011 elseif b:netrw_method == 5
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001012" call Decho("read via http (method #5)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001013 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001014 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001015 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001016 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00001017" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001018 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001019 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001020
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001021 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
1022 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaarc236c162008-07-13 17:41:49 +00001023" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)")
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001024 if exists("g:netrw_http_xcmd")
1025" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape("http://".g:netrw_machine.b:netrw_fname,1)." ".g:netrw_http_xcmd." ".shellescape(tmpfile,1))
1026 exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape("http://".g:netrw_machine.b:netrw_fname,1)." ".g:netrw_http_xcmd." ".shellescape(tmpfile,1)
1027 else
1028" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape("http://".g:netrw_machine.b:netrw_fname,1))
1029 exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape("http://".g:netrw_machine.b:netrw_fname,1)
1030 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00001031 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001032
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001033 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001034 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaaradc21822011-04-01 18:03:16 +02001035" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)")
Bram Moolenaarc236c162008-07-13 17:41:49 +00001036 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
1037 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001038" call Decho("netrw_html<".netrw_html.">")
1039" call Decho("netrw_tag <".netrw_tag.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +00001040" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape("http://".g:netrw_machine.netrw_html,1))
1041 exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape("http://".g:netrw_machine.netrw_html,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00001042 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001043" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/')
Bram Moolenaaradc21822011-04-01 18:03:16 +02001044 exe 'keepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001045 endif
1046 let b:netrw_lastfile = choice
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001047" call Decho("(NetRead) setl ro")
1048 setl ro
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001049
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001050 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001051 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001052 elseif b:netrw_method == 6
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001053" call Decho("read via cadaver (method #6)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001054
Bram Moolenaar5c736222010-01-06 20:54:52 +01001055 if !executable(g:netrw_dav_cmd)
1056 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
1057" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
1058 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001059 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01001060 if g:netrw_dav_cmd =~ "curl"
1061" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_dav_cmd." ".shellescape("dav://".g:netrw_machine.b:netrw_fname,1)." ".shellescape(tmpfile,1))
1062 exe s:netrw_silentxfer."!".g:netrw_dav_cmd." ".shellescape("dav://".g:netrw_machine.b:netrw_fname,1)." ".shellescape(tmpfile,1)
1063 else
1064 " Construct execution string (four lines) which will be passed through filter
1065 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
1066 new
1067 setlocal ff=unix
1068 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001069 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01001070 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001071 keepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01001072 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001073 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
1074 keepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
1075 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001076 keepj put ='get '.netrw_fname.' '.tmpfile
1077 keepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001078
Bram Moolenaar5c736222010-01-06 20:54:52 +01001079 " perform cadaver operation:
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001080 keepj norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001081" call Decho("executing: %!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01001082 exe s:netrw_silentxfer."%!".g:netrw_dav_cmd
1083 bd!
1084 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00001085 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001086 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001087
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001088 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001089 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001090 elseif b:netrw_method == 7
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001091" call Decho("read via rsync (method #7)")
Bram Moolenaarc236c162008-07-13 17:41:49 +00001092" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1))
1093 exe s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00001094 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001095 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001096
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001097 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001098 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001099 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001100 elseif b:netrw_method == 8
Bram Moolenaar9964e462007-05-05 17:54:07 +00001101" call Decho("read via fetch (method #8)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001102 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001103 if !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02001104 keepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001105 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001106" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001107 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001108 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02001109 if exists("g:netrw_option") && g:netrw_option == ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001110 let netrw_option= "http"
1111 else
1112 let netrw_option= "ftp"
1113 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001114" call Decho("read via fetch for ".netrw_option)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001115
Bram Moolenaar446cb832008-06-24 21:56:24 +00001116 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00001117" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".shellescape(tmpfile,1)." ".shellescape(netrw_option."://".g:netrw_uid.':'.s:netrw_passwd.'@'.g:netrw_machine."/".b:netrw_fname,1))
1118 exe s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".shellescape(tmpfile,1)." ".shellescape(netrw_option."://".g:netrw_uid.':'.s:netrw_passwd.'@'.g:netrw_machine."/".b:netrw_fname,1)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001119 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00001120" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".shellescape(tmpfile,1)." ".shellescape(netrw_option."://".g:netrw_machine."/".b:netrw_fname,1))
1121 exe s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".shellescape(tmpfile,1)." ".shellescape(netrw_option."://".g:netrw_machine."/".b:netrw_fname,1)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001122 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001123
Bram Moolenaar446cb832008-06-24 21:56:24 +00001124 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001125 let b:netrw_lastfile = choice
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001126" call Decho("(NetRead) setl ro")
1127 setl ro
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001128
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001129 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001130 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001131 elseif b:netrw_method == 9
Bram Moolenaar9964e462007-05-05 17:54:07 +00001132" call Decho("read via sftp (method #9)")
Bram Moolenaarc236c162008-07-13 17:41:49 +00001133" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".tmpfile)
1134 exe s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +00001135 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001136 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001137
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001138 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001139 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001140 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00001141 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001142 endif
1143 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001144
Bram Moolenaar5c736222010-01-06 20:54:52 +01001145 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001146 if exists("b:netrw_method")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001147" call Decho("cleanup b:netrw_method and b:netrw_fname")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001148 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001149 unlet b:netrw_fname
1150 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02001151 if s:FileReadable(tmpfile) && tmpfile !~ '.tar.bz2$' && tmpfile !~ '.tar.gz$' && tmpfile !~ '.zip' && tmpfile !~ '.tar' && readcmd != 't' && tmpfile !~ '.tar.xz$' && tmpfile !~ '.txz'
Bram Moolenaar9964e462007-05-05 17:54:07 +00001152" call Decho("cleanup by deleting tmpfile<".tmpfile.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02001153 keepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00001154 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02001155 keepj call s:NetrwOptionRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00001156
Bram Moolenaar9964e462007-05-05 17:54:07 +00001157" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001158endfun
1159
1160" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001161" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001162fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00001163" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001164
Bram Moolenaar5c736222010-01-06 20:54:52 +01001165 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001166 let mod= 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00001167 call s:NetrwOptionSave("w:")
1168 call s:NetrwSafeOptions()
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001169
Bram Moolenaar5c736222010-01-06 20:54:52 +01001170 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00001171 let tmpfile= s:GetTempfile("")
1172 if tmpfile == ""
1173" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001174 return
1175 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001176
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001177 if a:0 == 0
1178 let ichoice = 0
1179 else
1180 let ichoice = 1
1181 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001182
Bram Moolenaar9964e462007-05-05 17:54:07 +00001183 let curbufname= expand("%")
1184" call Decho("curbufname<".curbufname.">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001185 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00001186 " For binary writes, always write entire file.
1187 " (line numbers don't really make sense for that).
1188 " Also supports the writing of tar and zip files.
Bram Moolenaaradc21822011-04-01 18:03:16 +02001189" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile))
1190 exe "sil keepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00001191 elseif g:netrw_cygwin
1192 " write (selected portion of) file to temporary
1193 let cygtmpfile= substitute(tmpfile,'/cygdrive/\(.\)','\1:','')
Bram Moolenaaradc21822011-04-01 18:03:16 +02001194" call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001195 exe "sil keepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001196 else
1197 " write (selected portion of) file to temporary
Bram Moolenaaradc21822011-04-01 18:03:16 +02001198" call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001199 exe "sil keepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001200 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001201
Bram Moolenaar9964e462007-05-05 17:54:07 +00001202 if curbufname == ""
1203 " if the file is [No Name], and one attempts to Nwrite it, the buffer takes
1204 " on the temporary file's name. Deletion of the temporary file during
1205 " cleanup then causes an error message.
1206 0file!
1207 endif
1208
Bram Moolenaar5c736222010-01-06 20:54:52 +01001209 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001210 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001211
Bram Moolenaar9964e462007-05-05 17:54:07 +00001212 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001213 " attempt to repeat with previous host-file-etc
1214 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001215" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001216 let choice = b:netrw_lastfile
1217 let ichoice= ichoice + 1
1218 else
1219 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001220
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001221 " Reconstruct Choice if choice starts with '"'
1222 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001223 echomsg 'NetWrite Usage:"'
1224 echomsg ':Nwrite machine:path uses rcp'
1225 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
1226 echomsg ':Nwrite "machine id password path" uses ftp'
1227 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
1228 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
1229 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
1230 echomsg ':Nwrite rcp://machine/path uses rcp'
1231 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
1232 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
1233 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00001234 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001235 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001236
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001237 elseif match(choice,"^\"") != -1
1238 if match(choice,"\"$") != -1
1239 " case "..."
1240 let choice=strpart(choice,1,strlen(choice)-2)
1241 else
1242 " case "... ... ..."
1243 let choice = strpart(choice,1,strlen(choice)-1)
1244 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001245
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001246 while match(choice,"\"$") == -1
1247 let wholechoice= wholechoice . " " . choice
1248 let ichoice = ichoice + 1
1249 if choice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001250 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001251 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001252 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00001253" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001254 return
1255 endif
1256 let choice= a:{ichoice}
1257 endwhile
1258 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
1259 endif
1260 endif
1261 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001262 let ichoice= ichoice + 1
Bram Moolenaar9964e462007-05-05 17:54:07 +00001263" call Decho("choice<" . choice . "> ichoice=".ichoice)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001264
Bram Moolenaar9964e462007-05-05 17:54:07 +00001265 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaaradc21822011-04-01 18:03:16 +02001266 keepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01001267 if !exists("b:netrw_method") || b:netrw_method < 0
1268" call Dfunc("netrw#NetWrite : unsupported method")
1269 return
1270 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001271
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001272 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01001273 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001274 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001275 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
1276 echo "(netrw) Processing your write request..."
Bram Moolenaar446cb832008-06-24 21:56:24 +00001277" call Decho("(netrw) Processing your write request...")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001278 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001279
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001280 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001281 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001282 if b:netrw_method == 1
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001283" call Decho("write via rcp (method #1)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001284 if s:netrw_has_nt_rcp == 1
1285 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
1286 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
1287 else
1288 let uid_machine = g:netrw_machine .'.'. $USERNAME
1289 endif
1290 else
1291 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
1292 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
1293 else
1294 let uid_machine = g:netrw_machine
1295 endif
1296 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00001297" call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".shellescape(tmpfile,1)." ".shellescape(uid_machine.":".b:netrw_fname,1))
1298 exe s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".shellescape(tmpfile,1)." ".shellescape(uid_machine.":".b:netrw_fname,1)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001299 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001300
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001301 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001302 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001303 elseif b:netrw_method == 2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001304" call Decho("write via ftp+.netrc (method #2)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001305 let netrw_fname = b:netrw_fname
1306
1307 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
1308 let bhkeep = &l:bh
1309 let curbuf = bufnr("%")
1310 setlocal bh=hide
1311 enew
1312
Bram Moolenaar446cb832008-06-24 21:56:24 +00001313" call Decho("filter input window#".winnr())
Bram Moolenaar8299df92004-07-10 09:47:34 +00001314 setlocal ff=unix
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001315 keepj put =g:netrw_ftpmode
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001316" call Decho("filter input: ".getline('$'))
Bram Moolenaar9964e462007-05-05 17:54:07 +00001317 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001318 keepj put =g:netrw_ftpextracmd
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001319" call Decho("filter input: ".getline("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00001320 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02001321 keepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001322" call Decho("filter input: ".getline("$"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001323 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02001324" call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
1325 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001326 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00001327" call Decho("filter input window#".winnr())
Bram Moolenaaradc21822011-04-01 18:03:16 +02001328" call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
1329 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001330 endif
1331 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1332 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001333 if !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02001334 keepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001335 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001336 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001337 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01001338
1339 " remove enew buffer (quietly)
1340 let filtbuf= bufnr("%")
1341 exe curbuf."b!"
1342 let &l:bh = bhkeep
1343 exe filtbuf."bw!"
1344
Bram Moolenaar071d4272004-06-13 20:20:40 +00001345 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001346
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001347 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001348 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001349 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01001350 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaar9964e462007-05-05 17:54:07 +00001351" call Decho("read via ftp+mipf (method #3)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001352 let netrw_fname = b:netrw_fname
1353 let bhkeep = &l:bh
1354
1355 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
1356 let curbuf = bufnr("%")
1357 setlocal bh=hide
1358 enew
Bram Moolenaar8299df92004-07-10 09:47:34 +00001359 setlocal ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01001360
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001361 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001362 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar446cb832008-06-24 21:56:24 +00001363" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001364 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001365 keepj put ='open '.g:netrw_machine
Bram Moolenaar446cb832008-06-24 21:56:24 +00001366" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001367 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001368 if exists("g:netrw_uid") && g:netrw_uid != ""
1369 if exists("g:netrw_ftp") && g:netrw_ftp == 1
1370 keepj put =g:netrw_uid
1371" call Decho("filter input: ".getline('.'))
1372 if exists("s:netrw_passwd") && s:netrw_passwd != ""
1373 keepj put ='\"'.s:netrw_passwd.'\"'
1374 endif
1375" call Decho("filter input: ".getline('.'))
1376 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
1377 keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
1378" call Decho("filter input: ".getline('.'))
1379 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001380 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001381 keepj put =g:netrw_ftpmode
Bram Moolenaar5c736222010-01-06 20:54:52 +01001382" call Decho("filter input: ".getline('$'))
1383 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001384 keepj put =g:netrw_ftpextracmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01001385" call Decho("filter input: ".getline("$"))
1386 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001387 keepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaar446cb832008-06-24 21:56:24 +00001388" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001389 " save choice/id/password for future use
1390 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001391
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001392 " perform ftp:
1393 " -i : turns off interactive prompting from ftp
1394 " -n unix : DON'T use <.netrc>, even though it exists
1395 " -n win32: quit being obnoxious about password
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001396 keepj norm! 1Gdd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001397" call Decho("executing: %!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
1398 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001399 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1400 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001401 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001402 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001403 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001404 let mod=1
1405 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01001406
1407 " remove enew buffer (quietly)
1408 let filtbuf= bufnr("%")
1409 exe curbuf."b!"
1410 let &l:bh= bhkeep
1411 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001412
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001413 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001414 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001415 elseif b:netrw_method == 4
Bram Moolenaar9964e462007-05-05 17:54:07 +00001416" call Decho("write via scp (method #4)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001417 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00001418 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001419 else
1420 let useport= ""
1421 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00001422" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1))
1423 exe s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001424 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001425
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001426 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001427 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001428 elseif b:netrw_method == 5
Bram Moolenaar9964e462007-05-05 17:54:07 +00001429" call Decho("write via http (method #5)")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001430 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001431 call netrw#ErrorMsg(s:ERROR,"currently <netrw.vim> does not support writing using http:",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001432 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001433
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001434 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001435 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001436 elseif b:netrw_method == 6
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001437" call Decho("write via cadaver (method #6)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001438
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001439 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01001440 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
1441 let bhkeep = &l:bh
1442
1443 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
1444 let curbuf = bufnr("%")
1445 setlocal bh=hide
1446 enew
1447
Bram Moolenaar8299df92004-07-10 09:47:34 +00001448 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001449 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001450 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001451 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001452 keepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001453 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001454 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001455 keepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00001456 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001457 keepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001458
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001459 " perform cadaver operation:
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001460 keepj norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001461" call Decho("executing: %!".g:netrw_dav_cmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +00001462 exe s:netrw_silentxfer."%!".g:netrw_dav_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01001463
1464 " remove enew buffer (quietly)
1465 let filtbuf= bufnr("%")
1466 exe curbuf."b!"
1467 let &l:bh = bhkeep
1468 exe filtbuf."bw!"
1469
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001470 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001471
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001472 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001473 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001474 elseif b:netrw_method == 7
Bram Moolenaar9964e462007-05-05 17:54:07 +00001475" call Decho("write via rsync (method #7)")
Bram Moolenaarc236c162008-07-13 17:41:49 +00001476" call Decho("executing: !".g:netrw_rsync_cmd." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1))
1477 exe s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001478 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001479
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001480 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001481 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001482 elseif b:netrw_method == 9
Bram Moolenaar97d62492012-11-15 21:28:22 +01001483" call Decho("write via sftp (method #9)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001484 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001485 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
1486 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
1487 else
1488 let uid_machine = g:netrw_machine
1489 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01001490
1491 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
1492 let bhkeep = &l:bh
1493 let curbuf = bufnr("%")
1494 setlocal bh=hide
1495 enew
1496
Bram Moolenaar8299df92004-07-10 09:47:34 +00001497 setlocal ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01001498 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00001499" call Decho("filter input: ".getline('.'))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001500" call Decho("executing: %!".g:netrw_sftp_cmd.' '.shellescape(uid_machine,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01001501 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
1502 exe s:netrw_silentxfer."%!".sftpcmd.' '.shellescape(uid_machine,1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01001503 let filtbuf= bufnr("%")
1504 exe curbuf."b!"
1505 let &l:bh = bhkeep
1506 exe filtbuf."bw!"
1507 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001508
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001509 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001510 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001511 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00001512 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02001513 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001514 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001515 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001516
Bram Moolenaar5c736222010-01-06 20:54:52 +01001517 " NetWrite: Cleanup: {{{3
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001518" call Decho("cleanup")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001519 if s:FileReadable(tmpfile)
1520" call Decho("tmpfile<".tmpfile."> readable, will now delete it")
Bram Moolenaarc236c162008-07-13 17:41:49 +00001521 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00001522 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00001523 call s:NetrwOptionRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001524
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001525 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001526 " restore modifiability; usually equivalent to set nomod
1527 let &mod= mod
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001528" call Decho("(NetWrite) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02001529 elseif !exists("leavemod")
1530 " indicate that the buffer has not been modified since last written
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001531" call Decho("(NetWrite) set nomod")
Bram Moolenaaradc21822011-04-01 18:03:16 +02001532 set nomod
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001533" call Decho("(NetWrite) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar071d4272004-06-13 20:20:40 +00001534 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001535
Bram Moolenaar9964e462007-05-05 17:54:07 +00001536" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001537endfun
1538
1539" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001540" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001541" uses NetRead to get a copy of the file into a temporarily file,
1542" then sources that file,
1543" then removes that file.
1544fun! netrw#NetSource(...)
1545" call Dfunc("netrw#NetSource() a:0=".a:0)
1546 if a:0 > 0 && a:1 == '?'
1547 " give help
1548 echomsg 'NetSource Usage:'
1549 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
1550 echomsg ':Nsource fetch://machine/path uses fetch'
1551 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02001552 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00001553 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
1554 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
1555 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
1556 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
1557 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001558 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00001559 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001560 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00001561 call netrw#NetRead(3,a:{i})
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001562" call Decho("(netrw#NetSource) s:netread_tmpfile<".s:netrw_tmpfile.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001563 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001564" call Decho("(netrw#NetSource) exe so ".fnameescape(s:netrw_tmpfile))
1565 exe "so ".fnameescape(s:netrw_tmpfile)
1566" call Decho("(netrw#NetSource) delete(".s:netrw_tmpfile.")")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001567 call delete(s:netrw_tmpfile)
1568 unlet s:netrw_tmpfile
1569 else
1570 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
1571 endif
1572 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001573 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00001574 endif
1575" call Dret("netrw#NetSource")
1576endfun
1577
1578" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00001579" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001580" readcmd == %r : replace buffer with newly read file
1581" == 0r : read file at top of buffer
1582" == r : read file after current line
1583" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00001584fun! s:NetrwGetFile(readcmd, tfile, method)
1585" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001586
1587 " readcmd=='t': simply do nothing
1588 if a:readcmd == 't'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001589" call Decho("(NetrwGetFile) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001590" call Dret("NetrwGetFile : skip read of <".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001591 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001592 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001593
Bram Moolenaar9964e462007-05-05 17:54:07 +00001594 " get name of remote filename (ie. url and all)
1595 let rfile= bufname("%")
1596" call Decho("rfile<".rfile.">")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001597
Bram Moolenaar9964e462007-05-05 17:54:07 +00001598 if exists("*NetReadFixup")
1599 " for the use of NetReadFixup (not otherwise used internally)
1600 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001601 endif
1602
Bram Moolenaar9964e462007-05-05 17:54:07 +00001603 if a:readcmd[0] == '%'
1604 " get file into buffer
1605" call Decho("get file into buffer")
1606
1607 " rename the current buffer to the temp file (ie. tfile)
1608 if g:netrw_cygwin
1609 let tfile= substitute(a:tfile,'/cygdrive/\(.\)','\1:','')
1610 else
1611 let tfile= a:tfile
1612 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02001613" call Decho("exe sil! keepalt file ".fnameescape(tfile))
1614 exe "sil! keepalt file ".fnameescape(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00001615
1616 " edit temporary file (ie. read the temporary file in)
1617 if rfile =~ '\.zip$'
1618" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)")
1619 call zip#Browse(tfile)
1620 elseif rfile =~ '\.tar$'
1621" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)")
1622 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02001623 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00001624" call Decho("handling remote gzip-compressed tar file")
1625 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02001626 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00001627" call Decho("handling remote bz2-compressed tar file")
1628 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02001629 elseif rfile =~ '\.tar\.xz$'
1630" call Decho("handling remote xz-compressed tar file")
1631 call tar#Browse(tfile)
1632 elseif rfile =~ '\.txz$'
1633" call Decho("handling remote xz-compressed tar file (.txz)")
1634 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00001635 else
1636" call Decho("edit temporary file")
1637 e!
1638 endif
1639
1640 " rename buffer back to remote filename
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02001641" call Decho("exe sil! keepalt file ".fnameescape(rfile))
Bram Moolenaaradc21822011-04-01 18:03:16 +02001642 exe "sil! keepj keepalt file ".fnameescape(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001643
Bram Moolenaar97d62492012-11-15 21:28:22 +01001644 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001645 " Note that isk must not include a "/" for scripts.vim
1646 " to process this detection correctly.
1647" call Decho("detect filetype of local version of remote file")
Bram Moolenaar97d62492012-11-15 21:28:22 +01001648 let iskkeep= &l:isk
1649 setl isk-=/
Bram Moolenaar5c736222010-01-06 20:54:52 +01001650 filetype detect
Bram Moolenaar97d62492012-11-15 21:28:22 +01001651 let &l:isk= iskkeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00001652" call Dredir("renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">","ls!")
1653 let line1 = 1
1654 let line2 = line("$")
1655
1656 elseif s:FileReadable(a:tfile)
1657 " read file after current line
1658" call Decho("read file<".a:tfile."> after current line")
1659 let curline = line(".")
1660 let lastline= line("$")
Bram Moolenaarc236c162008-07-13 17:41:49 +00001661" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline)
Bram Moolenaaradc21822011-04-01 18:03:16 +02001662 exe "keepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00001663 let line1= curline + 1
1664 let line2= line("$") - lastline + 1
1665
1666 else
1667 " not readable
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001668" call Decho("(NetrwGetFile) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001669" call Decho("tfile<".a:tfile."> not readable")
Bram Moolenaaradc21822011-04-01 18:03:16 +02001670 keepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00001671" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001672 return
1673 endif
1674
1675 " User-provided (ie. optional) fix-it-up command
1676 if exists("*NetReadFixup")
1677" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02001678 keepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00001679" else " Decho
1680" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")")
1681 endif
1682
Bram Moolenaaradc21822011-04-01 18:03:16 +02001683 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00001684 " update the Buffers menu
Bram Moolenaaradc21822011-04-01 18:03:16 +02001685 keepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00001686 endif
1687
1688" call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> tfile<".a:tfile."> readable=".s:FileReadable(a:tfile))
1689
1690 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00001691" redraw!
1692
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001693" call Decho("(NetrwGetFile) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001694" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001695endfun
1696
Bram Moolenaar9964e462007-05-05 17:54:07 +00001697" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001698" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01001699" Input:
1700" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
1701" Output:
1702" b:netrw_method= 1: rcp
1703" 2: ftp + <.netrc>
1704" 3: ftp + machine, id, password, and [path]filename
1705" 4: scp
Bram Moolenaar15146672011-10-20 22:22:38 +02001706" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01001707" 6: dav
1708" 7: rsync
1709" 8: fetch
1710" 9: sftp
1711" g:netrw_machine= hostname
1712" b:netrw_fname = filename
1713" g:netrw_port = optional port number (for ftp)
1714" g:netrw_choice = copy of input url (choice)
1715fun! s:NetrwMethod(choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00001716" call Dfunc("NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001717
Bram Moolenaar251e1912011-06-19 05:09:16 +02001718 " sanity check: choice should have at least three slashes in it
1719 if strlen(substitute(a:choice,'[^/]','','g')) < 3
1720 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
1721 let b:netrw_method = -1
1722" call Dret("NetrwMethod : incorrect url format<".a:choice.">")
1723 return
1724 endif
1725
Bram Moolenaar5c736222010-01-06 20:54:52 +01001726 " record current g:netrw_machine, if any
1727 " curmachine used if protocol == ftp and no .netrc
1728 if exists("g:netrw_machine")
1729 let curmachine= g:netrw_machine
1730" call Decho("curmachine<".curmachine.">")
1731 else
1732 let curmachine= "N O T A HOST"
1733 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02001734 if exists("g:netrw_port")
1735 let netrw_port= g:netrw_port
1736 endif
1737
1738 " insure that netrw_ftp_cmd starts off every method determination
1739 " with the current g:netrw_ftp_cmd
1740 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01001741
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001742 " initialization
1743 let b:netrw_method = 0
1744 let g:netrw_machine = ""
1745 let b:netrw_fname = ""
1746 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001747 let g:netrw_choice = a:choice
1748
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001749 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001750 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00001751 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
1752 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001753 " rcpurm : rcp://[user@]host/filename Use rcp
1754 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001755 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02001756 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01001757 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001758 " rsyncurm : rsync://host[:port]/path Use rsync
1759 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
1760 " sftpurm : sftp://[user@]host/filename Use scp
1761 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
1762 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02001763" let ftpurm = '^ftp://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
1764" let rcpurm = '^rcp://\%(\([^/@]\{-}\)@\)\=\([^/]\{-}\)/\(.*\)$'
1765" let fetchurm = '^fetch://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
1766 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
1767 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001768 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001769 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02001770 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00001771 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001772 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02001773 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001774 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001775
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001776" call Decho("determine method:")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001777 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02001778 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001779 if match(a:choice,rcpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001780" call Decho("rcp://...")
Bram Moolenaar83bab712005-08-01 21:58:57 +00001781 let b:netrw_method = 1
1782 let userid = substitute(a:choice,rcpurm,'\1',"")
1783 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
1784 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001785 if userid != ""
1786 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00001787 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001788
Bram Moolenaaradc21822011-04-01 18:03:16 +02001789 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001790 elseif match(a:choice,scpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001791" call Decho("scp://...")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001792 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00001793 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
1794 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
1795 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001796
Bram Moolenaar15146672011-10-20 22:22:38 +02001797 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001798 elseif match(a:choice,httpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001799" call Decho("http://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001800 let b:netrw_method = 5
1801 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
1802 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001803
Bram Moolenaaradc21822011-04-01 18:03:16 +02001804 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001805 elseif match(a:choice,davurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001806" call Decho("dav://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001807 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02001808 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001809 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
1810 else
1811 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
1812 endif
1813 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001814
Bram Moolenaaradc21822011-04-01 18:03:16 +02001815 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001816 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001817" call Decho("rsync://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001818 let b:netrw_method = 7
1819 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
1820 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001821
Bram Moolenaaradc21822011-04-01 18:03:16 +02001822 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001823 elseif match(a:choice,ftpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001824" call Decho("ftp://...")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001825 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001826 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
1827 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
1828 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001829" call Decho("g:netrw_machine<".g:netrw_machine.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001830 if userid != ""
1831 let g:netrw_uid= userid
1832 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001833
Bram Moolenaaradc21822011-04-01 18:03:16 +02001834 if curmachine != g:netrw_machine
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001835 if exists("s:netwr_hup[".g:netrw_machine."]")
1836 call NetUserPass("ftp:".g:netrw_machine)
1837 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02001838 " if there's a change in hostname, require password re-entry
1839 unlet s:netrw_passwd
1840 endif
1841 if exists("netrw_port")
1842 unlet netrw_port
1843 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01001844 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001845
Bram Moolenaar446cb832008-06-24 21:56:24 +00001846 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001847 let b:netrw_method = 3
1848 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001849 let host= substitute(g:netrw_machine,'\..*$','','')
1850 if exists("s:netrw_hup[host]")
1851 call NetUserPass("ftp:".host)
1852
1853 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~ '-[sS]:'
Bram Moolenaaradc21822011-04-01 18:03:16 +02001854" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">")
1855" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">")
1856 if g:netrw_ftp_cmd =~ '-[sS]:\S*MACHINE\>'
1857 let machine = substitute(g:netrw_machine,'\([^.]\+\)\.\S*','\1','')
1858 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',machine.".ftp",'')
1859" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">")
1860 endif
1861 let b:netrw_method= 2
1862 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
1863" call Decho("using <".expand("$HOME/.netrc")."> (readable)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001864 let b:netrw_method= 2
1865 else
1866 if !exists("g:netrw_uid") || g:netrw_uid == ""
1867 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00001868 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001869 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00001870 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001871 endif
1872 let b:netrw_method= 3
1873 endif
1874 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001875
Bram Moolenaaradc21822011-04-01 18:03:16 +02001876 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001877 elseif match(a:choice,fetchurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001878" call Decho("fetch://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001879 let b:netrw_method = 8
1880 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
1881 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
1882 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
1883 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001884
Bram Moolenaaradc21822011-04-01 18:03:16 +02001885 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001886 elseif match(a:choice,mipf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001887" call Decho("(ftp) host id pass file")
Bram Moolenaar071d4272004-06-13 20:20:40 +00001888 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001889 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
1890 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001891 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001892 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001893 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001894
Bram Moolenaaradc21822011-04-01 18:03:16 +02001895 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001896 elseif match(a:choice,mf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001897" call Decho("(ftp) host file")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001898 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001899 let b:netrw_method = 3
1900 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
1901 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001902
Bram Moolenaar9964e462007-05-05 17:54:07 +00001903 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001904 let b:netrw_method = 2
1905 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
1906 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
1907 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001908
Bram Moolenaaradc21822011-04-01 18:03:16 +02001909 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001910 elseif match(a:choice,sftpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001911" call Decho("sftp://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001912 let b:netrw_method = 9
1913 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
1914 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001915
Bram Moolenaaradc21822011-04-01 18:03:16 +02001916 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001917 elseif match(a:choice,rcphf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001918" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001919 let b:netrw_method = 1
1920 let userid = substitute(a:choice,rcphf,'\2',"")
1921 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
1922 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001923" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">")
1924" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">")
1925" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">")
1926" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001927 if userid != ""
1928 let g:netrw_uid= userid
1929 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001930
Bram Moolenaaradc21822011-04-01 18:03:16 +02001931 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001932 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001933 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001934 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001935 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001936 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001937 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02001938 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00001939
Bram Moolenaar81695252004-12-29 20:58:21 +00001940 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02001941 " remove any leading [:#] from port number
1942 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
1943 elseif exists("netrw_port")
1944 " retain port number as implicit for subsequent ftp operations
1945 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00001946 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001947
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001948" call Decho("a:choice <".a:choice.">")
1949" call Decho("b:netrw_method <".b:netrw_method.">")
1950" call Decho("g:netrw_machine<".g:netrw_machine.">")
1951" call Decho("g:netrw_port <".g:netrw_port.">")
1952" if exists("g:netrw_uid") "Decho
1953" call Decho("g:netrw_uid <".g:netrw_uid.">")
1954" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00001955" if exists("s:netrw_passwd") "Decho
1956" call Decho("s:netrw_passwd <".s:netrw_passwd.">")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001957" endif "Decho
1958" call Decho("b:netrw_fname <".b:netrw_fname.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02001959" call Dret("NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001960endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00001961
1962" ------------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00001963" NetReadFixup: this sort of function is typically written by the user {{{2
1964" to handle extra junk that their system's ftp dumps
1965" into the transfer. This function is provided as an
1966" example and as a fix for a Windows 95 problem: in my
1967" experience, win95's ftp always dumped four blank lines
1968" at the end of the transfer.
1969if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
1970 fun! NetReadFixup(method, line1, line2)
1971" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001972
1973 " sanity checks -- attempt to convert inputs to integers
1974 let method = a:method + 0
1975 let line1 = a:line1 + 0
1976 let line2 = a:line2 + 0
1977 if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
1978" call Dret("NetReadFixup")
1979 return
1980 endif
1981
Bram Moolenaar9964e462007-05-05 17:54:07 +00001982 if method == 3 " ftp (no <.netrc>)
1983 let fourblanklines= line2 - 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01001984 if fourblanklines >= line1
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001985 exe "sil keepj ".fourblanklines.",".line2."g/^\s*$/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01001986 call histdel("/",-1)
1987 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00001988 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01001989
Bram Moolenaar9964e462007-05-05 17:54:07 +00001990" call Dret("NetReadFixup")
1991 endfun
1992endif
1993
1994" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001995" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001996" Usage: :call NetUserPass() -- will prompt for userid and password
1997" :call NetUserPass("uid") -- will prompt for password
1998" :call NetUserPass("uid","password") -- sets global userid and password
1999" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
2000" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00002001fun! NetUserPass(...)
2002
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002003" call Dfunc("NetUserPass() a:0=".a:0)
2004
2005 if !exists('s:netrw_hup')
2006 let s:netrw_hup= {}
2007 endif
2008
Bram Moolenaar071d4272004-06-13 20:20:40 +00002009 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01002010 " case: no input arguments
2011
2012 " change host and username if not previously entered; get new password
2013 if !exists("g:netrw_machine")
2014 let g:netrw_machine= input('Enter hostname: ')
2015 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002016 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01002017 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00002018 let g:netrw_uid= input('Enter username: ')
2019 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01002020 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00002021 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002022
2023 " set up hup database
2024 let host = substitute(g:netrw_machine,'\..*$','','')
2025 if !exists('s:netrw_hup[host]')
2026 let s:netrw_hup[host]= {}
2027 endif
2028 let s:netrw_hup[host].uid = g:netrw_uid
2029 let s:netrw_hup[host].passwd = s:netrw_passwd
2030
2031 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01002032 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002033
2034 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01002035 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002036 " access userid and password from hup (host-user-passwd) dictionary
2037 let host = substitute(a:1,'^ftp:','','')
2038 let host = substitute(host,'\..*','','')
2039 if exists("s:netrw_hup[host]")
2040 let g:netrw_uid = s:netrw_hup[host].uid
2041 let s:netrw_passwd = s:netrw_hup[host].passwd
2042" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">")
2043" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">")
2044 else
2045 let g:netrw_uid = input("Enter UserId: ")
2046 let s:netrw_passwd = inputsecret("Enter Password: ")
2047 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01002048
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002049 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01002050 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002051 if exists("g:netrw_machine")
2052 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01002053 else
2054 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002055 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01002056 let g:netrw_uid = a:1
2057" call Decho("set g:netrw_uid= <".g:netrw_uid.">")
2058 if exists("g:netrw_passwd")
2059 " ask for password if one not previously entered
2060 let s:netrw_passwd= g:netrw_passwd
2061 else
2062 let s:netrw_passwd = inputsecret("Enter Password: ")
2063 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002064 endif
2065
2066" call Decho("host<".host.">")
2067 if exists("host")
2068 if !exists('s:netrw_hup[host]')
2069 let s:netrw_hup[host]= {}
2070 endif
2071 let s:netrw_hup[host].uid = g:netrw_uid
2072 let s:netrw_hup[host].passwd = s:netrw_passwd
2073 endif
2074
2075 elseif a:0 == 2
2076 let g:netrw_uid = a:1
2077 let s:netrw_passwd = a:2
2078
2079 elseif a:0 == 3
2080 " enter hostname, user-id, and password into the hup dictionary
2081 let host = substitute(a:1,'^\a\+:','','')
2082 let host = substitute(host,'\..*$','','')
2083 if !exists('s:netrw_hup[host]')
2084 let s:netrw_hup[host]= {}
2085 endif
2086 let s:netrw_hup[host].uid = a:2
2087 let s:netrw_hup[host].passwd = a:3
2088 let g:netrw_uid = s:netrw_hup[host].uid
2089 let s:netrw_passwd = s:netrw_hup[host].passwd
2090" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">")
2091" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00002092 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002093
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002094" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00002095endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00002096
Bram Moolenaar9964e462007-05-05 17:54:07 +00002097" ===========================================
2098" Shared Browsing Support: {{{1
2099" ===========================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00002100
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00002101" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02002102" s:NetrwMaps: {{{2
2103fun! s:NetrwMaps(islocal)
2104" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02002105
2106 " set up Rexplore and [ 2-leftmouse-click -or- c-leftmouse ]
2107" call Decho("set up Rexplore command")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002108 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,"not a former netrw window",79)|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02002109 if g:netrw_mousemaps && g:netrw_retmap
2110" call Decho("set up Rexplore 2-leftmouse")
2111 if !hasmapto("<Plug>NetrwReturn")
2112 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
2113" call Decho("making map for 2-leftmouse")
2114 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
2115 elseif maparg("<c-leftmouse>","n") == ""
2116" call Decho("making map for c-leftmouse")
2117 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
2118 endif
2119 endif
2120 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
2121" call Decho("made <Plug>NetrwReturn map")
2122 endif
2123
Bram Moolenaar9964e462007-05-05 17:54:07 +00002124 if a:islocal
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002125" call Decho("make local maps")
Bram Moolenaar15146672011-10-20 22:22:38 +02002126 " local normal-mode maps
2127 nnoremap <buffer> <silent> a :call <SID>NetrwHide(1)<cr>
2128 nnoremap <buffer> <silent> % :call <SID>NetrwOpenFile(1)<cr>
2129 nnoremap <buffer> <silent> c :exe "keepjumps lcd ".fnameescape(b:netrw_curdir)<cr>
2130 nnoremap <buffer> <silent> C :let g:netrw_chgwin= winnr()<cr>
2131 nnoremap <buffer> <silent> <cr> :call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
2132 nnoremap <buffer> <silent> d :call <SID>NetrwMakeDir("")<cr>
2133 nnoremap <buffer> <silent> - :exe "norm! 0"<bar>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,'../'))<cr>
2134 nnoremap <buffer> <silent> gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
2135 nnoremap <buffer> <silent> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
2136 nnoremap <buffer> <silent> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
2137 nnoremap <buffer> <silent> gh :<c-u>call <SID>NetrwHidden(1)<cr>
2138 nnoremap <buffer> <silent> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
2139 nnoremap <buffer> <silent> I :call <SID>NetrwBannerCtrl(1)<cr>
2140 nnoremap <buffer> <silent> i :call <SID>NetrwListStyle(1)<cr>
2141 nnoremap <buffer> <silent> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
2142 nnoremap <buffer> <silent> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
2143 nnoremap <buffer> <silent> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
2144 nnoremap <buffer> <silent> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
2145 nnoremap <buffer> <silent> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
2146 nnoremap <buffer> <silent> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
2147 nnoremap <buffer> <silent> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
2148 nnoremap <buffer> <silent> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
2149 nnoremap <buffer> <silent> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
2150 nnoremap <buffer> <silent> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
2151 nnoremap <buffer> <silent> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
2152 nnoremap <buffer> <silent> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
2153 nnoremap <buffer> <silent> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
2154 nnoremap <buffer> <silent> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
2155 nnoremap <buffer> <silent> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
2156 nnoremap <buffer> <silent> mx :<c-u>call <SID>NetrwMarkFileExe(1)<cr>
2157 nnoremap <buffer> <silent> mX :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
2158 nnoremap <buffer> <silent> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
2159 nnoremap <buffer> <silent> O :call <SID>NetrwObtain(1)<cr>
2160 nnoremap <buffer> <silent> o :call <SID>NetrwSplit(3)<cr>
2161 nnoremap <buffer> <silent> p :call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
2162 nnoremap <buffer> <silent> P :call <SID>NetrwPrevWinOpen(1)<cr>
2163 nnoremap <buffer> <silent> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
2164 nnoremap <buffer> <silent> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
2165 nnoremap <buffer> <silent> r :let g:netrw_sort_direction= (g:netrw_sort_direction =~ 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,'./'))<cr>
2166 nnoremap <buffer> <silent> s :call <SID>NetrwSortStyle(1)<cr>
2167 nnoremap <buffer> <silent> S :call <SID>NetSortSequence(1)<cr>
2168 nnoremap <buffer> <silent> T :call <SID>NetrwSplit(4)<bar>norm! gT<cr>
2169 nnoremap <buffer> <silent> t :call <SID>NetrwSplit(4)<cr>
2170 nnoremap <buffer> <silent> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
2171 nnoremap <buffer> <silent> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
2172 nnoremap <buffer> <silent> v :call <SID>NetrwSplit(5)<cr>
2173 nnoremap <buffer> <silent> x :call netrw#NetrwBrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
Bram Moolenaar97d62492012-11-15 21:28:22 +01002174 nnoremap <buffer> <silent> X :call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar15146672011-10-20 22:22:38 +02002175 " local insert-mode maps
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002176 inoremap <buffer> <silent> a <c-o>:call <SID>NetrwHide(1)<cr>
Bram Moolenaaradc21822011-04-01 18:03:16 +02002177 inoremap <buffer> <silent> c <c-o>:exe "keepjumps lcd ".fnameescape(b:netrw_curdir)<cr>
2178 inoremap <buffer> <silent> C <c-o>:let g:netrw_chgwin= winnr()<cr>
2179 inoremap <buffer> <silent> % <c-o>:call <SID>NetrwOpenFile(1)<cr>
2180 inoremap <buffer> <silent> - <c-o>:exe "norm! 0"<bar>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,'../'))<cr>
2181 inoremap <buffer> <silent> <cr> <c-o>:call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
2182 inoremap <buffer> <silent> d <c-o>:call <SID>NetrwMakeDir("")<cr>
2183 inoremap <buffer> <silent> gb <c-o>:<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
2184 inoremap <buffer> <silent> gh <c-o>:<c-u>call <SID>NetrwHidden(1)<cr>
2185 inoremap <buffer> <silent> gp <c-o>:<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
2186 inoremap <buffer> <silent> I <c-o>:call <SID>NetrwBannerCtrl(1)<cr>
2187 inoremap <buffer> <silent> i <c-o>:call <SID>NetrwListStyle(1)<cr>
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002188 inoremap <buffer> <silent> mb <c-o>:<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaaradc21822011-04-01 18:03:16 +02002189 inoremap <buffer> <silent> mB <c-o>:<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002190 inoremap <buffer> <silent> mc <c-o>:<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
2191 inoremap <buffer> <silent> md <c-o>:<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
2192 inoremap <buffer> <silent> me <c-o>:<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
2193 inoremap <buffer> <silent> mf <c-o>:<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
2194 inoremap <buffer> <silent> mg <c-o>:<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
2195 inoremap <buffer> <silent> mh <c-o>:<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
2196 inoremap <buffer> <silent> mm <c-o>:<c-u>call <SID>NetrwMarkFileMove(1)<cr>
2197 inoremap <buffer> <silent> mp <c-o>:<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
2198 inoremap <buffer> <silent> mr <c-o>:<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
2199 inoremap <buffer> <silent> ms <c-o>:<c-u>call <SID>NetrwMarkFileSource(1)<cr>
2200 inoremap <buffer> <silent> mT <c-o>:<c-u>call <SID>NetrwMarkFileTag(1)<cr>
2201 inoremap <buffer> <silent> mt <c-o>:<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
2202 inoremap <buffer> <silent> mu <c-o>:<c-u>call <SID>NetrwUnMarkFile(1)<cr>
2203 inoremap <buffer> <silent> mx <c-o>:<c-u>call <SID>NetrwMarkFileExe(1)<cr>
Bram Moolenaar15146672011-10-20 22:22:38 +02002204 inoremap <buffer> <silent> mX <c-o>:<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002205 inoremap <buffer> <silent> mz <c-o>:<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002206 inoremap <buffer> <silent> O <c-o>:call <SID>NetrwObtain(1)<cr>
Bram Moolenaaradc21822011-04-01 18:03:16 +02002207 inoremap <buffer> <silent> o <c-o>:call <SID>NetrwSplit(3)<cr>
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002208 inoremap <buffer> <silent> p <c-o>:call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
2209 inoremap <buffer> <silent> P <c-o>:call <SID>NetrwPrevWinOpen(1)<cr>
2210 inoremap <buffer> <silent> qb <c-o>:<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002211 inoremap <buffer> <silent> qf <c-o>:<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
2212 inoremap <buffer> <silent> r <c-o>:let g:netrw_sort_direction= (g:netrw_sort_direction =~ 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,'./'))<cr>
2213 inoremap <buffer> <silent> s <c-o>:call <SID>NetrwSortStyle(1)<cr>
2214 inoremap <buffer> <silent> S <c-o>:call <SID>NetSortSequence(1)<cr>
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002215 inoremap <buffer> <silent> T <c-o>:call <SID>NetrwSplit(4)<bar>norm! gT<cr>
Bram Moolenaaradc21822011-04-01 18:03:16 +02002216 inoremap <buffer> <silent> t <c-o>:call <SID>NetrwSplit(4)<cr>
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002217 inoremap <buffer> <silent> u <c-o>:<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
2218 inoremap <buffer> <silent> U <c-o>:<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
2219 inoremap <buffer> <silent> v <c-o>:call <SID>NetrwSplit(5)<cr>
2220 inoremap <buffer> <silent> x <c-o>:call netrw#NetrwBrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00002221 if !hasmapto('<Plug>NetrwHideEdit')
2222 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002223 imap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaar446cb832008-06-24 21:56:24 +00002224 endif
2225 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
2226 if !hasmapto('<Plug>NetrwRefresh')
2227 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002228 imap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaar446cb832008-06-24 21:56:24 +00002229 endif
2230 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,'./'))<cr>
Bram Moolenaar9964e462007-05-05 17:54:07 +00002231 if s:didstarstar || !mapcheck("<s-down>","n")
2232 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002233 inoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaar9964e462007-05-05 17:54:07 +00002234 endif
2235 if s:didstarstar || !mapcheck("<s-up>","n")
2236 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002237 inoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaar9964e462007-05-05 17:54:07 +00002238 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002239 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002240 if g:netrw_mousemaps == 1
Bram Moolenaar251e1912011-06-19 05:09:16 +02002241 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
2242 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(1)<cr>
2243 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
2244 nno <buffer> <silent> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(1)<cr>
2245 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
2246 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
2247 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
2248 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
2249 imap <buffer> <leftmouse> <Plug>ILeftmouse
2250 ino <buffer> <silent> <Plug>ILeftmouse <c-o><leftmouse><c-o>:call <SID>NetrwLeftmouse(1)<cr>
2251 imap <buffer> <middlemouse> <Plug>IMiddlemouse
2252 ino <buffer> <silent> <Plug>IMiddlemouse <c-o><leftmouse><c-o>:call <SID>NetrwPrevWinOpen(1)<cr>
2253 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
2254 ino <buffer> <silent> <Plug>ISLeftmouse <c-o><leftmouse><c-o>:call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002255 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
2256 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002257 exe 'inoremap <buffer> <silent> <rightmouse> <c-o><leftmouse><c-o>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaar446cb832008-06-24 21:56:24 +00002258 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002259 exe 'nnoremap <buffer> <silent> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002260 exe 'nnoremap <buffer> <silent> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002261 exe 'nnoremap <buffer> <silent> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaar446cb832008-06-24 21:56:24 +00002262 exe 'nnoremap <buffer> <silent> <Leader>m :call <SID>NetrwMakeDir("")<cr>'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002263 exe 'vnoremap <buffer> <silent> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
2264 exe 'vnoremap <buffer> <silent> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
2265 exe 'vnoremap <buffer> <silent> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
2266 exe 'inoremap <buffer> <silent> <del> <c-o>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
2267 exe 'inoremap <buffer> <silent> D <c-o>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
2268 exe 'inoremap <buffer> <silent> R <c-o>:call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
2269 exe 'inoremap <buffer> <silent> <Leader>m <c-o>:call <SID>NetrwMakeDir("")<cr>'
Bram Moolenaar446cb832008-06-24 21:56:24 +00002270 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002271
Bram Moolenaar9964e462007-05-05 17:54:07 +00002272 else " remote
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002273" call Decho("make remote maps")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002274 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar15146672011-10-20 22:22:38 +02002275 " remote normal-mode maps
Bram Moolenaar446cb832008-06-24 21:56:24 +00002276 nnoremap <buffer> <silent> <cr> :call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
2277 nnoremap <buffer> <silent> <c-l> :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
2278 nnoremap <buffer> <silent> - :exe "norm! 0"<bar>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,'../'))<cr>
2279 nnoremap <buffer> <silent> a :call <SID>NetrwHide(0)<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +01002280 nnoremap <buffer> <silent> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00002281 nnoremap <buffer> <silent> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
2282 nnoremap <buffer> <silent> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
2283 nnoremap <buffer> <silent> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
2284 nnoremap <buffer> <silent> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
2285 nnoremap <buffer> <silent> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
2286 nnoremap <buffer> <silent> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
2287 nnoremap <buffer> <silent> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
2288 nnoremap <buffer> <silent> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
2289 nnoremap <buffer> <silent> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
2290 nnoremap <buffer> <silent> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00002291 nnoremap <buffer> <silent> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaar15146672011-10-20 22:22:38 +02002292 nnoremap <buffer> <silent> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00002293 nnoremap <buffer> <silent> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
2294 nnoremap <buffer> <silent> mx :<c-u>call <SID>NetrwMarkFileExe(0)<cr>
Bram Moolenaar15146672011-10-20 22:22:38 +02002295 nnoremap <buffer> <silent> mX :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00002296 nnoremap <buffer> <silent> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaar97d62492012-11-15 21:28:22 +01002297 nnoremap <buffer> <silent> gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
Bram Moolenaaradc21822011-04-01 18:03:16 +02002298 nnoremap <buffer> <silent> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
2299 nnoremap <buffer> <silent> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00002300 nnoremap <buffer> <silent> gh :<c-u>call <SID>NetrwHidden(0)<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +01002301 nnoremap <buffer> <silent> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
Bram Moolenaar9964e462007-05-05 17:54:07 +00002302 nnoremap <buffer> <silent> C :let g:netrw_chgwin= winnr()<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00002303 nnoremap <buffer> <silent> i :call <SID>NetrwListStyle(0)<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +01002304 nnoremap <buffer> <silent> I :call <SID>NetrwBannerCtrl(1)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00002305 nnoremap <buffer> <silent> o :call <SID>NetrwSplit(0)<cr>
2306 nnoremap <buffer> <silent> O :call <SID>NetrwObtain(0)<cr>
2307 nnoremap <buffer> <silent> p :call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
2308 nnoremap <buffer> <silent> P :call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +01002309 nnoremap <buffer> <silent> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
2310 nnoremap <buffer> <silent> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00002311 nnoremap <buffer> <silent> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
2312 nnoremap <buffer> <silent> r :let g:netrw_sort_direction= (g:netrw_sort_direction =~ 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
2313 nnoremap <buffer> <silent> s :call <SID>NetrwSortStyle(0)<cr>
Bram Moolenaar9964e462007-05-05 17:54:07 +00002314 nnoremap <buffer> <silent> S :call <SID>NetSortSequence(0)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00002315 nnoremap <buffer> <silent> t :call <SID>NetrwSplit(1)<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +01002316 nnoremap <buffer> <silent> T :call <SID>NetrwSplit(1)<bar>norm! gT<cr>
2317 nnoremap <buffer> <silent> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
2318 nnoremap <buffer> <silent> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00002319 nnoremap <buffer> <silent> v :call <SID>NetrwSplit(2)<cr>
2320 nnoremap <buffer> <silent> x :call netrw#NetrwBrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaarc236c162008-07-13 17:41:49 +00002321 nnoremap <buffer> <silent> % :call <SID>NetrwOpenFile(0)<cr>
Bram Moolenaar15146672011-10-20 22:22:38 +02002322 " remote insert-mode maps
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002323 inoremap <buffer> <silent> <cr> <c-o>:call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
2324 inoremap <buffer> <silent> <c-l> <c-o>:call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
2325 inoremap <buffer> <silent> - <c-o>:exe "norm! 0"<bar>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,'../'))<cr>
2326 inoremap <buffer> <silent> a <c-o>:call <SID>NetrwHide(0)<cr>
2327 inoremap <buffer> <silent> mb <c-o>:<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
2328 inoremap <buffer> <silent> mc <c-o>:<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
2329 inoremap <buffer> <silent> md <c-o>:<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
2330 inoremap <buffer> <silent> me <c-o>:<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
2331 inoremap <buffer> <silent> mf <c-o>:<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
2332 inoremap <buffer> <silent> mg <c-o>:<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
2333 inoremap <buffer> <silent> mh <c-o>:<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
2334 inoremap <buffer> <silent> mm <c-o>:<c-u>call <SID>NetrwMarkFileMove(0)<cr>
2335 inoremap <buffer> <silent> mp <c-o>:<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
2336 inoremap <buffer> <silent> mr <c-o>:<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
2337 inoremap <buffer> <silent> ms <c-o>:<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002338 inoremap <buffer> <silent> mt <c-o>:<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaar15146672011-10-20 22:22:38 +02002339 inoremap <buffer> <silent> mT <c-o>:<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002340 inoremap <buffer> <silent> mu <c-o>:<c-u>call <SID>NetrwUnMarkFile(0)<cr>
2341 inoremap <buffer> <silent> mx <c-o>:<c-u>call <SID>NetrwMarkFileExe(0)<cr>
Bram Moolenaar15146672011-10-20 22:22:38 +02002342 inoremap <buffer> <silent> mX <c-o>:<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002343 inoremap <buffer> <silent> mz <c-o>:<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaar97d62492012-11-15 21:28:22 +01002344 inoremap <buffer> <silent> gb <c-o>:<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002345 inoremap <buffer> <silent> gh <c-o>:<c-u>call <SID>NetrwHidden(0)<cr>
2346 inoremap <buffer> <silent> gp <c-o>:<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
2347 inoremap <buffer> <silent> C <c-o>:let g:netrw_chgwin= winnr()<cr>
2348 inoremap <buffer> <silent> i <c-o>:call <SID>NetrwListStyle(0)<cr>
2349 inoremap <buffer> <silent> I <c-o>:call <SID>NetrwBannerCtrl(1)<cr>
2350 inoremap <buffer> <silent> o <c-o>:call <SID>NetrwSplit(0)<cr>
2351 inoremap <buffer> <silent> O <c-o>:call <SID>NetrwObtain(0)<cr>
2352 inoremap <buffer> <silent> p <c-o>:call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
2353 inoremap <buffer> <silent> P <c-o>:call <SID>NetrwPrevWinOpen(0)<cr>
2354 inoremap <buffer> <silent> qb <c-o>:<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
2355 inoremap <buffer> <silent> mB <c-o>:<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
2356 inoremap <buffer> <silent> qf <c-o>:<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
2357 inoremap <buffer> <silent> r <c-o>:let g:netrw_sort_direction= (g:netrw_sort_direction =~ 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
2358 inoremap <buffer> <silent> s <c-o>:call <SID>NetrwSortStyle(0)<cr>
2359 inoremap <buffer> <silent> S <c-o>:call <SID>NetSortSequence(0)<cr>
2360 inoremap <buffer> <silent> t <c-o>:call <SID>NetrwSplit(1)<cr>
2361 inoremap <buffer> <silent> T <c-o>:call <SID>NetrwSplit(1)<bar>norm! gT<cr>
2362 inoremap <buffer> <silent> u <c-o>:<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
2363 inoremap <buffer> <silent> U <c-o>:<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
2364 inoremap <buffer> <silent> v <c-o>:call <SID>NetrwSplit(2)<cr>
2365 inoremap <buffer> <silent> x <c-o>:call netrw#NetrwBrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
2366 inoremap <buffer> <silent> % <c-o>:call <SID>NetrwOpenFile(0)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00002367 if !hasmapto('<Plug>NetrwHideEdit')
2368 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002369 imap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaar446cb832008-06-24 21:56:24 +00002370 endif
2371 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
2372 if !hasmapto('<Plug>NetrwRefresh')
2373 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002374 imap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaar446cb832008-06-24 21:56:24 +00002375 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002376
2377 let mapsafepath = escape(s:path, s:netrw_map_escape)
2378 let mapsafeusermach = escape(s:user.s:machine, s:netrw_map_escape)
2379
Bram Moolenaar251e1912011-06-19 05:09:16 +02002380 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00002381 if g:netrw_mousemaps == 1
Bram Moolenaar251e1912011-06-19 05:09:16 +02002382 nmap <leftmouse> <Plug>NetrwLeftmouse
2383 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(0)<cr>
2384 nmap <middlemouse> <Plug>NetrwMiddlemouse
2385 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(0)<cr>
2386 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
2387 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
2388 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
2389 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
2390 imap <buffer> <leftmouse> <Plug>ILeftmouse
2391 ino <buffer> <silent> <Plug>ILeftmouse <c-o><leftmouse><c-o>:call <SID>NetrwLeftmouse(0)<cr>
2392 imap <buffer> <middlemouse> <Plug>IMiddlemouse
2393 ino <buffer> <silent> <Plug>IMiddlemouse <c-o><leftmouse><c-o>:call <SID>NetrwPrevWinOpen(0)<cr>
2394 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
2395 ino <buffer> <silent> <Plug>ISLeftmouse <c-o><leftmouse><c-o>:call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002396 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
2397 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002398 exe 'inoremap <buffer> <silent> <rightmouse> <c-o><leftmouse><c-o>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaar446cb832008-06-24 21:56:24 +00002399 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002400 exe 'nnoremap <buffer> <silent> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002401 exe 'nnoremap <buffer> <silent> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
2402 exe 'nnoremap <buffer> <silent> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
2403 exe 'nnoremap <buffer> <silent> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002404 exe 'vnoremap <buffer> <silent> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002405 exe 'vnoremap <buffer> <silent> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
2406 exe 'vnoremap <buffer> <silent> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
2407 exe 'inoremap <buffer> <silent> <del> <c-o>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
2408 exe 'inoremap <buffer> <silent> d <c-o>:call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
2409 exe 'inoremap <buffer> <silent> D <c-o>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
2410 exe 'inoremap <buffer> <silent> R <c-o>:call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaarc236c162008-07-13 17:41:49 +00002411 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002412 inoremap <buffer> <F1> <c-o>:he netrw-quickhelp<cr>
Bram Moolenaar9964e462007-05-05 17:54:07 +00002413 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002414
Bram Moolenaaradc21822011-04-01 18:03:16 +02002415 keepj call s:SetRexDir(a:islocal,b:netrw_curdir)
Bram Moolenaar251e1912011-06-19 05:09:16 +02002416
Bram Moolenaaradc21822011-04-01 18:03:16 +02002417" call Dret("s:NetrwMaps")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002418endfun
2419
2420" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002421" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
2422fun! s:ExplorePatHls(pattern)
2423" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
2424 let repat= substitute(a:pattern,'^**/\{1,2}','','')
2425" call Decho("repat<".repat.">")
2426 let repat= escape(repat,'][.\')
2427" call Decho("repat<".repat.">")
2428 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
2429" call Dret("s:ExplorePatHls repat<".repat.">")
2430 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00002431endfun
2432
2433" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01002434" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00002435" 0: (user: <mb>) bookmark current directory
2436" 1: (user: <gb>) change to the bookmarked directory
2437" 2: (user: <qb>) list bookmarks
2438" 3: (browsing) record current directory history
2439" 4: (user: <u>) go up (previous) bookmark
2440" 5: (user: <U>) go down (next) bookmark
2441" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01002442fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002443" call Dfunc("s:NetrwBookHistHandler(chg=".a:chg." curdir<".a:curdir.">) cnt=".v:count." histcnt=".g:netrw_dirhist_cnt." histmax=".g:netrw_dirhistmax)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002444
Bram Moolenaar97d62492012-11-15 21:28:22 +01002445 let ykeep= @@
Bram Moolenaar9964e462007-05-05 17:54:07 +00002446 if a:chg == 0
2447 " bookmark the current directory
2448" call Decho("(user: <b>) bookmark the current directory")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002449 if !exists("g:netrw_bookmarklist")
2450 let g:netrw_bookmarklist= []
2451 endif
2452 if index(g:netrw_bookmarklist,a:curdir) == -1
2453 " curdir not currently in g:netrw_bookmarklist, so include it
2454 call add(g:netrw_bookmarklist,a:curdir)
2455 call sort(g:netrw_bookmarklist)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002456 endif
2457 echo "bookmarked the current directory"
2458
2459 elseif a:chg == 1
2460 " change to the bookmarked directory
Bram Moolenaar5c736222010-01-06 20:54:52 +01002461" call Decho("(user: <".v:count."mb>) change to the bookmarked directory")
2462 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002463 exe "keepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00002464 else
2465 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
2466 endif
2467
2468 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00002469" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002470 let didwork= 0
2471 " list user's bookmarks
2472" call Decho("(user: <q>) list user's bookmarks")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002473 if exists("g:netrw_bookmarklist")
2474" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks')
2475 let cnt= 1
2476 for bmd in g:netrw_bookmarklist
2477" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1])
2478 echo "Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1]
2479 let didwork = 1
2480 let cnt = cnt + 1
2481 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00002482 endif
2483
2484 " list directory history
Bram Moolenaar5c736222010-01-06 20:54:52 +01002485 let cnt = g:netrw_dirhist_cnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00002486 let first = 1
2487 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02002488 if g:netrw_dirhistmax > 0
2489 while ( first || cnt != g:netrw_dirhist_cnt )
Bram Moolenaar5c736222010-01-06 20:54:52 +01002490" call Decho("first=".first." cnt=".cnt." dirhist_cnt=".g:netrw_dirhist_cnt)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002491 let histcnt= histcnt + 1
2492 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002493" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02002494 echo "Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt}
2495 let didwork= 1
2496 endif
2497 let first = 0
2498 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
2499 if cnt < 0
2500 let cnt= cnt + g:netrw_dirhistmax
2501 endif
2502 endwhile
2503 else
2504 let g:netrw_dirhist_cnt= 0
2505 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002506 if didwork
2507 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
2508 endif
2509
2510 elseif a:chg == 3
2511 " saves most recently visited directories (when they differ)
2512" call Decho("(browsing) record curdir history")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002513 if !exists("g:netrw_dirhist_cnt") || !exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}") || g:netrw_dirhist_{g:netrw_dirhist_cnt} != a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02002514 if g:netrw_dirhistmax > 0
2515 let g:netrw_dirhist_cnt = ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax
2516 let g:netrw_dirhist_{g:netrw_dirhist_cnt} = a:curdir
2517 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002518" call Decho("save dirhist#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002519 endif
2520
2521 elseif a:chg == 4
2522 " u: change to the previous directory stored on the history list
2523" call Decho("(user: <u>) chg to prev dir from history")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002524 if g:netrw_dirhistmax > 0
2525 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt - 1 ) % g:netrw_dirhistmax
2526 if g:netrw_dirhist_cnt < 0
2527 let g:netrw_dirhist_cnt= g:netrw_dirhist_cnt + g:netrw_dirhistmax
2528 endif
2529 else
2530 let g:netrw_dirhist_cnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002531 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002532 if exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}")
2533" call Decho("changedir u#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002534 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002535 setl ma noro
2536" call Decho("(NetrwBookHistHandler) setl ma noro")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002537 sil! keepj %d
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002538 setl nomod
2539" call Decho("(NetrwBookHistHandler) setl nomod")
2540" call Decho("(NetrwBookHistHandler) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002541 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002542" " call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt}))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002543 exe "keepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00002544 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02002545 if g:netrw_dirhistmax > 0
2546 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax
2547 else
2548 let g:netrw_dirhist_cnt= 0
2549 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002550 echo "Sorry, no predecessor directory exists yet"
2551 endif
2552
2553 elseif a:chg == 5
2554 " U: change to the subsequent directory stored on the history list
2555" call Decho("(user: <U>) chg to next dir from history")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002556 if g:netrw_dirhistmax > 0
2557 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax
2558 if exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002559" call Decho("changedir U#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002560 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002561" call Decho("(NetrwBookHistHandler) setl ma noro")
2562 setl ma noro
Bram Moolenaaradc21822011-04-01 18:03:16 +02002563 sil! keepj %d
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002564" call Decho("removed all lines from buffer (%d)")
2565" call Decho("(NetrwBookHistHandler) setl nomod")
2566 setl nomod
2567" call Decho("(set nomod) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002568 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002569" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt}))
Bram Moolenaaradc21822011-04-01 18:03:16 +02002570 exe "keepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt})
2571 else
2572 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt - 1 ) % g:netrw_dirhistmax
2573 if g:netrw_dirhist_cnt < 0
2574 let g:netrw_dirhist_cnt= g:netrw_dirhist_cnt + g:netrw_dirhistmax
2575 endif
2576 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002577 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002578 else
2579 let g:netrw_dirhist_cnt= 0
2580 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002581 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002582
2583 elseif a:chg == 6
Bram Moolenaar5c736222010-01-06 20:54:52 +01002584 " delete the v:count'th bookmark
2585" call Decho("delete bookmark#".v:count."<".g:netrw_bookmarklist[v:count-1].">")
2586 let savefile= s:NetrwHome()."/.netrwbook"
2587 if filereadable(savefile)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002588 keepj call s:NetrwBookHistSave() " done here to merge bookmarks first
2589 keepj call delete(savefile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002590 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002591 keepj call remove(g:netrw_bookmarklist,v:count-1)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002592 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002593 call s:NetrwBookmarkMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01002594 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002595" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002596endfun
2597
2598" ---------------------------------------------------------------------
2599" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
2600" Sister function: s:NetrwBookHistSave()
2601fun! s:NetrwBookHistRead()
2602" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01002603 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01002604 if !exists("s:netrw_initbookhist")
2605 let home = s:NetrwHome()
2606 let savefile= home."/.netrwbook"
2607 if filereadable(savefile)
2608" call Decho("sourcing .netrwbook")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002609 exe "keepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01002610 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002611 if g:netrw_dirhistmax > 0
2612 let savefile= home."/.netrwhist"
2613 if filereadable(savefile)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002614" call Decho("sourcing .netrwhist")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002615 exe "keepj so ".savefile
2616 endif
2617 let s:netrw_initbookhist= 1
2618 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01002619 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002620 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01002621 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01002622" call Dret("s:NetrwBookHistRead")
2623endfun
2624
2625" ---------------------------------------------------------------------
2626" s:NetrwBookHistSave: this function saves bookmarks and history {{{2
2627" Sister function: s:NetrwBookHistRead()
2628" I used to do this via viminfo but that appears to
2629" be unreliable for long-term storage
Bram Moolenaar5c736222010-01-06 20:54:52 +01002630fun! s:NetrwBookHistSave()
2631" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002632 if g:netrw_dirhistmax <= 0
2633" call Dret("s:NetrwBookHistSave : dirhistmax=".g:netrw_dirhistmax)
2634 return
2635 endif
2636
Bram Moolenaar5c736222010-01-06 20:54:52 +01002637 let savefile= s:NetrwHome()."/.netrwhist"
2638 1split
2639 call s:NetrwEnew()
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002640 setlocal cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
Bram Moolenaar5c736222010-01-06 20:54:52 +01002641 setlocal nocin noai noci magic nospell nohid wig= noaw
2642 setlocal ma noro write
2643 if exists("&acd") | setlocal noacd | endif
Bram Moolenaar15146672011-10-20 22:22:38 +02002644 sil! keepj keepalt %d
Bram Moolenaar5c736222010-01-06 20:54:52 +01002645
2646 " save .netrwhist -- no attempt to merge
Bram Moolenaaradc21822011-04-01 18:03:16 +02002647 sil! file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01002648 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
2649 call setline(2,"let g:netrw_dirhist_cnt =".g:netrw_dirhist_cnt)
2650 let lastline = line("$")
2651 let cnt = 1
2652 while cnt <= g:netrw_dirhist_cnt
2653 call setline((cnt+lastline),'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
2654 let cnt= cnt + 1
2655 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002656 exe "sil! w! ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01002657
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002658 sil keepj %d
Bram Moolenaar5c736222010-01-06 20:54:52 +01002659 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
2660 " merge and write .netrwbook
2661 let savefile= s:NetrwHome()."/.netrwbook"
2662
2663 if filereadable(savefile)
2664 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002665 exe "sil keepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01002666 for bdm in booklist
2667 if index(g:netrw_bookmarklist,bdm) == -1
2668 call add(g:netrw_bookmarklist,bdm)
2669 endif
2670 endfor
2671 call sort(g:netrw_bookmarklist)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002672 exe "sil! w! ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01002673 endif
2674
2675 " construct and save .netrwbook
2676 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002677 exe "sil! w! ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01002678 endif
2679 let bgone= bufnr("%")
2680 q!
2681 exe bgone."bwipe!"
2682
2683" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002684endfun
2685
2686" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002687" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
2688" list of the contents of a local or remote directory. It is assumed that the
2689" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
2690" with the requested remote hostname first.
2691fun! s:NetrwBrowse(islocal,dirname)
2692 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002693" call Dfunc("s:NetrwBrowse(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".w:netrw_liststyle." ".g:loaded_netrw." buf#".bufnr("%")."<".bufname("%")."> win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002694" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")." modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002695" call Dredir("ls!")
Bram Moolenaar97d62492012-11-15 21:28:22 +01002696 " s:NetrwBrowse: initialize history {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002697 if !exists("s:netrw_initbookhist")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002698 keepj call s:NetrwBookHistRead()
Bram Moolenaar5c736222010-01-06 20:54:52 +01002699 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002700
Bram Moolenaar97d62492012-11-15 21:28:22 +01002701 " s:NetrwBrowse: simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002702 if a:dirname !~ '^\a\+://'
2703 let dirname= simplify(a:dirname)
2704 else
2705 let dirname= a:dirname
2706 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002707
2708 if exists("s:netrw_skipbrowse")
2709 unlet s:netrw_skipbrowse
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002710" call Decho("(NetrwBrowse) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002711" call Dret("s:NetrwBrowse : s:netrw_skipbrowse=".s:netrw_skipbrowse)
2712 return
2713 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01002714
2715 " s:NetrwBrowse: sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002716 if !exists("*shellescape")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002717 keepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002718" call Dret("s:NetrwBrowse : missing shellescape()")
2719 return
2720 endif
2721 if !exists("*fnameescape")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002722 keepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002723" call Dret("s:NetrwBrowse : missing fnameescape()")
2724 return
2725 endif
2726
Bram Moolenaar97d62492012-11-15 21:28:22 +01002727 " s:NetrwBrowse: save options: {{{3
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002728 call s:NetrwOptionSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002729
Bram Moolenaar97d62492012-11-15 21:28:22 +01002730 " s:NetrwBrowse: re-instate any marked files {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002731 if exists("s:netrwmarkfilelist_{bufnr('%')}")
2732" call Decho("clearing marked files")
2733 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
2734 endif
2735
2736 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar97d62492012-11-15 21:28:22 +01002737 " s:NetrwBrowse: set up "safe" options for local directory/file {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002738" call Decho("handle w:netrw_acdkeep:")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002739" call Decho("keepjumps lcd ".fnameescape(dirname)." (due to w:netrw_acdkeep=".w:netrw_acdkeep." - acd=".&acd.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002740 exe 'keepj lcd '.fnameescape(dirname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002741 call s:NetrwSafeOptions()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002742" call Decho("getcwd<".getcwd().">")
2743
Bram Moolenaar5c736222010-01-06 20:54:52 +01002744 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar97d62492012-11-15 21:28:22 +01002745 " s:NetrwBrowse: looks like a remote regular file, attempt transfer {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002746" call Decho("attempt transfer as regular file<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002747
Bram Moolenaar97d62492012-11-15 21:28:22 +01002748 " remove any filetype indicator from end of dirname, except for the
Bram Moolenaar446cb832008-06-24 21:56:24 +00002749 " "this is a directory" indicator (/).
2750 " There shouldn't be one of those here, anyway.
Bram Moolenaar5c736222010-01-06 20:54:52 +01002751 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaar446cb832008-06-24 21:56:24 +00002752" call Decho("new path<".path.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002753 call s:RemotePathAnalysis(dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002754
Bram Moolenaar97d62492012-11-15 21:28:22 +01002755 " s:NetrwBrowse: remote-read the requested file into current buffer {{{3
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002756 keepj mark '
Bram Moolenaar5c736222010-01-06 20:54:52 +01002757 call s:NetrwEnew(dirname)
2758 call s:NetrwSafeOptions()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002759 setlocal ma noro
2760" call Decho("setlocal ma noro")
Bram Moolenaar15146672011-10-20 22:22:38 +02002761 let b:netrw_curdir = dirname
2762 let url = s:method."://".s:user.s:machine.(s:port ? ":".s:port : "")."/".s:path
2763" call Decho("exe sil! keepalt file ".fnameescape(url)." (bt=".&bt.")")
2764 exe "sil! keepj keepalt file ".fnameescape(url)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002765 exe "sil! keepj keepalt doau BufReadPre ".fnameescape(s:fname)
Bram Moolenaar15146672011-10-20 22:22:38 +02002766 sil call netrw#NetRead(2,url)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002767 if s:path !~ '.tar.bz2$' && s:path !~ '.tar.gz' && s:path !~ '.tar.xz' && s:path !~ '.txz'
Bram Moolenaar446cb832008-06-24 21:56:24 +00002768 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaaradc21822011-04-01 18:03:16 +02002769 exe "sil keepj keepalt doau BufReadPost ".fnameescape(s:fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002770 endif
2771
Bram Moolenaar97d62492012-11-15 21:28:22 +01002772 " s:NetrwBrowse: save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002773 call s:SetBufWinVars()
2774 call s:NetrwOptionRestore("w:")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002775" call Decho("setl ma nomod")
2776 setl ma nomod
2777" call Decho("(NetrwBrowse) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002778
Bram Moolenaar446cb832008-06-24 21:56:24 +00002779" call Dret("s:NetrwBrowse : file<".s:fname.">")
2780 return
2781 endif
2782
Bram Moolenaaradc21822011-04-01 18:03:16 +02002783 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002784 call s:UseBufWinVars()
2785
2786 " set up some variables {{{3
2787 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01002788 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00002789 let s:last_sort_by = g:netrw_sort_by
2790
2791 " set up menu {{{3
Bram Moolenaaradc21822011-04-01 18:03:16 +02002792 keepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002793
Bram Moolenaar97d62492012-11-15 21:28:22 +01002794 " get/set-up buffer {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002795 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
2796 " maintain markfile highlighting
2797 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
2798" call Decho("bufnr(%)=".bufnr('%'))
2799" call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/")
2800 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
2801 else
2802" call Decho("2match none")
2803 2match none
2804 endif
2805 if reusing
2806 call s:NetrwOptionRestore("w:")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002807" call Decho("(NetrwBrowse) setl noma nomod nowrap")
2808 setl noma nomod nowrap
2809" call Decho("(set noma nomod nowrap) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002810" call Dret("s:NetrwBrowse : re-using buffer")
2811 return
2812 endif
2813
2814 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002815" call Decho("set b:netrw_curdir to the new directory name: (buf#".bufnr("%").")")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002816 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00002817 if b:netrw_curdir =~ '[/\\]$'
2818 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
2819 endif
2820 if b:netrw_curdir == ''
2821 if has("amiga")
2822 " On the Amiga, the empty string connotes the current directory
2823 let b:netrw_curdir= getcwd()
2824 else
2825 " under unix, when the root directory is encountered, the result
2826 " from the preceding substitute is an empty string.
2827 let b:netrw_curdir= '/'
2828 endif
2829 endif
2830 if !a:islocal && b:netrw_curdir !~ '/$'
2831 let b:netrw_curdir= b:netrw_curdir.'/'
2832 endif
2833" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
2834
2835 " ------------
2836 " (local only) {{{3
2837 " ------------
2838 if a:islocal
2839" call Decho("local only:")
2840
2841 " Set up ShellCmdPost handling. Append current buffer to browselist
2842 call s:LocalFastBrowser()
2843
2844 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
2845 if !g:netrw_keepdir
2846" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd)
2847" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"))
2848 if !exists("&l:acd") || !&l:acd
2849" call Decho('exe keepjumps lcd '.fnameescape(b:netrw_curdir))
2850 try
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002851 exe 'keepj lcd '.fnameescape(b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002852 catch /^Vim\%((\a\+)\)\=:E472/
2853 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".b:netrw_curdir."> (permissions?)",61)
2854 if exists("w:netrw_prvdir")
2855 let b:netrw_curdir= w:netrw_prvdir
2856 else
2857 call s:NetrwOptionRestore("w:")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002858" call Decho("(NetrwBrowse) setl noma nomod nowrap")
2859 setl noma nomod nowrap
2860" call Decho("(NetrwBrowse) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002861 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00002862" call Dret("s:NetrwBrowse : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
2863 return
2864 endif
2865 endtry
2866 endif
2867 endif
2868
2869 " --------------------------------
2870 " remote handling: {{{3
2871 " --------------------------------
2872 else
2873" call Decho("remote only:")
2874
Bram Moolenaar97d62492012-11-15 21:28:22 +01002875 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002876" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist")."> dirname<".dirname.">")
2877 if dirname =~ "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00002878 let dirname= b:netrw_curdir
Bram Moolenaar97d62492012-11-15 21:28:22 +01002879" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002880 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
2881 let dirname= substitute(b:netrw_curdir,'\\','/','g')
2882 if dirname !~ '/$'
2883 let dirname= dirname.'/'
2884 endif
2885 let b:netrw_curdir = dirname
2886" call Decho("(liststyle is TREELIST) dirname<".dirname.">")
2887 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01002888 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaar446cb832008-06-24 21:56:24 +00002889" call Decho("(normal) dirname<".dirname.">")
2890 endif
2891
2892 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
2893 if dirname !~ dirpat
2894 if !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002895 keepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002896 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002897 keepj call s:NetrwOptionRestore("w:")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002898" call Decho("(NetrwBrowse) setl noma nomod nowrap")
2899 setl noma nomod nowrap
2900" call Decho("(NetrwBrowse) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002901" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
2902 return
2903 endif
2904 let b:netrw_curdir= dirname
2905" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)")
2906 endif " (additional remote handling)
2907
2908 " -----------------------
2909 " Directory Listing: {{{3
2910 " -----------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02002911 keepj call s:NetrwMaps(a:islocal)
2912 keepj call s:PerformListing(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02002913 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002914 let &l:bexpr= "netrw#NetrwBalloonHelp()"
Bram Moolenaar15146672011-10-20 22:22:38 +02002915" call Decho("set up balloon help: l:bexpr=".&l:bexpr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002916 set beval
2917 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02002918 call s:NetrwOptionRestore("w:")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002919
2920 " The s:LocalBrowseShellCmdRefresh() function is called by an autocmd
2921 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow, medium speed).
2922 " However, s:NetrwBrowse() causes the ShellCmdPost event itself to fire once; setting
2923 " the variable below avoids that second refresh of the screen. The s:LocalBrowseShellCmdRefresh()
2924 " function gets called due to that autocmd; it notices that the following variable is set
2925 " and skips the refresh and sets s:locbrowseshellcmd to zero. Oct 13, 2008
2926 let s:locbrowseshellcmd= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00002927
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002928" call Decho("(NetrwBrowse) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002929" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002930 return
2931endfun
2932
2933" ---------------------------------------------------------------------
2934" s:NetrwFileInfo: supports qf (query for file information) {{{2
2935fun! s:NetrwFileInfo(islocal,fname)
2936" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01002937 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00002938 if a:islocal
2939 if (has("unix") || has("macunix")) && executable("/bin/ls")
2940 if exists("b:netrw_curdir")
2941" call Decho('using ls with b:netrw_curdir<'.b:netrw_curdir.'>')
2942 if b:netrw_curdir =~ '/$'
2943 echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir.a:fname))
2944 else
2945 echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir."/".a:fname))
2946 endif
2947 else
2948" call Decho('using ls '.a:fname." using cwd<".getcwd().">")
2949 echo system("/bin/ls -lsad ".shellescape(a:fname))
2950 endif
2951 else
2952 " use vim functions to return information about file below cursor
2953" call Decho("using vim functions to query for file info")
2954 if !isdirectory(a:fname) && !filereadable(a:fname) && a:fname =~ '[*@/]'
2955 let fname= substitute(a:fname,".$","","")
2956 else
2957 let fname= a:fname
2958 endif
2959 let t = getftime(fname)
2960 let sz = getfsize(fname)
2961 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname))
2962" call Decho(fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)))
2963 endif
2964 else
2965 echo "sorry, \"qf\" not supported yet for remote files"
2966 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01002967 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00002968" call Dret("s:NetrwFileInfo")
2969endfun
2970
2971" ---------------------------------------------------------------------
2972" s:NetrwGetBuffer: {{{2
2973" returns 0=cleared buffer
2974" 1=re-used buffer
2975fun! s:NetrwGetBuffer(islocal,dirname)
2976" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
2977 let dirname= a:dirname
2978
2979 " re-use buffer if possible {{{3
2980" call Decho("--re-use a buffer if possible--")
2981 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
2982 " find NetrwTreeList buffer if there is one
Bram Moolenaar97d62492012-11-15 21:28:22 +01002983" call Decho("case liststyle=treelist: find NetrwTreeList buffer if there is one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002984 if exists("w:netrw_treebufnr") && w:netrw_treebufnr > 0
2985" call Decho(" re-use w:netrw_treebufnr=".w:netrw_treebufnr)
2986 let eikeep= &ei
2987 set ei=all
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002988 exe "sil! b ".w:netrw_treebufnr
Bram Moolenaar446cb832008-06-24 21:56:24 +00002989 let &ei= eikeep
Bram Moolenaar97d62492012-11-15 21:28:22 +01002990" call Dret("s:NetrwGetBuffer 1<buffer not cleared> : bufnum#".w:netrw_treebufnr."<NetrwTreeListing>")
2991 return 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00002992 endif
2993 let bufnum= -1
2994" call Decho(" liststyle=TREE but w:netrw_treebufnr doesn't exist")
2995
2996 else
2997 " find buffer number of buffer named precisely the same as dirname {{{3
Bram Moolenaar97d62492012-11-15 21:28:22 +01002998" call Decho("case listtyle not treelist: find buffer numnber of buffer named precisely the same as dirname--")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002999" call Dredir("ls!")
3000
3001 " get dirname and associated buffer number
3002 let bufnum = bufnr(escape(dirname,'\'))
3003" call Decho(" find buffer<".dirname.">'s number ")
3004" call Decho(" bufnr(dirname<".escape(dirname,'\').">)=".bufnum)
3005
3006 if bufnum < 0 && dirname !~ '/$'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003007 " try appending a trailing /
Bram Moolenaar446cb832008-06-24 21:56:24 +00003008" call Decho(" try appending a trailing / to dirname<".dirname.">")
3009 let bufnum= bufnr(escape(dirname.'/','\'))
3010 if bufnum > 0
3011 let dirname= dirname.'/'
3012 endif
3013 endif
3014
3015 if bufnum < 0 && dirname =~ '/$'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003016 " try removing a trailing /
Bram Moolenaar446cb832008-06-24 21:56:24 +00003017" call Decho(" try removing a trailing / from dirname<".dirname.">")
3018 let bufnum= bufnr(escape(substitute(dirname,'/$','',''),'\'))
3019 if bufnum > 0
3020 let dirname= substitute(dirname,'/$','','')
3021 endif
3022 endif
3023
3024" call Decho(" findbuf1: bufnum=bufnr('".dirname."')=".bufnum." bufname(".bufnum.")<".bufname(bufnum)."> (initial)")
3025 " note: !~ was used just below, but that means using ../ to go back would match (ie. abc/def/ and abc/ matches)
3026 if bufnum > 0 && bufname(bufnum) != dirname && bufname(bufnum) != '.'
3027 " handle approximate matches
Bram Moolenaar97d62492012-11-15 21:28:22 +01003028" call Decho(" handling approx match: bufnum#".bufnum.">0 AND bufname<".bufname(bufnum).">!=dirname<".dirname."> AND bufname(".bufnum.")!='.'")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003029 let ibuf = 1
3030 let buflast = bufnr("$")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003031" call Decho(" findbuf2: buflast=bufnr($)=".buflast)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003032 while ibuf <= buflast
3033 let bname= substitute(bufname(ibuf),'\\','/','g')
Bram Moolenaarc236c162008-07-13 17:41:49 +00003034 let bname= substitute(bname,'.\zs/$','','')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003035" call Decho(" findbuf3: while [ibuf=",ibuf."]<=[buflast=".buflast."]: dirname<".dirname."> bname=bufname(".ibuf.")<".bname.">")
3036 if bname != '' && dirname =~ '/'.bname.'/\=$' && dirname !~ '^/'
3037 " bname is not empty
3038 " dirname ends with bname,
3039 " dirname doesn't start with /, so its not a absolute path
3040" call Decho(" findbuf3a: passes test 1 : dirname<".dirname.'> =~ /'.bname.'/\=$ && dirname !~ ^/')
Bram Moolenaar5c736222010-01-06 20:54:52 +01003041 break
3042 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003043 if bname =~ '^'.dirname.'/\=$'
3044 " bname begins with dirname
3045" call Decho(' findbuf3b: passes test 2 : bname<'.bname.'>=~^'.dirname.'/\=$')
Bram Moolenaar5c736222010-01-06 20:54:52 +01003046 break
3047 endif
3048 if dirname =~ '^'.bname.'/$'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003049" call Decho(' findbuf3c: passes test 3 : dirname<'.dirname.'>=~^'.bname.'/$')
3050 break
3051 endif
3052 if bname != '' && dirname =~ '/'.bname.'$' && bname == bufname("%") && line("$") == 1
3053" call Decho(' findbuf3d: passes test 4 : dirname<'.dirname.'>=~ /'.bname.'$')
Bram Moolenaar5c736222010-01-06 20:54:52 +01003054 break
3055 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003056 let ibuf= ibuf + 1
3057 endwhile
3058 if ibuf > buflast
3059 let bufnum= -1
3060 else
3061 let bufnum= ibuf
3062 endif
3063" call Decho(" findbuf4: bufnum=".bufnum." (ibuf=".ibuf." buflast=".buflast.")")
3064 endif
3065 endif
3066
3067 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaar97d62492012-11-15 21:28:22 +01003068" call Decho(" get enew buffer and name it OR re-use buffer")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003069 sil! keepj mark '
Bram Moolenaar446cb832008-06-24 21:56:24 +00003070 if bufnum < 0 || !bufexists(bufnum)
Bram Moolenaar97d62492012-11-15 21:28:22 +01003071" call Decho("--get enew buffer and name it (bufnum#".bufnum."<0 OR bufexists(".bufnum.")=".bufexists(bufnum)."==0)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003072 call s:NetrwEnew(dirname)
3073" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)")
3074 " name the buffer
3075 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
3076 " Got enew buffer; transform into a NetrwTreeListing
3077" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --")
3078 if !exists("s:netrw_treelistnum")
3079 let s:netrw_treelistnum= 1
3080 else
3081 let s:netrw_treelistnum= s:netrw_treelistnum + 1
3082 endif
3083 let w:netrw_treebufnr= bufnr("%")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003084" call Decho(" exe sil! keepalt file NetrwTreeListing ".fnameescape(s:netrw_treelistnum))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003085 exe 'sil! keepalt file NetrwTreeListing\ '.fnameescape(s:netrw_treelistnum)
3086 set bt=nofile noswf
Bram Moolenaaradc21822011-04-01 18:03:16 +02003087 nnoremap <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
3088 nnoremap <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
3089 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[')<cr>
3090 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00003091" call Decho(" tree listing#".s:netrw_treelistnum." bufnr=".w:netrw_treebufnr)
3092 else
3093" let v:errmsg= "" " Decho
3094 let escdirname= fnameescape(dirname)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003095" call Decho(" errmsg<".v:errmsg."> bufnr(escdirname<".escdirname.">)=".bufnr(escdirname)." bufname()<".bufname(bufnr(escdirname)).">")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003096" call Decho(' exe sil! keepalt file '.escdirname)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003097" let v:errmsg= "" " Decho
3098 exe 'sil! keepalt file '.escdirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003099" call Decho(" errmsg<".v:errmsg."> bufnr(".escdirname.")=".bufnr(escdirname)."<".bufname(bufnr(escdirname)).">")
3100 endif
3101" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">")
3102
3103 else " Re-use the buffer
Bram Moolenaar97d62492012-11-15 21:28:22 +01003104" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003105 let eikeep= &ei
3106 set ei=all
3107 if getline(2) =~ '^" Netrw Directory Listing'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003108" call Decho(" getline(2)<".getline(2).'> matches "Netrw Directory Listing" : using keepalt b '.bufnum)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003109 exe "sil! keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00003110 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003111" call Decho(" getline(2)<".getline(2).'> does not match "Netrw Directory Listing" : using b '.bufnum)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003112 exe "sil! b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00003113 endif
3114 if bufname("%") == '.'
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003115" call Decho("exe sil! keepalt file ".fnameescape(getcwd()))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003116 exe "sil! keepalt file ".fnameescape(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00003117 endif
3118 let &ei= eikeep
3119 if line("$") <= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02003120 keepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01003121" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
3122 return 0
3123 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
3124 keepj call s:NetrwListSettings(a:islocal)
3125 sil keepj %d
3126" 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 +00003127 return 0
3128 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
3129" call Decho("--re-use tree listing--")
3130" call Decho(" clear buffer<".expand("%")."> with :%d")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003131 sil keepj %d
Bram Moolenaaradc21822011-04-01 18:03:16 +02003132 keepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01003133" 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 +00003134 return 0
3135 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003136" call Dret("s:NetrwGetBuffer 1<buffer not cleared> : buf#".bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003137 return 1
3138 endif
3139 endif
3140
3141 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
3142 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
3143 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
3144 " med 1 D H
3145 " fast 2 H H
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003146" call Decho("--do netrw settings: make this buffer#".bufnr("%")." not-a-file, modifiable, not line-numbered, etc--")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003147 let fname= expand("%")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003148 keepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003149" call Decho("exe sil! keepalt file ".fnameescape(fname))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003150 exe "sil! keepj keepalt file ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003151
3152 " delete all lines from buffer {{{3
3153" call Decho("--delete all lines from buffer--")
3154" call Decho(" clear buffer<".expand("%")."> with :%d")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003155 sil! keepalt keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00003156
Bram Moolenaar97d62492012-11-15 21:28:22 +01003157" call Dret("s:NetrwGetBuffer 0<cleared buffer> : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003158 return 0
3159endfun
3160
3161" ---------------------------------------------------------------------
3162" s:NetrwGetcwd: get the current directory. {{{2
3163" Change backslashes to forward slashes, if any.
3164" If doesc is true, escape certain troublesome characters
3165fun! s:NetrwGetcwd(doesc)
3166" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
3167 let curdir= substitute(getcwd(),'\\','/','ge')
3168 if curdir !~ '[\/]$'
3169 let curdir= curdir.'/'
3170 endif
3171 if a:doesc
3172 let curdir= fnameescape(curdir)
3173 endif
3174" call Dret("NetrwGetcwd <".curdir.">")
3175 return curdir
3176endfun
3177
3178" ---------------------------------------------------------------------
3179" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
3180fun! s:NetrwGetWord()
3181" call Dfunc("s:NetrwGetWord() line#".line(".")." liststyle=".g:netrw_liststyle." virtcol=".virtcol("."))
3182 call s:UseBufWinVars()
3183
3184 " insure that w:netrw_liststyle is set up
3185 if !exists("w:netrw_liststyle")
3186 if exists("g:netrw_liststyle")
3187 let w:netrw_liststyle= g:netrw_liststyle
3188 else
3189 let w:netrw_liststyle= s:THINLIST
3190 endif
3191" call Decho("w:netrw_liststyle=".w:netrw_liststyle)
3192 endif
3193
3194 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
3195 " Active Banner support
3196" call Decho("active banner handling")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003197 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00003198 let dirname= "./"
3199 let curline= getline('.')
3200
3201 if curline =~ '"\s*Sorted by\s'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003202 keepj norm s
Bram Moolenaar446cb832008-06-24 21:56:24 +00003203 let s:netrw_skipbrowse= 1
3204 echo 'Pressing "s" also works'
3205
3206 elseif curline =~ '"\s*Sort sequence:'
3207 let s:netrw_skipbrowse= 1
3208 echo 'Press "S" to edit sorting sequence'
3209
3210 elseif curline =~ '"\s*Quick Help:'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003211 keepj norm ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00003212 let s:netrw_skipbrowse= 1
3213 echo 'Pressing "?" also works'
3214
3215 elseif curline =~ '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003216 keepj norm a
Bram Moolenaar446cb832008-06-24 21:56:24 +00003217 let s:netrw_skipbrowse= 1
3218 echo 'Pressing "a" also works'
3219
3220 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003221 exe 'sil keepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00003222 endif
3223
3224 elseif w:netrw_liststyle == s:THINLIST
3225" call Decho("thin column handling")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003226 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00003227 let dirname= getline('.')
3228
3229 elseif w:netrw_liststyle == s:LONGLIST
3230" call Decho("long column handling")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003231 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00003232 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
3233
3234 elseif w:netrw_liststyle == s:TREELIST
3235" call Decho("treelist handling")
3236 let dirname= substitute(getline('.'),'^\(| \)*','','e')
3237
3238 else
3239" call Decho("obtain word from wide listing")
3240 let dirname= getline('.')
3241
3242 if !exists("b:netrw_cpf")
3243 let b:netrw_cpf= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003244 exe 'sil keepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003245 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003246" call Decho("computed cpf=".b:netrw_cpf)
3247 endif
3248
3249" call Decho("buf#".bufnr("%")."<".bufname("%").">")
3250 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
3251" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt)
3252" call Decho("1: dirname<".dirname.">")
3253 if filestart == 0
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003254 keepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00003255 else
3256 call cursor(line("."),filestart+1)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003257 keepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00003258 endif
3259 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00003260 let eofname= filestart + b:netrw_cpf + 1
3261 if eofname <= col("$")
3262 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003263 keepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00003264 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003265 keepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00003266 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003267 let dirname = @a
3268 let @a = rega
3269" call Decho("2: dirname<".dirname.">")
3270 let dirname= substitute(dirname,'\s\+$','','e')
3271" call Decho("3: dirname<".dirname.">")
3272 endif
3273
3274 " symlinks are indicated by a trailing "@". Remove it before further processing.
3275 let dirname= substitute(dirname,"@$","","")
3276
3277 " executables are indicated by a trailing "*". Remove it before further processing.
3278 let dirname= substitute(dirname,"\*$","","")
3279
3280" call Dret("s:NetrwGetWord <".dirname.">")
3281 return dirname
3282endfun
3283
3284" ---------------------------------------------------------------------
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003285" s:NetrwListSettings: make standard settings for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003286fun! s:NetrwListSettings(islocal)
3287" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
3288 let fname= bufname("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003289" call Decho("setlocal bt=nofile nobl ma nonu nowrap noro")
Bram Moolenaarc236c162008-07-13 17:41:49 +00003290 setlocal bt=nofile nobl ma nonu nowrap noro
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003291" call Decho("exe sil! keepalt file ".fnameescape(fname))
3292 exe "sil! keepalt file ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003293 if g:netrw_use_noswf
3294 setlocal noswf
3295 endif
3296" call Dredir("ls!")
Bram Moolenaar97d62492012-11-15 21:28:22 +01003297" call Decho("(LocalListing) exe setl ts=".(g:netrw_maxfilenamelen+1))
3298 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003299 setlocal isk+=.,~,-
3300 if g:netrw_fastbrowse > a:islocal
3301 setlocal bh=hide
3302 else
3303 setlocal bh=delete
3304 endif
3305" call Dret("s:NetrwListSettings")
3306endfun
3307
3308" ---------------------------------------------------------------------
3309" s:NetrwListStyle: {{{2
3310" islocal=0: remote browsing
3311" =1: local browsing
3312fun! s:NetrwListStyle(islocal)
3313" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar97d62492012-11-15 21:28:22 +01003314 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00003315 let fname = s:NetrwGetWord()
3316 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
3317 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
3318" call Decho("fname<".fname.">")
3319" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle)
3320" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">")
3321
3322 if w:netrw_liststyle == s:THINLIST
3323 " use one column listing
3324" call Decho("use one column list")
3325 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
3326
3327 elseif w:netrw_liststyle == s:LONGLIST
3328 " use long list
3329" call Decho("use long list")
3330 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
3331
3332 elseif w:netrw_liststyle == s:WIDELIST
3333 " give wide list
3334" call Decho("use wide list")
3335 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
3336
3337 elseif w:netrw_liststyle == s:TREELIST
3338" call Decho("use tree list")
3339 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
3340
3341 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003342 keepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003343 let g:netrw_liststyle = s:THINLIST
3344 let w:netrw_liststyle = g:netrw_liststyle
3345 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
3346 endif
3347 setlocal ma noro
3348" call Decho("setlocal ma noro")
3349
3350 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
3351" call Decho("clear buffer<".expand("%")."> with :%d")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003352 sil! keepj %d
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003353 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003354" call Decho("(NetrwListStyle) setl nomod")
3355 setl nomod
3356" call Decho("(NetrwListStyle) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003357
3358 " refresh the listing
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003359" call Decho("(NetrwListStyle) refresh the listing")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003360 let svpos= netrw#NetrwSavePosn()
Bram Moolenaaradc21822011-04-01 18:03:16 +02003361 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
3362 keepj call netrw#NetrwRestorePosn(svpos)
3363 keepj call s:NetrwCursor()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003364
3365 " keep cursor on the filename
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003366 sil! keepj $
Bram Moolenaar446cb832008-06-24 21:56:24 +00003367 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
3368" call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'))
3369 if result <= 0 && exists("w:netrw_bannercnt")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003370 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00003371 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003372 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00003373
3374" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
3375endfun
3376
3377" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003378" s:NetrwBannerCtrl: toggles the display of the banner {{{2
3379fun! s:NetrwBannerCtrl(islocal)
3380" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
3381
Bram Moolenaar97d62492012-11-15 21:28:22 +01003382 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01003383 " toggle the banner (enable/suppress)
3384 let g:netrw_banner= !g:netrw_banner
3385
3386 " refresh the listing
3387 let svpos= netrw#NetrwSavePosn()
3388 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
3389
3390 " keep cursor on the filename
3391 let fname= s:NetrwGetWord()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003392 sil keepj $
Bram Moolenaar5c736222010-01-06 20:54:52 +01003393 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
3394" call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'))
3395 if result <= 0 && exists("w:netrw_bannercnt")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003396 exe "keepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01003397 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003398 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01003399" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
3400endfun
3401
3402" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003403" s:NetrwBookmarkMenu: Uses menu priorities {{{2
3404" .2.[cnt] for bookmarks, and
3405" .3.[cnt] for history
3406" (see s:NetrwMenu())
3407fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003408 if !exists("s:netrw_menucnt")
3409 return
3410 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003411" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhist_cnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003412
3413 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02003414 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00003415 if exists("g:NetrwTopLvlMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003416" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003417 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
3418 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003419 endif
3420 if !exists("s:netrw_initbookhist")
3421 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003422 endif
3423
3424 " show bookmarked places
Bram Moolenaar5c736222010-01-06 20:54:52 +01003425 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
3426 let cnt= 1
3427 for bmd in g:netrw_bookmarklist
Bram Moolenaaradc21822011-04-01 18:03:16 +02003428" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003429 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003430
3431 " show bookmarks for goto menu
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003432 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003433
3434 " show bookmarks for deletion menu
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003435 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 +01003436 let cnt= cnt + 1
3437 endfor
3438
3439 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003440
3441 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003442 if g:netrw_dirhistmax > 0
3443 let cnt = g:netrw_dirhist_cnt
3444 let first = 1
3445 let histcnt = 0
3446 while ( first || cnt != g:netrw_dirhist_cnt )
3447 let histcnt = histcnt + 1
3448 let priority = g:netrw_dirhist_cnt + histcnt
3449 if exists("g:netrw_dirhist_{cnt}")
3450 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
3451" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir)
3452 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
3453 endif
3454 let first = 0
3455 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3456 if cnt < 0
3457 let cnt= cnt + g:netrw_dirhistmax
3458 endif
3459 endwhile
3460 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003461
Bram Moolenaar9964e462007-05-05 17:54:07 +00003462 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003463" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003464endfun
3465
3466" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003467" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
3468" directory and a new directory name. Also, if the
3469" "new directory name" is actually a file,
3470" NetrwBrowseChgDir() edits the file.
3471fun! s:NetrwBrowseChgDir(islocal,newdir,...)
3472" call Dfunc("s:NetrwBrowseChgDir(islocal=".a:islocal."> newdir<".a:newdir.">) a:0=".a:0." curpos<".string(getpos("."))."> b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "").">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003473
Bram Moolenaar97d62492012-11-15 21:28:22 +01003474 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00003475 if !exists("b:netrw_curdir")
3476 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
3477 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01003478 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00003479" call Decho("(NetrwBrowseChgDir) b:netrw_curdir doesn't exist!")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003480" call Decho("(NetrwBrowseChgDir) getcwd<".getcwd().">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003481" call Dredir("ls!")
3482" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003483 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00003484 endif
3485
Bram Moolenaar97d62492012-11-15 21:28:22 +01003486 " NetrwBrowseChgDir: save options and initialize {{{3
Bram Moolenaaradc21822011-04-01 18:03:16 +02003487 keepj call s:NetrwOptionSave("s:")
3488 keepj call s:NetrwSafeOptions()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003489 let nbcd_curpos = netrw#NetrwSavePosn()
3490 let s:nbcd_curpos_{bufnr('%')} = nbcd_curpos
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003491" call Decho("(NetrwBrowseChgDir) setting s:nbcd_curpos_".bufnr('%')." to SavePosn")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003492 if (has("win32") || has("win95") || has("win64") || has("win16"))
3493 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
3494 else
3495 let dirname= b:netrw_curdir
3496 endif
3497 let newdir = a:newdir
3498 let dolockout = 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003499
Bram Moolenaar446cb832008-06-24 21:56:24 +00003500 " set up o/s-dependent directory recognition pattern
3501 if has("amiga")
3502 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00003503 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00003504 let dirpat= '[\/]$'
3505 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003506" call Decho("(NetrwBrowseChgDir) dirname<".dirname."> dirpat<".dirpat.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003507
3508 if dirname !~ dirpat
3509 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02003510 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00003511 let dirname= dirname.'/'
3512" call Decho("adjusting dirname<".dirname.">")
3513 endif
3514
3515 if newdir !~ dirpat
Bram Moolenaar97d62492012-11-15 21:28:22 +01003516 " ------------------------------
3517 " NetrwBrowseChgDir: edit a file {{{3
3518 " ------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003519" call Decho('(NetrwBrowseChgDir) case "handling a file": newdir<'.newdir.'> !~ dirpat<'.dirpat.">")
3520
Bram Moolenaar97d62492012-11-15 21:28:22 +01003521 " save position for benefit of Rexplore
3522 let s:rexposn_{bufnr("%")}= netrw#NetrwSavePosn()
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003523
Bram Moolenaar97d62492012-11-15 21:28:22 +01003524" call Decho("(NetrwBrowseChgDir) setting s:rexposn_".bufnr("%")." to SavePosn")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003525 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
3526 let dirname= s:NetrwTreeDir()
3527 if dirname =~ '/$'
3528 let dirname= dirname.newdir
3529 else
3530 let dirname= s:NetrwTreeDir()."/".newdir
3531 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003532" call Decho("(NetrwBrowseChgDir) dirname<".dirname.">")
3533" call Decho("(NetrwBrowseChgDir) tree listing")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003534 elseif newdir =~ '^\(/\|\a:\)'
3535 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00003536 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00003537 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003538 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003539" call Decho("(NetrwBrowseChgDir) handling a file: dirname<".dirname."> (a:0=".a:0.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003540 " this lets NetrwBrowseX avoid the edit
3541 if a:0 < 1
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003542" call Decho("(NetrwBrowseChgDir) set up windows for editing<".fnameescape(dirname)."> didsplit=".(exists("s:didsplit")? s:didsplit : "doesn't exist"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003543 keepj call s:NetrwOptionRestore("s:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003544 if !exists("s:didsplit")
Bram Moolenaar97d62492012-11-15 21:28:22 +01003545" call Decho("s:didsplit does not exist; g:netrw_browse_split=".g:netrw_browse_split." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00003546 if g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003547 " horizontally splitting the window first
Bram Moolenaar446cb832008-06-24 21:56:24 +00003548 new
Bram Moolenaar5c736222010-01-06 20:54:52 +01003549 if !&ea
3550 wincmd _
3551 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003552 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01003553 " vertically splitting the window first
Bram Moolenaar446cb832008-06-24 21:56:24 +00003554 rightb vert new
Bram Moolenaar5c736222010-01-06 20:54:52 +01003555 if !&ea
3556 wincmd |
3557 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003558 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01003559 " open file in new tab
Bram Moolenaar446cb832008-06-24 21:56:24 +00003560 tabnew
3561 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01003562 " act like "P" (ie. open previous window)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003563 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01003564 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00003565" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003566 return
3567 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003568 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00003569 " handling a file, didn't split, so remove menu
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003570" call Decho("(NetrwBrowseChgDir) handling a file+didn't split, so remove menu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003571 call s:NetrwMenu(0)
3572 " optional change to window
3573 if g:netrw_chgwin >= 1
3574 exe "keepjumps ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003575 endif
3576 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003577 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003578
Bram Moolenaar446cb832008-06-24 21:56:24 +00003579 " the point where netrw actually edits the (local) file
3580 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
3581 if a:islocal
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003582" call Decho("(NetrwBrowseChgDir) edit local file: exe e! ".fnameescape(dirname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003583 exe "e! ".fnameescape(dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01003584 call s:NetrwCursor()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003585 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003586" call Decho("(NetrwBrowseChgDir) remote file: NetrwBrowse will edit it")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003587 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003588 let dolockout= 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003589
3590 " handle g:Netrw_funcref -- call external-to-netrw functions
3591 " This code will handle g:Netrw_funcref as an individual function reference
3592 " or as a list of function references. It will ignore anything that's not
3593 " a function reference. See :help Funcref for information about function references.
3594 if exists("g:Netrw_funcref")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003595" call Decho("(NetrwBrowseChgDir) handle optional Funcrefs")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003596 if type(g:Netrw_funcref) == 2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003597" call Decho("(NetrwBrowseChgDir) handling a g:Netrw_funcref")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003598 keepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003599 elseif type(g:Netrw_funcref) == 3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003600" call Decho("(NetrwBrowseChgDir) handling a list of g:Netrw_funcrefs")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003601 for Fncref in g:Netrw_funcref
3602 if type(FncRef) == 2
Bram Moolenaaradc21822011-04-01 18:03:16 +02003603 keepj call FncRef()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003604 endif
3605 endfor
3606 endif
3607 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003608 endif
3609
3610 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003611 " ----------------------------------------------------
3612 " NetrwBrowseChgDir: just go to the new directory spec {{{3
3613 " ----------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003614" call Decho('(NetrwBrowseChgDir) case "just go to new directory spec": newdir<'.newdir.'>')
Bram Moolenaar97d62492012-11-15 21:28:22 +01003615 let dirname = newdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003616 keepj call s:SetRexDir(a:islocal,dirname)
3617 keepj call s:NetrwOptionRestore("s:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003618
3619 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003620 " ---------------------------------------------
3621 " NetrwBrowseChgDir: refresh the directory list {{{3
3622 " ---------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003623" call Decho('(NetrwBrowseChgDir) case "refresh directory listing": newdir == "./"')
Bram Moolenaaradc21822011-04-01 18:03:16 +02003624 keepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003625
3626 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003627 " --------------------------------------
3628 " NetrwBrowseChgDir: go up one directory {{{3
3629 " --------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003630" call Decho('(NetrwBrowseChgDir) case "go up one directory": newdir == "../"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003631
3632 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
3633 " force a refresh
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003634" call Decho("(NetrwBrowseChgDir) clear buffer<".expand("%")."> with :%d")
3635" call Decho("(NetrwBrowseChgDir) setl noro ma")
3636 setl noro ma
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003637 keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00003638 endif
3639
3640 if has("amiga")
3641 " amiga
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003642" call Decho('(NetrwBrowseChgDir) case "go up one directory": newdir == "../" and amiga')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003643 if a:islocal
3644 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
3645 let dirname= substitute(dirname,'/$','','')
3646 else
3647 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
3648 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003649" call Decho("(NetrwBrowseChgDir) amiga: dirname<".dirname."> (go up one dir)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003650
3651 else
3652 " unix or cygwin
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003653" call Decho('(NetrwBrowseChgDir) case "go up one directory": newdir == "../" and unix or cygwin')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003654 if a:islocal
3655 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
3656 if dirname == ""
3657 let dirname= '/'
3658 endif
3659 else
3660 let dirname= substitute(dirname,'^\(\a\+://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
3661 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003662" call Decho("(NetrwBrowseChgDir) unix: dirname<".dirname."> (go up one dir)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003663 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003664 keepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003665
3666 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01003667 " --------------------------------------
3668 " NetrwBrowseChgDir: Handle Tree Listing {{{3
3669 " --------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003670" call Decho('(NetrwBrowseChgDir) case liststyle is TREELIST and w:netrw_treedict exists')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003671 " force a refresh (for TREELIST, wait for NetrwTreeDir() to force the refresh)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003672" call Decho("(NetrwBrowseChgDir) setl noro ma")
3673 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00003674 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003675" call Decho("(NetrwBrowseChgDir) clear buffer<".expand("%")."> with :%d")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003676 keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00003677 endif
3678 let treedir = s:NetrwTreeDir()
3679 let s:treecurpos = nbcd_curpos
3680 let haskey= 0
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003681" call Decho("(NetrwBrowseChgDir) w:netrw_treedict<".string(w:netrw_treedict).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003682
3683 " search treedict for tree dir as-is
3684 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003685" call Decho('(NetrwBrowseChgDir) ....searched for treedir<'.treedir.'> : found it!')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003686 let haskey= 1
3687 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003688" call Decho('(NetrwBrowseChgDir) ....searched for treedir<'.treedir.'> : not found')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003689 endif
3690
3691 " search treedict for treedir with a / appended
3692 if !haskey && treedir !~ '/$'
3693 if has_key(w:netrw_treedict,treedir."/")
3694 let treedir= treedir."/"
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003695" call Decho('(NetrwBrowseChgDir) ....searched.for treedir<'.treedir.'> found it!')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003696 let haskey = 1
3697 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003698" call Decho('(NetrwBrowseChgDir) ....searched for treedir<'.treedir.'/> : not found')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003699 endif
3700 endif
3701
3702 " search treedict for treedir with any trailing / elided
3703 if !haskey && treedir =~ '/$'
3704 let treedir= substitute(treedir,'/$','','')
3705 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003706" call Decho('(NetrwBrowseChgDir) ....searched.for treedir<'.treedir.'> found it!')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003707 let haskey = 1
3708 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003709" call Decho('(NetrwBrowseChgDir) ....searched for treedir<'.treedir.'> : not found')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003710 endif
3711 endif
3712
3713 if haskey
3714 " close tree listing for selected subdirectory
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003715" call Decho("(NetrwBrowseChgDir) closing selected subdirectory<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003716 call remove(w:netrw_treedict,treedir)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003717" call Decho("(NetrwBrowseChgDir) removed entry<".treedir."> from treedict")
3718" call Decho("(NetrwBrowseChgDir) yielding treedict<".string(w:netrw_treedict).">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003719 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00003720 else
3721 " go down one directory
3722 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003723" call Decho("(NetrwBrowseChgDir) go down one dir: treedir<".treedir.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003724 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003725 keepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003726 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00003727
3728 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003729 " ----------------------------------------
3730 " NetrwBrowseChgDir: Go down one directory {{{3
3731 " ----------------------------------------
3732 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003733" call Decho("(NetrwBrowseChgDir) go down one dir: dirname<".dirname."> newdir<".newdir.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003734 keepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003735 endif
3736
Bram Moolenaar97d62492012-11-15 21:28:22 +01003737 " --------------------------------------
3738 " NetrwBrowseChgDir: Restore and Cleanup {{{3
3739 " --------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02003740 keepj call s:NetrwOptionRestore("s:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003741 if dolockout
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003742" call Decho("(NetrwBrowseChgDir) filewritable(dirname<".dirname.">)=".filewritable(dirname))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003743 if filewritable(dirname)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003744" call Decho("(NetrwBrowseChgDir) doing modification lockout settings: ma nomod noro")
3745" call Decho("(NetrwBrowseChgDir) setl ma nomod noro")
3746 setl ma nomod noro
3747" call Decho("(NetrwBrowseChgDir) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003748 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003749" call Decho("(NetrwBrowseChgDir) doing modification lockout settings: ma nomod ro")
3750" call Decho("(NetrwBrowseChgDir) setl ma nomod noro")
3751 setl ma nomod ro
3752" call Decho("(NetrwBrowseChgDir) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003753 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003754 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003755 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00003756
Bram Moolenaar446cb832008-06-24 21:56:24 +00003757" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
3758 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00003759endfun
3760
3761" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003762" s:NetrwBrowseX: (implements "x") executes a special "viewer" script or program for the {{{2
3763" given filename; typically this means given their extension.
3764" 0=local, 1=remote
Bram Moolenaar446cb832008-06-24 21:56:24 +00003765fun! netrw#NetrwBrowseX(fname,remote)
3766" call Dfunc("NetrwBrowseX(fname<".a:fname."> remote=".a:remote.")")
3767
Bram Moolenaar97d62492012-11-15 21:28:22 +01003768 let ykeep = @@
3769 let screenposn = netrw#NetrwSavePosn()
3770
Bram Moolenaar5c736222010-01-06 20:54:52 +01003771 " special core dump handler
3772 if a:fname =~ '/core\(\.\d\+\)\=$'
3773 if exists("g:Netrw_corehandler")
3774 if type(g:Netrw_corehandler) == 2
3775 " g:Netrw_corehandler is a function reference (see :help Funcref)
3776" call Decho("g:Netrw_corehandler is a funcref")
3777 call g:Netrw_corehandler(a:fname)
Bram Moolenaar15146672011-10-20 22:22:38 +02003778 elseif type(g:Netrw_corehandler) == 3)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003779 " g:Netrw_corehandler is a List of function references (see :help Funcref)
3780" call Decho("g:Netrw_corehandler is a List")
3781 for Fncref in g:Netrw_corehandler
3782 if type(FncRef) == 2
3783 call FncRef(a:fname)
3784 endif
3785 endfor
3786 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003787 call netrw#NetrwRestorePosn(screenposn)
3788 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01003789" call Dret("NetrwBrowseX : coredump handler invoked")
3790 return
3791 endif
3792 endif
3793
Bram Moolenaar446cb832008-06-24 21:56:24 +00003794 " set up the filename
3795 " (lower case the extension, make a local copy of a remote file)
3796 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
3797 if has("win32") || has("win95") || has("win64") || has("win16")
3798 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00003799 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003800" call Decho("exten<".exten.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003801
3802 " seems kde systems often have gnome-open due to dependencies, even though
3803 " gnome-open's subsidiary display tools are largely absent. Kde systems
3804 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
3805 if !exists("s:haskdeinit")
Bram Moolenaar97d62492012-11-15 21:28:22 +01003806 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaarc236c162008-07-13 17:41:49 +00003807 let s:haskdeinit= system("ps -e") =~ 'kdeinit'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003808 if v:shell_error
3809 let s:haskdeinit = 0
3810 endif
3811 else
3812 let s:haskdeinit= 0
3813 endif
3814" call Decho("setting s:haskdeinit=".s:haskdeinit)
3815 endif
3816
3817 if a:remote == 1
3818 " create a local copy
Bram Moolenaar97d62492012-11-15 21:28:22 +01003819" call Decho("(remote) a:remote=".a:remote.": create a local copy of <".a:fname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003820 setlocal bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01003821 call netrw#NetRead(3,a:fname)
3822 " attempt to rename tempfile
3823 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01003824 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01003825" call Decho("basename<".basename.">")
3826" call Decho("newname <".newname.">")
3827 if rename(s:netrw_tmpfile,newname) == 0
3828 " renaming succeeded
3829 let fname= newname
3830 else
3831 " renaming failed
3832 let fname= s:netrw_tmpfile
3833 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00003834 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003835" call Decho("(local) a:remote=".a:remote.": handling local copy of <".a:fname.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +00003836 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003837 " special ~ handler for local
3838 if fname =~ '^\~' && expand("$HOME") != ""
3839" call Decho('invoking special ~ handler')
3840 let fname= substitute(fname,'^\~',expand("$HOME"),'')
3841 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003842 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003843" call Decho("fname<".fname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003844" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten))
3845
3846 " set up redirection
3847 if &srr =~ "%s"
3848 if (has("win32") || has("win95") || has("win64") || has("win16"))
3849 let redir= substitute(&srr,"%s","nul","")
3850 else
3851 let redir= substitute(&srr,"%s","/dev/null","")
3852 endif
3853 elseif (has("win32") || has("win95") || has("win64") || has("win16"))
3854 let redir= &srr . "nul"
3855 else
3856 let redir= &srr . "/dev/null"
3857 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003858" call Decho("set up redirection: redir{".redir."} srr{".&srr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003859
3860 " extract any viewing options. Assumes that they're set apart by quotes.
Bram Moolenaar97d62492012-11-15 21:28:22 +01003861" call Decho("extract any viewing options")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003862 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003863" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003864 if g:netrw_browsex_viewer =~ '\s'
3865 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
3866 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
3867 let oviewer = ''
3868 let cnt = 1
3869 while !executable(viewer) && viewer != oviewer
3870 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
3871 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
3872 let cnt = cnt + 1
3873 let oviewer = viewer
3874" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">")
3875 endwhile
3876 else
3877 let viewer = g:netrw_browsex_viewer
3878 let viewopt = ""
3879 endif
3880" call Decho("viewer<".viewer."> viewopt<".viewopt.">")
3881 endif
3882
3883 " execute the file handler
Bram Moolenaar97d62492012-11-15 21:28:22 +01003884" call Decho("execute the file handler (if any)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003885 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
3886" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">")
3887 let ret= netrwFileHandlers#Invoke(exten,fname)
3888
3889 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
3890" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003891" call Decho("exe sil !".viewer." ".viewopt.shellescape(fname,1).redir)
3892 exe "sil !".viewer." ".viewopt.shellescape(fname,1).redir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003893 let ret= v:shell_error
3894
3895 elseif has("win32") || has("win64")
Bram Moolenaar97d62492012-11-15 21:28:22 +01003896" call Decho("windows")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003897 if executable("start")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003898" call Decho('exe sil !start rundll32 url.dll,FileProtocolHandler '.shellescape(fname,1))
3899 exe 'sil !start rundll32 url.dll,FileProtocolHandler '.shellescape(fname,1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003900 elseif executable("rundll32")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003901" call Decho('exe sil !rundll32 url.dll,FileProtocolHandler '.shellescape(fname,1))
3902 exe 'sil !rundll32 url.dll,FileProtocolHandler '.shellescape(fname,1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003903 else
3904 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
3905 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003906 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3907 let ret= v:shell_error
3908
Bram Moolenaar97d62492012-11-15 21:28:22 +01003909 elseif has("win32unix")
3910 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
3911" call Decho("cygwin: winfname<".shellescape(winfname,1).">")
3912 if executable("start")
3913" call Decho('exe sil !start rundll32 url.dll,FileProtocolHandler '.shellescape(winfname,1))
3914 exe 'sil !start rundll32 url.dll,FileProtocolHandler '.shellescape(winfname,1)
3915 elseif executable("rundll32")
3916" call Decho('exe sil !rundll32 url.dll,FileProtocolHandler '.shellescape(winfname,1))
3917 exe 'sil !rundll32 url.dll,FileProtocolHandler '.shellescape(winfname,1)
3918 else
3919 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
3920 endif
3921 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3922 let ret= v:shell_error
3923
3924 elseif has("unix") && executable("xdg-open") && !s:haskdeinit
3925" call Decho("unix and xdg-open")
3926" call Decho("exe sil !xdg-open ".shellescape(fname,1)." ".redir)
3927 exe "sil !xdg-open ".shellescape(fname,1).redir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003928 let ret= v:shell_error
3929
3930 elseif has("unix") && executable("kfmclient") && s:haskdeinit
Bram Moolenaar97d62492012-11-15 21:28:22 +01003931" call Decho("unix and kfmclient")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003932" call Decho("exe sil !kfmclient exec ".shellescape(fname,1)." ".redir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003933 exe "sil !kfmclient exec ".shellescape(fname,1)." ".redir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003934 let ret= v:shell_error
3935
3936 elseif has("macunix") && executable("open")
Bram Moolenaar97d62492012-11-15 21:28:22 +01003937" call Decho("macunix and open")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003938" call Decho("exe sil !open ".shellescape(fname,1)." ".redir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003939 exe "sil !open ".shellescape(fname,1)." ".redir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003940 let ret= v:shell_error
3941
3942 else
3943 " netrwFileHandlers#Invoke() always returns 0
3944 let ret= netrwFileHandlers#Invoke(exten,fname)
3945 endif
3946
3947 " if unsuccessful, attempt netrwFileHandlers#Invoke()
3948 if ret
3949 let ret= netrwFileHandlers#Invoke(exten,fname)
3950 endif
3951
Bram Moolenaarc236c162008-07-13 17:41:49 +00003952 " restoring redraw! after external file handlers
3953 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00003954
3955 " cleanup: remove temporary file,
3956 " delete current buffer if success with handler,
3957 " return to prior buffer (directory listing)
3958 " Feb 12, 2008: had to de-activiate removal of
3959 " temporary file because it wasn't getting seen.
3960" if a:remote == 1 && fname != a:fname
Bram Moolenaar97d62492012-11-15 21:28:22 +01003961"" call Decho("deleting temporary file<".fname.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +00003962" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003963" endif
3964
3965 if a:remote == 1
3966 setlocal bh=delete bt=nofile
3967 if g:netrw_use_noswf
3968 setlocal noswf
3969 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003970 exe "sil! keepj norm! \<c-o>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003971" redraw!
3972 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003973 call netrw#NetrwRestorePosn(screenposn)
3974 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00003975
3976" call Dret("NetrwBrowseX")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003977endfun
3978
3979" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003980" s:NetrwChgPerm: (implements "gp") change file permission {{{2
3981fun! s:NetrwChgPerm(islocal,curdir)
3982" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01003983 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01003984 call inputsave()
3985 let newperm= input("Enter new permission: ")
3986 call inputrestore()
3987 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',shellescape(expand("<cfile>")),'')
3988 let chgperm= substitute(chgperm,'\<PERM\>',shellescape(newperm),'')
3989" call Decho("chgperm<".chgperm.">")
3990 call system(chgperm)
3991 if v:shell_error != 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003992 keepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003993 endif
3994 if a:islocal
Bram Moolenaaradc21822011-04-01 18:03:16 +02003995 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003996 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003997 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01003998" call Dret("s:NetrwChgPerm")
3999endfun
4000
4001" ---------------------------------------------------------------------
4002" s:NetrwClearExplore: clear explore variables (if any) {{{2
4003fun! s:NetrwClearExplore()
4004" call Dfunc("s:NetrwClearExplore()")
4005 2match none
4006 if exists("s:explore_match") |unlet s:explore_match |endif
4007 if exists("s:explore_indx") |unlet s:explore_indx |endif
4008 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
4009 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
4010 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
4011 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
4012 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
4013 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
4014 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
4015" redraw!
4016 echo " "
4017 echo " "
4018" call Dret("s:NetrwClearExplore")
4019endfun
4020
4021" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00004022" netrw#Explore: launch the local browser in the directory of the current file {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01004023" indx: == -1: Nexplore
4024" == -2: Pexplore
4025" == +: this is overloaded:
4026" * If Nexplore/Pexplore is in use, then this refers to the
4027" indx'th item in the w:netrw_explore_list[] of items which
4028" matched the */pattern **/pattern *//pattern **//pattern
4029" * If Hexplore or Vexplore, then this will override
4030" g:netrw_winsize to specify the qty of rows or columns the
4031" newly split window should have.
4032" dosplit==0: the window will be split iff the current file has been modified
4033" dosplit==1: the window will be split before running the local browser
4034" style == 0: Explore style == 1: Explore!
4035" == 2: Hexplore style == 3: Hexplore!
4036" == 4: Vexplore style == 5: Vexplore!
4037" == 6: Texplore
Bram Moolenaar9964e462007-05-05 17:54:07 +00004038fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004039" call Dfunc("netrw#Explore(indx=".a:indx." dosplit=".a:dosplit." style=".a:style.",a:1<".a:1.">) &modified=".&modified." modifiable=".&modifiable." a:0=".a:0." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00004040 if !exists("b:netrw_curdir")
4041 let b:netrw_curdir= getcwd()
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00004042" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004043 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004044 let curdir = simplify(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004045 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
4046" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004047
4048 " save registers
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004049 sil! let keepregstar = @*
4050 sil! let keepregplus = @+
4051 sil! let keepregslash= @/
Bram Moolenaar9964e462007-05-05 17:54:07 +00004052
4053 " if dosplit or file has been modified
4054 if a:dosplit || &modified || a:style == 6
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004055" call Decho("case dosplit=".a:dosplit." modified=".&modified." a:style=".a:style.": dosplit or file has been modified")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004056 call s:SaveWinVars()
Bram Moolenaar251e1912011-06-19 05:09:16 +02004057 let winsz= g:netrw_winsize
Bram Moolenaar5c736222010-01-06 20:54:52 +01004058 if a:indx > 0
Bram Moolenaar251e1912011-06-19 05:09:16 +02004059 let winsz= a:indx
Bram Moolenaar5c736222010-01-06 20:54:52 +01004060 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004061
4062 if a:style == 0 " Explore, Sexplore
4063" call Decho("style=0: Explore or Sexplore")
Bram Moolenaar15146672011-10-20 22:22:38 +02004064 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar251e1912011-06-19 05:09:16 +02004065 exe winsz."wincmd s"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004066
4067 elseif a:style == 1 "Explore!, Sexplore!
4068" call Decho("style=1: Explore! or Sexplore!")
Bram Moolenaar15146672011-10-20 22:22:38 +02004069 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar251e1912011-06-19 05:09:16 +02004070 exe winsz."wincmd v"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004071
4072 elseif a:style == 2 " Hexplore
4073" call Decho("style=2: Hexplore")
Bram Moolenaar15146672011-10-20 22:22:38 +02004074 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar251e1912011-06-19 05:09:16 +02004075 exe "bel ".winsz."wincmd s"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004076
4077 elseif a:style == 3 " Hexplore!
4078" call Decho("style=3: Hexplore!")
Bram Moolenaar15146672011-10-20 22:22:38 +02004079 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar251e1912011-06-19 05:09:16 +02004080 exe "abo ".winsz."wincmd s"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004081
4082 elseif a:style == 4 " Vexplore
4083" call Decho("style=4: Vexplore")
Bram Moolenaar15146672011-10-20 22:22:38 +02004084 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar251e1912011-06-19 05:09:16 +02004085 exe "lefta ".winsz."wincmd v"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004086
4087 elseif a:style == 5 " Vexplore!
4088" call Decho("style=5: Vexplore!")
Bram Moolenaar15146672011-10-20 22:22:38 +02004089 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar251e1912011-06-19 05:09:16 +02004090 exe "rightb ".winsz."wincmd v"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004091
4092 elseif a:style == 6 " Texplore
4093 call s:SaveBufVars()
4094" call Decho("style = 6: Texplore")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004095 exe "tabnew ".fnameescape(curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004096 call s:RestoreBufVars()
4097 endif
4098 call s:RestoreWinVars()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004099" else " Decho
4100" call Decho("case a:dosplit=".a:dosplit." AND modified=".&modified." AND a:style=".a:style." is not 6")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004101 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004102 keepj norm! 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00004103
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00004104 if a:0 > 0
Bram Moolenaar15146672011-10-20 22:22:38 +02004105" call Decho("case [a:0=".a:0."] > 0")
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00004106 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaar15146672011-10-20 22:22:38 +02004107" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004108 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaar15146672011-10-20 22:22:38 +02004109" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)")
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00004110 elseif a:1 == '.'
Bram Moolenaar15146672011-10-20 22:22:38 +02004111" call Decho("..case a:1<".a:1.">: matches .")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004112 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00004113 if dirname !~ '/$'
4114 let dirname= dirname."/"
4115 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004116" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")")
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00004117 elseif a:1 =~ '\$'
Bram Moolenaar15146672011-10-20 22:22:38 +02004118" call Decho("..case a:1<".a:1.">: matches ending $")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004119 let dirname= simplify(expand(a:1))
Bram Moolenaar15146672011-10-20 22:22:38 +02004120" call Decho("..using user-specified dirname<".dirname."> with $env-var")
4121 elseif a:1 !~ '^\*\{1,2}/'
4122" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004123 let dirname= simplify(a:1)
Bram Moolenaar15146672011-10-20 22:22:38 +02004124" call Decho("..using user-specified dirname<".dirname.">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004125 else
Bram Moolenaar15146672011-10-20 22:22:38 +02004126" call Decho("..case a:1: pattern or filepattern")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004127 let dirname= a:1
Bram Moolenaar9964e462007-05-05 17:54:07 +00004128 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004129 else
4130 " clear explore
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004131" call Decho("case a:0=".a:0.": clearing Explore list")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004132 call s:NetrwClearExplore()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004133" call Dret("netrw#Explore : cleared list")
4134 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004135 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004136
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004137" call Decho("dirname<".dirname.">")
4138 if dirname =~ '\.\./\=$'
4139 let dirname= simplify(fnamemodify(dirname,':p:h'))
4140 elseif dirname =~ '\.\.' || dirname == '.'
4141 let dirname= simplify(fnamemodify(dirname,':p'))
4142 endif
4143" call Decho("dirname<".dirname."> (after simplify)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004144
Bram Moolenaar15146672011-10-20 22:22:38 +02004145 if dirname =~ '^\*//'
4146 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
4147" call Decho("case Explore *//pattern")
4148 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
4149 let starpat= 1
4150" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">")
4151 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
4152
4153 elseif dirname =~ '^\*\*//'
4154 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
4155" call Decho("case Explore **//pattern")
4156 let pattern= substitute(dirname,'^\*\*//','','')
4157 let starpat= 2
4158" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">")
4159
4160 elseif dirname =~ '/\*\*/'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004161 " handle .../**/.../filepat
4162" call Decho("case Explore .../**/.../filepat")
4163 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
4164 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && (has("win32") || has("win95") || has("win64") || has("win16")))
4165 let b:netrw_curdir = prefixdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004166 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004167 let b:netrw_curdir= getcwd().'/'.prefixdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004168 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004169 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
4170 let starpat= 4;
Bram Moolenaar15146672011-10-20 22:22:38 +02004171" call Decho("..pwd<".getcwd()."> dirname<".dirname.">")
4172" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004173
4174 elseif dirname =~ '^\*/'
4175 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
4176 let starpat= 3
4177" call Decho("case Explore */filepat (starpat=".starpat.")")
4178
4179 elseif dirname=~ '^\*\*/'
4180 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
4181 let starpat= 4
4182" call Decho("case Explore **/filepat (starpat=".starpat.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004183
Bram Moolenaar446cb832008-06-24 21:56:24 +00004184 else
4185 let starpat= 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004186" call Decho("default case: starpat=".starpat)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004187 endif
4188
4189 if starpat == 0 && a:indx >= 0
4190 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaar5c736222010-01-06 20:54:52 +01004191" call Decho("case starpat==0 && a:indx=".a:indx.": dirname<".dirname."> Explore Hexplore Vexplore Sexplore")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004192 if dirname == ""
Bram Moolenaar5c736222010-01-06 20:54:52 +01004193 let dirname= curfiledir
Bram Moolenaar15146672011-10-20 22:22:38 +02004194" call Decho("..empty dirname, using current file's directory<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004195 endif
4196 if dirname =~ '^scp:' || dirname =~ '^ftp:'
Bram Moolenaar15146672011-10-20 22:22:38 +02004197" call Decho("..calling NetrwBrowse(0,dirname<".dirname.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004198 call s:NetrwBrowse(0,dirname)
4199 else
4200 if dirname == ""|let dirname= getcwd()|endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004201" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004202 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004203" call Decho("win#".winnr()." buf#".bufnr("%")." modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004204 endif
4205
Bram Moolenaar5c736222010-01-06 20:54:52 +01004206" call Decho("curdir<".curdir.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004207 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004208 keepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004209 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004210 keepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004211 endif
4212
4213 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
4214 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
4215 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
4216 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
4217 elseif a:indx <= 0
4218 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaar5c736222010-01-06 20:54:52 +01004219" call Decho("case a:indx<=0: Nexplore, Pexplore, <s-down>, <s-up> starpat=".starpat." a:indx=".a:indx)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004220 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaar15146672011-10-20 22:22:38 +02004221" call Decho("..set up <s-up> and <s-down> maps")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004222 let s:didstarstar= 1
4223 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
4224 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
4225 endif
4226
4227 if has("path_extra")
Bram Moolenaar15146672011-10-20 22:22:38 +02004228" call Decho("..starpat=".starpat.": has +path_extra")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004229 if !exists("w:netrw_explore_indx")
4230 let w:netrw_explore_indx= 0
4231 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004232
Bram Moolenaar9964e462007-05-05 17:54:07 +00004233 let indx = a:indx
Bram Moolenaar15146672011-10-20 22:22:38 +02004234" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004235
Bram Moolenaar9964e462007-05-05 17:54:07 +00004236 if indx == -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004237 " Nexplore
Bram Moolenaar15146672011-10-20 22:22:38 +02004238" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004239 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaaradc21822011-04-01 18:03:16 +02004240 keepj call netrw#ErrorMsg(s:WARNING,"using Nexplore or <s-down> improperly; see help for netrw-starstar",40)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004241 sil! let @* = keepregstar
4242 sil! let @+ = keepregstar
4243 sil! let @/ = keepregslash
Bram Moolenaar9964e462007-05-05 17:54:07 +00004244" call Dret("netrw#Explore")
4245 return
4246 endif
4247 let indx= w:netrw_explore_indx
4248 if indx < 0 | let indx= 0 | endif
4249 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
4250 let curfile= w:netrw_explore_list[indx]
Bram Moolenaar15146672011-10-20 22:22:38 +02004251" call Decho("....indx=".indx." curfile<".curfile.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004252 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
4253 let indx= indx + 1
Bram Moolenaar15146672011-10-20 22:22:38 +02004254" call Decho("....indx=".indx." (Nexplore while loop)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004255 endwhile
4256 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004257" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004258
4259 elseif indx == -2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004260 " Pexplore
4261" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004262 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaaradc21822011-04-01 18:03:16 +02004263 keepj call netrw#ErrorMsg(s:WARNING,"using Pexplore or <s-up> improperly; see help for netrw-starstar",41)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004264 sil! let @* = keepregstar
4265 sil! let @+ = keepregstar
4266 sil! let @/ = keepregslash
Bram Moolenaar9964e462007-05-05 17:54:07 +00004267" call Dret("netrw#Explore")
4268 return
4269 endif
4270 let indx= w:netrw_explore_indx
4271 if indx < 0 | let indx= 0 | endif
4272 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
4273 let curfile= w:netrw_explore_list[indx]
Bram Moolenaar15146672011-10-20 22:22:38 +02004274" call Decho("....indx=".indx." curfile<".curfile.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004275 while indx >= 0 && curfile == w:netrw_explore_list[indx]
4276 let indx= indx - 1
Bram Moolenaar15146672011-10-20 22:22:38 +02004277" call Decho("....indx=".indx." (Pexplore while loop)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004278 endwhile
4279 if indx < 0 | let indx= 0 | endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004280" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004281
4282 else
4283 " Explore -- initialize
4284 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaar15146672011-10-20 22:22:38 +02004285" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004286 keepj call s:NetrwClearExplore()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004287 let w:netrw_explore_indx= 0
4288 if !exists("b:netrw_curdir")
4289 let b:netrw_curdir= getcwd()
4290 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004291" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004292
Bram Moolenaar446cb832008-06-24 21:56:24 +00004293 " switch on starpat to build the w:netrw_explore_list of files
4294 if starpat == 1
4295 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaar15146672011-10-20 22:22:38 +02004296" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls)
4297" call Decho("....pattern<".pattern.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004298 try
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004299 exe "keepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004300 catch /^Vim\%((\a\+)\)\=:E480/
4301 call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
4302" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
4303 return
4304 endtry
4305 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004306 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
4307
4308 elseif starpat == 2
4309 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaar15146672011-10-20 22:22:38 +02004310" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)")
4311" call Decho("....pattern<".pattern.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004312 try
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004313 exe "sil keepj noautocmd vimgrep /".pattern."/gj "."**/*"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004314 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar5c736222010-01-06 20:54:52 +01004315 call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004316 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02004317 sil! let @* = keepregstar
4318 sil! let @+ = keepregstar
4319 sil! let @/ = keepregslash
Bram Moolenaar446cb832008-06-24 21:56:24 +00004320" call Dret("netrw#Explore : no files matched pattern")
4321 return
4322 endtry
4323 let s:netrw_curdir = b:netrw_curdir
4324 let w:netrw_explore_list = getqflist()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004325 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
Bram Moolenaar15146672011-10-20 22:22:38 +02004326 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004327
4328 elseif starpat == 3
4329 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaar15146672011-10-20 22:22:38 +02004330" call Decho("..case starpat=".starpat.": build */filepat list (curdir-only srch filenames matching filepat) &hls=".&hls)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004331 let filepat= substitute(dirname,'^\*/','','')
4332 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaar15146672011-10-20 22:22:38 +02004333" call Decho("....b:netrw_curdir<".b:netrw_curdir.">")
4334" call Decho("....filepat<".filepat.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004335 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
4336 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004337
4338 elseif starpat == 4
4339 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaar15146672011-10-20 22:22:38 +02004340" call Decho("..case starpat=".starpat.": build **/filepat list (recursive descent srch filenames matching filepat) &hls=".&hls)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004341 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004342 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
4343 endif " switch on starpat to build w:netrw_explore_list
Bram Moolenaar9964e462007-05-05 17:54:07 +00004344
4345 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaar15146672011-10-20 22:22:38 +02004346" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">")
4347" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004348
4349 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaaradc21822011-04-01 18:03:16 +02004350 keepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004351 sil! let @* = keepregstar
4352 sil! let @+ = keepregstar
4353 sil! let @/ = keepregslash
Bram Moolenaar9964e462007-05-05 17:54:07 +00004354" call Dret("netrw#Explore : no files matched")
4355 return
4356 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004357 endif " if indx ... endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004358
4359 " NetrwStatusLine support - for exploring support
4360 let w:netrw_explore_indx= indx
Bram Moolenaar15146672011-10-20 22:22:38 +02004361" call Decho("....w:netrw_explore_list<".join(w:netrw_explore_list,',')."> len=".w:netrw_explore_listlen)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004362
4363 " wrap the indx around, but issue a note
4364 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaar15146672011-10-20 22:22:38 +02004365" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004366 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
4367 let w:netrw_explore_indx= indx
Bram Moolenaaradc21822011-04-01 18:03:16 +02004368 keepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004369 endif
4370
4371 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaar15146672011-10-20 22:22:38 +02004372" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004373 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaar15146672011-10-20 22:22:38 +02004374" call Decho("....newdir<".newdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004375
Bram Moolenaar15146672011-10-20 22:22:38 +02004376" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004377 call netrw#LocalBrowseCheck(newdir)
4378 if !exists("w:netrw_liststyle")
4379 let w:netrw_liststyle= g:netrw_liststyle
4380 endif
4381 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004382 keepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004383 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004384 keepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004385 endif
4386 let w:netrw_explore_mtchcnt = indx + 1
4387 let w:netrw_explore_bufnr = bufnr("%")
4388 let w:netrw_explore_line = line(".")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004389 keepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaar15146672011-10-20 22:22:38 +02004390" call Decho("....explore: mtchcnt=".w:netrw_explore_mtchcnt." bufnr=".w:netrw_explore_bufnr." line#".w:netrw_explore_line)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004391
4392 else
Bram Moolenaar15146672011-10-20 22:22:38 +02004393" call Decho("..your vim does not have +path_extra")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004394 if !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004395 keepj call netrw#ErrorMsg(s:WARNING,"your vim needs the +path_extra feature for Exploring with **!",44)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004396 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004397 sil! let @* = keepregstar
4398 sil! let @+ = keepregstar
4399 sil! let @/ = keepregslash
Bram Moolenaar9964e462007-05-05 17:54:07 +00004400" call Dret("netrw#Explore : missing +path_extra")
4401 return
4402 endif
4403
4404 else
Bram Moolenaar15146672011-10-20 22:22:38 +02004405" call Decho("..default case: Explore newdir<".dirname.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004406 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004407 sil! unlet w:netrw_treedict
4408 sil! unlet w:netrw_treetop
Bram Moolenaar9964e462007-05-05 17:54:07 +00004409 endif
4410 let newdir= dirname
4411 if !exists("b:netrw_curdir")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004412 keepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaar9964e462007-05-05 17:54:07 +00004413 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02004414 keepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaar9964e462007-05-05 17:54:07 +00004415 endif
4416 endif
4417
Bram Moolenaar446cb832008-06-24 21:56:24 +00004418 " visual display of **/ **// */ Exploration files
Bram Moolenaar5c736222010-01-06 20:54:52 +01004419" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"))
4420" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004421 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004422" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004423 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
4424 " only update match list if current directory isn't the same as before
Bram Moolenaar5c736222010-01-06 20:54:52 +01004425" call Decho("only update match list if current directory not the same as before")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004426 let s:explore_prvdir = b:netrw_curdir
4427 let s:explore_match = ""
Bram Moolenaar5c736222010-01-06 20:54:52 +01004428 let dirlen = s:Strlen(b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004429 if b:netrw_curdir !~ '/$'
4430 let dirlen= dirlen + 1
4431 endif
4432 let prvfname= ""
4433 for fname in w:netrw_explore_list
4434" call Decho("fname<".fname.">")
4435 if fname =~ '^'.b:netrw_curdir
4436 if s:explore_match == ""
Bram Moolenaar5c736222010-01-06 20:54:52 +01004437 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004438 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004439 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004440 endif
4441 elseif fname !~ '^/' && fname != prvfname
4442 if s:explore_match == ""
Bram Moolenaar5c736222010-01-06 20:54:52 +01004443 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004444 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004445 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004446 endif
4447 endif
4448 let prvfname= fname
4449 endfor
4450" call Decho("explore_match<".s:explore_match.">")
4451 exe "2match netrwMarkFile /".s:explore_match."/"
4452 endif
4453 echo "<s-up>==Pexplore <s-down>==Nexplore"
4454 else
4455 2match none
4456 if exists("s:explore_match") | unlet s:explore_match | endif
4457 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
4458 echo " "
4459" call Decho("cleared explore match list")
4460 endif
4461
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004462 sil! let @* = keepregstar
4463 sil! let @+ = keepregstar
4464 sil! let @/ = keepregslash
Bram Moolenaar9964e462007-05-05 17:54:07 +00004465" call Dret("netrw#Explore : @/<".@/.">")
4466endfun
4467
4468" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004469" s:NetrwExploreListUniq: {{{2
4470fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02004471" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004472
4473 " this assumes that the list is already sorted
4474 let newexplist= []
4475 for member in a:explist
4476 if !exists("uniqmember") || member != uniqmember
4477 let uniqmember = member
4478 let newexplist = newexplist + [ member ]
4479 endif
4480 endfor
4481
Bram Moolenaar15146672011-10-20 22:22:38 +02004482" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004483 return newexplist
4484endfun
4485
4486" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02004487" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
4488fun! s:NetrwForceChgDir(islocal,newdir)
4489" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004490 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02004491 if a:newdir !~ '/$'
4492 " ok, looks like force is needed to get directory-style treatment
4493 if a:newdir =~ '@$'
4494 let newdir= substitute(a:newdir,'@$','/','')
4495 elseif a:newdir =~ '[*=|\\]$'
4496 let newdir= substitute(a:newdir,'.$','/','')
4497 else
4498 let newdir= a:newdir.'/'
4499 endif
4500" call Decho("adjusting newdir<".newdir."> due to gd")
4501 else
4502 " should already be getting treatment as a directory
4503 let newdir= a:newdir
4504 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004505 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02004506 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004507 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02004508" call Dret("s:NetrwForceChgDir")
4509endfun
4510
4511" ---------------------------------------------------------------------
4512" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
4513fun! s:NetrwForceFile(islocal,newfile)
4514" " call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newdir.">)")
4515 if a:newfile =~ '[/@*=|\\]$'
4516 let newfile= substitute(a:newfile,'.$','','')
4517 else
4518 let newfile= a:newfile
4519 endif
4520 call s:NetrwBrowseChgDir(a:islocal,newfile)
4521" call Dret("s:NetrwForceFile")
4522endfun
4523
4524" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004525" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
4526" and switches the hiding mode. The actual hiding is done by
4527" s:NetrwListHide().
4528" g:netrw_hide= 0: show all
4529" 1: show not-hidden files
4530" 2: show hidden files only
4531fun! s:NetrwHide(islocal)
4532" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004533 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004534 let svpos= netrw#NetrwSavePosn()
4535
4536 if exists("s:netrwmarkfilelist_{bufnr('%')}")
4537" call Decho(((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">")
4538" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">")
4539
4540 " hide the files in the markfile list
4541 for fname in s:netrwmarkfilelist_{bufnr("%")}
4542" call Decho("match(g:netrw_list_hide<".g:netrw_list_hide.'> fname<\<'.fname.'\>>)='.match(g:netrw_list_hide,'\<'.fname.'\>')." isk=".&isk)
4543 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
4544 " remove fname from hiding list
4545 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
4546 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
4547 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
4548" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">")
4549 else
4550 " append fname to hiding list
4551 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
4552 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
4553 else
4554 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
4555 endif
4556" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">")
4557 endif
4558 endfor
Bram Moolenaaradc21822011-04-01 18:03:16 +02004559 keepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004560 let g:netrw_hide= 1
4561
4562 else
4563
4564 " switch between show-all/show-not-hidden/show-hidden
4565 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004566 exe "keepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004567 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02004568 keepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004569 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004570" call Dret("NetrwHide")
4571 return
4572 endif
4573 endif
4574
Bram Moolenaaradc21822011-04-01 18:03:16 +02004575 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4576 keepj call netrw#NetrwRestorePosn(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004577 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004578" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004579endfun
4580
4581" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004582" s:NetrwHidden: invoked by "gh" {{{2
4583fun! s:NetrwHidden(islocal)
4584" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004585 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004586 " save current position
4587 let svpos= netrw#NetrwSavePosn()
4588
4589 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
4590 " remove pattern from hiding list
4591 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01004592 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004593 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
4594 else
4595 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
4596 endif
4597
4598 " refresh screen and return to saved position
Bram Moolenaaradc21822011-04-01 18:03:16 +02004599 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4600 keepj call netrw#NetrwRestorePosn(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004601 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004602" call Dret("s:NetrwHidden")
4603endfun
4604
4605" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004606" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
4607fun! s:NetrwHome()
4608 if exists("g:netrw_home")
4609 let home= g:netrw_home
4610 else
4611 " go to vim plugin home
4612 for home in split(&rtp,',') + ['']
4613 if isdirectory(home) && filewritable(home) | break | endif
4614 let basehome= substitute(home,'[/\\]\.vim$','','')
4615 if isdirectory(basehome) && filewritable(basehome)
4616 let home= basehome."/.vim"
4617 break
4618 endif
4619 endfor
4620 if home == ""
4621 " just pick the first directory
4622 let home= substitute(&rtp,',.*$','','')
4623 endif
4624 if (has("win32") || has("win95") || has("win64") || has("win16"))
4625 let home= substitute(home,'/','\\','g')
4626 endif
4627 endif
4628 " insure that the home directory exists
4629 if !isdirectory(home)
4630 if exists("g:netrw_mkdir")
4631 call system(g:netrw_mkdir." ".shellescape(home))
4632 else
4633 call mkdir(home)
4634 endif
4635 endif
4636 let g:netrw_home= home
4637 return home
4638endfun
4639
4640" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004641" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
4642fun! s:NetrwLeftmouse(islocal)
4643" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004644
Bram Moolenaar97d62492012-11-15 21:28:22 +01004645 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004646 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02004647 while getchar(0) != 0
4648 "clear the input stream
4649 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004650 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004651 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004652 let mouse_lnum = v:mouse_lnum
4653 let wlastline = line('w$')
4654 let lastline = line('$')
4655" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr())
4656" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0))
4657 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
4658 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01004659 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004660" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
4661 return
4662 endif
4663 if v:mouse_col != col('.')
Bram Moolenaar97d62492012-11-15 21:28:22 +01004664 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004665" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
4666 return
4667 endif
4668
Bram Moolenaar446cb832008-06-24 21:56:24 +00004669 if a:islocal
4670 if exists("b:netrw_curdir")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004671 keepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004672 endif
4673 else
4674 if exists("b:netrw_curdir")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004675 keepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004676 endif
4677 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004678 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004679" call Dret("s:NetrwLeftmouse")
4680endfun
4681
4682" ---------------------------------------------------------------------
4683" s:NetrwListHide: uses [range]g~...~d to delete files that match comma {{{2
4684" separated patterns given in g:netrw_list_hide
4685fun! s:NetrwListHide()
Bram Moolenaaradc21822011-04-01 18:03:16 +02004686" call Dfunc("NetrwListHide() g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004687 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004688
4689 " find a character not in the "hide" string to use as a separator for :g and :v commands
4690 " How-it-works: take the hiding command, convert it into a range. Duplicate
4691 " characters don't matter. Remove all such characters from the '/~...90'
4692 " string. Use the first character left as a separator character.
4693 let listhide= g:netrw_list_hide
4694 let sep = strpart(substitute('/~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
4695" call Decho("sep=".sep)
4696
4697 while listhide != ""
4698 if listhide =~ ','
4699 let hide = substitute(listhide,',.*$','','e')
4700 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
4701 else
4702 let hide = listhide
4703 let listhide = ""
4704 endif
4705
4706 " Prune the list by hiding any files which match
4707 if g:netrw_hide == 1
4708" call Decho("hiding<".hide."> listhide<".listhide.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004709 exe 'sil! keepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004710 elseif g:netrw_hide == 2
4711" call Decho("showing<".hide."> listhide<".listhide.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004712 exe 'sil! keepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004713 endif
4714 endwhile
4715 if g:netrw_hide == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004716 exe 'sil! keepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
4717 exe 'sil! keepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004718 endif
4719
Bram Moolenaaradc21822011-04-01 18:03:16 +02004720 " remove any blank lines that have somehow remained.
4721 " This seems to happen under Windows.
4722 exe 'sil! keepj 1,$g@^\s*$@d'
4723
Bram Moolenaar97d62492012-11-15 21:28:22 +01004724 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004725" call Dret("NetrwListHide")
4726endfun
4727
4728" ---------------------------------------------------------------------
4729" NetrwHideEdit: allows user to edit the file/directory hiding list
4730fun! s:NetrwHideEdit(islocal)
4731" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
4732
Bram Moolenaar97d62492012-11-15 21:28:22 +01004733 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004734 " save current cursor position
4735 let svpos= netrw#NetrwSavePosn()
4736
4737 " get new hiding list from user
4738 call inputsave()
4739 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
4740 call inputrestore()
4741 let g:netrw_list_hide= newhide
4742" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">")
4743
4744 " refresh the listing
Bram Moolenaaradc21822011-04-01 18:03:16 +02004745 sil keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004746
4747 " restore cursor position
4748 call netrw#NetrwRestorePosn(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004749 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004750
4751" call Dret("NetrwHideEdit")
4752endfun
4753
4754" ---------------------------------------------------------------------
4755" NetSortSequence: allows user to edit the sorting sequence
4756fun! s:NetSortSequence(islocal)
4757" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
4758
Bram Moolenaar97d62492012-11-15 21:28:22 +01004759 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004760 let svpos= netrw#NetrwSavePosn()
4761 call inputsave()
4762 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
4763 call inputrestore()
4764
4765 " refresh the listing
4766 let g:netrw_sort_sequence= newsortseq
Bram Moolenaaradc21822011-04-01 18:03:16 +02004767 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4768 keepj call netrw#NetrwRestorePosn(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004769 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004770
4771" call Dret("NetSortSequence")
4772endfun
4773
4774" ---------------------------------------------------------------------
4775" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
4776fun! s:NetrwMakeDir(usrhost)
4777" call Dfunc("NetrwMakeDir(usrhost<".a:usrhost.">)")
4778
Bram Moolenaar97d62492012-11-15 21:28:22 +01004779 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004780 " get name of new directory from user. A bare <CR> will skip.
4781 " if its currently a directory, also request will be skipped, but with
4782 " a message.
4783 call inputsave()
4784 let newdirname= input("Please give directory name: ")
4785 call inputrestore()
4786" call Decho("newdirname<".newdirname.">")
4787
4788 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01004789 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004790" call Dret("NetrwMakeDir : user aborted with bare <cr>")
4791 return
4792 endif
4793
4794 if a:usrhost == ""
4795" call Decho("local mkdir")
4796
4797 " Local mkdir:
4798 " sanity checks
4799 let fullnewdir= b:netrw_curdir.'/'.newdirname
4800" call Decho("fullnewdir<".fullnewdir.">")
4801 if isdirectory(fullnewdir)
4802 if !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004803 keepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004804 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004805 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004806" call Dret("NetrwMakeDir : directory<".newdirname."> exists previously")
4807 return
4808 endif
4809 if s:FileReadable(fullnewdir)
4810 if !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004811 keepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004812 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004813 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004814" call Dret("NetrwMakeDir : file<".newdirname."> exists previously")
4815 return
4816 endif
4817
4818 " requested new local directory is neither a pre-existing file or
4819 " directory, so make it!
4820 if exists("*mkdir")
4821 call mkdir(fullnewdir,"p")
4822 else
4823 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004824 exe 'keepj lcd '.fnameescape(b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004825" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004826" call Decho("exe sil! !".g:netrw_localmkdir.' '.shellescape(newdirname,1))
4827 exe "sil! !".g:netrw_localmkdir.' '.shellescape(newdirname,1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004828 if v:shell_error != 0
4829 let @@= ykeep
4830 call netrw#ErrorMsg(s:ERROR,"consider setting g:netrw_localmkdir<".g:netrw_localmkdir."> to something that works",80)
4831" call Dret("NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.shellescape(newdirname,1))
4832 return
4833 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004834 if !g:netrw_keepdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004835 exe 'keepj lcd '.fnameescape(netrw_origdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004836" call Decho("netrw_keepdir=".g:netrw_keepdir.": keepjumps lcd ".fnameescape(netrw_origdir)." getcwd<".getcwd().">")
4837 endif
4838 endif
4839
4840 if v:shell_error == 0
4841 " refresh listing
4842" call Decho("refresh listing")
4843 let svpos= netrw#NetrwSavePosn()
4844 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
4845 call netrw#NetrwRestorePosn(svpos)
4846 elseif !exists("g:netrw_quiet")
4847 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
4848 endif
4849" redraw!
4850
4851 elseif !exists("b:netrw_method") || b:netrw_method == 4
4852 " Remote mkdir:
4853" call Decho("remote mkdir")
4854 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
4855 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaaradc21822011-04-01 18:03:16 +02004856" call Decho("exe sil! !".mkdircmd." ".shellescape(newdirname,1))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004857 exe "sil! !".mkdircmd." ".shellescape(newdirname,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004858 if v:shell_error == 0
4859 " refresh listing
4860 let svpos= netrw#NetrwSavePosn()
Bram Moolenaaradc21822011-04-01 18:03:16 +02004861 keepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
4862 keepj call netrw#NetrwRestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004863 elseif !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004864 keepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004865 endif
4866" redraw!
4867
4868 elseif b:netrw_method == 2
Bram Moolenaar15146672011-10-20 22:22:38 +02004869 let svpos= netrw#NetrwSavePosn()
4870 call s:NetrwRemoteFtpCmd("",g:netrw_remote_mkdir.' "'.newdirname.'"')
4871 keepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
4872 keepj call netrw#NetrwRestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004873 elseif b:netrw_method == 3
Bram Moolenaar15146672011-10-20 22:22:38 +02004874 let svpos= netrw#NetrwSavePosn()
4875 call s:NetrwRemoteFtpCmd("",g:netrw_remote_mkdir.' "'.newdirname.'"')
4876 keepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
4877 keepj call netrw#NetrwRestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004878 endif
4879
Bram Moolenaar97d62492012-11-15 21:28:22 +01004880 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004881" call Dret("NetrwMakeDir")
4882endfun
4883
4884" ---------------------------------------------------------------------
4885" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
4886" mark and unmark files. If a markfile list exists,
4887" then the rename and delete functions will use it instead
4888" of whatever may happen to be under the cursor at that
4889" moment. When the mouse and gui are available,
4890" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00004891"
4892" Creates two lists
4893" s:netrwmarkfilelist -- holds complete paths to all marked files
4894" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
4895"
4896" Creates a marked file match string
4897" s:netrwmarfilemtch_# -- used with 2match to display marked files
4898"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00004899" Creates a buffer version of islocal
4900" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00004901fun! s:NetrwMarkFile(islocal,fname)
4902" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004903 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004904 let curbufnr= bufnr("%")
4905 let curdir = b:netrw_curdir
Bram Moolenaar97d62492012-11-15 21:28:22 +01004906 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
Bram Moolenaaradc21822011-04-01 18:03:16 +02004907
Bram Moolenaar446cb832008-06-24 21:56:24 +00004908 if exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004909 " markfile list pre-exists
Bram Moolenaar446cb832008-06-24 21:56:24 +00004910" call Decho("starting s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">")
4911" call Decho("starting s:netrwmarkfilemtch_{curbufnr}<".s:netrwmarkfilemtch_{curbufnr}.">")
Bram Moolenaared39e1d2008-08-09 17:55:22 +00004912 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00004913
4914 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00004915 " append filename to buffer's markfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00004916" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">")
4917 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004918 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|\<'.escape(a:fname,g:netrw_markfileesc."'".g:netrw_markfileesc."'").trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00004919
4920 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00004921 " remove filename from buffer's markfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00004922" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">")
4923 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
4924 if s:netrwmarkfilelist_{curbufnr} == []
4925 " local markfilelist is empty; remove it entirely
Bram Moolenaar5c736222010-01-06 20:54:52 +01004926" call Decho("markfile list now empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004927 call s:NetrwUnmarkList(curbufnr,curdir)
4928 else
4929 " rebuild match list to display markings correctly
4930" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr)
4931 let s:netrwmarkfilemtch_{curbufnr}= ""
4932 let first = 1
4933 for fname in s:netrwmarkfilelist_{curbufnr}
4934 if first
Bram Moolenaar5c736222010-01-06 20:54:52 +01004935 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\<'.escape(fname,g:netrw_markfileesc."'".g:netrw_markfileesc."'").trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00004936 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004937 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|\<'.escape(fname,g:netrw_markfileesc."'".g:netrw_markfileesc."'").trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00004938 endif
4939 let first= 0
4940 endfor
Bram Moolenaar15146672011-10-20 22:22:38 +02004941" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004942 endif
4943 endif
4944
4945 else
4946 " initialize new markfilelist
4947
4948" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr)
4949 let s:netrwmarkfilelist_{curbufnr}= []
4950 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
4951" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">")
4952
4953 " build initial markfile matching pattern
4954 if a:fname =~ '/$'
4955 let s:netrwmarkfilemtch_{curbufnr}= '\<'.escape(a:fname,g:netrw_markfileesc)
4956 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004957 let s:netrwmarkfilemtch_{curbufnr}= '\<'.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00004958 endif
4959" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">")
4960 endif
4961
4962 " handle global markfilelist
4963 if exists("s:netrwmarkfilelist")
4964 let dname= s:ComposePath(b:netrw_curdir,a:fname)
4965 if index(s:netrwmarkfilelist,dname) == -1
4966 " append new filename to global markfilelist
4967 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
4968" call Decho("append filename<".a:fname."> to global markfilelist<".string(s:netrwmarkfilelist).">")
4969 else
4970 " remove new filename from global markfilelist
4971" call Decho("filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")")
4972 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
4973" call Decho("ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">")
4974 if s:netrwmarkfilelist == []
4975 unlet s:netrwmarkfilelist
4976 endif
4977 endif
4978 else
4979 " initialize new global-directory markfilelist
4980 let s:netrwmarkfilelist= []
4981 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
4982" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">")
4983 endif
4984
4985 " set up 2match'ing to netrwmarkfilemtch list
4986 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
4987" call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004988 if exists("g:did_drchip_netrwlist_syntax")
4989 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
4990 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004991 else
4992" call Decho("2match none")
4993 2match none
4994 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004995 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02004996" call Dret("s:NetrwMarkFile : s:netrwmarkfilelist_".curbufnr."<".(exists("s:netrwmarkfilelist_{curbufnr}")? string(s:netrwmarkfilelist_{curbufnr}) : " doesn't exist").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004997endfun
4998
4999" ---------------------------------------------------------------------
5000" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
5001" compress/decompress files using the programs
5002" in g:netrw_compress and g:netrw_uncompress,
5003" using g:netrw_compress_suffix to know which to
5004" do. By default:
5005" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005006" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00005007fun! s:NetrwMarkFileCompress(islocal)
5008" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
5009 let svpos = netrw#NetrwSavePosn()
5010 let curdir = b:netrw_curdir
5011 let curbufnr = bufnr("%")
5012
5013 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
5014 for fname in s:netrwmarkfilelist_{curbufnr}
5015 " for every filename in the marked list
5016 for sfx in sort(keys(g:netrw_decompress))
5017 if fname =~ '\'.sfx.'$'
5018 " fname has a suffix indicating that its compressed; apply associated decompression routine
Bram Moolenaar5c736222010-01-06 20:54:52 +01005019 let exe= netrw#WinPath(g:netrw_decompress[sfx])
Bram Moolenaar446cb832008-06-24 21:56:24 +00005020" call Decho("fname<".fname."> is compressed so decompress with <".exe.">")
5021 if a:islocal
5022 if g:netrw_keepdir
Bram Moolenaarc236c162008-07-13 17:41:49 +00005023 let fname= shellescape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005024 endif
5025 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00005026 let fname= shellescape(b:netrw_curdir.fname,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005027 endif
5028 if executable(exe)
5029 if a:islocal
5030 call system(exe." ".fname)
5031 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02005032 keepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005033 endif
5034 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02005035 keepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005036 endif
5037 break
5038 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005039 unlet sfx
Bram Moolenaar446cb832008-06-24 21:56:24 +00005040 endfor
5041 if exists("exe")
5042 unlet exe
5043 elseif a:islocal
5044 " fname not a compressed file, so compress it
Bram Moolenaar5c736222010-01-06 20:54:52 +01005045 call system(netrw#WinPath(g:netrw_compress)." ".shellescape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005046 else
5047 " fname not a compressed file, so compress it
Bram Moolenaaradc21822011-04-01 18:03:16 +02005048 keepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".shellescape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005049 endif
5050 endfor
5051 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005052 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
5053 keepj call netrw#NetrwRestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005054 endif
5055" call Dret("s:NetrwMarkFileCompress")
5056endfun
5057
5058" ---------------------------------------------------------------------
5059" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
5060" If no marked files, then set up directory as the
5061" target. Currently does not support copying entire
5062" directories. Uses the local-buffer marked file list.
5063" Returns 1=success (used by NetrwMarkFileMove())
5064" 0=failure
5065fun! s:NetrwMarkFileCopy(islocal)
5066" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---').">")
5067
5068 " sanity checks
5069 if !exists("s:netrwmarkfilelist_{bufnr('%')}") || empty(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar251e1912011-06-19 05:09:16 +02005070 keepj call netrw#ErrorMsg(s:ERROR,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005071" call Dret("s:NetrwMarkFileCopy 0")
5072 return 0
5073 endif
5074" call Decho("sanity chk passed: s:netrwmarkfilelist_".bufnr('%')."<".string(s:netrwmarkfilelist_{bufnr('%')}))
5075 if !exists("s:netrwmftgt")
Bram Moolenaar251e1912011-06-19 05:09:16 +02005076 keepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005077" call Dret("s:NetrwMarkFileCopy 0")
5078 return 0
5079 endif
5080" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">")
5081 let curdir = b:netrw_curdir
5082 let curbufnr = bufnr("%")
5083
5084 if a:islocal && s:netrwmftgt_islocal
5085 " Copy marked files, local directory to local directory
5086" call Decho("copy from local to local")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005087 if !executable(g:netrw_localcopycmd) && g:netrw_localcopycmd !~ '^cmd '
5088 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
5089" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
5090 return
5091 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00005092 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"shellescape(b:netrw_curdir.\"/\".v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005093" call Decho("system(".g:netrw_localcopycmd." ".args." ".shellescape(s:netrwmftgt).")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005094 call system(netrw#WinPath(g:netrw_localcopycmd)." ".args." ".shellescape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005095 if v:shell_error != 0
5096 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localcopycmd<".g:netrw_localcopycmd."> to something that works",80)
5097" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".shellescape(s:netrwmftgt))
5098 return 0
5099 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005100
5101 elseif a:islocal && !s:netrwmftgt_islocal
5102 " Copy marked files, local directory to remote directory
5103" call Decho("copy from local to remote")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005104 keepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005105
5106 elseif !a:islocal && s:netrwmftgt_islocal
5107" call Decho("copy from remote to local")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005108 keepj call netrw#NetrwObtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005109
5110 elseif !a:islocal && !s:netrwmftgt_islocal
5111" call Decho("copy from remote to remote")
5112 let curdir = getcwd()
5113 let tmpdir = s:GetTempfile("")
5114 if tmpdir !~ '/'
5115 let tmpdir= curdir."/".tmpdir
5116 endif
5117 if exists("*mkdir")
5118 call mkdir(tmpdir)
5119 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005120 exe "sil! !".g:netrw_localmkdir.' '.shellescape(tmpdir,1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005121 if v:shell_error != 0
5122 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localmkdir<".g:netrw_localmkdir."> to something that works",80)
5123" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.shellescape(tmpdir,1) )
5124 return
5125 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005126 endif
5127 if isdirectory(tmpdir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005128 exe "keepj lcd ".fnameescape(tmpdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005129 keepj call netrw#NetrwObtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00005130 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaaradc21822011-04-01 18:03:16 +02005131 keepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005132 if getcwd() == tmpdir
5133 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaaradc21822011-04-01 18:03:16 +02005134 keepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005135 endfor
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005136 exe "keepj lcd ".fnameescape(curdir)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005137 exe "sil !".g:netrw_localrmdir." ".shellescape(tmpdir,1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005138 if v:shell_error != 0
5139 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localrmdir<".g:netrw_localrmdir."> to something that works",80)
5140" call Dret("s:NetrwMarkFileCopy : failed: sil !".g:netrw_localrmdir." ".shellescape(tmpdir,1) )
5141 return
5142 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005143 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005144 exe "keepj lcd ".fnameescape(curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005145 endif
5146 endif
5147 endif
5148
5149 " -------
5150 " cleanup
5151 " -------
5152" call Decho("cleanup")
5153
5154 " remove markings from local buffer
5155 call s:NetrwUnmarkList(curbufnr,curdir)
5156
5157 " refresh buffers
5158 if !s:netrwmftgt_islocal
5159 call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
5160 endif
5161 if a:islocal
Bram Moolenaaradc21822011-04-01 18:03:16 +02005162 keepj call s:NetrwRefreshDir(a:islocal,curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005163 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005164 if g:netrw_fastbrowse <= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02005165 keepj call s:LocalBrowseShellCmdRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005166 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005167
5168" call Dret("s:NetrwMarkFileCopy 1")
5169 return 1
5170endfun
5171
5172" ---------------------------------------------------------------------
5173" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
5174" invoke vim's diff mode on the marked files.
5175" Either two or three files can be so handled.
5176" Uses the global marked file list.
5177fun! s:NetrwMarkFileDiff(islocal)
5178" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
5179 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005180
Bram Moolenaare37d50a2008-08-06 17:06:04 +00005181 if exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005182 let cnt = 0
5183 let curdir = b:netrw_curdir
5184 for fname in s:netrwmarkfilelist
5185 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005186 if cnt == 1
Bram Moolenaare37d50a2008-08-06 17:06:04 +00005187" call Decho("diffthis: fname<".fname.">")
5188 exe "e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005189 diffthis
5190 elseif cnt == 2 || cnt == 3
5191 vsplit
5192 wincmd l
5193" call Decho("diffthis: ".fname)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00005194 exe "e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005195 diffthis
5196 else
5197 break
5198 endif
5199 endfor
5200 call s:NetrwUnmarkList(curbufnr,curdir)
5201 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00005202
Bram Moolenaar446cb832008-06-24 21:56:24 +00005203" call Dret("s:NetrwMarkFileDiff")
5204endfun
5205
5206" ---------------------------------------------------------------------
5207" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
5208" Uses global markfilelist
5209fun! s:NetrwMarkFileEdit(islocal)
5210" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
5211
5212 let curdir = b:netrw_curdir
5213 let curbufnr = bufnr("%")
5214 if exists("s:netrwmarkfilelist_{curbufnr}")
5215 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00005216 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005217 " unmark markedfile list
5218" call s:NetrwUnmarkList(curbufnr,curdir)
5219 call s:NetrwUnmarkAll()
Bram Moolenaaradc21822011-04-01 18:03:16 +02005220" call Decho("exe sil args ".flist)
5221 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00005222 endif
5223
5224" call Dret("s:NetrwMarkFileEdit")
5225endfun
5226
5227" ---------------------------------------------------------------------
Bram Moolenaar15146672011-10-20 22:22:38 +02005228" s:NetrwMarkFileExe: (invoked by mx) execute arbitrary system command on marked files, one at a time {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00005229" Uses the local marked-file list.
5230fun! s:NetrwMarkFileExe(islocal)
5231" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.")")
5232 let svpos = netrw#NetrwSavePosn()
5233 let curdir = b:netrw_curdir
5234 let curbufnr = bufnr("%")
5235
5236 if exists("s:netrwmarkfilelist_{curbufnr}")
5237 " get the command
5238 call inputsave()
5239 let cmd= input("Enter command: ","","file")
5240 call inputrestore()
5241" call Decho("cmd<".cmd.">")
Bram Moolenaar15146672011-10-20 22:22:38 +02005242 if cmd == ""
5243" " call Dret("s:NetrwMarkFileExe : early exit, empty command")
5244 return
5245 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005246
5247 " apply command to marked files. Substitute: filename -> %
5248 " If no %, then append a space and the filename to the command
5249 for fname in s:netrwmarkfilelist_{curbufnr}
5250 if a:islocal
5251 if g:netrw_keepdir
Bram Moolenaar5c736222010-01-06 20:54:52 +01005252 let fname= shellescape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005253 endif
5254 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005255 let fname= shellescape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005256 endif
5257 if cmd =~ '%'
5258 let xcmd= substitute(cmd,'%',fname,'g')
5259 else
5260 let xcmd= cmd.' '.fname
5261 endif
5262 if a:islocal
5263" call Decho("local: xcmd<".xcmd.">")
5264 let ret= system(xcmd)
5265 else
5266" call Decho("remote: xcmd<".xcmd.">")
5267 let ret= s:RemoteSystem(xcmd)
5268 endif
5269 if v:shell_error < 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02005270 keepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005271 break
5272 else
5273 echo ret
5274 endif
5275 endfor
5276
5277 " unmark marked file list
5278 call s:NetrwUnmarkList(curbufnr,curdir)
5279
5280 " refresh the listing
Bram Moolenaaradc21822011-04-01 18:03:16 +02005281 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
5282 keepj call netrw#NetrwRestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005283 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02005284 keepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005285 endif
5286
5287" call Dret("s:NetrwMarkFileExe")
5288endfun
5289
5290" ---------------------------------------------------------------------
5291" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
5292" as the marked file(s) (toggles suffix presence)
5293" Uses the local marked file list.
5294fun! s:NetrwMarkHideSfx(islocal)
5295" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
5296 let svpos = netrw#NetrwSavePosn()
5297 let curbufnr = bufnr("%")
5298
5299 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
5300 if exists("s:netrwmarkfilelist_{curbufnr}")
5301
5302 for fname in s:netrwmarkfilelist_{curbufnr}
5303" call Decho("s:NetrwMarkFileCopy: fname<".fname.">")
5304 " construct suffix pattern
5305 if fname =~ '\.'
5306 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
5307 else
5308 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
5309 endif
5310 " determine if its in the hiding list or not
5311 let inhidelist= 0
5312 if g:netrw_list_hide != ""
5313 let itemnum = 0
5314 let hidelist= split(g:netrw_list_hide,',')
5315 for hidepat in hidelist
5316 if sfxpat == hidepat
5317 let inhidelist= 1
5318 break
5319 endif
5320 let itemnum= itemnum + 1
5321 endfor
5322 endif
5323" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">")
5324 if inhidelist
5325 " remove sfxpat from list
5326 call remove(hidelist,itemnum)
5327 let g:netrw_list_hide= join(hidelist,",")
5328 elseif g:netrw_list_hide != ""
5329 " append sfxpat to non-empty list
5330 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
5331 else
5332 " set hiding list to sfxpat
5333 let g:netrw_list_hide= sfxpat
5334 endif
5335 endfor
5336
5337 " refresh the listing
Bram Moolenaaradc21822011-04-01 18:03:16 +02005338 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
5339 keepj call netrw#NetrwRestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005340 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02005341 keepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005342 endif
5343
5344" call Dret("s:NetrwMarkHideSfx")
5345endfun
5346
5347" ---------------------------------------------------------------------
Bram Moolenaar15146672011-10-20 22:22:38 +02005348" s:NetrwMarkFileVimCmd: (invoked by mX) execute arbitrary vim command on marked files, one at a time {{{2
5349" Uses the local marked-file list.
5350fun! s:NetrwMarkFileVimCmd(islocal)
5351" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
5352 let svpos = netrw#NetrwSavePosn()
5353 let curdir = b:netrw_curdir
5354 let curbufnr = bufnr("%")
5355
5356 if exists("s:netrwmarkfilelist_{curbufnr}")
5357 " get the command
5358 call inputsave()
5359 let cmd= input("Enter vim command: ","","file")
5360 call inputrestore()
5361" call Decho("cmd<".cmd.">")
5362 if cmd == ""
5363" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
5364 return
5365 endif
5366
5367 " apply command to marked files. Substitute: filename -> %
5368 " If no %, then append a space and the filename to the command
5369 for fname in s:netrwmarkfilelist_{curbufnr}
5370" call Decho("fname<".fname.">")
5371 if a:islocal
5372 1split
5373 exe "sil! keepalt e ".fnameescape(fname)
5374" call Decho("local<".fname.">: exe ".cmd)
5375 exe cmd
5376 exe "sil! keepalt wq!"
5377 else
5378 " COMBAK -- not supported yet
5379" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET")
5380 echo "sorry, \"mX\" not supported yet for remote files"
5381 endif
5382 endfor
5383
5384 " unmark marked file list
5385 call s:NetrwUnmarkList(curbufnr,curdir)
5386
5387 " refresh the listing
5388 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
5389 keepj call netrw#NetrwRestorePosn(svpos)
5390 else
5391 keepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
5392 endif
5393
5394" call Dret("s:NetrwMarkFileVimCmd")
5395endfun
5396
5397" ---------------------------------------------------------------------
5398" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
5399" as the marked file(s) (toggles suffix presence)
5400" Uses the local marked file list.
5401fun! s:NetrwMarkHideSfx(islocal)
5402" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
5403 let svpos = netrw#NetrwSavePosn()
5404 let curbufnr = bufnr("%")
5405
5406 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
5407 if exists("s:netrwmarkfilelist_{curbufnr}")
5408
5409 for fname in s:netrwmarkfilelist_{curbufnr}
5410" call Decho("s:NetrwMarkFileCopy: fname<".fname.">")
5411 " construct suffix pattern
5412 if fname =~ '\.'
5413 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
5414 else
5415 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
5416 endif
5417 " determine if its in the hiding list or not
5418 let inhidelist= 0
5419 if g:netrw_list_hide != ""
5420 let itemnum = 0
5421 let hidelist= split(g:netrw_list_hide,',')
5422 for hidepat in hidelist
5423 if sfxpat == hidepat
5424 let inhidelist= 1
5425 break
5426 endif
5427 let itemnum= itemnum + 1
5428 endfor
5429 endif
5430" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">")
5431 if inhidelist
5432 " remove sfxpat from list
5433 call remove(hidelist,itemnum)
5434 let g:netrw_list_hide= join(hidelist,",")
5435 elseif g:netrw_list_hide != ""
5436 " append sfxpat to non-empty list
5437 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
5438 else
5439 " set hiding list to sfxpat
5440 let g:netrw_list_hide= sfxpat
5441 endif
5442 endfor
5443
5444 " refresh the listing
5445 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
5446 keepj call netrw#NetrwRestorePosn(svpos)
5447 else
5448 keepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
5449 endif
5450
5451" call Dret("s:NetrwMarkHideSfx")
5452endfun
5453
5454" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005455" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
5456" Uses the global markfilelist
5457fun! s:NetrwMarkFileGrep(islocal)
5458" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
5459 let svpos = netrw#NetrwSavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005460 let curbufnr = bufnr("%")
5461
5462 if exists("s:netrwmarkfilelist")
5463" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">")
Bram Moolenaare37d50a2008-08-06 17:06:04 +00005464 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005465 call s:NetrwUnmarkAll()
5466
5467 " ask user for pattern
5468 call inputsave()
5469 let pat= input("Enter pattern: ","")
5470 call inputrestore()
5471 if pat !~ '^\s'
5472 if pat !~ '^/'
5473 let pat= '/'.pat.'/'
5474 endif
5475 let pat= " ".pat
5476 endif
5477
5478 " use vimgrep for both local and remote
5479" call Decho("exe vimgrep".pat." ".netrwmarkfilelist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005480 try
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005481 exe "keepj noautocmd vimgrep".pat." ".netrwmarkfilelist
Bram Moolenaar5c736222010-01-06 20:54:52 +01005482 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar97d62492012-11-15 21:28:22 +01005483 keepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
5484" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pattern.">")
5485 return
Bram Moolenaar5c736222010-01-06 20:54:52 +01005486 endtry
Bram Moolenaar446cb832008-06-24 21:56:24 +00005487
5488 2match none
Bram Moolenaaradc21822011-04-01 18:03:16 +02005489 keepj call netrw#NetrwRestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005490 endif
5491
5492" call Dret("s:NetrwMarkFileGrep")
5493endfun
5494
5495" ---------------------------------------------------------------------
5496" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
5497" uses the global marked file list
5498" s:netrwmfloc= 0: target directory is remote
5499" = 1: target directory is local
5500fun! s:NetrwMarkFileMove(islocal)
5501" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
5502 let curdir = b:netrw_curdir
5503 let curbufnr = bufnr("%")
5504
5505 " sanity check
5506 if !exists("s:netrwmarkfilelist_{bufnr('%')}") || empty(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaaradc21822011-04-01 18:03:16 +02005507 keepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005508" call Dret("s:NetrwMarkFileMove")
5509 return
5510 endif
5511" call Decho("sanity chk passed: s:netrwmarkfilelist_".bufnr('%')."<".string(s:netrwmarkfilelist_{bufnr('%')}))
5512 if !exists("s:netrwmftgt")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005513 keepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005514" call Dret("s:NetrwMarkFileCopy 0")
5515 return 0
5516 endif
5517" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">")
5518
5519 if a:islocal && s:netrwmftgt_islocal
5520 " move: local -> local
5521" call Decho("move from local to local")
5522" call Decho("(s:NetrwMarkFileMove) local to local move")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005523 if !executable(g:netrw_localmovecmd) && g:netrw_localmovecmd !~ '^cmd '
5524 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
5525" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
5526 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00005527 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005528 for fname in s:netrwmarkfilelist_{bufnr("%")}
5529" call Decho("system(".g:netrw_localmovecmd." ".shellescape(fname)." ".shellescape(s:netrwmftgt).")")
5530 let ret= system(g:netrw_localmovecmd." ".shellescape(fname)." ".shellescape(s:netrwmftgt))
5531 if v:shell_error < 0
5532 call netrw#ErrorMsg(s:ERROR,"command<".g:netrw_localmovecmd."> failed, aborting",54)
5533 break
5534 endif
5535 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00005536
5537 elseif a:islocal && !s:netrwmftgt_islocal
5538 " move: local -> remote
5539" call Decho("move from local to remote")
5540" call Decho("copy")
5541 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaaradc21822011-04-01 18:03:16 +02005542 keepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005543" call Decho("remove")
5544 for fname in mflist
5545 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
5546 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
5547 endfor
5548 unlet mflist
5549
5550 elseif !a:islocal && s:netrwmftgt_islocal
5551 " move: remote -> local
5552" call Decho("move from remote to local")
5553" call Decho("copy")
5554 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaaradc21822011-04-01 18:03:16 +02005555 keepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005556" call Decho("remove")
5557 for fname in mflist
5558 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
5559 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
5560 endfor
5561 unlet mflist
5562
5563 elseif !a:islocal && !s:netrwmftgt_islocal
5564 " move: remote -> remote
5565" call Decho("move from remote to remote")
5566" call Decho("copy")
5567 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaaradc21822011-04-01 18:03:16 +02005568 keepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005569" call Decho("remove")
5570 for fname in mflist
5571 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
5572 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
5573 endfor
5574 unlet mflist
5575 endif
5576
5577 " -------
5578 " cleanup
5579 " -------
5580" call Decho("cleanup")
5581
5582 " remove markings from local buffer
5583 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
5584
5585 " refresh buffers
5586 if !s:netrwmftgt_islocal
Bram Moolenaaradc21822011-04-01 18:03:16 +02005587" call Decho("refresh netrwmftgt<".s:netrwmftgt.">")
5588 keepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005589 endif
5590 if a:islocal
Bram Moolenaaradc21822011-04-01 18:03:16 +02005591" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">")
5592 keepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005593 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005594 if g:netrw_fastbrowse <= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02005595" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh")
5596 keepj call s:LocalBrowseShellCmdRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005597 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005598
5599" call Dret("s:NetrwMarkFileMove")
5600endfun
5601
5602" ---------------------------------------------------------------------
5603" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
5604" using the hardcopy command. Local marked-file list only.
5605fun! s:NetrwMarkFilePrint(islocal)
5606" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
5607 let curbufnr= bufnr("%")
5608 if exists("s:netrwmarkfilelist_{curbufnr}")
5609 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
5610 let curdir = b:netrw_curdir
5611 call s:NetrwUnmarkList(curbufnr,curdir)
5612 for fname in netrwmarkfilelist
5613 if a:islocal
5614 if g:netrw_keepdir
5615 let fname= s:ComposePath(curdir,fname)
5616 endif
5617 else
5618 let fname= curdir.fname
5619 endif
5620 1split
5621 " the autocmds will handle both local and remote files
Bram Moolenaaradc21822011-04-01 18:03:16 +02005622" call Decho("exe sil e ".escape(fname,' '))
5623 exe "sil e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005624" call Decho("hardcopy")
5625 hardcopy
5626 q
5627 endfor
5628 2match none
5629 endif
5630" call Dret("s:NetrwMarkFilePrint")
5631endfun
5632
5633" ---------------------------------------------------------------------
5634" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
5635" files when given a regexp (for which a prompt is
5636" issued).
5637fun! s:NetrwMarkFileRegexp(islocal)
5638" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
5639
5640 " get the regular expression
5641 call inputsave()
5642 let regexp= input("Enter regexp: ","","file")
5643 call inputrestore()
5644
5645 if a:islocal
5646 " get the matching list of files using local glob()
5647" call Decho("handle local regexp")
5648 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005649 let files = glob(s:ComposePath(dirname,regexp))
5650" call Decho("files<".files.">")
5651 let filelist= split(files,"\n")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005652
5653 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01005654 for fname in filelist
5655" call Decho("fname<".fname.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005656 keepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005657 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00005658
5659 else
5660" call Decho("handle remote regexp")
5661
5662 " convert displayed listing into a filelist
5663 let eikeep = &ei
5664 let areg = @a
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005665 sil keepj %y a
Bram Moolenaar446cb832008-06-24 21:56:24 +00005666 set ei=all ma
5667" call Decho("set ei=all ma")
5668 1split
Bram Moolenaaradc21822011-04-01 18:03:16 +02005669 keepj call s:NetrwEnew()
5670 keepj call s:NetrwSafeOptions()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005671 sil keepj norm! "ap
5672 keepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00005673 let bannercnt= search('^" =====','W')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005674 exe "sil keepj 1,".bannercnt."d"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005675 set bt=nofile
5676 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005677 sil keepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01005678 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005679 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005680 sil keepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01005681 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005682 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005683 sil keepj %s/^| //e
5684 sil! keepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01005685 call histdel("/",-1)
5686 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005687 endif
5688 " convert regexp into the more usual glob-style format
5689 let regexp= substitute(regexp,'\*','.*','g')
5690" call Decho("regexp<".regexp.">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005691 exe "sil! keepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01005692 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005693 let filelist= getline(1,line("$"))
5694 q!
5695 for filename in filelist
Bram Moolenaaradc21822011-04-01 18:03:16 +02005696 keepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005697 endfor
5698 unlet filelist
5699 let @a = areg
5700 let &ei = eikeep
5701 endif
5702
5703" call Dret("s:NetrwMarkFileRegexp")
5704endfun
5705
5706" ---------------------------------------------------------------------
5707" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
5708" Uses the local marked file list.
5709fun! s:NetrwMarkFileSource(islocal)
5710" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
5711 let curbufnr= bufnr("%")
5712 if exists("s:netrwmarkfilelist_{curbufnr}")
5713 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
5714 let curdir = b:netrw_curdir
5715 call s:NetrwUnmarkList(curbufnr,curdir)
5716 for fname in netrwmarkfilelist
5717 if a:islocal
5718 if g:netrw_keepdir
5719 let fname= s:ComposePath(curdir,fname)
5720 endif
5721 else
5722 let fname= curdir.fname
5723 endif
5724 " the autocmds will handle sourcing both local and remote files
Bram Moolenaarc236c162008-07-13 17:41:49 +00005725" call Decho("exe so ".fnameescape(fname))
5726 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005727 endfor
5728 2match none
5729 endif
5730" call Dret("s:NetrwMarkFileSource")
5731endfun
5732
5733" ---------------------------------------------------------------------
5734" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
5735" Uses the global markfilelist
5736fun! s:NetrwMarkFileTag(islocal)
5737" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
5738 let svpos = netrw#NetrwSavePosn()
5739 let curdir = b:netrw_curdir
5740 let curbufnr = bufnr("%")
5741
5742 if exists("s:netrwmarkfilelist")
5743" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">")
Bram Moolenaare37d50a2008-08-06 17:06:04 +00005744 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "shellescape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005745 call s:NetrwUnmarkAll()
5746
5747 if a:islocal
5748 if executable(g:netrw_ctags)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005749" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")")
5750 call system(g:netrw_ctags." ".netrwmarkfilelist)
5751 else
5752 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
5753 endif
5754 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00005755 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005756 call netrw#NetrwObtain(a:islocal,"tags")
5757 let curdir= b:netrw_curdir
5758 1split
5759 e tags
5760 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
5761" call Decho("curdir<".curdir."> path<".path.">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005762 exe 'keepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01005763 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005764 wq!
5765 endif
5766 2match none
5767 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
5768 call netrw#NetrwRestorePosn(svpos)
5769 endif
5770
5771" call Dret("s:NetrwMarkFileTag")
5772endfun
5773
5774" ---------------------------------------------------------------------
5775" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
5776" Sets up two variables,
5777" s:netrwmftgt : holds the target directory
5778" s:netrwmftgt_islocal : 0=target directory is remote
5779" 1=target directory is local
5780fun! s:NetrwMarkFileTgt(islocal)
5781" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
5782 let svpos = netrw#NetrwSavePosn()
5783 let curdir = b:netrw_curdir
5784 let hadtgt = exists("s:netrwmftgt")
5785 if !exists("w:netrw_bannercnt")
5786 let w:netrw_bannercnt= b:netrw_bannercnt
5787 endif
5788
5789 " set up target
5790 if line(".") < w:netrw_bannercnt
5791 " if cursor in banner region, use b:netrw_curdir for the target
5792 let s:netrwmftgt= b:netrw_curdir
5793" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">")
5794
5795 else
5796 " get word under cursor.
5797 " * If directory, use it for the target.
5798 " * If file, use b:netrw_curdir for the target
5799 let curword= s:NetrwGetWord()
5800 let tgtdir = s:ComposePath(curdir,curword)
5801 if a:islocal && isdirectory(tgtdir)
5802 let s:netrwmftgt = tgtdir
5803" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">")
5804 elseif !a:islocal && tgtdir =~ '/$'
5805 let s:netrwmftgt = tgtdir
5806" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">")
5807 else
5808 let s:netrwmftgt = curdir
5809" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">")
5810 endif
5811 endif
5812 if a:islocal
5813 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
5814 let s:netrwmftgt= simplify(s:netrwmftgt)
5815" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">")
5816 endif
5817 if g:netrw_cygwin
5818 let s:netrwmftgt= substitute(system("cygpath ".shellescape(s:netrwmftgt)),'\n$','','')
5819 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
5820 endif
5821 let s:netrwmftgt_islocal= a:islocal
5822
Bram Moolenaar5c736222010-01-06 20:54:52 +01005823 if g:netrw_fastbrowse <= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005824 call s:LocalBrowseShellCmdRefresh()
5825 endif
5826 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
5827 call netrw#NetrwRestorePosn(svpos)
5828 if !hadtgt
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005829 sil! keepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00005830 endif
5831
5832" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
5833endfun
5834
5835" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00005836" s:NetrwOpenFile: query user for a filename and open it {{{2
5837fun! s:NetrwOpenFile(islocal)
5838" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005839 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00005840 call inputsave()
5841 let fname= input("Enter filename: ")
5842 call inputrestore()
5843 if fname !~ '[/\\]'
5844 if exists("b:netrw_curdir")
5845 if exists("g:netrw_quiet")
5846 let netrw_quiet_keep = g:netrw_quiet
5847 endif
5848 let g:netrw_quiet = 1
5849 if b:netrw_curdir =~ '/$'
5850 exe "e ".fnameescape(b:netrw_curdir.fname)
5851 else
5852 exe "e ".fnameescape(b:netrw_curdir."/".fname)
5853 endif
5854 if exists("netrw_quiet_keep")
5855 let g:netrw_quiet= netrw_quiet_keep
5856 else
5857 unlet g:netrw_quiet
5858 endif
5859 endif
5860 else
5861 exe "e ".fnameescape(fname)
5862 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005863 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00005864" call Dret("s:NetrwOpenFile")
5865endfun
5866
5867" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005868" s:NetrwUnmarkList: delete local marked file lists and remove their contents from the global marked-file list {{{2
5869fun! s:NetrwUnmarkList(curbufnr,curdir)
5870" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
5871
5872 " remove all files in local marked-file list from global list
5873 if exists("s:netrwmarkfilelist_{a:curbufnr}")
5874 for mfile in s:netrwmarkfilelist_{a:curbufnr}
5875 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
5876 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
5877 call remove(s:netrwmarkfilelist,idx) " remove from global list
5878 endfor
5879 if s:netrwmarkfilelist == []
5880 unlet s:netrwmarkfilelist
5881 endif
5882
5883 " getting rid of the local marked-file lists is easy
5884 unlet s:netrwmarkfilelist_{a:curbufnr}
5885 endif
5886 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
5887 unlet s:netrwmarkfilemtch_{a:curbufnr}
5888 endif
5889 2match none
5890" call Dret("s:NetrwUnmarkList")
5891endfun
5892
5893" ---------------------------------------------------------------------
5894" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
5895fun! s:NetrwUnmarkAll()
5896" call Dfunc("s:NetrwUnmarkAll()")
5897 if exists("s:netrwmarkfilelist")
5898 unlet s:netrwmarkfilelist
5899 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005900 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005901 2match none
5902" call Dret("s:NetrwUnmarkAll")
5903endfun
5904
5905" ---------------------------------------------------------------------
5906" s:NetrwUnmarkAll2: {{{2
5907fun! s:NetrwUnmarkAll2()
5908" call Dfunc("s:NetrwUnmarkAll2()")
5909 redir => netrwmarkfilelist_let
5910 let
5911 redir END
5912 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
5913 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
5914 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
5915 for flist in netrwmarkfilelist_list
5916 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
5917 unlet s:netrwmarkfilelist_{curbufnr}
5918 unlet s:netrwmarkfilemtch_{curbufnr}
5919 endfor
5920" call Dret("s:NetrwUnmarkAll2")
5921endfun
5922
5923" ---------------------------------------------------------------------
5924" s:NetrwUnMarkFile: {{{2
5925fun! s:NetrwUnMarkFile(islocal)
5926" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
5927 let svpos = netrw#NetrwSavePosn()
5928 let curbufnr = bufnr("%")
5929
5930 " unmark marked file list (although I expect s:NetrwUpload()
5931 " to do it, I'm just making sure)
5932 if exists("s:netrwmarkfilelist_{bufnr('%')}")
5933" call Decho("unlet'ing: s:netrwmarkfile[list|mtch]_".bufnr("%"))
5934 unlet s:netrwmarkfilelist
5935 unlet s:netrwmarkfilelist_{curbufnr}
5936 unlet s:netrwmarkfilemtch_{curbufnr}
5937 2match none
5938 endif
5939
5940" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
5941 call netrw#NetrwRestorePosn(svpos)
5942" call Dret("s:NetrwUnMarkFile")
5943endfun
5944
5945" ---------------------------------------------------------------------
5946" s:NetrwMenu: generates the menu for gvim and netrw {{{2
5947fun! s:NetrwMenu(domenu)
5948
5949 if !exists("g:NetrwMenuPriority")
5950 let g:NetrwMenuPriority= 80
5951 endif
5952
Bram Moolenaaradc21822011-04-01 18:03:16 +02005953 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00005954" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
5955
5956 if !exists("s:netrw_menu_enabled") && a:domenu
5957" call Decho("initialize menu")
5958 let s:netrw_menu_enabled= 1
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005959 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
5960 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
5961 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
5962 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
5963 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
5964 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
5965 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
5966 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
5967 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
5968 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
5969 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
5970 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
5971 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
5972 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005973 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005974 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
5975 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
5976 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
5977 exe 'sil! menu '.g:NetrwMenuPriority.'.11.4 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Window<tab>o o'
5978 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
5979 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
5980 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
5981 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
5982 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
5983 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
5984 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
5985 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
5986 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
5987 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
5988 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
5989 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
5990 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
5991 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
5992 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
5993 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
5994 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
5995 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
5996 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
5997 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
5998 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
5999 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
6000 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
6001 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
6002 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
6003 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1 '.g:NetrwTopLvlMenu.'Style.Listing\ Style\ (thin-long-wide-tree)<tab>i i'
6004 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show<tab>a a'
6005 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
6006 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method\ (name-time-size)<tab>s s'
6007 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
6008 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar5c736222010-01-06 20:54:52 +01006009 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
Bram Moolenaar446cb832008-06-24 21:56:24 +00006010 let s:netrw_menucnt= 28
6011
6012 elseif !a:domenu
6013 let s:netrwcnt = 0
6014 let curwin = winnr()
6015 windo if getline(2) =~ "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
6016 exe curwin."wincmd w"
6017
6018 if s:netrwcnt <= 1
6019" call Decho("clear menus")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006020 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaaradc21822011-04-01 18:03:16 +02006021" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006022 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00006023 endif
6024 endif
6025" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02006026 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006027 endif
6028
6029endfun
6030
6031" ---------------------------------------------------------------------
6032" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
6033" Used by the O maps (as <SID>NetrwObtain())
6034fun! s:NetrwObtain(islocal)
6035" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
6036
Bram Moolenaar97d62492012-11-15 21:28:22 +01006037 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006038 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaar5c736222010-01-06 20:54:52 +01006039 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\+://'
6040 call netrw#NetrwObtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00006041 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
6042 else
6043 call netrw#NetrwObtain(a:islocal,expand("<cWORD>"))
6044 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006045 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006046
6047" call Dret("NetrwObtain")
6048endfun
6049
6050" ---------------------------------------------------------------------
6051" netrw#NetrwObtain: {{{2
6052" netrw#NetrwObtain(islocal,fname[,tgtdirectory])
6053" islocal=0 obtain from remote source
6054" =1 obtain from local source
6055" fname : a filename or a list of filenames
6056" tgtdir : optional place where files are to go (not present, uses getcwd())
6057fun! netrw#NetrwObtain(islocal,fname,...)
6058" call Dfunc("netrw#NetrwObtain(islocal=".a:islocal." fname<".((type(a:fname) == 1)? a:fname : string(a:fname)).">) a:0=".a:0)
6059 " NetrwStatusLine support - for obtaining support
6060
6061 if type(a:fname) == 1
6062 let fnamelist= [ a:fname ]
6063 elseif type(a:fname) == 3
6064 let fnamelist= a:fname
6065 else
6066 call netrw#ErrorMsg(s:ERROR,"attempting to use NetrwObtain on something not a filename or a list",62)
6067" call Dret("netrw#NetrwObtain")
6068 return
6069 endif
6070" call Decho("fnamelist<".string(fnamelist).">")
6071 if a:0 > 0
6072 let tgtdir= a:1
6073 else
6074 let tgtdir= getcwd()
6075 endif
6076" call Decho("tgtdir<".tgtdir.">")
6077
Bram Moolenaar5c736222010-01-06 20:54:52 +01006078 if exists("b:netrw_islocal") && b:netrw_islocal
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006079 " obtain a file from local b:netrw_curdir to (local) tgtdir
6080" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006081 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
6082 let topath= s:ComposePath(tgtdir,"")
6083 if (has("win32") || has("win95") || has("win64") || has("win16"))
6084 " transfer files one at time
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006085" call Decho("transfer files one at a time")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006086 for fname in fnamelist
Bram Moolenaarc236c162008-07-13 17:41:49 +00006087" call Decho("system(".g:netrw_localcopycmd." ".shellescape(fname)." ".shellescape(topath).")")
6088 call system(g:netrw_localcopycmd." ".shellescape(fname)." ".shellescape(topath))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006089 if v:shell_error != 0
6090 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localcopycmd<".g:netrw_localcopycmd."> to something that works",80)
6091" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".shellescape(fname)." ".shellescape(topath))
6092 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006093 endfor
6094 else
6095 " transfer files with one command
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006096" call Decho("transfer files with one command")
6097 let filelist= join(map(deepcopy(fnamelist),"shellescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006098" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".shellescape(topath).")")
6099 call system(g:netrw_localcopycmd." ".filelist." ".shellescape(topath))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006100 if v:shell_error != 0
6101 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localcopycmd<".g:netrw_localcopycmd."> to something that works",80)
6102" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".shellescape(topath))
6103 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006104 endif
6105 elseif !exists("b:netrw_curdir")
6106 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
6107 else
6108 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
6109 endif
6110
6111 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006112 " obtain files from remote b:netrw_curdir to local tgtdir
6113" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006114 if type(a:fname) == 1
6115 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
6116 endif
6117 call s:NetrwMethod(b:netrw_curdir)
6118
6119 if b:netrw_method == 4
6120 " obtain file using scp
6121" call Decho("obtain via scp (method#4)")
6122 if exists("g:netrw_port") && g:netrw_port != ""
6123 let useport= " ".g:netrw_scpport." ".g:netrw_port
6124 else
6125 let useport= ""
6126 endif
6127 if b:netrw_fname =~ '/'
6128 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
6129 else
6130 let path= ""
6131 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006132 let filelist= join(map(deepcopy(fnamelist),'shellescape(g:netrw_machine.":".path.v:val,1)'))
Bram Moolenaarc236c162008-07-13 17:41:49 +00006133" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_scp_cmd.shellescape(useport,1)." ".filelist." ".shellescape(tgtdir,1))
6134 exe s:netrw_silentxfer."!".g:netrw_scp_cmd.shellescape(useport,1)." ".filelist." ".shellescape(tgtdir,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006135
6136 elseif b:netrw_method == 2
6137 " obtain file using ftp + .netrc
6138" call Decho("obtain via ftp+.netrc (method #2)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006139 call s:SaveBufVars()|sil keepjumps new|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006140 let tmpbufnr= bufnr("%")
6141 setlocal ff=unix
6142 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006143 keepj put =g:netrw_ftpmode
Bram Moolenaar446cb832008-06-24 21:56:24 +00006144" call Decho("filter input: ".getline('$'))
6145 endif
6146
6147 if exists("b:netrw_fname") && b:netrw_fname != ""
6148 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
6149" call Decho("filter input: ".getline('$'))
6150 endif
6151
6152 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006153 keepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00006154" call Decho("filter input: ".getline('$'))
6155 endif
6156 for fname in fnamelist
6157 call setline(line("$")+1,'get "'.fname.'"')
6158" call Decho("filter input: ".getline('$'))
6159 endfor
6160 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02006161" call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
6162 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006163 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02006164" call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
6165 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006166 endif
6167 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
6168 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
6169 let debugkeep= &debug
6170 setlocal debug=msg
6171 call netrw#ErrorMsg(s:ERROR,getline(1),4)
6172 let &debug= debugkeep
6173 endif
6174
6175 elseif b:netrw_method == 3
6176 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
6177" call Decho("obtain via ftp+mipf (method #3)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006178 call s:SaveBufVars()|sil keepjumps new|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006179 let tmpbufnr= bufnr("%")
6180 setlocal ff=unix
6181
6182 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006183 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar446cb832008-06-24 21:56:24 +00006184" call Decho("filter input: ".getline('$'))
6185 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006186 keepj put ='open '.g:netrw_machine
Bram Moolenaar446cb832008-06-24 21:56:24 +00006187" call Decho("filter input: ".getline('$'))
6188 endif
6189
Bram Moolenaar5b435d62012-04-05 17:33:26 +02006190 if exists("g:netrw_uid") && g:netrw_uid != ""
6191 if exists("g:netrw_ftp") && g:netrw_ftp == 1
6192 keepj put =g:netrw_uid
6193" call Decho("filter input: ".getline('$'))
6194 if exists("s:netrw_passwd") && s:netrw_passwd != ""
6195 keepj put ='\"'.s:netrw_passwd.'\"'
6196 endif
6197" call Decho("filter input: ".getline('$'))
6198 elseif exists("s:netrw_passwd")
6199 keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
6200" call Decho("filter input: ".getline('$'))
6201 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006202 endif
6203
6204 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006205 keepj put =g:netrw_ftpmode
Bram Moolenaar446cb832008-06-24 21:56:24 +00006206" call Decho("filter input: ".getline('$'))
6207 endif
6208
6209 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006210 keepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00006211" call Decho("filter input: ".getline('$'))
6212 endif
6213
6214 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006215 keepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00006216" call Decho("filter input: ".getline('$'))
6217 endif
6218
6219 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006220 keepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00006221" call Decho("filter input: ".getline('$'))
6222 endif
6223 for fname in fnamelist
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006224 keepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00006225 endfor
6226" call Decho("filter input: ".getline('$'))
6227
6228 " perform ftp:
6229 " -i : turns off interactive prompting from ftp
6230 " -n unix : DON'T use <.netrc>, even though it exists
6231 " -n win32: quit being obnoxious about password
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006232 keepj norm! 1Gdd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02006233" call Decho("executing: %!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
6234 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00006235 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
6236 if getline(1) !~ "^$"
6237" call Decho("error<".getline(1).">")
6238 if !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006239 keepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006240 endif
6241 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01006242 elseif !exists("b:netrw_method") || b:netrw_method < 0
6243" call Dfunc("netrw#NetrwObtain : unsupported method")
6244 return
6245 endif
6246
6247 " restore status line
6248 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006249 keepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006250 endif
6251
6252 endif
6253
6254 " cleanup
6255 if exists("tmpbufnr")
6256 if bufnr("%") != tmpbufnr
6257 exe tmpbufnr."bw!"
6258 else
6259 q!
6260 endif
6261 endif
6262
6263" call Dret("netrw#NetrwObtain")
6264endfun
6265
6266" ---------------------------------------------------------------------
6267" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
6268" If there's only one window, then the window will first be split.
6269" Returns:
6270" choice = 0 : didn't have to choose
6271" choice = 1 : saved modified file in window first
6272" choice = 2 : didn't save modified file, opened window
6273" choice = 3 : cancel open
6274fun! s:NetrwPrevWinOpen(islocal)
6275" call Dfunc("NetrwPrevWinOpen(islocal=".a:islocal.")")
6276
Bram Moolenaar97d62492012-11-15 21:28:22 +01006277 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006278 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
6279 let curdir = b:netrw_curdir
6280
6281 " get last window number and the word currently under the cursor
6282 let lastwinnr = winnr("$")
6283 let curword = s:NetrwGetWord()
6284 let choice = 0
6285" call Decho("lastwinnr=".lastwinnr." curword<".curword.">")
6286
6287 let didsplit = 0
6288 if lastwinnr == 1
6289 " if only one window, open a new one first
6290" call Decho("only one window, so open a new one (g:netrw_alto=".g:netrw_alto.")")
6291 if g:netrw_preview
Bram Moolenaar15146672011-10-20 22:22:38 +02006292 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
6293" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s")
6294 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00006295 else
Bram Moolenaar15146672011-10-20 22:22:38 +02006296 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
6297" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s")
6298 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00006299 endif
6300 let didsplit = 1
6301
6302 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02006303 keepj call s:SaveBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006304" call Decho("wincmd p")
6305 wincmd p
Bram Moolenaaradc21822011-04-01 18:03:16 +02006306 keepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006307 " if the previous window's buffer has been changed (is modified),
6308 " and it doesn't appear in any other extant window, then ask the
6309 " user if s/he wants to abandon modifications therein.
6310 let bnr = winbufnr(0)
6311 let bnrcnt = 0
6312 if &mod
6313" call Decho("detected: prev window's buffer has been modified: bnr=".bnr." winnr#".winnr())
6314 let eikeep= &ei
6315 set ei=all
6316 windo if winbufnr(0) == bnr | let bnrcnt=bnrcnt+1 | endif
6317 exe bnr."wincmd p"
6318 let &ei= eikeep
6319" call Decho("bnr=".bnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr#".winnr())
6320 if bnrcnt == 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01006321 let bufname = bufname(winbufnr(winnr()))
6322 let choice = confirm("Save modified file<".bufname.">?","&Yes\n&No\n&Cancel")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006323" call Decho("bufname<".bufname."> choice=".choice." winnr#".winnr())
6324
6325 if choice == 1
6326 " Yes -- write file & then browse
6327 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02006328 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00006329 if v:errmsg != ""
6330 call netrw#ErrorMsg(s:ERROR,"unable to write <".bufname.">!",30)
6331 if didsplit
6332 q
6333 else
6334 wincmd p
6335 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006336 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006337" call Dret("NetrwPrevWinOpen ".choice." : unable to write <".bufname.">")
6338 return choice
6339 endif
6340
6341 elseif choice == 2
6342 " No -- don't worry about changed file, just browse anyway
Bram Moolenaar5b435d62012-04-05 17:33:26 +02006343" call Decho("(NetrwPrevWinOpen) setl nomod")
6344 setl nomod
6345" call Decho("(NetrwPrevWinOpen) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006346 keepj call netrw#ErrorMsg(s:WARNING,bufname." changes to ".bufname." abandoned",31)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006347 wincmd p
6348
6349 else
6350 " Cancel -- don't do this
6351 if didsplit
6352 q
6353 else
6354 wincmd p
6355 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006356 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006357" call Dret("NetrwPrevWinOpen ".choice." : cancelled")
6358 return choice
6359 endif
6360 endif
6361 endif
6362 endif
6363
6364 " restore b:netrw_curdir (window split/enew may have lost it)
6365 let b:netrw_curdir= curdir
6366 if a:islocal < 2
6367 if a:islocal
6368 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
6369 else
6370 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
6371 endif
6372 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006373 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006374" call Dret("NetrwPrevWinOpen ".choice)
6375 return choice
6376endfun
6377
6378" ---------------------------------------------------------------------
6379" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
6380" Always assumed to be local -> remote
6381" call s:NetrwUpload(filename, target)
6382" call s:NetrwUpload(filename, target, fromdirectory)
6383fun! s:NetrwUpload(fname,tgt,...)
6384" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
6385
6386 if a:tgt =~ '^\a\+://'
6387 let tgtdir= substitute(a:tgt,'^\a\+://[^/]\+/\(.\{-}\)$','\1','')
6388 else
6389 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
6390 endif
6391" call Decho("tgtdir<".tgtdir.">")
6392
6393 if a:0 > 0
6394 let fromdir= a:1
6395 else
6396 let fromdir= getcwd()
6397 endif
6398" call Decho("fromdir<".fromdir.">")
6399
6400 if type(a:fname) == 1
6401 " handle uploading a single file using NetWrite
6402" call Decho("handle uploading a single file via NetWrite")
6403 1split
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006404" call Decho("exe e ".fnameescape(a:fname))
6405 exe "e ".fnameescape(a:fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006406" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines")
6407 if a:tgt =~ '/$'
6408 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaarc236c162008-07-13 17:41:49 +00006409" call Decho("exe w! ".fnameescape(wfname))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006410 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006411 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00006412" call Decho("writing local->remote: exe w ".fnameescape(a:tgt))
6413 exe "w ".fnameescape(a:tgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006414" call Decho("done writing local->remote")
6415 endif
6416 q!
6417
6418 elseif type(a:fname) == 3
6419 " handle uploading a list of files via scp
6420" call Decho("handle uploading a list of files via scp")
6421 let curdir= getcwd()
6422 if a:tgt =~ '^scp:'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006423 exe "keepjumps sil lcd ".fnameescape(fromdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006424 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
6425 let args = join(map(filelist,"shellescape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006426 if exists("g:netrw_port") && g:netrw_port != ""
6427 let useport= " ".g:netrw_scpport." ".g:netrw_port
6428 else
6429 let useport= ""
6430 endif
6431 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
6432 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaarc236c162008-07-13 17:41:49 +00006433" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_scp_cmd.shellescape(useport,1)." ".args." ".shellescape(machine.":".tgt,1))
6434 exe s:netrw_silentxfer."!".g:netrw_scp_cmd.shellescape(useport,1)." ".args." ".shellescape(machine.":".tgt,1)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006435 exe "keepjumps sil lcd ".fnameescape(curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006436
6437 elseif a:tgt =~ '^ftp:'
6438 call s:NetrwMethod(a:tgt)
6439
6440 if b:netrw_method == 2
6441 " handle uploading a list of files via ftp+.netrc
6442 let netrw_fname = b:netrw_fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006443 sil keepj new
Bram Moolenaar446cb832008-06-24 21:56:24 +00006444" call Decho("filter input window#".winnr())
6445
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006446 keepj put =g:netrw_ftpmode
Bram Moolenaar446cb832008-06-24 21:56:24 +00006447" call Decho("filter input: ".getline('$'))
6448
6449 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006450 keepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00006451" call Decho("filter input: ".getline('$'))
6452 endif
6453
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006454 keepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00006455" call Decho("filter input: ".getline('$'))
6456
Bram Moolenaaradc21822011-04-01 18:03:16 +02006457 if tgtdir == ""
6458 let tgtdir= '/'
6459 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006460 keepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00006461" call Decho("filter input: ".getline('$'))
6462
6463 for fname in a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006464 keepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00006465" call Decho("filter input: ".getline('$'))
6466 endfor
6467
6468 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02006469" call Decho("executing: ".s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
6470 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006471 else
6472" call Decho("filter input window#".winnr())
Bram Moolenaaradc21822011-04-01 18:03:16 +02006473" call Decho("executing: ".s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
6474 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006475 endif
6476 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006477 sil keepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01006478 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006479 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
6480 call netrw#ErrorMsg(s:ERROR,getline(1),14)
6481 else
6482 bw!|q
6483 endif
6484
6485 elseif b:netrw_method == 3
6486 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
6487 let netrw_fname= b:netrw_fname
Bram Moolenaaradc21822011-04-01 18:03:16 +02006488 keepj call s:SaveBufVars()|sil keepj new|keepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006489 let tmpbufnr= bufnr("%")
6490 setlocal ff=unix
6491
6492 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006493 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar446cb832008-06-24 21:56:24 +00006494" call Decho("filter input: ".getline('$'))
6495 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006496 keepj put ='open '.g:netrw_machine
Bram Moolenaar446cb832008-06-24 21:56:24 +00006497" call Decho("filter input: ".getline('$'))
6498 endif
6499
Bram Moolenaar5b435d62012-04-05 17:33:26 +02006500 if exists("g:netrw_uid") && g:netrw_uid != ""
6501 if exists("g:netrw_ftp") && g:netrw_ftp == 1
6502 keepj put =g:netrw_uid
6503" call Decho("filter input: ".getline('$'))
6504 if exists("s:netrw_passwd")
6505 keepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
6506 endif
6507" call Decho("filter input: ".getline('$'))
6508 elseif exists("s:netrw_passwd")
6509 keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
6510" call Decho("filter input: ".getline('$'))
6511 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006512 endif
6513
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006514 keepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00006515" call Decho("filter input: ".getline('$'))
6516
6517 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006518 keepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00006519" call Decho("filter input: ".getline('$'))
6520 endif
6521
6522 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006523 keepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00006524" call Decho("filter input: ".getline('$'))
6525 endif
6526
6527 for fname in a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006528 keepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00006529" call Decho("filter input: ".getline('$'))
6530 endfor
6531
6532 " perform ftp:
6533 " -i : turns off interactive prompting from ftp
6534 " -n unix : DON'T use <.netrc>, even though it exists
6535 " -n win32: quit being obnoxious about password
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006536 keepj norm! 1Gdd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02006537" call Decho("executing: ".s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
6538 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00006539 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006540 sil keepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01006541 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006542 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
6543 let debugkeep= &debug
6544 setlocal debug=msg
6545 call netrw#ErrorMsg(s:ERROR,getline(1),15)
6546 let &debug = debugkeep
6547 let mod = 1
6548 else
6549 bw!|q
6550 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01006551 elseif !exists("b:netrw_method") || b:netrw_method < 0
6552" call Dfunc("netrw#NetrwUpload : unsupported method")
6553 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006554 endif
6555 else
6556 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
6557 endif
6558 endif
6559
6560" call Dret("s:NetrwUpload")
6561endfun
6562
6563" ---------------------------------------------------------------------
6564" s:NetrwPreview: {{{2
6565fun! s:NetrwPreview(path) range
6566" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01006567 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02006568 keepj call s:NetrwOptionSave("s:")
6569 keepj call s:NetrwSafeOptions()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006570 if has("quickfix")
6571 if !isdirectory(a:path)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006572 if g:netrw_preview && !g:netrw_alto
Bram Moolenaar15146672011-10-20 22:22:38 +02006573 let pvhkeep = &pvh
6574 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
6575 let &pvh = winwidth(0) - winsz
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006576 endif
6577 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
6578 if exists("pvhkeep")
6579 let &pvh= pvhkeep
6580 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006581 elseif !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006582 keepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006583 endif
6584 elseif !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006585 keepj call netrw#ErrorMsg(s:WARNING,"sorry, to preview your vim needs the quickfix feature compiled in",39)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006586 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006587 keepj call s:NetrwOptionRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01006588 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006589" call Dret("NetrwPreview")
6590endfun
6591
6592" ---------------------------------------------------------------------
6593" s:NetrwRefresh: {{{2
6594fun! s:NetrwRefresh(islocal,dirname)
6595" call Dfunc("NetrwRefresh(islocal<".a:islocal.">,dirname=".a:dirname.") hide=".g:netrw_hide." sortdir=".g:netrw_sort_direction)
6596 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaar97d62492012-11-15 21:28:22 +01006597 " (defunct) NetrwBrowseChgDir() may clear the display; hence a NetrwSavePosn() may not work if its placed here.
6598 " (defunct) Also, NetrwBrowseChgDir() now does a NetrwSavePosn() itself.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006599 setlocal ma noro
6600" call Decho("setlocal ma noro")
6601" call Decho("clear buffer<".expand("%")."> with :%d")
Bram Moolenaar97d62492012-11-15 21:28:22 +01006602 let ykeep = @@
6603 let screenposn = netrw#NetrwSavePosn()
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006604 sil! keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00006605 if a:islocal
Bram Moolenaaradc21822011-04-01 18:03:16 +02006606 keepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006607 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02006608 keepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006609 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006610 keepj call netrw#NetrwRestorePosn(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006611
6612 " restore file marks
6613 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
6614" call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/")
6615 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
6616 else
6617" call Decho("2match none")
6618 2match none
6619 endif
6620
Bram Moolenaar97d62492012-11-15 21:28:22 +01006621" restore
6622 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006623" call Dret("NetrwRefresh")
6624endfun
6625
6626" ---------------------------------------------------------------------
6627" s:NetrwRefreshDir: refreshes a directory by name {{{2
6628" Called by NetrwMarkFileCopy()
6629" Interfaces to s:NetrwRefresh() and s:LocalBrowseShellCmdRefresh()
6630fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006631" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006632 if g:netrw_fastbrowse == 0
6633 " slowest mode (keep buffers refreshed, local or remote)
6634" call Decho("slowest mode: keep buffers refreshed, local or remote")
6635 let tgtwin= bufwinnr(a:dirname)
6636" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin)
6637
6638 if tgtwin > 0
6639 " tgtwin is being displayed, so refresh it
6640 let curwin= winnr()
6641" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")")
6642 exe tgtwin."wincmd w"
Bram Moolenaaradc21822011-04-01 18:03:16 +02006643 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006644 exe curwin."wincmd w"
6645
6646 elseif bufnr(a:dirname) > 0
6647 let bn= bufnr(a:dirname)
6648" call Decho("bd bufnr(".a:dirname.")=".bn)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006649 exe "sil bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00006650 endif
6651
6652 elseif g:netrw_fastbrowse <= 1
6653" call Decho("medium-speed mode: refresh local buffers only")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006654 keepj call s:LocalBrowseShellCmdRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006655 endif
6656" call Dret("s:NetrwRefreshDir")
6657endfun
6658
6659" ---------------------------------------------------------------------
6660" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
6661" What this function does is to compute a priority for the patterns
6662" in the g:netrw_sort_sequence. It applies a substitute to any
6663" "files" that satisfy each pattern, putting the priority / in
6664" front. An "*" pattern handles the default priority.
6665fun! s:NetrwSetSort()
6666" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006667 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006668 if w:netrw_liststyle == s:LONGLIST
6669 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
6670 else
6671 let seqlist = g:netrw_sort_sequence
6672 endif
6673 " sanity check -- insure that * appears somewhere
6674 if seqlist == ""
6675 let seqlist= '*'
6676 elseif seqlist !~ '\*'
6677 let seqlist= seqlist.',*'
6678 endif
6679 let priority = 1
6680 while seqlist != ""
6681 if seqlist =~ ','
6682 let seq = substitute(seqlist,',.*$','','e')
6683 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
6684 else
6685 let seq = seqlist
6686 let seqlist = ""
6687 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006688 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01006689 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00006690 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01006691 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00006692 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01006693 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00006694 endif
6695" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">")
6696
6697 " sanity check
6698 if w:netrw_bannercnt > line("$")
6699 " apparently no files were left after a Hiding pattern was used
6700" call Dret("SetSort : no files left after hiding")
6701 return
6702 endif
6703 if seq == '*'
6704 let starpriority= spriority
6705 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006706 exe 'sil keepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01006707 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006708 " sometimes multiple sorting patterns will match the same file or directory.
6709 " The following substitute is intended to remove the excess matches.
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006710 exe 'sil keepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006711 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006712 endif
6713 let priority = priority + 1
6714 endwhile
6715 if exists("starpriority")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006716 exe 'sil keepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006717 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006718 endif
6719
6720 " Following line associated with priority -- items that satisfy a priority
6721 " pattern get prefixed by ###/ which permits easy sorting by priority.
6722 " Sometimes files can satisfy multiple priority patterns -- only the latest
6723 " priority pattern needs to be retained. So, at this point, these excess
6724 " priority prefixes need to be removed, but not directories that happen to
6725 " be just digits themselves.
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006726 exe 'sil keepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006727 keepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006728 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006729
6730" call Dret("SetSort")
6731endfun
6732
6733" =====================================================================
6734" s:NetrwSortStyle: change sorting style (name - time - size) and refresh display {{{2
6735fun! s:NetrwSortStyle(islocal)
6736" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006737 keepj call s:NetrwSaveWordPosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006738 let svpos= netrw#NetrwSavePosn()
6739
6740 let g:netrw_sort_by= (g:netrw_sort_by =~ 'n')? 'time' : (g:netrw_sort_by =~ 't')? 'size' : 'name'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006741 keepj norm! 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02006742 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
6743 keepj call netrw#NetrwRestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006744
6745" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
6746endfun
6747
6748" ---------------------------------------------------------------------
6749" s:NetrwSplit: mode {{{2
6750" =0 : net and o
6751" =1 : net and t
6752" =2 : net and v
6753" =3 : local and o
6754" =4 : local and t
6755" =5 : local and v
6756fun! s:NetrwSplit(mode)
6757" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
6758
Bram Moolenaar97d62492012-11-15 21:28:22 +01006759 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006760 call s:SaveWinVars()
6761
6762 if a:mode == 0
6763 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02006764 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
6765" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s")
Bram Moolenaar251e1912011-06-19 05:09:16 +02006766 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00006767 let s:didsplit= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02006768 keepj call s:RestoreWinVars()
6769 keepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006770 unlet s:didsplit
6771
6772 elseif a:mode == 1
6773 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01006774 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00006775" call Decho("tabnew")
6776 tabnew
6777 let s:didsplit= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02006778 keepj call s:RestoreWinVars()
6779 keepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006780 unlet s:didsplit
6781
6782 elseif a:mode == 2
6783 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02006784 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
6785" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v")
Bram Moolenaar251e1912011-06-19 05:09:16 +02006786 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00006787 let s:didsplit= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02006788 keepj call s:RestoreWinVars()
6789 keepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006790 unlet s:didsplit
6791
6792 elseif a:mode == 3
6793 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02006794 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
6795" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s")
Bram Moolenaar251e1912011-06-19 05:09:16 +02006796 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00006797 let s:didsplit= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02006798 keepj call s:RestoreWinVars()
6799 keepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006800 unlet s:didsplit
6801
6802 elseif a:mode == 4
6803 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00006804 let cursorword = s:NetrwGetWord()
Bram Moolenaar5c736222010-01-06 20:54:52 +01006805 let netrw_curdir= s:NetrwTreeDir()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006806" call Decho("tabnew")
6807 tabnew
6808 let b:netrw_curdir= netrw_curdir
6809 let s:didsplit= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02006810 keepj call s:RestoreWinVars()
6811 keepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006812 unlet s:didsplit
6813
6814 elseif a:mode == 5
6815 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02006816 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
6817" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v")
Bram Moolenaar251e1912011-06-19 05:09:16 +02006818 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00006819 let s:didsplit= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02006820 keepj call s:RestoreWinVars()
6821 keepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006822 unlet s:didsplit
6823
6824 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02006825 keepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006826 endif
6827
Bram Moolenaar97d62492012-11-15 21:28:22 +01006828 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006829" call Dret("s:NetrwSplit")
6830endfun
6831
6832" ---------------------------------------------------------------------
6833" NetrwStatusLine: {{{2
6834fun! NetrwStatusLine()
6835
6836" vvv NetrwStatusLine() debugging vvv
6837" let g:stlmsg=""
6838" if !exists("w:netrw_explore_bufnr")
6839" let g:stlmsg="!X<explore_bufnr>"
6840" elseif w:netrw_explore_bufnr != bufnr("%")
6841" let g:stlmsg="explore_bufnr!=".bufnr("%")
6842" endif
6843" if !exists("w:netrw_explore_line")
6844" let g:stlmsg=" !X<explore_line>"
6845" elseif w:netrw_explore_line != line(".")
6846" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
6847" endif
6848" if !exists("w:netrw_explore_list")
6849" let g:stlmsg=" !X<explore_list>"
6850" endif
6851" ^^^ NetrwStatusLine() debugging ^^^
6852
6853 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")
6854 " restore user's status line
6855 let &stl = s:netrw_users_stl
6856 let &laststatus = s:netrw_users_ls
6857 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
6858 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
6859 return ""
6860 else
6861 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
6862 endif
6863endfun
6864
6865" ---------------------------------------------------------------------
6866" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
6867" (full path directory with trailing slash returned)
6868fun! s:NetrwTreeDir()
6869" call Dfunc("NetrwTreeDir() curline#".line(".")."<".getline('.')."> b:netrw_curdir<".b:netrw_curdir."> tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%").">")
6870
6871 let treedir= b:netrw_curdir
6872" call Decho("set initial treedir<".treedir.">")
6873 let s:treecurpos= netrw#NetrwSavePosn()
6874
6875 if w:netrw_liststyle == s:TREELIST
6876" call Decho("w:netrrw_liststyle is TREELIST:")
6877" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01006878
6879 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006880 if getline('.') =~ '/$'
6881 let treedir= substitute(getline('.'),'^\%(| \)*\([^|].\{-}\)$','\1','e')
6882 else
6883 let treedir= ""
6884 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006885" call Decho("treedir<".treedir.">")
6886
6887 " detect user attempting to close treeroot
6888 if getline('.') !~ '|' && getline('.') != '..'
6889" call Decho("user attempted to close treeroot")
6890 " now force a refresh
6891" call Decho("clear buffer<".expand("%")."> with :%d")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006892 sil! keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00006893" call Dret("NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".string(s:treecurpos).">")
6894 return b:netrw_curdir
6895 endif
6896
6897 " elide all non-depth information
6898 let depth = substitute(getline('.'),'^\(\%(| \)*\)[^|].\{-}$','\1','e')
Bram Moolenaar5c736222010-01-06 20:54:52 +01006899" call Decho("depth<".depth."> 1st subst (non-depth info removed)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006900
6901 " elide first depth
6902 let depth = substitute(depth,'^| ','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01006903" call Decho("depth<".depth."> 2nd subst (first depth removed)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006904
6905 " construct treedir by searching backwards at correct depth
6906" call Decho("constructing treedir<".treedir."> depth<".depth.">")
6907 while depth != "" && search('^'.depth.'[^|].\{-}/$','bW')
6908 let dirname= substitute(getline('.'),'^\(| \)*','','e')
6909 let treedir= dirname.treedir
6910 let depth = substitute(depth,'^| ','','')
6911" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">")
6912 endwhile
6913 if w:netrw_treetop =~ '/$'
6914 let treedir= w:netrw_treetop.treedir
6915 else
6916 let treedir= w:netrw_treetop.'/'.treedir
6917 endif
6918" call Decho("bufnr(.)=".bufnr("%")." line($)=".line("$")." line(.)=".line("."))
6919 endif
6920 let treedir= substitute(treedir,'//$','/','')
6921
Bram Moolenaar446cb832008-06-24 21:56:24 +00006922" call Dret("NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".string(s:treecurpos).">")
6923 return treedir
6924endfun
6925
6926" ---------------------------------------------------------------------
6927" s:NetrwTreeDisplay: recursive tree display {{{2
6928fun! s:NetrwTreeDisplay(dir,depth)
6929" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
6930
6931 " insure that there are no folds
6932 setlocal nofen
6933
6934 " install ../ and shortdir
6935 if a:depth == ""
6936 call setline(line("$")+1,'../')
6937" call Decho("setline#".line("$")." ../ (depth is zero)")
6938 endif
6939 if a:dir =~ '^\a\+://'
6940 if a:dir == w:netrw_treetop
6941 let shortdir= a:dir
6942 else
6943 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
6944 endif
6945 call setline(line("$")+1,a:depth.shortdir)
6946 else
6947 let shortdir= substitute(a:dir,'^.*/','','e')
6948 call setline(line("$")+1,a:depth.shortdir.'/')
6949 endif
6950" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">")
6951
6952 " append a / to dir if its missing one
6953 let dir= a:dir
6954 if dir !~ '/$'
6955 let dir= dir.'/'
6956 endif
6957
6958 " display subtrees (if any)
6959 let depth= "| ".a:depth
6960
6961" call Decho("display subtrees with depth<".depth."> and current leaves")
6962 for entry in w:netrw_treedict[a:dir]
6963 let direntry= substitute(dir.entry,'/$','','e')
6964" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">")
6965 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
6966" call Decho("<".direntry."> is a key in treedict - display subtree for it")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006967 keepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006968 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
6969" call Decho("<".direntry."/> is a key in treedict - display subtree for it")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006970 keepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006971 else
6972" call Decho("<".entry."> is not a key in treedict (no subtree)")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006973 sil! keepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006974 endif
6975 endfor
6976" call Dret("NetrwTreeDisplay")
6977endfun
6978
6979" ---------------------------------------------------------------------
6980" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
6981fun! s:NetrwTreeListing(dirname)
6982 if w:netrw_liststyle == s:TREELIST
6983" call Dfunc("NetrwTreeListing() bufname<".expand("%").">")
6984" call Decho("curdir<".a:dirname.">")
6985" call Decho("win#".winnr().": w:netrw_treetop ".(exists("w:netrw_treetop")? "exists" : "doesn't exit")." w:netrw_treedict ".(exists("w:netrw_treedict")? "exists" : "doesn't exit"))
6986
6987 " update the treetop
6988" call Decho("update the treetop")
6989 if !exists("w:netrw_treetop")
6990 let w:netrw_treetop= a:dirname
6991" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)")
6992 elseif (w:netrw_treetop =~ ('^'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop)) || a:dirname !~ ('^'.w:netrw_treetop)
6993 let w:netrw_treetop= a:dirname
6994" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)")
6995 endif
6996
6997 " insure that we have at least an empty treedict
6998 if !exists("w:netrw_treedict")
6999 let w:netrw_treedict= {}
7000 endif
7001
7002 " update the directory listing for the current directory
7003" call Decho("updating dictionary with ".a:dirname.":[..directory listing..]")
7004" call Decho("bannercnt=".w:netrw_bannercnt." line($)=".line("$"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007005 exe "sil! keepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00007006 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007007" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007008 exe "sil! keepj ".w:netrw_bannercnt.",$d"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007009
7010 " if past banner, record word
7011 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
7012 let fname= expand("<cword>")
7013 else
7014 let fname= ""
7015 endif
7016" call Decho("fname<".fname.">")
7017
7018 " display from treetop on down
Bram Moolenaaradc21822011-04-01 18:03:16 +02007019 keepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007020
7021" call Dret("NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007022 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007023 endif
7024endfun
7025
7026" ---------------------------------------------------------------------
7027" s:NetrwWideListing: {{{2
7028fun! s:NetrwWideListing()
7029
7030 if w:netrw_liststyle == s:WIDELIST
7031" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
7032 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007033 " cpf: characters per filename
7034 " fpl: filenames per line
7035 " fpc: filenames per column
Bram Moolenaar446cb832008-06-24 21:56:24 +00007036 setlocal ma noro
7037" call Decho("setlocal ma noro")
7038 let b:netrw_cpf= 0
7039 if line("$") >= w:netrw_bannercnt
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007040 exe 'sil keepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
Bram Moolenaaradc21822011-04-01 18:03:16 +02007041 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007042 else
7043" call Dret("NetrwWideListing")
7044 return
7045 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007046 let b:netrw_cpf= b:netrw_cpf + 2
7047" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007048
7049 " determine qty files per line (fpl)
7050 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
7051 if w:netrw_fpl <= 0
7052 let w:netrw_fpl= 1
7053 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007054" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007055
7056 " make wide display
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007057 exe 'sil keepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'s",submatch(0)),"\\")/'
Bram Moolenaaradc21822011-04-01 18:03:16 +02007058 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007059 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
7060 let newcolstart = w:netrw_bannercnt + fpc
7061 let newcolend = newcolstart + fpc - 1
7062" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007063 sil! let keepregstar = @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00007064 while line("$") >= newcolstart
7065 if newcolend > line("$") | let newcolend= line("$") | endif
7066 let newcolqty= newcolend - newcolstart
7067 exe newcolstart
7068 if newcolqty == 0
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007069 exe "sil! keepj norm! 0\<c-v>$hx".w:netrw_bannercnt."G$p"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007070 else
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007071 exe "sil! keepj norm! 0\<c-v>".newcolqty.'j$hx'.w:netrw_bannercnt.'G$p'
Bram Moolenaar446cb832008-06-24 21:56:24 +00007072 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007073 exe "sil! keepj ".newcolstart.','.newcolend.'d'
7074 exe 'sil! keepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00007075 endwhile
Bram Moolenaaradc21822011-04-01 18:03:16 +02007076 sil! let @*= keepregstar
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007077 exe "sil! keepj ".w:netrw_bannercnt.',$s/\s\+$//e'
Bram Moolenaaradc21822011-04-01 18:03:16 +02007078 keepj call histdel("/",-1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007079" call Decho("NetrwWideListing) setl noma nomod ro")
7080 setl noma nomod ro
7081" call Decho("(NetrwWideListing) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007082" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007083 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007084 endif
7085
7086endfun
7087
7088" ---------------------------------------------------------------------
7089" s:PerformListing: {{{2
7090fun! s:PerformListing(islocal)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007091" call Dfunc("s:PerformListing(islocal=".a:islocal.") bufnr(%)=".bufnr("%")."<".bufname("%").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007092
Bram Moolenaar15146672011-10-20 22:22:38 +02007093 " set up syntax highlighting {{{3
7094" call Decho("set up syntax highlighting")
7095 if has("syntax")
7096 if !exists("g:syntax_on") || !g:syntax_on
7097" call Decho("but g:syntax_on".(exists("g:syntax_on")? "=".g:syntax_on : "<doesn't exist>"))
7098 setlocal ft=
7099 elseif &ft != "netrw"
7100 setlocal ft=netrw
7101 endif
7102 endif
7103
Bram Moolenaaradc21822011-04-01 18:03:16 +02007104 keepj call s:NetrwSafeOptions()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007105 setlocal noro ma
7106" call Decho("setlocal noro ma")
7107
7108" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
7109" call Decho("(netrw) Processing your browsing request...")
7110" endif " Decho
7111
7112" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'))
7113 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
7114 " force a refresh for tree listings
7115" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007116 sil! keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00007117 endif
7118
7119 " save current directory on directory history list
Bram Moolenaaradc21822011-04-01 18:03:16 +02007120 keepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007121
7122 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01007123 if g:netrw_banner
7124" call Decho("set up banner")
Bram Moolenaaradc21822011-04-01 18:03:16 +02007125 keepj call setline(1,'" ============================================================================')
7126 keepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
7127 keepj call setline(3,'" '.b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007128 let w:netrw_bannercnt= 3
Bram Moolenaaradc21822011-04-01 18:03:16 +02007129 keepj exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01007130 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007131 keepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01007132 let w:netrw_bannercnt= 1
7133 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007134
7135 let sortby= g:netrw_sort_by
7136 if g:netrw_sort_direction =~ "^r"
7137 let sortby= sortby." reversed"
7138 endif
7139
7140 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01007141 if g:netrw_banner
7142" call Decho("handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">")
7143 if g:netrw_sort_by =~ "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007144" call Decho("directories will be sorted by name")
Bram Moolenaar5c736222010-01-06 20:54:52 +01007145 " sorted by name
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007146 keepj put ='\" Sorted by '.sortby
7147 keepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01007148 let w:netrw_bannercnt= w:netrw_bannercnt + 2
7149 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00007150" call Decho("directories will be sorted by size or time")
Bram Moolenaar5c736222010-01-06 20:54:52 +01007151 " sorted by size or date
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007152 keepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01007153 let w:netrw_bannercnt= w:netrw_bannercnt + 1
7154 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007155 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00007156 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007157
7158 " show copy/move target, if any
Bram Moolenaar5c736222010-01-06 20:54:52 +01007159 if g:netrw_banner
7160 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
7161" call Decho("show copy/move target<".s:netrwmftgt.">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007162 keepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01007163 if s:netrwmftgt_islocal
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007164 sil! keepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01007165 else
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007166 sil! keepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01007167 endif
7168 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007169 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01007170" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007171 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007172 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00007173 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007174
7175 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01007176 if g:netrw_banner
7177" call Decho("handle hiding/showing (g:netrw_hide=".g:netrw_list_hide." g:netrw_list_hide<".g:netrw_list_hide.">)")
7178 if g:netrw_list_hide != "" && g:netrw_hide
7179 if g:netrw_hide == 1
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007180 keepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01007181 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007182 keepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01007183 endif
7184 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007185 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007186 exe "keepjumps ".w:netrw_bannercnt
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007187 keepj put ='\" Quick Help: <F1>:help -:go up dir D:delete R:rename s:sort-by x:exec'
7188 keepj put ='\" ============================================================================'
Bram Moolenaar5c736222010-01-06 20:54:52 +01007189 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007190 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007191
7192 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01007193 if g:netrw_banner
7194 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007195 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01007196" call Decho("bannercnt=".w:netrw_bannercnt." (should index line just after banner) line($)=".line("$"))
7197 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007198
Bram Moolenaar446cb832008-06-24 21:56:24 +00007199 " get list of files
7200" call Decho("Get list of files - islocal=".a:islocal)
7201 if a:islocal
Bram Moolenaaradc21822011-04-01 18:03:16 +02007202 keepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007203 else " remote
Bram Moolenaaradc21822011-04-01 18:03:16 +02007204 keepj call s:NetrwRemoteListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007205 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007206" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007207
7208 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007209 if !exists("w:netrw_bannercnt")
7210 let w:netrw_bannercnt= 0
7211 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007212 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00007213" call Decho("manipulate directory listing (hide)")
7214" call Decho("g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">")
7215 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02007216 keepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007217 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007218 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00007219" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">")
7220
7221 if g:netrw_sort_by =~ "^n"
7222 " sort by name
Bram Moolenaaradc21822011-04-01 18:03:16 +02007223 keepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007224
Bram Moolenaar5c736222010-01-06 20:54:52 +01007225 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007226" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")")
7227 if g:netrw_sort_direction =~ 'n'
7228 " normal direction sorting
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007229 exe 'sil keepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00007230 else
7231 " reverse direction sorting
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007232 exe 'sil keepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00007233 endif
7234 endif
7235 " remove priority pattern prefix
7236" call Decho("remove priority pattern prefix")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007237 exe 'sil! keepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
Bram Moolenaaradc21822011-04-01 18:03:16 +02007238 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007239
7240 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01007241 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007242" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction)
7243 if g:netrw_sort_direction =~ 'n'
Bram Moolenaaradc21822011-04-01 18:03:16 +02007244" call Decho('exe sil keepjumps '.w:netrw_bannercnt.',$sort')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007245 exe 'sil! keepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00007246 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02007247" call Decho('exe sil keepjumps '.w:netrw_bannercnt.',$sort!')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007248 exe 'sil! keepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00007249 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007250 exe 'sil! keepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
Bram Moolenaaradc21822011-04-01 18:03:16 +02007251 keepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007252 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007253 endif
7254
7255 elseif g:netrw_sort_direction =~ 'r'
7256" call Decho('reverse the sorted listing')
Bram Moolenaar5c736222010-01-06 20:54:52 +01007257 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007258 exe 'sil! keepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01007259 call histdel("/",-1)
7260 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007261 endif
7262 endif
7263
7264 " convert to wide/tree listing {{{3
7265" call Decho("modify display if wide/tree listing style")
Bram Moolenaaradc21822011-04-01 18:03:16 +02007266 keepj call s:NetrwWideListing()
7267 keepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007268
Bram Moolenaar5c736222010-01-06 20:54:52 +01007269 if exists("w:netrw_bannercnt") && (line("$") > w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007270 " place cursor on the top-left corner of the file listing
7271" call Decho("place cursor on top-left corner of file listing")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007272 exe 'sil! keepj '.w:netrw_bannercnt
7273 sil! keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007274 endif
7275
7276 " record previous current directory
7277 let w:netrw_prvdir= b:netrw_curdir
7278" call Decho("record netrw_prvdir<".w:netrw_prvdir.">")
7279
7280 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaaradc21822011-04-01 18:03:16 +02007281 keepj call s:SetBufWinVars()
7282 keepj call s:NetrwOptionRestore("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007283
7284 " set display to netrw display settings
7285" call Decho("set display to netrw display settings (noma nomod etc)")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007286 exe "setl ".g:netrw_bufsettings
Bram Moolenaar97d62492012-11-15 21:28:22 +01007287 if g:netrw_liststyle == s:LONGLIST
7288" call Decho("(LocalListing) exe setl ts=".(g:netrw_maxfilenamelen+1))
7289 exe "setl ts=".(g:netrw_maxfilenamelen+1)
7290 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007291 if exists("s:treecurpos")
7292
Bram Moolenaaradc21822011-04-01 18:03:16 +02007293 keepj call netrw#NetrwRestorePosn(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007294 unlet s:treecurpos
7295 endif
7296
7297" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
7298endfun
7299
7300" ---------------------------------------------------------------------
7301" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00007302fun! s:SetupNetrwStatusLine(statline)
7303" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
7304
7305 if !exists("s:netrw_setup_statline")
7306 let s:netrw_setup_statline= 1
7307" call Decho("do first-time status line setup")
7308
7309 if !exists("s:netrw_users_stl")
7310 let s:netrw_users_stl= &stl
7311 endif
7312 if !exists("s:netrw_users_ls")
7313 let s:netrw_users_ls= &laststatus
7314 endif
7315
7316 " set up User9 highlighting as needed
7317 let keepa= @a
7318 redir @a
7319 try
7320 hi User9
7321 catch /^Vim\%((\a\+)\)\=:E411/
7322 if &bg == "dark"
7323 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
7324 else
7325 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
7326 endif
7327 endtry
7328 redir END
7329 let @a= keepa
7330 endif
7331
7332 " set up status line (may use User9 highlighting)
7333 " insure that windows have a statusline
7334 " make sure statusline is displayed
7335 let &stl=a:statline
7336 setlocal laststatus=2
7337" call Decho("stl=".&stl)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007338 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +00007339
7340" call Dret("SetupNetrwStatusLine : stl=".&stl)
7341endfun
7342
7343" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007344" Remote Directory Browsing Support: {{{1
7345" ===========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00007346
7347" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007348" s:NetrwRemoteListing: {{{2
7349fun! s:NetrwRemoteListing()
7350" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">)")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00007351
Bram Moolenaar446cb832008-06-24 21:56:24 +00007352 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007353
Bram Moolenaar446cb832008-06-24 21:56:24 +00007354 " sanity check:
7355 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
7356" call Decho("b:netrw_method=".b:netrw_method)
7357 if !executable("ftp")
7358 if !exists("g:netrw_quiet")
7359 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
7360 endif
7361 call s:NetrwOptionRestore("w:")
7362" call Dret("s:NetrwRemoteListing")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00007363 return
7364 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007365
7366 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
7367 if !exists("g:netrw_quiet")
7368 if g:netrw_list_cmd == ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02007369 keepj call netrw#ErrorMsg(s:ERROR,g:netrw_ssh_cmd." is not executable on your system",47)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007370 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02007371 keepj 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 +00007372 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007373 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007374
Bram Moolenaaradc21822011-04-01 18:03:16 +02007375 keepj call s:NetrwOptionRestore("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007376" call Dret("s:NetrwRemoteListing")
7377 return
7378 endif " (remote handling sanity check)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007379
Bram Moolenaar446cb832008-06-24 21:56:24 +00007380 if exists("b:netrw_method")
7381" call Decho("setting w:netrw_method<".b:netrw_method.">")
7382 let w:netrw_method= b:netrw_method
7383 endif
7384
7385 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +02007386 " use ftp to get remote file listing {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00007387" call Decho("use ftp to get remote file listing")
7388 let s:method = "ftp"
7389 let listcmd = g:netrw_ftp_list_cmd
7390 if g:netrw_sort_by =~ '^t'
7391 let listcmd= g:netrw_ftp_timelist_cmd
7392 elseif g:netrw_sort_by =~ '^s'
7393 let listcmd= g:netrw_ftp_sizelist_cmd
7394 endif
7395" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)")
7396 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007397" exe "sil! keepalt keepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00007398
7399 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || w:netrw_liststyle == s:TREELIST
7400 " shorten the listing
7401" call Decho("generate short listing")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007402 exe "sil! keepalt keepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00007403
7404 " cleanup
7405 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007406 exe "sil! keepalt keepj g/".g:netrw_ftp_browse_reject."/keepj d"
Bram Moolenaaradc21822011-04-01 18:03:16 +02007407 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007408 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007409 sil! keepj %s/\r$//e
Bram Moolenaaradc21822011-04-01 18:03:16 +02007410 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007411
7412 " if there's no ../ listed, then put ./ and ../ in
7413 let line1= line(".")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007414 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +01007415 let line2= search('\.\.\/\%(\s\|$\)','cnW')
7416" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007417 if line2 == 0
7418" call Decho("netrw is putting ./ and ../ into listing")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007419 sil! keepj put='../'
7420 sil! keepj put='./'
Bram Moolenaar446cb832008-06-24 21:56:24 +00007421 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007422 exe "sil! keepj ".line1
7423 sil! keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007424
7425" call Decho("line1=".line1." line2=".line2." line(.)=".line("."))
7426 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
7427" call Decho("M$ ftp cleanup")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007428 exe 'sil! keepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
Bram Moolenaaradc21822011-04-01 18:03:16 +02007429 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007430 else " normal ftp cleanup
7431" call Decho("normal ftp cleanup")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007432 exe 'sil! keepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
7433 exe "sil! keepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
7434 exe "sil! keepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
Bram Moolenaaradc21822011-04-01 18:03:16 +02007435 keepj call histdel("/",-1)
7436 keepj call histdel("/",-1)
7437 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007438 endif
7439 endif
7440
7441 else
7442 " use ssh to get remote file listing {{{3
7443" call Decho("use ssh to get remote file listing: s:path<".s:path.">")
7444 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
7445" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)")
7446 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaaradc21822011-04-01 18:03:16 +02007447" call Decho("1: exe sil r! ".shellescape(listcmd.s:path, 1))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007448 exe "sil! keepj r! ".listcmd.shellescape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007449 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007450 sil! keepj g/^Listing directory/keepj d
7451 sil! keepj g/^d[-rwx][-rwx][-rwx]/keepj s+$+/+e
7452 sil! keepj g/^l[-rwx][-rwx][-rwx]/keepj s+$+@+e
Bram Moolenaaradc21822011-04-01 18:03:16 +02007453 keepj call histdel("/",-1)
7454 keepj call histdel("/",-1)
7455 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007456 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007457 sil! keepj g/^[dlsp-][-rwx][-rwx][-rwx]/keepj s/^.*\s\(\S\+\)$/\1/e
Bram Moolenaaradc21822011-04-01 18:03:16 +02007458 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007459 endif
7460 else
7461 if s:path == ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02007462" call Decho("2: exe sil r! ".listcmd)
Bram Moolenaar15146672011-10-20 22:22:38 +02007463 exe "sil! keepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00007464 else
Bram Moolenaar251e1912011-06-19 05:09:16 +02007465" call Decho("3: exe sil r! ".listcmd.' '.shellescape(fnameescape(s:path),1))
Bram Moolenaar15146672011-10-20 22:22:38 +02007466 exe "sil! keepj keepalt r! ".listcmd.' '.shellescape(fnameescape(s:path),1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007467" call Decho("listcmd<".listcmd."> path<".s:path.">")
7468 endif
7469 endif
7470
7471 " cleanup
7472 if g:netrw_ftp_browse_reject != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02007473" call Decho("(cleanup) exe sil! g/".g:netrw_ssh_browse_reject."/keepjumps d")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007474 exe "sil! g/".g:netrw_ssh_browse_reject."/keepj d"
Bram Moolenaaradc21822011-04-01 18:03:16 +02007475 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007476 endif
7477 endif
7478
7479 if w:netrw_liststyle == s:LONGLIST
7480 " do a long listing; these substitutions need to be done prior to sorting {{{3
7481" call Decho("fix long listing:")
7482
7483 if s:method == "ftp"
7484 " cleanup
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007485 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00007486 while getline('.') =~ g:netrw_ftp_browse_reject
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007487 sil! keepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +00007488 endwhile
7489 " if there's no ../ listed, then put ./ and ../ in
7490 let line1= line(".")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007491 sil! keepj 1
7492 sil! keepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007493 let line2= line(".")
7494 if line2 == 0
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007495 exe 'sil! keepj '.w:netrw_bannercnt."put='./'"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007496 if b:netrw_curdir != '/'
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007497 exe 'sil! keepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007498 endif
7499 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007500 exe "sil! keepj ".line1
7501 sil! keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007502 endif
7503
7504 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
7505" call Decho("M$ ftp site listing cleanup")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007506 exe 'sil! keepj '.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 +00007507 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
7508" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007509 exe 'sil keepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
7510 exe 'sil keepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2\t\1/e'
7511 exe 'sil keepj '.w:netrw_bannercnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02007512 keepj call histdel("/",-1)
7513 keepj call histdel("/",-1)
7514 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007515 endif
7516 endif
7517
7518" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007519" exe "keepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00007520" endif " Decho
7521" call Dret("s:NetrwRemoteListing")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007522endfun
7523
Bram Moolenaar446cb832008-06-24 21:56:24 +00007524" ---------------------------------------------------------------------
7525" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
7526fun! s:NetrwRemoteRm(usrhost,path) range
7527" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
7528" call Decho("firstline=".a:firstline." lastline=".a:lastline)
7529 let svpos= netrw#NetrwSavePosn()
7530
7531 let all= 0
7532 if exists("s:netrwmarkfilelist_{bufnr('%')}")
7533 " remove all marked files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007534" call Decho("remove all marked files with bufnr#".bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007535 for fname in s:netrwmarkfilelist_{bufnr("%")}
7536 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
7537 if ok =~ 'q\%[uit]'
7538 break
7539 elseif ok =~ 'a\%[ll]'
7540 let all= 1
7541 endif
7542 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01007543 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007544
7545 else
7546 " remove files specified by range
Bram Moolenaar5c736222010-01-06 20:54:52 +01007547" call Decho("remove files specified by range")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007548
7549 " preparation for removing multiple files/directories
7550 let ctr= a:firstline
7551
7552 " remove multiple files and directories
7553 while ctr <= a:lastline
Bram Moolenaar15146672011-10-20 22:22:38 +02007554 exe "keepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +00007555 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
7556 if ok =~ 'q\%[uit]'
7557 break
7558 elseif ok =~ 'a\%[ll]'
7559 let all= 1
7560 endif
7561 let ctr= ctr + 1
7562 endwhile
7563 endif
7564
7565 " refresh the (remote) directory listing
7566" call Decho("refresh remote directory listing")
Bram Moolenaaradc21822011-04-01 18:03:16 +02007567 keepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
7568 keepj call netrw#NetrwRestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007569
7570" call Dret("s:NetrwRemoteRm")
7571endfun
7572
7573" ---------------------------------------------------------------------
7574" s:NetrwRemoteRmFile: {{{2
7575fun! s:NetrwRemoteRmFile(path,rmfile,all)
7576" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
7577
7578 let all= a:all
7579 let ok = ""
7580
7581 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
7582 " attempt to remove file
7583" call Decho("attempt to remove file (all=".all.")")
7584 if !all
7585 echohl Statement
7586" call Decho("case all=0:")
7587 call inputsave()
7588 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
7589 call inputrestore()
7590 echohl NONE
7591 if ok == ""
7592 let ok="no"
7593 endif
7594 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
7595 if ok =~ 'a\%[ll]'
7596 let all= 1
7597 endif
7598 endif
7599
7600 if all || ok =~ 'y\%[es]' || ok == ""
7601" call Decho("case all=".all." or ok<".ok.">".(exists("w:netrw_method")? ': netrw_method='.w:netrw_method : ""))
7602 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
7603" call Decho("case ftp:")
7604 let path= a:path
7605 if path =~ '^\a\+://'
7606 let path= substitute(path,'^\a\+://[^/]\+/','','')
7607 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007608 sil! keepj .,$d
Bram Moolenaar446cb832008-06-24 21:56:24 +00007609 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
7610 else
7611" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">")
7612 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
7613" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">")
7614 if !exists("b:netrw_curdir")
Bram Moolenaaradc21822011-04-01 18:03:16 +02007615 keepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007616 let ok="q"
7617 else
7618 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
7619" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">")
7620" call Decho("remotedir<".remotedir.">")
7621" call Decho("rmfile<".a:rmfile.">")
7622 if remotedir != ""
7623 let netrw_rm_cmd= netrw_rm_cmd." ".shellescape(fnameescape(remotedir.a:rmfile))
7624 else
7625 let netrw_rm_cmd= netrw_rm_cmd." ".shellescape(fnameescape(a:rmfile))
7626 endif
7627" call Decho("call system(".netrw_rm_cmd.")")
7628 let ret= system(netrw_rm_cmd)
7629 if ret != 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02007630 keepj call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007631 endif
7632" call Decho("returned=".ret." errcode=".v:shell_error)
7633 endif
7634 endif
7635 elseif ok =~ 'q\%[uit]'
7636" call Decho("ok==".ok)
7637 break
7638 endif
7639
7640 else
7641 " attempt to remove directory
7642" call Decho("attempt to remove directory")
7643 if !all
7644 call inputsave()
7645 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
7646 call inputrestore()
7647 if ok == ""
7648 let ok="no"
7649 endif
7650 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
7651 if ok =~ 'a\%[ll]'
7652 let all= 1
7653 endif
7654 endif
7655
7656 if all || ok =~ 'y\%[es]' || ok == ""
7657 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaaradc21822011-04-01 18:03:16 +02007658 keepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007659 else
7660 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01007661 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.shellescape(netrw#WinPath(rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007662" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")")
Bram Moolenaarc236c162008-07-13 17:41:49 +00007663 let ret= system(netrw_rmdir_cmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007664" call Decho("returned=".ret." errcode=".v:shell_error)
7665
7666 if v:shell_error != 0
Bram Moolenaarc236c162008-07-13 17:41:49 +00007667" call Decho("v:shell_error not 0")
Bram Moolenaar5c736222010-01-06 20:54:52 +01007668 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.shellescape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007669" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")")
7670 let ret= system(netrw_rmf_cmd)
7671" call Decho("returned=".ret." errcode=".v:shell_error)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007672
7673 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02007674 keepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007675 endif
7676 endif
7677 endif
7678
7679 elseif ok =~ 'q\%[uit]'
7680 break
7681 endif
7682 endif
7683
7684" call Dret("s:NetrwRemoteRmFile ".ok)
7685 return ok
7686endfun
7687
7688" ---------------------------------------------------------------------
7689" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
7690" This function assumes that a long listing will be received. Size, time,
7691" and reverse sorts will be requested of the server but not otherwise
7692" enforced here.
7693fun! s:NetrwRemoteFtpCmd(path,listcmd)
7694" call Dfunc("NetrwRemoteFtpCmd(path<".a:path."> listcmd<".a:listcmd.">) netrw_method=".w:netrw_method)
7695" call Decho("line($)=".line("$")." bannercnt=".w:netrw_bannercnt)
7696
7697 " because WinXX ftp uses unix style input
7698 let ffkeep= &ff
7699 setlocal ma ff=unix noro
7700" call Decho("setlocal ma ff=unix noro")
7701
7702 " clear off any older non-banner lines
7703 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaaradc21822011-04-01 18:03:16 +02007704" call Decho('exe sil! keepjumps '.w:netrw_bannercnt.",$d (clear off old non-banner lines)")
7705 exe "sil! keepjumps ".w:netrw_bannercnt.",$d"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007706
7707 ".........................................
7708 if w:netrw_method == 2 || w:netrw_method == 5
7709 " ftp + <.netrc>: Method #2
7710 if a:path != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007711 keepj put ='cd \"'.a:path.'\"'
Bram Moolenaar446cb832008-06-24 21:56:24 +00007712 endif
7713 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007714 keepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00007715" call Decho("filter input: ".getline('.'))
7716 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02007717 keepj call setline(line("$")+1,a:listcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007718" exe "keepjumps ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."))'
7719 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02007720" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
Bram Moolenaar15146672011-10-20 22:22:38 +02007721 exe s:netrw_silentxfer." keepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007722 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02007723" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
Bram Moolenaar15146672011-10-20 22:22:38 +02007724 exe s:netrw_silentxfer." keepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007725 endif
7726
7727 ".........................................
7728 elseif w:netrw_method == 3
7729 " ftp + machine,id,passwd,filename: Method #3
7730 setlocal ff=unix
7731 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007732 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar446cb832008-06-24 21:56:24 +00007733 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007734 keepj put ='open '.g:netrw_machine
Bram Moolenaar446cb832008-06-24 21:56:24 +00007735 endif
7736
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007737 " handle userid and password
7738 let host= substitute(g:netrw_machine,'\..*$','','')
7739" call Decho("host<".host.">")
7740 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
7741 call NetUserPass("ftp:".host)
7742 endif
7743 if exists("g:netrw_uid") && g:netrw_uid != ""
7744 if exists("g:netrw_ftp") && g:netrw_ftp == 1
7745 keepj put =g:netrw_uid
7746 if exists("s:netrw_passwd") && s:netrw_passwd != ""
7747 keepj put ='\"'.s:netrw_passwd.'\"'
7748 endif
7749 elseif exists("s:netrw_passwd")
7750 keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
7751 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007752 endif
7753
7754 if a:path != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007755 keepj put ='cd \"'.a:path.'\"'
Bram Moolenaar446cb832008-06-24 21:56:24 +00007756 endif
7757 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007758 keepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00007759" call Decho("filter input: ".getline('.'))
7760 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007761 keepj call setline(line("$")+1,a:listcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007762
7763 " perform ftp:
7764 " -i : turns off interactive prompting from ftp
7765 " -n unix : DON'T use <.netrc>, even though it exists
7766 " -n win32: quit being obnoxious about password
7767" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."))'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007768" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
7769 exe s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00007770
7771 ".........................................
7772 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02007773 keepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",23)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007774 endif
7775
7776 " cleanup for Windows
7777 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007778 sil! keepj %s/\r$//e
Bram Moolenaaradc21822011-04-01 18:03:16 +02007779 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007780 endif
7781 if a:listcmd == "dir"
7782 " infer directory/link based on the file permission string
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007783 sil! keepj g/d\%([-r][-w][-x]\)\{3}/keepj s@$@/@
7784 sil! keepj g/l\%([-r][-w][-x]\)\{3}/keepj s/$/@/
Bram Moolenaaradc21822011-04-01 18:03:16 +02007785 keepj call histdel("/",-1)
7786 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007787 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || w:netrw_liststyle == s:TREELIST
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007788 exe "sil! keepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
Bram Moolenaaradc21822011-04-01 18:03:16 +02007789 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007790 endif
7791 endif
7792
7793 " ftp's listing doesn't seem to include ./ or ../
7794 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007795 exe 'keepj '.w:netrw_bannercnt
7796 keepj put ='./'
Bram Moolenaar446cb832008-06-24 21:56:24 +00007797 endif
7798 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007799 exe 'keepj '.w:netrw_bannercnt
7800 keepj put ='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +00007801 endif
7802
7803 " restore settings
7804 let &ff= ffkeep
7805" call Dret("NetrwRemoteFtpCmd")
7806endfun
7807
7808" ---------------------------------------------------------------------
7809" s:NetrwRemoteRename: rename a remote file or directory {{{2
7810fun! s:NetrwRemoteRename(usrhost,path) range
7811" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
7812
7813 " preparation for removing multiple files/directories
7814 let svpos = netrw#NetrwSavePosn()
7815 let ctr = a:firstline
7816 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
7817
7818 " rename files given by the markfilelist
7819 if exists("s:netrwmarkfilelist_{bufnr('%')}")
7820 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7821" call Decho("oldname<".oldname.">")
7822 if exists("subfrom")
7823 let newname= substitute(oldname,subfrom,subto,'')
7824" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">")
7825 else
7826 call inputsave()
7827 let newname= input("Moving ".oldname." to : ",oldname)
7828 call inputrestore()
7829 if newname =~ '^s/'
7830 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
7831 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
7832 let newname = substitute(oldname,subfrom,subto,'')
7833" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">")
7834 endif
7835 endif
7836
7837 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaaradc21822011-04-01 18:03:16 +02007838 keepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007839 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00007840 let oldname= shellescape(a:path.oldname)
7841 let newname= shellescape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007842" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")")
7843 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007844 endif
7845
7846 endfor
7847 call s:NetrwUnMarkFile(1)
7848
7849 else
7850
7851 " attempt to rename files/directories
7852 while ctr <= a:lastline
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007853 exe "keepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +00007854
7855 let oldname= s:NetrwGetWord()
7856" call Decho("oldname<".oldname.">")
7857
7858 call inputsave()
7859 let newname= input("Moving ".oldname." to : ",oldname)
7860 call inputrestore()
7861
7862 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
7863 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
7864 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00007865 let oldname= shellescape(a:path.oldname)
7866 let newname= shellescape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007867" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")")
7868 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007869 endif
7870
7871 let ctr= ctr + 1
7872 endwhile
7873 endif
7874
7875 " refresh the directory
Bram Moolenaaradc21822011-04-01 18:03:16 +02007876 keepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
7877 keepj call netrw#NetrwRestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007878
7879" call Dret("NetrwRemoteRename")
7880endfun
7881
7882" ---------------------------------------------------------------------
7883" Local Directory Browsing Support: {{{1
7884" ==========================================
7885
7886" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +01007887" netrw#FileUrlRead: handles reading file://* files {{{2
7888" Should accept: file://localhost/etc/fstab
7889" file:///etc/fstab
7890" file:///c:/WINDOWS/clock.avi
7891" file:///c|/WINDOWS/clock.avi
7892" file://localhost/c:/WINDOWS/clock.avi
7893" file://localhost/c|/WINDOWS/clock.avi
7894" file://c:/foo.txt
7895" file:///c:/foo.txt
7896" and %XX (where X is [0-9a-fA-F] is converted into a character with the given hexadecimal value
7897fun! netrw#FileUrlRead(fname)
7898" call Dfunc("netrw#FileUrlRead(fname<".a:fname.">)")
7899 let fname = a:fname
7900 if fname =~ '^file://localhost/'
7901" call Decho('converting file://localhost/ -to- file:///')
7902 let fname= substitute(fname,'^file://localhost/','file:///','')
7903" call Decho("fname<".fname.">")
7904 endif
7905 if (has("win32") || has("win95") || has("win64") || has("win16"))
7906 if fname =~ '^file:///\=\a[|:]/'
7907" call Decho('converting file:///\a|/ -to- file://\a:/')
7908 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
7909" call Decho("fname<".fname.">")
7910 endif
7911 endif
7912 let fname2396 = netrw#RFC2396(fname)
7913 let fname2396e= fnameescape(fname2396)
7914 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
7915 if (has("win32") || has("win95") || has("win64") || has("win16"))
7916" call Decho("windows exception for plainfname")
7917 if plainfname =~ '^/\+\a:'
7918" call Decho('removing leading "/"s')
7919 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
7920 endif
7921 endif
7922" call Decho("fname2396<".fname2396.">")
7923" call Decho("plainfname<".plainfname.">")
7924 exe "sil doau BufReadPre ".fname2396e
7925 exe 'keepj r '.plainfname
7926 exe 'file! '.plainfname
7927 keepj 1d
7928" call Decho("(FileUrlRead) setl nomod")
7929 setl nomod
7930" call Decho("(FileUrlRead) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
7931" call Dret("netrw#FileUrlRead")
7932 exe "sil doau BufReadPost ".fname2396e
7933endfun
7934
7935" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007936" netrw#LocalBrowseCheck: {{{2
7937fun! netrw#LocalBrowseCheck(dirname)
7938 " unfortunate interaction -- split window debugging can't be
7939 " used here, must use D-echoRemOn or D-echoTabOn -- the BufEnter
7940 " event triggers another call to LocalBrowseCheck() when attempts
7941 " to write to the DBG buffer are made.
7942 " The &ft == "netrw" test was installed because the BufEnter event
7943 " would hit when re-entering netrw windows, creating unexpected
7944 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007945" call Decho("netrw#LocalBrowseCheck: isdir<".a:dirname.">=".isdirectory(a:dirname).((exists("s:treeforceredraw")? " treeforceredraw" : "")))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007946" call Dredir("LocalBrowseCheck","ls!")|redraw!|sleep 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01007947 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00007948 if isdirectory(a:dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007949" call Decho(" 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)
7950 let svposn= netrw#NetrwSavePosn()
7951 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02007952 sil! keepj call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007953 call netrw#NetrwRestorePosn(svposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007954 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02007955 sil! keepj call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007956 call netrw#NetrwRestorePosn(svposn)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007957 elseif exists("s:treeforceredraw")
7958 unlet s:treeforceredraw
Bram Moolenaaradc21822011-04-01 18:03:16 +02007959 sil! keepj call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007960 call netrw#NetrwRestorePosn(svposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007961 endif
7962 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007963 " following code wipes out currently unused netrw buffers
7964 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
7965 " AND IF the listing style is not a tree listing
7966 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
7967 let ibuf = 1
7968 let buflast = bufnr("$")
7969 while ibuf <= buflast
7970 if bufwinnr(ibuf) == -1 && isdirectory(bufname(ibuf))
7971 exe "sil! ".ibuf."bw!"
7972 endif
7973 let ibuf= ibuf + 1
7974 endwhile
7975 endif
7976 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00007977 " not a directory, ignore it
7978endfun
7979
7980" ---------------------------------------------------------------------
7981" s:LocalListing: does the job of "ls" for local directories {{{2
7982fun! s:LocalListing()
7983" call Dfunc("s:LocalListing()")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007984" call Decho("(LocalListing) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
7985" call Decho("(LocalListing) tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007986
7987" if exists("b:netrw_curdir") |call Decho('b:netrw_curdir<'.b:netrw_curdir.">") |else|call Decho("b:netrw_curdir doesn't exist") |endif
7988" if exists("g:netrw_sort_by")|call Decho('g:netrw_sort_by<'.g:netrw_sort_by.">")|else|call Decho("g:netrw_sort_by doesn't exist")|endif
7989
7990 " get the list of files contained in the current directory
Bram Moolenaaradc21822011-04-01 18:03:16 +02007991 let dirname = b:netrw_curdir
Bram Moolenaar5c736222010-01-06 20:54:52 +01007992 let dirnamelen = s:Strlen(b:netrw_curdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007993 let filelist = glob(s:ComposePath(dirname,"*"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007994" call Decho("(LocalListing) glob(dirname<".dirname."/*>)=".filelist)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007995 if filelist != ""
7996 let filelist= filelist."\n"
7997 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007998 let filelist= filelist.glob(s:ComposePath(dirname,".*"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007999" call Decho("(LocalListing) glob(dirname<".dirname."/.*>)=".filelist)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008000
8001 " Coding choice: either elide ./ if present
8002 " or include ./ if not present
8003 if filelist =~ '[\\/]\.[\\/]\=\(\n\|$\)'
8004 " elide /path/. from glob() entries if present
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008005" call Decho("(LocalListing) elide /path/. from glob entries if present")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008006 let filelist = substitute(filelist,'\n','\t','g')
8007 let filelist = substitute(filelist,'^[^\t]\+[/\\]\.\t','','')
8008 let filelist = substitute(filelist,'[^\t]\+[/\\]\.$','','')
8009 let filelist = substitute(filelist,'\t\zs[^\t]\+[/\\]\.\t','','')
8010 let filelist = substitute(filelist,'\t','\n','g')
8011 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008012" call Decho("(LocalListing) filelist<".filelist.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008013 if filelist !~ '[\\/]\.\.[\\/]\=\(\n\|$\)'
8014 " include ../ in the glob() entry if its missing
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008015" call Decho("(LocalListing) forcibly tacking on ..")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008016 let filelist= filelist."\n".s:ComposePath(b:netrw_curdir,"../")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008017" call Decho("(LocalListing) filelist<".filelist.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008018 endif
8019 if b:netrw_curdir == '/'
8020 " remove .. from filelist when current directory is root directory
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008021" call Decho("(LocalListing) remove .. from filelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008022 let filelist= substitute(filelist,'/\.\.\n','','')
8023 endif
8024 " remove multiple contiguous newlines
8025 let filelist= substitute(filelist,'\n\{2,}','\n','ge')
8026 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
8027 " change all \s to /s
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008028" call Decho('(LocalListing) change all \s to /s')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008029 let filelist= substitute(filelist,'\','/','g')
8030 else
8031 " escape all \s to \\
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008032" call Decho('(LocalListing) escape all \s to \\')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008033 let filelist= substitute(filelist,'\','\\','g')
8034 endif
8035
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008036" call Decho("(LocalListing) (before while) dirname<".dirname.">")
8037" call Decho("(LocalListing) (before while) dirnamelen<".dirnamelen.">")
8038" call Decho("(LocalListing) (before while) filelist<".filelist.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008039
Bram Moolenaar97d62492012-11-15 21:28:22 +01008040
8041 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
8042 let g:netrw_maxfilenamelen = max(map(split(filelist, '\n'), 'len(fnamemodify(v:val, ":t"))')) + 1
8043 endif
8044
Bram Moolenaar446cb832008-06-24 21:56:24 +00008045 while filelist != ""
8046 if filelist =~ '\n'
8047 let filename = substitute(filelist,'\n.*$','','e')
8048 let filelist = substitute(filelist,'^.\{-}\n\(.*\)$','\1','e')
8049 else
8050 let filename = filelist
8051 let filelist = ""
8052 endif
8053" call Decho(" ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008054" call Decho("(LocalListing) (while) filelist<".filelist.">")
8055" call Decho("(LocalListing) (while) filename<".filename.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008056
8057 if getftype(filename) == "link"
8058 " indicate a symbolic link
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008059" call Decho("(LocalListing) indicate <".filename."> is a symbolic link with trailing @")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008060 let pfile= filename."@"
8061
8062 elseif getftype(filename) == "socket"
8063 " indicate a socket
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008064" call Decho("(LocalListing) indicate <".filename."> is a socket with trailing =")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008065 let pfile= filename."="
8066
8067 elseif getftype(filename) == "fifo"
8068 " indicate a fifo
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008069" call Decho("(LocalListing) indicate <".filename."> is a fifo with trailing |")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008070 let pfile= filename."|"
8071
8072 elseif isdirectory(filename)
8073 " indicate a directory
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008074" call Decho("(LocalListing) indicate <".filename."> is a directory with trailing /")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008075 let pfile= filename."/"
8076
8077 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(filename)
8078 if (has("win32") || has("win95") || has("win64") || has("win16"))
8079 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
8080 " indicate an executable
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008081" call Decho("(LocalListing) indicate <".filename."> is executable with trailing *")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008082 let pfile= filename."*"
8083 else
8084 " normal file
8085 let pfile= filename
8086 endif
8087 elseif executable(filename)
8088 " indicate an executable
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008089" call Decho("(LocalListing) indicate <".filename."> is executable with trailing *")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008090 let pfile= filename."*"
8091 else
8092 " normal file
8093 let pfile= filename
8094 endif
8095
8096 else
8097 " normal file
8098 let pfile= filename
8099 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008100" call Decho("(LocalListing) pfile<".pfile."> (after *@/ appending)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008101
8102 if pfile =~ '//$'
8103 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008104" call Decho("(LocalListing) change // to /: pfile<".pfile.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008105 endif
8106 let pfile= strpart(pfile,dirnamelen)
8107 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008108" call Decho("(LocalListing) filename<".filename.">")
8109" call Decho("(LocalListing) pfile <".pfile.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008110
8111 if w:netrw_liststyle == s:LONGLIST
8112 let sz = getfsize(filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01008113 let fsz = strpart(" ",1,15-strlen(sz)).sz
Bram Moolenaar446cb832008-06-24 21:56:24 +00008114 let pfile= pfile."\t".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008115" call Decho("(LocalListing) sz=".sz." fsz=".fsz)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008116 endif
8117
8118 if g:netrw_sort_by =~ "^t"
8119 " sort by time (handles time up to 1 quintillion seconds, US)
8120" call Decho("getftime(".filename.")=".getftime(filename))
8121 let t = getftime(filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01008122 let ft = strpart("000000000000000000",1,18-strlen(t)).t
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008123" call Decho("(LocalListing) exe keepjumps put ='".ft.'/'.filename."'")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008124 let ftpfile= ft.'/'.pfile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008125 sil! keepj put=ftpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008126
8127 elseif g:netrw_sort_by =~ "^s"
8128 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008129" call Decho("(LocalListing) getfsize(".filename.")=".getfsize(filename))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008130 let sz = getfsize(filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01008131 let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008132" call Decho("(LocalListing) exe keepj put ='".fsz.'/'.filename."'")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008133 let fszpfile= fsz.'/'.pfile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008134 sil! keepj put =fszpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008135
8136 else
8137 " sort by name
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008138" call Decho("(LocalListing) exe keepjumps put ='".pfile."'")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008139 sil! keepj put=pfile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008140 endif
8141 endwhile
8142
8143 " cleanup any windows mess at end-of-line
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008144 sil! keepj g/^$/d
8145 sil! keepj %s/\r$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008146 call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008147" call Decho("(LocalListing) exe setl ts=".(g:netrw_maxfilenamelen+1))
8148 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008149
8150" call Dret("s:LocalListing")
8151endfun
8152
8153" ---------------------------------------------------------------------
8154" s:LocalBrowseShellCmdRefresh: this function is called after a user has {{{2
8155" performed any shell command. The idea is to cause all local-browsing
8156" buffers to be refreshed after a user has executed some shell command,
8157" on the chance that s/he removed/created a file/directory with it.
8158fun! s:LocalBrowseShellCmdRefresh()
8159" call Dfunc("LocalBrowseShellCmdRefresh() browselist=".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "empty")." ".tabpagenr("$")." tabs")
8160 " determine which buffers currently reside in a tab
8161 if !exists("s:netrw_browselist")
8162" call Dret("LocalBrowseShellCmdRefresh : browselist is empty")
8163 return
8164 endif
8165 if !exists("w:netrw_bannercnt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008166" call Dret("LocalBrowseShellCmdRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008167 return
8168 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008169 if exists("s:locbrowseshellcmd")
8170 if s:locbrowseshellcmd
8171 let s:locbrowseshellcmd= 0
8172" call Dret("LocalBrowseShellCmdRefresh : NetrwBrowse itself caused the refresh")
8173 return
8174 endif
8175 let s:locbrowseshellcmd= 0
8176 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008177 let itab = 1
8178 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +01008179 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008180 while itab <= tabpagenr("$")
8181 let buftablist = buftablist + tabpagebuflist()
8182 let itab = itab + 1
8183 tabn
8184 endwhile
8185" call Decho("buftablist".string(buftablist))
8186" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">")
8187 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
8188 " | refresh any netrw window
8189 " | wipe out any non-displaying netrw buffer
8190 let curwin = winnr()
8191 let ibl = 0
8192 for ibuf in s:netrw_browselist
8193" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf))
8194 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
8195 " wipe out any non-displaying netrw buffer
8196" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008197 exe "sil! bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008198 call remove(s:netrw_browselist,ibl)
8199" call Decho("browselist=".string(s:netrw_browselist))
8200 continue
8201 elseif index(tabpagebuflist(),ibuf) != -1
8202 " refresh any netrw buffer
8203" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf))
8204 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaradc21822011-04-01 18:03:16 +02008205 keepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008206 endif
8207 let ibl= ibl + 1
8208 endfor
8209 exe curwin."wincmd w"
Bram Moolenaar97d62492012-11-15 21:28:22 +01008210 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008211
8212" call Dret("LocalBrowseShellCmdRefresh")
8213endfun
8214
8215" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +01008216" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
8217"
8218" g:netrw_ Directory Is
8219" fastbrowse Local Remote
8220" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
8221" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
8222" fast 2 H H
8223"
8224" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
8225" Hiding a buffer means that it will be re-used when examined, hence "fast".
8226" (re-using a buffer may not be as accurate)
8227fun! s:LocalFastBrowser()
8228" call Dfunc("LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse." s:netrw_browser_shellcmd ".(exists("s:netrw_browser_shellcmd")? "exists" : "does not exist"))
8229
8230 " initialize browselist, a list of buffer numbers that the local browser has used
8231 if !exists("s:netrw_browselist")
8232" call Decho("initialize s:netrw_browselist")
8233 let s:netrw_browselist= []
8234 endif
8235
8236 " append current buffer to fastbrowse list
8237 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
8238" call Decho("appendng current buffer to browselist")
8239 call add(s:netrw_browselist,bufnr("%"))
8240" call Decho("browselist=".string(s:netrw_browselist))
8241 endif
8242
8243 " enable autocmd events to handle refreshing/removing local browser buffers
8244 " If local browse buffer is currently showing: refresh it
8245 " If local browse buffer is currently hidden : wipe it
8246 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
8247 " =1 : medium speed, re-use directory listing for remote only
8248 " =2 : fast speed, always re-use directory listing when possible
8249 if !exists("s:netrw_browser_shellcmd") && g:netrw_fastbrowse <= 1
8250" call Decho("setting up local-browser shell command refresh")
8251 let s:netrw_browser_shellcmd= 1
8252 augroup AuNetrwShellCmd
8253 au!
8254 if (has("win32") || has("win95") || has("win64") || has("win16"))
8255" call Decho("autocmd: ShellCmdPost * call s:LocalBrowseShellCmdRefresh()")
8256 au ShellCmdPost * call s:LocalBrowseShellCmdRefresh()
8257 else
8258 au ShellCmdPost,FocusGained * call s:LocalBrowseShellCmdRefresh()
8259" call Decho("autocmd: ShellCmdPost,FocusGained * call s:LocalBrowseShellCmdRefresh()")
8260 endif
8261 augroup END
8262 endif
8263
8264 " user must have changed fastbrowse to its fast setting, so remove
8265 " the associated autocmd events
8266 if g:netrw_fastbrowse > 1 && exists("s:netrw_browser_shellcmd")
8267" call Decho("remove AuNetrwShellCmd autcmd group")
8268 unlet s:netrw_browser_shellcmd
8269 augroup AuNetrwShellCmd
8270 au!
8271 augroup END
8272 augroup! AuNetrwShellCmd
8273 endif
8274
8275" call Dret("LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
8276endfun
8277
8278" ---------------------------------------------------------------------
8279" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
8280fun! s:NetrwLocalExecute(cmd)
8281" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
8282 let ykeep= @@
8283 " sanity check
8284 if !executable(a:cmd)
8285 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
8286 let @@= ykeep
8287" call Dret("s:NetrwLocalExecute")
8288 return
8289 endif
8290
8291 let optargs= input(":!".a:cmd,"","file")
8292" call Decho("optargs<".optargs.">")
8293 let result= system(a:cmd.optargs)
8294" call Decho(result)
8295
8296 " strip any ansi escape sequences off
8297 let result = substitute(result,"\e\\[[0-9;]*m","","g")
8298
8299 " show user the result(s)
8300 echomsg result
8301 let @@= ykeep
8302
8303" call Dret("s:NetrwLocalExecute")
8304endfun
8305
8306" ---------------------------------------------------------------------
8307" s:NetrwLocalRename: rename a remote file or directory {{{2
8308fun! s:NetrwLocalRename(path) range
8309" call Dfunc("NetrwLocalRename(path<".a:path.">)")
8310
8311 " preparation for removing multiple files/directories
8312 let ykeep = @@
8313 let ctr = a:firstline
8314 let svpos = netrw#NetrwSavePosn()
8315
8316 " rename files given by the markfilelist
8317 if exists("s:netrwmarkfilelist_{bufnr('%')}")
8318 for oldname in s:netrwmarkfilelist_{bufnr("%")}
8319" call Decho("oldname<".oldname.">")
8320 if exists("subfrom")
8321 let newname= substitute(oldname,subfrom,subto,'')
8322" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">")
8323 else
8324 call inputsave()
8325 let newname= input("Moving ".oldname." to : ",oldname)
8326 call inputrestore()
8327 if newname =~ '^s/'
8328 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
8329 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
8330" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">")
8331 let newname = substitute(oldname,subfrom,subto,'')
8332 endif
8333 endif
8334 call rename(oldname,newname)
8335 endfor
8336 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
8337
8338 else
8339
8340 " attempt to rename files/directories
8341 while ctr <= a:lastline
8342 exe "keepj ".ctr
8343
8344 " sanity checks
8345 if line(".") < w:netrw_bannercnt
8346 let ctr= ctr + 1
8347 continue
8348 endif
8349 let curword= s:NetrwGetWord()
8350 if curword == "./" || curword == "../"
8351 let ctr= ctr + 1
8352 continue
8353 endif
8354
8355 keepj norm! 0
8356 let oldname= s:ComposePath(a:path,curword)
8357" call Decho("oldname<".oldname.">")
8358
8359 call inputsave()
8360 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
8361 call inputrestore()
8362
8363 call rename(oldname,newname)
8364" call Decho("renaming <".oldname."> to <".newname.">")
8365
8366 let ctr= ctr + 1
8367 endwhile
8368 endif
8369
8370 " refresh the directory
8371" call Decho("refresh the directory listing")
8372 keepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
8373 keepj call netrw#NetrwRestorePosn(svpos)
8374 let @@= ykeep
8375
8376" call Dret("NetrwLocalRename")
8377endfun
8378
8379" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008380" s:NetrwLocalRm: {{{2
8381fun! s:NetrwLocalRm(path) range
8382" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
8383" call Decho("firstline=".a:firstline." lastline=".a:lastline)
8384
8385 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +01008386 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008387 let ret = 0
8388 let all = 0
8389 let svpos = netrw#NetrwSavePosn()
8390
8391 if exists("s:netrwmarkfilelist_{bufnr('%')}")
8392 " remove all marked files
8393" call Decho("remove all marked files")
8394 for fname in s:netrwmarkfilelist_{bufnr("%")}
8395 let ok= s:NetrwLocalRmFile(a:path,fname,all)
8396 if ok =~ 'q\%[uit]' || ok == "no"
8397 break
8398 elseif ok =~ 'a\%[ll]'
8399 let all= 1
8400 endif
8401 endfor
8402 call s:NetrwUnMarkFile(1)
8403
8404 else
8405 " remove (multiple) files and directories
8406" call Decho("remove files in range [".a:firstline.",".a:lastline."]")
8407
8408 let ctr = a:firstline
8409 while ctr <= a:lastline
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008410 exe "keepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008411
8412 " sanity checks
8413 if line(".") < w:netrw_bannercnt
8414 let ctr= ctr + 1
8415 continue
8416 endif
8417 let curword= s:NetrwGetWord()
8418 if curword == "./" || curword == "../"
8419 let ctr= ctr + 1
8420 continue
8421 endif
8422 let ok= s:NetrwLocalRmFile(a:path,curword,all)
8423 if ok =~ 'q\%[uit]' || ok == "no"
8424 break
8425 elseif ok =~ 'a\%[ll]'
8426 let all= 1
8427 endif
8428 let ctr= ctr + 1
8429 endwhile
8430 endif
8431
8432 " refresh the directory
8433" call Decho("bufname<".bufname("%").">")
8434 if bufname("%") != "NetrwMessage"
Bram Moolenaaradc21822011-04-01 18:03:16 +02008435 keepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
8436 keepj call netrw#NetrwRestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008437 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008438 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008439
8440" call Dret("s:NetrwLocalRm")
8441endfun
8442
8443" ---------------------------------------------------------------------
8444" s:NetrwLocalRmFile: remove file fname given the path {{{2
8445" Give confirmation prompt unless all==1
8446fun! s:NetrwLocalRmFile(path,fname,all)
8447" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
8448
8449 let all= a:all
8450 let ok = ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008451 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008452 let rmfile= s:ComposePath(a:path,a:fname)
8453" call Decho("rmfile<".rmfile.">")
8454
8455 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
8456 " attempt to remove file
8457" call Decho("attempt to remove file<".rmfile.">")
8458 if !all
8459 echohl Statement
8460 call inputsave()
8461 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
8462 call inputrestore()
8463 echohl NONE
8464 if ok == ""
8465 let ok="no"
8466 endif
8467" call Decho("response: ok<".ok.">")
8468 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
8469" call Decho("response: ok<".ok."> (after sub)")
8470 if ok =~ 'a\%[ll]'
8471 let all= 1
8472 endif
8473 endif
8474
8475 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00008476 let ret= s:NetrwDelete(rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008477" call Decho("errcode=".v:shell_error." ret=".ret)
8478 endif
8479
8480 else
8481 " attempt to remove directory
8482 if !all
8483 echohl Statement
8484 call inputsave()
8485 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
8486 call inputrestore()
8487 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
8488 if ok == ""
8489 let ok="no"
8490 endif
8491 if ok =~ 'a\%[ll]'
8492 let all= 1
8493 endif
8494 endif
8495 let rmfile= substitute(rmfile,'[\/]$','','e')
8496
8497 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008498" call Decho("1st attempt: system(netrw#WinPath(".g:netrw_localrmdir.') '.shellescape(rmfile).')')
8499 call system(netrw#WinPath(g:netrw_localrmdir).' '.shellescape(rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008500" call Decho("v:shell_error=".v:shell_error)
8501
8502 if v:shell_error != 0
8503" call Decho("2nd attempt to remove directory<".rmfile.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +00008504 let errcode= s:NetrwDelete(rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008505" call Decho("errcode=".errcode)
8506
8507 if errcode != 0
8508 if has("unix")
8509" call Decho("3rd attempt to remove directory<".rmfile.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +00008510 call system("rm ".shellescape(rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008511 if v:shell_error != 0 && !exists("g:netrw_quiet")
8512 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",34)
8513 let ok="no"
8514 endif
8515 elseif !exists("g:netrw_quiet")
8516 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",35)
8517 let ok="no"
8518 endif
8519 endif
8520 endif
8521 endif
8522 endif
8523
8524" call Dret("s:NetrwLocalRmFile ".ok)
8525 return ok
8526endfun
8527
8528" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00008529" Support Functions: {{{1
8530
Bram Moolenaar488c6512005-08-11 20:09:58 +00008531" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008532" netrw#NetrwRestorePosn: restores the cursor and file position as saved by NetrwSavePosn() {{{2
8533fun! netrw#NetrwRestorePosn(...)
8534" call Dfunc("netrw#NetrwRestorePosn() a:0=".a:0." winnr=".(exists("w:netrw_winnr")? w:netrw_winnr : -1)." line=".(exists("w:netrw_line")? w:netrw_line : -1)." col=".(exists("w:netrw_col")? w:netrw_col : -1)." hline=".(exists("w:netrw_hline")? w:netrw_hline : -1))
8535 let eikeep= &ei
8536 set ei=all
8537 if expand("%") == "NetrwMessage"
8538 exe s:winBeforeErr."wincmd w"
8539 endif
8540
8541 if a:0 > 0
Bram Moolenaar15146672011-10-20 22:22:38 +02008542 exe "keepj ".a:1
Bram Moolenaarc236c162008-07-13 17:41:49 +00008543 endif
8544
8545 " restore window
8546 if exists("w:netrw_winnr")
Bram Moolenaaradc21822011-04-01 18:03:16 +02008547" call Decho("restore window: exe sil! ".w:netrw_winnr."wincmd w")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008548 exe "sil! ".w:netrw_winnr."wincmd w"
Bram Moolenaarc236c162008-07-13 17:41:49 +00008549 endif
8550 if v:shell_error == 0
8551 " as suggested by Bram M: redraw on no error
8552 " allows protocol error messages to remain visible
8553" redraw!
8554 endif
8555
8556 " restore top-of-screen line
8557 if exists("w:netrw_hline")
Bram Moolenaar15146672011-10-20 22:22:38 +02008558" call Decho("restore topofscreen: exe keepj norm! ".w:netrw_hline."G0z")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008559 exe "keepj norm! ".w:netrw_hline."G0z\<CR>"
Bram Moolenaarc236c162008-07-13 17:41:49 +00008560 endif
8561
8562 " restore position
8563 if exists("w:netrw_line") && exists("w:netrw_col")
Bram Moolenaar15146672011-10-20 22:22:38 +02008564" call Decho("restore posn: exe keepj norm! ".w:netrw_line."G0".w:netrw_col."|")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008565 exe "keepj norm! ".w:netrw_line."G0".w:netrw_col."\<bar>"
Bram Moolenaarc236c162008-07-13 17:41:49 +00008566 endif
8567
8568 let &ei= eikeep
8569" call Dret("netrw#NetrwRestorePosn")
8570endfun
8571
8572" ---------------------------------------------------------------------
8573" netrw#NetrwSavePosn: saves position of cursor on screen {{{2
8574fun! netrw#NetrwSavePosn()
8575" call Dfunc("netrw#NetrwSavePosn()")
8576 " Save current line and column
8577 let w:netrw_winnr= winnr()
8578 let w:netrw_line = line(".")
8579 let w:netrw_col = virtcol(".")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008580" call Decho("currently, win#".w:netrw_winnr." line#".w:netrw_line." col#".w:netrw_col)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008581
8582 " Save top-of-screen line
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008583 keepj norm! H0
Bram Moolenaarc236c162008-07-13 17:41:49 +00008584 let w:netrw_hline= line(".")
8585
8586 " set up string holding position parameters
8587 let ret = "let w:netrw_winnr=".w:netrw_winnr."|let w:netrw_line=".w:netrw_line."|let w:netrw_col=".w:netrw_col."|let w:netrw_hline=".w:netrw_hline
8588
Bram Moolenaaradc21822011-04-01 18:03:16 +02008589 keepj call netrw#NetrwRestorePosn()
Bram Moolenaarc236c162008-07-13 17:41:49 +00008590" call Dret("netrw#NetrwSavePosn : winnr=".w:netrw_winnr." line=".w:netrw_line." col=".w:netrw_col." hline=".w:netrw_hline)
8591 return ret
8592endfun
8593
8594" ------------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00008595" netrw#RFC2396: converts %xx into characters {{{2
8596fun! netrw#RFC2396(fname)
8597" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
8598 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t")
8599" call Dret("netrw#RFC2396 ".fname)
8600 return fname
8601endfun
8602
8603" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008604" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
8605fun! s:ComposePath(base,subdir)
8606" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
8607
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008608 if has("amiga")
Bram Moolenaarc236c162008-07-13 17:41:49 +00008609" call Decho("amiga")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008610 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +00008611 if ec != '/' && ec != ':'
8612 let ret = a:base . "/" . a:subdir
8613 else
8614 let ret = a:base . a:subdir
8615 endif
8616
8617 elseif a:subdir =~ '^\a:[/\\][^/\\]' && (has("win32") || has("win95") || has("win64") || has("win16"))
8618" call Decho("windows")
8619 let ret= a:subdir
8620
Bram Moolenaar5c736222010-01-06 20:54:52 +01008621 elseif a:base =~ '^\a:[/\\][^/\\]' && (has("win32") || has("win95") || has("win64") || has("win16"))
8622" call Decho("windows")
8623 if a:base =~ '[/\\]$'
8624 let ret= a:base.a:subdir
8625 else
8626 let ret= a:base."/".a:subdir
8627 endif
8628
Bram Moolenaarc236c162008-07-13 17:41:49 +00008629 elseif a:base =~ '^\a\+://'
8630" call Decho("remote linux/macos")
8631 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
8632 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
8633 if a:subdir == '../'
8634 if curpath =~ '[^/]/[^/]\+/$'
8635 let curpath= substitute(curpath,'[^/]\+/$','','')
8636 else
8637 let curpath=""
8638 endif
8639 let ret= urlbase.curpath
8640 else
8641 let ret= urlbase.curpath.a:subdir
8642 endif
8643" call Decho("urlbase<".urlbase.">")
8644" call Decho("curpath<".curpath.">")
8645" call Decho("ret<".ret.">")
8646
8647 else
8648" call Decho("local linux/macos")
8649 let ret = substitute(a:base."/".a:subdir,"//","/","g")
8650 if a:base =~ '^//'
8651 " keeping initial '//' for the benefit of network share listing support
8652 let ret= '/'.ret
8653 endif
8654 let ret= simplify(ret)
8655 endif
8656
8657" call Dret("s:ComposePath ".ret)
8658 return ret
8659endfun
8660
8661" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00008662" s:FileReadable: o/s independent filereadable {{{2
8663fun! s:FileReadable(fname)
8664" call Dfunc("s:FileReadable(fname<".a:fname.">)")
8665
8666 if g:netrw_cygwin
8667 let ret= filereadable(substitute(a:fname,'/cygdrive/\(.\)','\1:/',''))
8668 else
8669 let ret= filereadable(a:fname)
8670 endif
8671
8672" call Dret("s:FileReadable ".ret)
8673 return ret
8674endfun
8675
8676" ---------------------------------------------------------------------
8677" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
8678" Places correct suffix on end of temporary filename,
8679" using the suffix provided with fname
8680fun! s:GetTempfile(fname)
8681" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
8682
8683 if !exists("b:netrw_tmpfile")
8684 " get a brand new temporary filename
8685 let tmpfile= tempname()
8686" call Decho("tmpfile<".tmpfile."> : from tempname()")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008687
Bram Moolenaarc236c162008-07-13 17:41:49 +00008688 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaar9964e462007-05-05 17:54:07 +00008689" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008690
Bram Moolenaar9964e462007-05-05 17:54:07 +00008691 " sanity check -- does the temporary file's directory exist?
8692 if !isdirectory(substitute(tmpfile,'[^/]\+$','','e'))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008693" call Decho("(GetTempfile) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02008694 keepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00008695" call Dret("s:GetTempfile getcwd<".getcwd().">")
8696 return ""
8697 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008698
Bram Moolenaar9964e462007-05-05 17:54:07 +00008699 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar5c736222010-01-06 20:54:52 +01008700 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#NetrwBrowseX()
Bram Moolenaar9964e462007-05-05 17:54:07 +00008701" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008702
Bram Moolenaar9964e462007-05-05 17:54:07 +00008703 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +00008704 if g:netrw_cygwin != 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00008705 let tmpfile = substitute(tmpfile,'^\(\a\):','/cygdrive/\1','e')
8706 elseif has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008707 if !exists("+shellslash") || !&ssl
8708 let tmpfile = substitute(tmpfile,'/','\','g')
8709 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00008710 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00008711 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +00008712 endif
8713 let b:netrw_tmpfile= tmpfile
8714" call Decho("o/s dependent fixed tempname<".tmpfile.">")
8715 else
8716 " re-use temporary filename
8717 let tmpfile= b:netrw_tmpfile
8718" call Decho("tmpfile<".tmpfile."> re-using")
8719 endif
8720
8721 " use fname's suffix for the temporary file
8722 if a:fname != ""
8723 if a:fname =~ '\.[^./]\+$'
8724" call Decho("using fname<".a:fname.">'s suffix")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008725 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00008726 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008727 elseif a:fname =~ '.txz$'
8728 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +00008729 else
8730 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
8731 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00008732" call Decho("suffix<".suffix.">")
8733 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
8734" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)")
8735 let tmpfile .= suffix
8736" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">")
8737 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
8738 endif
8739 endif
8740
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008741" call Decho("(GetTempFile) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00008742" call Dret("s:GetTempfile <".tmpfile.">")
8743 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008744endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +00008745
8746" ---------------------------------------------------------------------
8747" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +00008748" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +00008749fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008750" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00008751 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user.s:machine,'')
8752 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00008753 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +00008754 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00008755 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +00008756 else
8757 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
8758 endif
8759" call Dret("s:MakeSshCmd <".sshcmd.">")
8760 return sshcmd
8761endfun
8762
8763" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008764" s:NetrwBMShow: {{{2
8765fun! s:NetrwBMShow()
8766" call Dfunc("s:NetrwBMShow()")
8767 redir => bmshowraw
8768 menu
8769 redir END
8770 let bmshowlist = split(bmshowraw,'\n')
8771 if bmshowlist != []
8772 let bmshowfuncs= filter(bmshowlist,'v:val =~ "<SNR>\\d\\+_BMShow()"')
8773 if bmshowfuncs != []
8774 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
8775 if bmshowfunc =~ '^call.*BMShow()'
Bram Moolenaaradc21822011-04-01 18:03:16 +02008776 exe "sil! keepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +00008777 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008778 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008779 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00008780" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
8781endfun
8782
8783" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02008784" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
8785fun! s:NetrwCursor()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008786 if !exists("w:netrw_liststyle")
8787 let w:netrw_liststyle= g:netrw_liststyle
8788 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02008789" 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 +02008790
8791 if &ft != "netrw"
8792 " if the current window isn't a netrw directory listing window, then use user cursorline/column
8793 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaar15146672011-10-20 22:22:38 +02008794" call Decho("case ft!=netrw: use user cul,cuc")
Bram Moolenaaradc21822011-04-01 18:03:16 +02008795 let &l:cursorline = s:netrw_usercul
8796 let &l:cursorcolumn = s:netrw_usercuc
8797
8798 elseif g:netrw_cursor == 4
8799 " all styles: cursorline, cursorcolumn
Bram Moolenaar15146672011-10-20 22:22:38 +02008800" call Decho("case g:netrw_cursor==4: setl cul cuc")
8801 setl cursorline
8802 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +02008803
8804 elseif g:netrw_cursor == 3
8805 " thin-long-tree: cursorline, user's cursorcolumn
8806 " wide : cursorline, cursorcolumn
8807 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaar15146672011-10-20 22:22:38 +02008808" call Decho("case g:netrw_cursor==3 and wide: setlocal cul cuc")
8809 setl cursorline
8810 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +02008811 else
Bram Moolenaar15146672011-10-20 22:22:38 +02008812" call Decho("case g:netrw_cursor==3 and not wide: setlocal cul (use user's cuc)")
8813 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +02008814 let &l:cursorcolumn = s:netrw_usercuc
8815 endif
8816
8817 elseif g:netrw_cursor == 2
8818 " thin-long-tree: cursorline, user's cursorcolumn
8819 " wide : cursorline, user's cursorcolumn
Bram Moolenaar15146672011-10-20 22:22:38 +02008820" call Decho("case g:netrw_cursor==2: setlocal cuc (use user's cul)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02008821 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar15146672011-10-20 22:22:38 +02008822 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +02008823
8824 elseif g:netrw_cursor == 1
8825 " thin-long-tree: user's cursorline, user's cursorcolumn
8826 " wide : cursorline, user's cursorcolumn
8827 let &l:cursorcolumn = s:netrw_usercuc
8828 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaar15146672011-10-20 22:22:38 +02008829" call Decho("case g:netrw_cursor==2 and wide: setlocal cul (use user's cuc)")
8830 set cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +02008831 else
Bram Moolenaar15146672011-10-20 22:22:38 +02008832" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02008833 let &l:cursorline = s:netrw_usercul
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008834 endif
8835
8836 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02008837 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaar15146672011-10-20 22:22:38 +02008838" call Decho("default: (use user's cul,cuc)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02008839 let &l:cursorline = s:netrw_usercul
8840 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008841 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008842
8843" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008844endfun
8845
8846" ---------------------------------------------------------------------
8847" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
8848fun! s:RestoreCursorline()
8849" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02008850 if exists("s:netrw_usercul")
8851 let &l:cursorline = s:netrw_usercul
8852 endif
8853 if exists("s:netrw_usercuc")
8854 let &l:cursorcolumn = s:netrw_usercuc
8855 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008856" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
8857endfun
8858
8859" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008860" s:NetrwDelete: Deletes a file. {{{2
8861" Uses Steve Hall's idea to insure that Windows paths stay
8862" acceptable. No effect on Unix paths.
8863" Examples of use: let result= s:NetrwDelete(path)
8864fun! s:NetrwDelete(path)
8865" call Dfunc("s:NetrwDelete(path<".a:path.">)")
8866
Bram Moolenaar5c736222010-01-06 20:54:52 +01008867 let path = netrw#WinPath(a:path)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008868 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
8869 if exists("+shellslash")
8870 let sskeep= &shellslash
8871 setlocal noshellslash
8872 let result = delete(path)
8873 let &shellslash = sskeep
8874 else
8875" call Decho("exe let result= ".a:cmd."('".path."')")
8876 let result= delete(path)
8877 endif
8878 else
8879" call Decho("let result= delete(".path.")")
8880 let result= delete(path)
8881 endif
8882 if result < 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02008883 keepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008884 endif
8885
8886" call Dret("s:NetrwDelete ".result)
8887 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +00008888endfun
8889
8890" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00008891" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01008892fun! s:NetrwEnew(...)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008893" call Dfunc("s:NetrwEnew() a:0=".a:0." bufnr($)=".bufnr("$"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01008894" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00008895
Bram Moolenaar446cb832008-06-24 21:56:24 +00008896 " grab a function-local-variable copy of buffer variables
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008897" call Decho("make function-local copy of netrw variables")
Bram Moolenaar9964e462007-05-05 17:54:07 +00008898 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
8899 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
8900 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
8901 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
8902 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
8903 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
8904 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
8905 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
8906 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
8907 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
8908 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
8909 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
8910 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
8911 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
8912 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
8913 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
8914
Bram Moolenaaradc21822011-04-01 18:03:16 +02008915 keepj call s:NetrwOptionRestore("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008916" call Decho("generate a buffer with keepjumps keepalt enew!")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008917 let netrw_keepdiff= &l:diff
Bram Moolenaaradc21822011-04-01 18:03:16 +02008918 " COMBAK: Benzinger: using tree mode, vim -o Foo/ file shows Foo/ Foo/ instead. Place return here, problem goes away (beeps result, but who knows)
8919" call Dredir("Benzinger 1:","ls!")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008920 keepj keepalt enew!
Bram Moolenaaradc21822011-04-01 18:03:16 +02008921" call Dredir("Benzinger 2:","ls!")
8922 " COMBAK: Benzinger: using tree mode, vim -o Foo/ file shows Foo/ Foo/ instead. Place return here, problem remains.
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008923 let &l:diff= netrw_keepdiff
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008924" call Decho("bufnr($)=".bufnr("$"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02008925 keepj call s:NetrwOptionSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +00008926
Bram Moolenaar446cb832008-06-24 21:56:24 +00008927 " copy function-local-variables to buffer variable equivalents
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008928" call Decho("copy function-local variables back to buffer netrw variables")
Bram Moolenaar9964e462007-05-05 17:54:07 +00008929 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
8930 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
8931 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
8932 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
8933 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
8934 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
8935 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
8936 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
8937 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
8938 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
8939 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
8940 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
8941 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
8942 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
8943 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
8944 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
8945
Bram Moolenaar5c736222010-01-06 20:54:52 +01008946 if a:0 > 0
8947 let b:netrw_curdir= a:1
8948 if b:netrw_curdir =~ '/$'
8949 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8950 file NetrwTreeListing
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008951 set bt=nowrite noswf
Bram Moolenaaradc21822011-04-01 18:03:16 +02008952 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
8953 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +01008954 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008955 exe "sil! keepalt file ".fnameescape(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +01008956 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00008957 endif
8958 endif
8959
Bram Moolenaar446cb832008-06-24 21:56:24 +00008960" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#").">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00008961endfun
8962
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008963" ---------------------------------------------------------------------
8964" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
8965fun! s:NetrwInsureWinVars()
Bram Moolenaar97d62492012-11-15 21:28:22 +01008966" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008967 if !exists("w:netrw_liststyle")
8968 let curbuf = bufnr("%")
8969 let curwin = winnr()
8970 let iwin = 1
8971 while iwin <= winnr("$")
8972 exe iwin."wincmd w"
8973 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
8974 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
8975 let winvars= w:
8976 break
8977 endif
8978 let iwin= iwin + 1
8979 endwhile
Bram Moolenaar97d62492012-11-15 21:28:22 +01008980 exe curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008981 if exists("winvars")
8982" call Decho("copying w#".iwin." window variables to w#".curwin)
8983 for k in keys(winvars)
8984 let w:{k}= winvars[k]
8985 endfor
8986 endif
8987 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008988" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008989endfun
8990
Bram Moolenaar9964e462007-05-05 17:54:07 +00008991" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008992" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
8993" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
8994fun! s:NetrwSaveWordPosn()
8995" call Dfunc("NetrwSaveWordPosn()")
8996 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
8997" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
8998endfun
8999
9000" ---------------------------------------------------------------------
9001" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
9002" changed sorting, etc. Also see s:NetrwSaveWordPosn().
9003fun! s:NetrwRestoreWordPosn()
9004" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +02009005 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009006" call Dret("NetrwRestoreWordPosn")
9007endfun
9008
9009" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00009010" s:RestoreBufVars: {{{2
9011fun! s:RestoreBufVars()
9012" call Dfunc("s:RestoreBufVars()")
9013
9014 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
9015 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
9016 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
9017 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
9018 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
9019 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
9020
9021" call Dret("s:RestoreBufVars")
9022endfun
9023
9024" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00009025" s:RemotePathAnalysis: {{{2
9026fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +02009027" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00009028
9029 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
9030 let s:method = substitute(a:dirname,dirpat,'\1','')
9031 let s:user = substitute(a:dirname,dirpat,'\2','')
9032 let s:machine = substitute(a:dirname,dirpat,'\3','')
9033 let s:port = substitute(a:dirname,dirpat,'\4','')
9034 let s:path = substitute(a:dirname,dirpat,'\5','')
9035 let s:fname = substitute(a:dirname,'^.*/\ze.','','')
9036
9037" call Decho("set up s:method <".s:method .">")
9038" call Decho("set up s:user <".s:user .">")
9039" call Decho("set up s:machine<".s:machine.">")
9040" call Decho("set up s:port <".s:port.">")
9041" call Decho("set up s:path <".s:path .">")
9042" call Decho("set up s:fname <".s:fname .">")
9043
9044" call Dret("s:RemotePathAnalysis")
9045endfun
9046
9047" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00009048" s:RemoteSystem: runs a command on a remote host using ssh {{{2
9049" Returns status
9050" Runs system() on
9051" [cd REMOTEDIRPATH;] a:cmd
9052" Note that it doesn't do shellescape(a:cmd)!
9053fun! s:RemoteSystem(cmd)
9054" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
9055 if !executable(g:netrw_ssh_cmd)
Bram Moolenaaradc21822011-04-01 18:03:16 +02009056 keepj call netrw#ErrorMsg(s:ERROR,"g:netrw_ssh_cmd<".g:netrw_ssh_cmd."> is not executable!",52)
Bram Moolenaarc236c162008-07-13 17:41:49 +00009057 elseif !exists("b:netrw_curdir")
Bram Moolenaaradc21822011-04-01 18:03:16 +02009058 keepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +00009059 else
9060 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
9061 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
9062 if remotedir != ""
9063 let cmd= cmd.' cd '.shellescape(remotedir).";"
9064 else
9065 let cmd= cmd.' '
9066 endif
9067 let cmd= cmd.a:cmd
9068" call Decho("call system(".cmd.")")
9069 let ret= system(cmd)
9070 endif
9071" call Dret("s:RemoteSystem ".ret)
9072 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +00009073endfun
9074
9075" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009076" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00009077fun! s:RestoreWinVars()
9078" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +00009079 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00009080 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
9081 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
9082 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
9083 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
9084 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
9085 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
9086 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
9087 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
9088 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
9089 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
9090 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
9091 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00009092 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
9093 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00009094 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
9095 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
9096 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
9097" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +00009098endfun
9099
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00009100" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009101" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
9102"
9103" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
9104" is true) and a command, :Rexplore, which call this function.
9105"
9106" s:nbcd_curpos_{bufnr('%')} is set up by s:NetrwBrowseChgDir()
9107fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaaradc21822011-04-01 18:03:16 +02009108" call Dfunc("s:NetrwRexplore() w:netrw_rexlocal=".w:netrw_rexlocal." w:netrw_rexdir<".w:netrw_rexdir.">")
Bram Moolenaar15146672011-10-20 22:22:38 +02009109 if !exists("w:netrw_rexlocal")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009110" " call Dret("s:NetrwRexplore() w:netrw_rexlocal doesn't exist")
Bram Moolenaar15146672011-10-20 22:22:38 +02009111 return
9112 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02009113 if w:netrw_rexlocal
9114 keepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009115 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02009116 keepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009117 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02009118 if exists("s:initbeval")
9119 set beval
9120 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009121 if exists("s:rexposn_".bufnr("%"))
9122" call Decho("(NetrwRexplore) restore posn, then unlet s:rexposn_".bufnr('%'))
9123 keepj call netrw#NetrwRestorePosn(s:rexposn_{bufnr('%')})
9124 unlet s:rexposn_{bufnr('%')}
9125 else
9126" call Decho("(NetrwRexplore) s:rexposn_".bufnr('%')." doesn't exist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009127 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009128 if exists("s:explore_match")
9129 exe "2match netrwMarkFile /".s:explore_match."/"
9130 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009131" call Dret("s:NetrwRexplore")
9132endfun
9133
9134" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00009135" s:SaveBufVars: {{{2
9136fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +01009137" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00009138
9139 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
9140 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
9141 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
9142 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
9143 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
9144 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
9145
9146" call Dret("s:SaveBufVars")
9147endfun
9148
9149" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009150" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00009151fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +01009152" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +00009153 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
9154 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
9155 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
9156 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
9157 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
9158 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
9159 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
9160 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
9161 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
9162 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
9163 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
9164 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
9165 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
9166 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
9167 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
9168 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
9169 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
9170 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
9171" call Dret("s:SaveWinVars")
9172endfun
9173
9174" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009175" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00009176" To allow separate windows to have their own activities, such as
9177" Explore **/pattern, several variables have been made window-oriented.
9178" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +00009179" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00009180" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +00009181fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +01009182" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +00009183 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
9184 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
9185 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
9186 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
9187 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
9188 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
9189 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
9190 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
9191 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
9192 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
9193" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00009194endfun
9195
9196" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009197" s:SetRexDir: set directory for :Rexplore {{{2
9198fun! s:SetRexDir(islocal,dirname)
9199" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02009200 let w:netrw_rexdir = a:dirname
9201 let w:netrw_rexlocal = a:islocal
Bram Moolenaar97d62492012-11-15 21:28:22 +01009202" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009203endfun
9204
9205" ---------------------------------------------------------------------
9206" s:Strlen: this function returns the length of a string, even if its {{{2
9207" using two-byte etc characters.
Bram Moolenaar5c736222010-01-06 20:54:52 +01009208" Solution from Nicolai Weibull, vim docs (:help strlen()), Tony Mechelynck,
9209" and a bit from me.
9210" if g:netrw_xstrlen is zero (default), then the builtin strlen() function is used.
Bram Moolenaar446cb832008-06-24 21:56:24 +00009211fun! s:Strlen(x)
9212" call Dfunc("s:Strlen(x<".a:x.">")
9213 if g:netrw_xstrlen == 1
9214 " number of codepoints (Latin a + combining circumflex is two codepoints)
9215 " (comment from TM, solution from NW)
9216 let ret= strlen(substitute(a:x,'.','c','g'))
9217
9218 elseif g:netrw_xstrlen == 2
9219 " number of spacing codepoints (Latin a + combining circumflex is one spacing
9220 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
9221 " (comment from TM, solution from TM)
9222 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
9223
9224 elseif g:netrw_xstrlen == 3
9225 " virtual length (counting, for instance, tabs as anything between 1 and
9226 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
9227 " preceded by lam, one otherwise, etc.)
9228 " (comment from TM, solution from me)
9229 let modkeep= &mod
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009230 exe "keepj norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009231 call setline(line("."),a:x)
9232 let ret= virtcol("$") - 1
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009233 keepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +00009234 let &mod= modkeep
9235
9236 else
9237 " at least give a decent default
Bram Moolenaar5c736222010-01-06 20:54:52 +01009238 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009239 endif
9240" call Dret("s:Strlen ".ret)
9241 return ret
9242endfun
9243
9244" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009245" s:TreeListMove: {{{2
9246fun! s:TreeListMove(dir)
9247" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
9248 let curline = getline('.')
9249 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
9250 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
9251 let curindent= substitute(curline,'^\([| ]*\).\{-}$','\1','')
9252 let indentm1 = substitute(curindent,'^| ','','')
9253" call Decho("prvline <".prvline."> #".line(".")-1)
9254" call Decho("curline <".curline."> #".line("."))
9255" call Decho("nxtline <".nxtline."> #".line(".")+1)
9256" call Decho("curindent<".curindent.">")
9257" call Decho("indentm1 <".indentm1.">")
9258
9259 if curline !~ '/$'
9260" call Decho('regfile')
9261 if a:dir == '[' && prvline != ''
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009262 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009263 let nl = search('^'.indentm1.'[^|]','bWe') " search backwards from regular file
9264" call Decho("regfile srch back: ".nl)
9265 elseif a:dir == ']' && nxtline != ''
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009266 keepj norm! $
Bram Moolenaar446cb832008-06-24 21:56:24 +00009267 let nl = search('^'.indentm1.'[^|]','We') " search forwards from regular file
9268" call Decho("regfile srch fwd: ".nl)
9269 endif
9270
9271 elseif a:dir == '[' && prvline != ''
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009272 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009273 let curline= line(".")
9274 let nl = search('^'.curindent.'[^|]','bWe') " search backwards From directory, same indentation
9275" call Decho("dir srch back ind: ".nl)
9276 if nl != 0
9277 if line(".") == curline-1
9278 let nl= search('^'.indentm1.'[^|]','bWe') " search backwards from directory, indentation - 1
9279" call Decho("dir srch back ind-1: ".nl)
9280 endif
9281 endif
9282
9283 elseif a:dir == ']' && nxtline != ''
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009284 keepj norm! $
Bram Moolenaar446cb832008-06-24 21:56:24 +00009285 let curline = line(".")
9286 let nl = search('^'.curindent.'[^|]','We') " search forwards from directory, same indentation
9287" call Decho("dir srch fwd ind: ".nl)
9288 if nl != 0
9289 if line(".") == curline+1
9290 let nl= search('^'.indentm1.'[^|]','We') " search forwards from directory, indentation - 1
9291" call Decho("dir srch fwd ind-1: ".nl)
9292 endif
9293 endif
9294
9295 endif
9296
9297" call Dret("s:TreeListMove")
9298endfun
9299
9300" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00009301" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
9302" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
9303" can't be called except via emenu. But due to locale, that menu line may not be called
9304" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
9305fun! s:UpdateBuffersMenu()
9306" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +02009307 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +00009308 try
Bram Moolenaaradc21822011-04-01 18:03:16 +02009309 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +00009310 catch /^Vim\%((\a\+)\)\=:E/
9311 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02009312 sil keepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +00009313 endtry
9314 endif
9315" call Dret("s:UpdateBuffersMenu")
9316endfun
9317
9318" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009319" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +02009320" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00009321fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +00009322" call Dfunc("s:UseBufWinVars()")
9323 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00009324 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
9325 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
9326 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
9327 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
9328 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
9329 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
9330 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
9331 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
9332 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 +00009333" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00009334endfun
9335
Bram Moolenaar1afcace2005-11-25 19:54:28 +00009336" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01009337" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
9338fun! netrw#WinPath(path)
9339" call Dfunc("netrw#WinPath(path<".a:path.">)")
9340 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && (has("win32") || has("win95") || has("win64") || has("win16"))
9341 " remove cygdrive prefix, if present
9342 let path = substitute(a:path,'/cygdrive/\(.\)','\1:','')
Bram Moolenaarc236c162008-07-13 17:41:49 +00009343 " remove trailing slash (Win95)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009344 let path = substitute(path, '\(\\\|/\)$', '', 'g')
Bram Moolenaarc236c162008-07-13 17:41:49 +00009345 " remove escaped spaces
9346 let path = substitute(path, '\ ', ' ', 'g')
9347 " convert slashes to backslashes
9348 let path = substitute(path, '/', '\', 'g')
9349 else
9350 let path= a:path
9351 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009352" call Dret("netrw#WinPath <".path.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +00009353 return path
9354endfun
9355
9356" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00009357" Settings Restoration: {{{2
Bram Moolenaar83bab712005-08-01 21:58:57 +00009358let &cpo= s:keepcpo
9359unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00009360
Bram Moolenaar071d4272004-06-13 20:20:40 +00009361" ------------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00009362" Modelines: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +00009363" vim:ts=8 fdm=marker