Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1 | " netrw.vim: Handles file transfer and remote directory listing across |
| 2 | " AUTOLOAD SECTION |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3 | " Date: Sep 26, 2011 |
| 4 | " Version: 143 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 5 | " Maintainer: Charles E Campbell, Jr <NdrOchip@ScampbellPfamily.AbizM-NOSPAM> |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 6 | " GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 7 | " Copyright: Copyright (C) 1999-2010 Charles E. Campbell, Jr. {{{1 |
Bram Moolenaar | 572cb56 | 2005-08-05 21:35:02 +0000 | [diff] [blame] | 8 | " 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 Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 11 | " netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 12 | " *as is* and come with no warranty of any kind, either |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 13 | " 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 Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 16 | "redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 17 | " |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 18 | " But be doers of the Word, and not only hearers, deluding your own selves {{{1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 19 | " (James 1:22 RSV) |
| 20 | " =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 21 | " Load Once: {{{1 |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 22 | if &cp || exists("g:loaded_netrw") |
| 23 | finish |
| 24 | endif |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 25 | let g:loaded_netrw = "v143" |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 26 | if v:version < 702 |
| 27 | echohl WarningMsg |
| 28 | echo "***warning*** this version of netrw needs vim 7.2" |
| 29 | echohl Normal |
| 30 | finish |
| 31 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 32 | if !exists("s:NOTE") |
| 33 | let s:NOTE = 0 |
| 34 | let s:WARNING = 1 |
| 35 | let s:ERROR = 2 |
| 36 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 37 | |
| 38 | " sanity checks |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 39 | if v:version < 700 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 40 | call netrw#ErrorMsg(s:WARNING,"you need vim version 7.0 or later for version ".g:loaded_netrw." of netrw",1) |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 41 | finish |
| 42 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 43 | |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 44 | let s:keepcpo= &cpo |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 45 | setlocal cpo&vim |
| 46 | "DechoTabOn |
| 47 | "call Decho("doing autoload/netrw.vim version ".g:loaded_netrw) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 48 | |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 49 | " ====================== |
| 50 | " Netrw Variables: {{{1 |
| 51 | " ====================== |
| 52 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 53 | " --------------------------------------------------------------------- |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 54 | " NetrwInit: initializes variables if they haven't been defined {{{2 |
| 55 | " Loosely, varname = value. |
| 56 | fun s:NetrwInit(varname,value) |
| 57 | if !exists(a:varname) |
| 58 | if type(a:value) == 0 |
| 59 | exe "let ".a:varname."=".a:value |
| 60 | elseif type(a:value) == 1 |
| 61 | exe "let ".a:varname."="."'".a:value."'" |
| 62 | else |
| 63 | exe "let ".a:varname."=".a:value |
| 64 | endif |
| 65 | endif |
| 66 | endfun |
| 67 | |
| 68 | " --------------------------------------------------------------------- |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 69 | " Netrw Constants: {{{2 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 70 | call s:NetrwInit("g:netrw_dirhist_cnt",0) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 71 | if !exists("s:LONGLIST") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 72 | call s:NetrwInit("s:THINLIST",0) |
| 73 | call s:NetrwInit("s:LONGLIST",1) |
| 74 | call s:NetrwInit("s:WIDELIST",2) |
| 75 | call s:NetrwInit("s:TREELIST",3) |
| 76 | call s:NetrwInit("s:MAXLIST" ,4) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 77 | endif |
| 78 | |
| 79 | " --------------------------------------------------------------------- |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 80 | " Default values for netrw's global protocol variables {{{2 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 81 | call s:NetrwInit("g:netrw_use_errorwindow",1) |
| 82 | |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 83 | if !exists("g:netrw_dav_cmd") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 84 | if executable("cadaver") |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 85 | let g:netrw_dav_cmd = "cadaver" |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 86 | elseif executable("curl") |
| 87 | let g:netrw_dav_cmd = "curl" |
| 88 | else |
| 89 | let g:netrw_dav_cmd = "" |
| 90 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 91 | endif |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 92 | if !exists("g:netrw_fetch_cmd") |
| 93 | if executable("fetch") |
| 94 | let g:netrw_fetch_cmd = "fetch -o" |
| 95 | else |
| 96 | let g:netrw_fetch_cmd = "" |
| 97 | endif |
| 98 | endif |
| 99 | if !exists("g:netrw_ftp_cmd") |
| 100 | let g:netrw_ftp_cmd = "ftp" |
| 101 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 102 | let s:netrw_ftp_cmd= g:netrw_ftp_cmd |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 103 | if !exists("g:netrw_http_cmd") |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 104 | if executable("elinks") |
| 105 | let g:netrw_http_cmd = "elinks" |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 106 | call s:NetrwInit("g:netrw_http_xcmd","-source >") |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 107 | elseif executable("links") |
| 108 | let g:netrw_http_cmd = "links" |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 109 | call s:NetrwInit("g:netrw_http_xcmd","-source >") |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 110 | elseif executable("curl") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 111 | let g:netrw_http_cmd = "curl" |
| 112 | call s:NetrwInit("g:netrw_http_xcmd","-o") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 113 | elseif executable("wget") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 114 | let g:netrw_http_cmd = "wget" |
| 115 | call s:NetrwInit("g:netrw_http_xcmd","-q -O") |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 116 | elseif executable("fetch") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 117 | let g:netrw_http_cmd = "fetch" |
| 118 | call s:NetrwInit("g:netrw_http_xcmd","-o") |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 119 | else |
| 120 | let g:netrw_http_cmd = "" |
| 121 | endif |
| 122 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 123 | call s:NetrwInit("g:netrw_rcp_cmd" , "rcp") |
| 124 | call s:NetrwInit("g:netrw_rsync_cmd", "rsync") |
| 125 | call s:NetrwInit("g:netrw_scp_cmd" , "scp -q") |
| 126 | call s:NetrwInit("g:netrw_sftp_cmd" , "sftp") |
| 127 | call s:NetrwInit("g:netrw_ssh_cmd" , "ssh") |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 128 | |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 129 | if (has("win32") || has("win95") || has("win64") || has("win16")) |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 130 | \ && exists("g:netrw_use_nt_rcp") |
| 131 | \ && g:netrw_use_nt_rcp |
| 132 | \ && executable( $SystemRoot .'/system32/rcp.exe') |
| 133 | let s:netrw_has_nt_rcp = 1 |
| 134 | let s:netrw_rcpmode = '-b' |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 135 | else |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 136 | let s:netrw_has_nt_rcp = 0 |
| 137 | let s:netrw_rcpmode = '' |
| 138 | endif |
| 139 | |
| 140 | " --------------------------------------------------------------------- |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 141 | " Default values for netrw's global variables {{{2 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 142 | " Cygwin Detection ------- {{{3 |
| 143 | if !exists("g:netrw_cygwin") |
| 144 | if has("win32") || has("win95") || has("win64") || has("win16") |
| 145 | if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$' |
| 146 | let g:netrw_cygwin= 1 |
| 147 | else |
| 148 | let g:netrw_cygwin= 0 |
| 149 | endif |
| 150 | else |
| 151 | let g:netrw_cygwin= 0 |
| 152 | endif |
| 153 | endif |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 154 | " Default values - a-c ---------- {{{3 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 155 | call s:NetrwInit("g:netrw_alto" , &sb) |
| 156 | call s:NetrwInit("g:netrw_altv" , &spr) |
| 157 | call s:NetrwInit("g:netrw_banner" , 1) |
| 158 | call s:NetrwInit("g:netrw_browse_split", 0) |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 159 | call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 160 | call s:NetrwInit("g:netrw_chgwin" , -1) |
| 161 | call s:NetrwInit("g:netrw_compress" , "gzip") |
| 162 | call s:NetrwInit("g:netrw_ctags" , "ctags") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 163 | if exists("g:netrw_cursorline") && !exists("g:netrw_cursor") |
| 164 | call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77) |
| 165 | let g:netrw_cursor= g:netrw_cursorline |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 166 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 167 | call s:NetrwInit("g:netrw_cursor" , 2) |
| 168 | let s:netrw_usercul = &cursorline |
| 169 | let s:netrw_usercuc = &cursorcolumn |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 170 | " Default values - d-g ---------- {{{3 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 171 | call s:NetrwInit("g:netrw_dirhist_cnt" , 0) |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 172 | call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }') |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 173 | call s:NetrwInit("g:netrw_dirhistmax" , 10) |
| 174 | call s:NetrwInit("g:netrw_fastbrowse" , 1) |
| 175 | call 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 Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 176 | if !exists("g:netrw_ftp_list_cmd") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 177 | if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin) |
| 178 | let g:netrw_ftp_list_cmd = "ls -lF" |
| 179 | let g:netrw_ftp_timelist_cmd = "ls -tlF" |
| 180 | let g:netrw_ftp_sizelist_cmd = "ls -slF" |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 181 | else |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 182 | let g:netrw_ftp_list_cmd = "dir" |
| 183 | let g:netrw_ftp_timelist_cmd = "dir" |
| 184 | let g:netrw_ftp_sizelist_cmd = "dir" |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 185 | endif |
| 186 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 187 | call s:NetrwInit("g:netrw_ftpmode",'binary') |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 188 | " Default values - h-lh ---------- {{{3 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 189 | call s:NetrwInit("g:netrw_hide",1) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 190 | if !exists("g:netrw_ignorenetrc") |
| 191 | if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$' |
| 192 | let g:netrw_ignorenetrc= 1 |
| 193 | else |
| 194 | let g:netrw_ignorenetrc= 0 |
| 195 | endif |
| 196 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 197 | call s:NetrwInit("g:netrw_keepdir",1) |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 198 | if !exists("g:netrw_list_cmd") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 199 | if g:netrw_scp_cmd =~ '^pscp' && executable("pscp") |
| 200 | " provide a 'pscp' listing command |
| 201 | if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable("c:\\private.ppk") |
| 202 | let g:netrw_scp_cmd ="pscp -i C:\\private.ppk" |
| 203 | endif |
| 204 | let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:" |
| 205 | elseif executable(g:netrw_ssh_cmd) |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 206 | " provide a default listing command |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 207 | let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa" |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 208 | else |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 209 | " call Decho(g:netrw_ssh_cmd." is not executable") |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 210 | let g:netrw_list_cmd= "" |
| 211 | endif |
| 212 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 213 | call s:NetrwInit("g:netrw_list_hide","") |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 214 | " Default values - lh-lz ---------- {{{3 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 215 | if !exists("g:netrw_localcopycmd") |
| 216 | if has("win32") || has("win95") || has("win64") || has("win16") |
| 217 | if g:netrw_cygwin |
| 218 | let g:netrw_localcopycmd= "cp" |
| 219 | else |
| 220 | let g:netrw_localcopycmd= "copy" |
| 221 | endif |
| 222 | elseif has("unix") || has("macunix") |
| 223 | let g:netrw_localcopycmd= "cp" |
| 224 | else |
| 225 | let g:netrw_localcopycmd= "" |
| 226 | endif |
| 227 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 228 | call s:NetrwInit("g:netrw_local_mkdir","mkdir") |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 229 | call s:NetrwInit("g:netrw_remote_mkdir","mkdir") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 230 | if !exists("g:netrw_localmovecmd") |
| 231 | if has("win32") || has("win95") || has("win64") || has("win16") |
| 232 | if g:netrw_cygwin |
| 233 | let g:netrw_localmovecmd= "mv" |
| 234 | else |
| 235 | let g:netrw_localmovecmd= "move" |
| 236 | endif |
| 237 | elseif has("unix") || has("macunix") |
| 238 | let g:netrw_localmovecmd= "mv" |
| 239 | else |
| 240 | let g:netrw_localmovecmd= "" |
| 241 | endif |
| 242 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 243 | call s:NetrwInit("g:netrw_local_rmdir", "rmdir") |
| 244 | call s:NetrwInit("g:netrw_liststyle" , s:THINLIST) |
| 245 | " sanity checks |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 246 | if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 247 | let g:netrw_liststyle= s:THINLIST |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 248 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 249 | if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp' |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 250 | let g:netrw_list_cmd= g:netrw_list_cmd." -l" |
| 251 | endif |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 252 | " Default values - m-r ---------- {{{3 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 253 | call s:NetrwInit("g:netrw_markfileesc" , '*./[\~') |
| 254 | call s:NetrwInit("g:netrw_maxfilenamelen", 32) |
| 255 | call s:NetrwInit("g:netrw_menu" , 1) |
| 256 | call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir") |
| 257 | call s:NetrwInit("g:netrw_mousemaps" , (exists("&mouse") && &mouse =~ '[anh]')) |
| 258 | call s:NetrwInit("g:netrw_retmap" , 0) |
| 259 | if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin) |
| 260 | call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME") |
| 261 | elseif has("win32") || has("win95") || has("win64") || has("win16") |
| 262 | call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM") |
| 263 | else |
| 264 | call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 265 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 266 | call s:NetrwInit("g:netrw_preview" , 0) |
| 267 | call s:NetrwInit("g:netrw_scpport" , "-P") |
| 268 | call s:NetrwInit("g:netrw_sshport" , "-p") |
| 269 | call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv") |
| 270 | call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm") |
| 271 | call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir") |
| 272 | call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f") |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 273 | " Default values - s ---------- {{{3 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 274 | " g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename |
| 275 | call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 276 | call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 277 | call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size |
| 278 | call s:NetrwInit("g:netrw_sort_options" , "") |
| 279 | call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...) |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 280 | if !exists("g:netrw_sort_sequence") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 281 | if has("unix") |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 282 | let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$' |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 283 | else |
| 284 | let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$' |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 285 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 286 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 287 | call s:NetrwInit("g:netrw_special_syntax" , 0) |
| 288 | call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$') |
| 289 | call s:NetrwInit("g:netrw_use_noswf" , 0) |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 290 | " Default values - t-w ---------- {{{3 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 291 | call s:NetrwInit("g:netrw_timefmt","%c") |
| 292 | call s:NetrwInit("g:netrw_xstrlen",0) |
| 293 | call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 294 | call s:NetrwInit("g:netrw_win95ftp",1) |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 295 | call s:NetrwInit("g:netrw_winsize",50) |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 296 | " --------------------------------------------------------------------- |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 297 | " Default values for netrw's script variables: {{{2 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 298 | call s:NetrwInit("g:netrw_fname_escape",' ?&;%') |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 299 | if has("win32") || has("win95") || has("win64") || has("win16") |
| 300 | call s:NetrwInit("g:netrw_glob_escape",'[]*?`{$') |
| 301 | else |
| 302 | call s:NetrwInit("g:netrw_glob_escape",'[]*?`{~$\') |
| 303 | endif |
| 304 | call s:NetrwInit("g:netrw_menu_escape",'./&? \') |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 305 | call s:NetrwInit("g:netrw_tmpfile_escape",' &;') |
| 306 | call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"") |
Bram Moolenaar | 8299df9 | 2004-07-10 09:47:34 +0000 | [diff] [blame] | 307 | |
| 308 | " BufEnter event ignored by decho when following variable is true |
| 309 | " Has a side effect that doau BufReadPost doesn't work, so |
| 310 | " files read by network transfer aren't appropriately highlighted. |
| 311 | "let g:decho_bufenter = 1 "Decho |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 312 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 313 | " ====================== |
| 314 | " Netrw Initialization: {{{1 |
| 315 | " ====================== |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 316 | if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on") |
| 317 | let s:initbeval = &beval |
| 318 | let &l:bexpr = "netrw#NetrwBalloonHelp()" |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 319 | set beval |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 320 | au BufWinEnter,WinEnter * if &ft == "netrw"|set beval|else|let &beval= s:initbeval|endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 321 | endif |
| 322 | |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 323 | " ============================== |
| 324 | " Netrw Utility Functions: {{{1 |
| 325 | " ============================== |
| 326 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 327 | " --------------------------------------------------------------------- |
| 328 | " netrw#NetrwBalloonHelp: {{{2 |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 329 | if v:version >= 700 && has("balloon_eval") && &beval == 1 && has("syntax") && exists("g:syntax_on") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 330 | fun! netrw#NetrwBalloonHelp() |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 331 | if !exists("w:netrw_bannercnt") || v:beval_lnum >= w:netrw_bannercnt || (exists("g:netrw_nobeval") && g:netrw_nobeval) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 332 | let mesg= "" |
| 333 | elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing" |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 334 | let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file" |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 335 | elseif getline(v:beval_lnum) =~ '^"\s*/' |
| 336 | let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window" |
| 337 | elseif v:beval_text == "Sorted" || v:beval_text == "by" |
| 338 | let mesg = 's: sort by name, time, or file size r: reverse sorting order mt: mark target' |
| 339 | elseif v:beval_text == "Sort" || v:beval_text == "sequence" |
| 340 | let mesg = "S: edit sorting sequence" |
| 341 | elseif v:beval_text == "Hiding" || v:beval_text == "Showing" |
| 342 | let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix" |
| 343 | elseif v:beval_text == "Quick" || v:beval_text == "Help" |
| 344 | let mesg = "Help: press <F1>" |
| 345 | elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt" |
| 346 | let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target" |
| 347 | else |
| 348 | let mesg= "" |
| 349 | endif |
| 350 | return mesg |
| 351 | endfun |
| 352 | endif |
| 353 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 354 | " ------------------------------------------------------------------------ |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 355 | " s:NetrwOptionSave: save options and set to "standard" form {{{2 |
| 356 | " 06/08/07 : removed call to NetrwSafeOptions(), either placed |
| 357 | " immediately after NetrwOptionSave() calls in NetRead |
| 358 | " and NetWrite, or after the s:NetrwEnew() call in |
| 359 | " NetrwBrowse. |
| 360 | " vt: normally its "w:" or "s:" (a variable type) |
| 361 | fun! s:NetrwOptionSave(vt) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 362 | " call Dfunc("s:NetrwOptionSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 363 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 364 | " call Decho(a:vt."netrw_optionsave".(exists("{a:vt}netrw_optionsave")? ("=".{a:vt}netrw_optionsave) : " doesn't exist")) |
| 365 | if !exists("{a:vt}netrw_optionsave") |
| 366 | let {a:vt}netrw_optionsave= 1 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 367 | else |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 368 | " call Dret("s:NetrwOptionSave : options already saved") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 369 | return |
| 370 | endif |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 371 | " call Decho("fo=".&fo.(exists("&acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 372 | |
| 373 | " Save current settings and current directory |
| 374 | let s:yykeep = @@ |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 375 | if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 376 | let {a:vt}netrw_aikeep = &l:ai |
| 377 | let {a:vt}netrw_awkeep = &l:aw |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 378 | let {a:vt}netrw_bhkeep = &l:bh |
| 379 | let {a:vt}netrw_blkeep = &l:bl |
| 380 | let {a:vt}netrw_btkeep = &l:bt |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 381 | let {a:vt}netrw_bombkeep = &l:bomb |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 382 | let {a:vt}netrw_cikeep = &l:ci |
| 383 | let {a:vt}netrw_cinkeep = &l:cin |
| 384 | let {a:vt}netrw_cinokeep = &l:cino |
| 385 | let {a:vt}netrw_comkeep = &l:com |
| 386 | let {a:vt}netrw_cpokeep = &l:cpo |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 387 | let {a:vt}netrw_diffkeep = &l:diff |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 388 | let {a:vt}netrw_fenkeep = &l:fen |
| 389 | let {a:vt}netrw_ffkeep = &l:ff |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 390 | let {a:vt}netrw_fokeep = &l:fo " formatoptions |
| 391 | let {a:vt}netrw_gdkeep = &l:gd " gdefault |
| 392 | let {a:vt}netrw_hidkeep = &l:hidden |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 393 | let {a:vt}netrw_imkeep = &l:im |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 394 | let {a:vt}netrw_iskkeep = &l:isk |
| 395 | let {a:vt}netrw_lskeep = &l:ls |
| 396 | let {a:vt}netrw_makeep = &l:ma |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 397 | let {a:vt}netrw_magickeep = &l:magic |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 398 | let {a:vt}netrw_modkeep = &l:mod |
| 399 | let {a:vt}netrw_nukeep = &l:nu |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 400 | let {a:vt}netrw_repkeep = &l:report |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 401 | let {a:vt}netrw_rokeep = &l:ro |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 402 | let {a:vt}netrw_selkeep = &l:sel |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 403 | let {a:vt}netrw_spellkeep = &l:spell |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 404 | let {a:vt}netrw_tskeep = &l:ts |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 405 | let {a:vt}netrw_twkeep = &l:tw " textwidth |
| 406 | let {a:vt}netrw_wigkeep = &l:wig " wildignore |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 407 | let {a:vt}netrw_wrapkeep = &l:wrap |
| 408 | let {a:vt}netrw_writekeep = &l:write |
| 409 | if g:netrw_use_noswf && has("win32") && !has("win95") |
| 410 | let {a:vt}netrw_swfkeep = &l:swf |
| 411 | endif |
| 412 | |
| 413 | " save a few selected netrw-related variables |
| 414 | if g:netrw_keepdir |
| 415 | let {a:vt}netrw_dirkeep = getcwd() |
| 416 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 417 | if has("win32") && !has("win95") |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 418 | let {a:vt}netrw_swfkeep = &l:swf " swapfile |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 419 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 420 | if &go =~# 'a' | sil! let {a:vt}netrw_regstar = @* | endif |
| 421 | sil! let {a:vt}netrw_regslash= @/ |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 422 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 423 | " call Dret("s:NetrwOptionSave : win#".winnr()." buf#".bufnr("%")) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 424 | endfun |
| 425 | |
| 426 | " ------------------------------------------------------------------------ |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 427 | " s:NetrwOptionRestore: restore options {{{2 |
| 428 | fun! s:NetrwOptionRestore(vt) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 429 | " call Dfunc("s:NetrwOptionRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")." winnr($)=".winnr("$")) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 430 | if !exists("{a:vt}netrw_optionsave") |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 431 | if exists("s:nbcd_curpos_{bufnr('%')}") |
| 432 | " call Decho("restoring previous position") |
| 433 | keepj call netrw#NetrwRestorePosn(s:nbcd_curpos_{bufnr('%')}) |
| 434 | " unlet s:nbcd_curpos_{bufnr('%')} |
| 435 | else |
| 436 | " call Decho("no previous position") |
| 437 | endif |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 438 | " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 439 | " call Dret("s:NetrwOptionRestore : ".a:vt."netrw_optionsave doesn't exist") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 440 | return |
| 441 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 442 | unlet {a:vt}netrw_optionsave |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 443 | |
| 444 | if exists("&acd") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 445 | if exists("{a:vt}netrw_acdkeep") |
| 446 | " call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd) |
| 447 | let curdir = getcwd() |
| 448 | let &l:acd = {a:vt}netrw_acdkeep |
| 449 | unlet {a:vt}netrw_acdkeep |
| 450 | if &l:acd |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 451 | " call Decho("exe keepj lcd ".fnameescape(curdir)) " NOTE: was g:netrw_fname_escape for some reason |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 452 | try |
| 453 | if !exists("&l:acd") && !&l:acd |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 454 | exe 'keepj lcd '.fnameescape(curdir) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 455 | endif |
| 456 | catch /^Vim\%((\a\+)\)\=:E472/ |
| 457 | call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".curdir."> (permissions?)",61) |
| 458 | endtry |
| 459 | endif |
| 460 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 461 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 462 | if exists("{a:vt}netrw_aikeep") |let &l:ai = {a:vt}netrw_aikeep |unlet {a:vt}netrw_aikeep |endif |
| 463 | if exists("{a:vt}netrw_awkeep") |let &l:aw = {a:vt}netrw_awkeep |unlet {a:vt}netrw_awkeep |endif |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 464 | if exists("{a:vt}netrw_bhkeep") |let &l:bh = {a:vt}netrw_bhkeep |unlet {a:vt}netrw_bhkeep |endif |
| 465 | if exists("{a:vt}netrw_blkeep") |let &l:bl = {a:vt}netrw_blkeep |unlet {a:vt}netrw_blkeep |endif |
| 466 | if exists("{a:vt}netrw_btkeep") |let &l:bt = {a:vt}netrw_btkeep |unlet {a:vt}netrw_btkeep |endif |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 467 | if exists("{a:vt}netrw_bombkeep") |let &l:bomb = {a:vt}netrw_bombkeep |unlet {a:vt}netrw_bombkeep |endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 468 | if exists("{a:vt}netrw_cikeep") |let &l:ci = {a:vt}netrw_cikeep |unlet {a:vt}netrw_cikeep |endif |
| 469 | if exists("{a:vt}netrw_cinkeep") |let &l:cin = {a:vt}netrw_cinkeep |unlet {a:vt}netrw_cinkeep |endif |
| 470 | if exists("{a:vt}netrw_cinokeep") |let &l:cino = {a:vt}netrw_cinokeep |unlet {a:vt}netrw_cinokeep |endif |
| 471 | if exists("{a:vt}netrw_comkeep") |let &l:com = {a:vt}netrw_comkeep |unlet {a:vt}netrw_comkeep |endif |
| 472 | if exists("{a:vt}netrw_cpokeep") |let &l:cpo = {a:vt}netrw_cpokeep |unlet {a:vt}netrw_cpokeep |endif |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 473 | if exists("{a:vt}netrw_diffkeep") |let &l:diff = {a:vt}netrw_diffkeep |unlet {a:vt}netrw_diffkeep |endif |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 474 | if exists("{a:vt}netrw_fenkeep") |let &l:fen = {a:vt}netrw_fenkeep |unlet {a:vt}netrw_fenkeep |endif |
| 475 | if exists("{a:vt}netrw_ffkeep") |let &l:ff = {a:vt}netrw_ffkeep |unlet {a:vt}netrw_ffkeep |endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 476 | if exists("{a:vt}netrw_fokeep") |let &l:fo = {a:vt}netrw_fokeep |unlet {a:vt}netrw_fokeep |endif |
| 477 | if exists("{a:vt}netrw_gdkeep") |let &l:gd = {a:vt}netrw_gdkeep |unlet {a:vt}netrw_gdkeep |endif |
| 478 | if exists("{a:vt}netrw_hidkeep") |let &l:hidden = {a:vt}netrw_hidkeep |unlet {a:vt}netrw_hidkeep |endif |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 479 | if exists("{a:vt}netrw_imkeep") |let &l:im = {a:vt}netrw_imkeep |unlet {a:vt}netrw_imkeep |endif |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 480 | if exists("{a:vt}netrw_iskkeep") |let &l:isk = {a:vt}netrw_iskkeep |unlet {a:vt}netrw_iskkeep |endif |
| 481 | if exists("{a:vt}netrw_lskeep") |let &l:ls = {a:vt}netrw_lskeep |unlet {a:vt}netrw_lskeep |endif |
| 482 | if exists("{a:vt}netrw_makeep") |let &l:ma = {a:vt}netrw_makeep |unlet {a:vt}netrw_makeep |endif |
| 483 | if exists("{a:vt}netrw_magickeep")|let &l:magic = {a:vt}netrw_magickeep |unlet {a:vt}netrw_magickeep|endif |
| 484 | if exists("{a:vt}netrw_modkeep") |let &l:mod = {a:vt}netrw_modkeep |unlet {a:vt}netrw_modkeep |endif |
| 485 | if exists("{a:vt}netrw_nukeep") |let &l:nu = {a:vt}netrw_nukeep |unlet {a:vt}netrw_nukeep |endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 486 | if exists("{a:vt}netrw_repkeep") |let &l:report = {a:vt}netrw_repkeep |unlet {a:vt}netrw_repkeep |endif |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 487 | if exists("{a:vt}netrw_rokeep") |let &l:ro = {a:vt}netrw_rokeep |unlet {a:vt}netrw_rokeep |endif |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 488 | if exists("{a:vt}netrw_selkeep") |let &l:sel = {a:vt}netrw_selkeep |unlet {a:vt}netrw_selkeep |endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 489 | if exists("{a:vt}netrw_spellkeep")|let &l:spell = {a:vt}netrw_spellkeep |unlet {a:vt}netrw_spellkeep|endif |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 490 | if exists("{a:vt}netrw_tskeep") |let &l:ts = {a:vt}netrw_tskeep |unlet {a:vt}netrw_tskeep |endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 491 | if exists("{a:vt}netrw_twkeep") |let &l:tw = {a:vt}netrw_twkeep |unlet {a:vt}netrw_twkeep |endif |
| 492 | if exists("{a:vt}netrw_wigkeep") |let &l:wig = {a:vt}netrw_wigkeep |unlet {a:vt}netrw_wigkeep |endif |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 493 | if exists("{a:vt}netrw_wrapkeep") |let &l:wrap = {a:vt}netrw_wrapkeep |unlet {a:vt}netrw_wrapkeep |endif |
| 494 | if exists("{a:vt}netrw_writekeep")|let &l:write = {a:vt}netrw_writekeep |unlet {a:vt}netrw_writekeep|endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 495 | if exists("s:yykeep") |let @@ = s:yykeep |unlet s:yykeep |endif |
| 496 | if exists("{a:vt}netrw_swfkeep") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 497 | if &directory == "" |
| 498 | " user hasn't specified a swapfile directory; |
| 499 | " netrw will temporarily set the swapfile directory |
| 500 | " to the current directory as returned by getcwd(). |
| 501 | let &l:directory = getcwd() |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 502 | sil! let &l:swf = {a:vt}netrw_swfkeep |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 503 | setlocal directory= |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 504 | unlet {a:vt}netrw_swfkeep |
| 505 | elseif &l:swf != {a:vt}netrw_swfkeep |
| 506 | " following line causes a Press ENTER in windows -- can't seem to work around it!!! |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 507 | sil! let &l:swf= {a:vt}netrw_swfkeep |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 508 | unlet {a:vt}netrw_swfkeep |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 509 | endif |
| 510 | endif |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 511 | if exists("{a:vt}netrw_dirkeep") && isdirectory({a:vt}netrw_dirkeep) && g:netrw_keepdir |
| 512 | let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g') |
| 513 | if exists("{a:vt}netrw_dirkeep") |exe "keepj lcd ".fnameescape(dirkeep)|unlet {a:vt}netrw_dirkeep |endif |
| 514 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 515 | if exists("{a:vt}netrw_regstar") |sil! let @*= {a:vt}netrw_regstar |unlet {a:vt}netrw_regstar |endif |
| 516 | if exists("{a:vt}netrw_regslash")|sil! let @/= {a:vt}netrw_regslash|unlet {a:vt}netrw_regslash|endif |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 517 | if exists("s:nbcd_curpos_{bufnr('%')}") |
| 518 | " call Decho("restoring previous position") |
| 519 | keepj call netrw#NetrwRestorePosn(s:nbcd_curpos_{bufnr('%')}) |
| 520 | " unlet s:nbcd_curpos_{bufnr('%')} |
| 521 | else |
| 522 | " call Decho("no previous position") |
| 523 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 524 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 525 | " call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd) |
| 526 | " call Decho("fo=".&fo.(exists("&acd")? " acd=".&acd : " acd doesn't exist")) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 527 | " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap) |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 528 | " call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist")) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 529 | " call Dret("s:NetrwOptionRestore : win#".winnr()." buf#".bufnr("%")) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 530 | endfun |
| 531 | |
| 532 | " --------------------------------------------------------------------- |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 533 | " s:NetrwSafeOptions: sets options to help netrw do its job {{{2 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 534 | fun! s:NetrwSafeOptions() |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 535 | " call Dfunc("s:NetrwSafeOptions() win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$")) |
| 536 | " call Decho("win#".winnr()."'s ft=".&ft) |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 537 | if exists("&acd") | setlocal noacd | endif |
| 538 | setlocal noai |
| 539 | setlocal noaw |
| 540 | setlocal nobomb |
| 541 | setlocal noci |
| 542 | setlocal nocin |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 543 | setlocal cino= |
| 544 | setlocal com= |
| 545 | setlocal cpo-=aA |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 546 | setlocal fo=nroql2 |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 547 | setlocal nohid |
| 548 | setlocal noim |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 549 | setlocal isk+=@ isk+=* isk+=/ |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 550 | setlocal magic |
| 551 | setlocal report=10000 |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 552 | setlocal sel=inclusive |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 553 | setlocal nospell |
| 554 | setlocal tw=0 |
| 555 | setlocal wig= |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 556 | if g:netrw_use_noswf && has("win32") && !has("win95") |
| 557 | setlocal noswf |
| 558 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 559 | call s:NetrwCursor() |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 560 | |
| 561 | " allow the user to override safe options |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 562 | " call Decho("ft<".&ft."> ei=".&ei) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 563 | if &ft == "netrw" |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 564 | " call Decho("do any netrw FileType autocmds") |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 565 | sil! keepalt keepj doau FileType netrw |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 566 | endif |
| 567 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 568 | " call Decho("fo=".&fo.(exists("&acd")? " acd=".&acd : " acd doesn't exist")) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 569 | " call Dret("s:NetrwSafeOptions") |
| 570 | endfun |
| 571 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 572 | " --------------------------------------------------------------------- |
| 573 | " netrw#NetrwClean: remove netrw {{{2 |
| 574 | " supports :NetrwClean -- remove netrw from first directory on runtimepath |
| 575 | " :NetrwClean! -- remove netrw from all directories on runtimepath |
| 576 | fun! netrw#NetrwClean(sys) |
| 577 | " call Dfunc("netrw#NetrwClean(sys=".a:sys.")") |
| 578 | |
| 579 | if a:sys |
| 580 | let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No") |
| 581 | else |
| 582 | let choice= confirm("Remove personal copy of netrw?","&Yes\n&No") |
| 583 | endif |
| 584 | " call Decho("choice=".choice) |
| 585 | let diddel= 0 |
| 586 | let diddir= "" |
| 587 | |
| 588 | if choice == 1 |
| 589 | for dir in split(&rtp,',') |
| 590 | if filereadable(dir."/plugin/netrwPlugin.vim") |
| 591 | " call Decho("removing netrw-related files from ".dir) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 592 | if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif |
| 593 | if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif |
| 594 | if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif |
| 595 | if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif |
| 596 | if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif |
| 597 | if s:NetrwDelete(dir."/syntax/netrwlist.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrwlist.vim",55) |endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 598 | let diddir= dir |
| 599 | let diddel= diddel + 1 |
| 600 | if !a:sys|break|endif |
| 601 | endif |
| 602 | endfor |
| 603 | endif |
| 604 | |
| 605 | echohl WarningMsg |
| 606 | if diddel == 0 |
| 607 | echomsg "netrw is either not installed or not removable" |
| 608 | elseif diddel == 1 |
| 609 | echomsg "removed one copy of netrw from <".diddir.">" |
| 610 | else |
| 611 | echomsg "removed ".diddel." copies of netrw" |
| 612 | endif |
| 613 | echohl None |
| 614 | |
| 615 | " call Dret("netrw#NetrwClean") |
| 616 | endfun |
| 617 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 618 | " --------------------------------------------------------------------- |
| 619 | " netrw#Nread: {{{2 |
| 620 | fun! netrw#Nread(mode,fname) |
| 621 | " call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)") |
| 622 | call netrw#NetrwSavePosn() |
| 623 | call netrw#NetRead(a:mode,a:fname) |
| 624 | call netrw#NetrwRestorePosn() |
| 625 | " call Dret("netrw#Nread") |
| 626 | endfun |
| 627 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 628 | " ------------------------------------------------------------------------ |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 629 | " Netrw Transfer Functions: {{{1 |
| 630 | " =============================== |
| 631 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 632 | " ------------------------------------------------------------------------ |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 633 | " netrw#NetRead: responsible for reading a file over the net {{{2 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 634 | " mode: =0 read remote file and insert before current line |
| 635 | " =1 read remote file and insert after current line |
| 636 | " =2 replace with remote file |
| 637 | " =3 obtain file, but leave in temporary format |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 638 | fun! netrw#NetRead(mode,...) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 639 | " call Dfunc("netrw#NetRead(mode=".a:mode.",...) a:0=".a:0." ".g:loaded_netrw) |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 640 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 641 | " NetRead: save options {{{3 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 642 | call s:NetrwOptionSave("w:") |
| 643 | call s:NetrwSafeOptions() |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 644 | call s:RestoreCursorline() |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 645 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 646 | " NetRead: interpret mode into a readcmd {{{3 |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 647 | if a:mode == 0 " read remote file before current line |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 648 | let readcmd = "0r" |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 649 | elseif a:mode == 1 " read file after current line |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 650 | let readcmd = "r" |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 651 | elseif a:mode == 2 " replace with remote file |
| 652 | let readcmd = "%r" |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 653 | elseif a:mode == 3 " skip read of file (leave as temporary) |
| 654 | let readcmd = "t" |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 655 | else |
| 656 | exe a:mode |
| 657 | let readcmd = "r" |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 658 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 659 | let ichoice = (a:0 == 0)? 0 : 1 |
| 660 | " call Decho("readcmd<".readcmd."> ichoice=".ichoice) |
| 661 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 662 | " NetRead: get temporary filename {{{3 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 663 | let tmpfile= s:GetTempfile("") |
| 664 | if tmpfile == "" |
| 665 | " call Dret("netrw#NetRead : unable to get a tempfile!") |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 666 | return |
| 667 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 668 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 669 | while ichoice <= a:0 |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 670 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 671 | " attempt to repeat with previous host-file-etc |
| 672 | if exists("b:netrw_lastfile") && a:0 == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 673 | " call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 674 | let choice = b:netrw_lastfile |
| 675 | let ichoice= ichoice + 1 |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 676 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 677 | else |
| 678 | exe "let choice= a:" . ichoice |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 679 | " call Decho("no lastfile: choice<" . choice . ">") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 680 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 681 | if match(choice,"?") == 0 |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 682 | " give help |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 683 | echomsg 'NetRead Usage:' |
| 684 | echomsg ':Nread machine:path uses rcp' |
| 685 | echomsg ':Nread "machine path" uses ftp with <.netrc>' |
| 686 | echomsg ':Nread "machine id password path" uses ftp' |
| 687 | echomsg ':Nread dav://machine[:port]/path uses cadaver' |
| 688 | echomsg ':Nread fetch://machine/path uses fetch' |
| 689 | echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>' |
| 690 | echomsg ':Nread http://[user@]machine/path uses http wget' |
| 691 | echomsg ':Nread rcp://[user@]machine/path uses rcp' |
| 692 | echomsg ':Nread rsync://machine[:port]/path uses rsync' |
| 693 | echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp' |
| 694 | echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp' |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 695 | sleep 4 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 696 | break |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 697 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 698 | elseif match(choice,'^"') != -1 |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 699 | " Reconstruct Choice if choice starts with '"' |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 700 | " call Decho("reconstructing choice") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 701 | if match(choice,'"$') != -1 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 702 | " case "..." |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 703 | let choice= strpart(choice,1,strlen(choice)-2) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 704 | else |
| 705 | " case "... ... ..." |
| 706 | let choice = strpart(choice,1,strlen(choice)-1) |
| 707 | let wholechoice = "" |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 708 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 709 | while match(choice,'"$') == -1 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 710 | let wholechoice = wholechoice . " " . choice |
| 711 | let ichoice = ichoice + 1 |
| 712 | if ichoice > a:0 |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 713 | if !exists("g:netrw_quiet") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 714 | call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3) |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 715 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 716 | " call Dret("netrw#NetRead :2 getcwd<".getcwd().">") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 717 | return |
| 718 | endif |
| 719 | let choice= a:{ichoice} |
| 720 | endwhile |
| 721 | let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1) |
| 722 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 723 | endif |
| 724 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 725 | |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 726 | " call Decho("choice<" . choice . ">") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 727 | let ichoice= ichoice + 1 |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 728 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 729 | " NetRead: Determine method of read (ftp, rcp, etc) {{{3 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 730 | call s:NetrwMethod(choice) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 731 | if !exists("b:netrw_method") || b:netrw_method < 0 |
| 732 | " call Dfunc("netrw#NetRead : unsupported method") |
| 733 | return |
| 734 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 735 | let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 736 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 737 | " Check if NetrwBrowse() should be handling this request |
| 738 | " call Decho("checking if NetrwBrowse() should handle choice<".choice."> with netrw_list_cmd<".g:netrw_list_cmd.">") |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 739 | if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://' |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 740 | " call Decho("yes, choice matches '^.*[\/]$'") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 741 | keepj call s:NetrwBrowse(0,choice) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 742 | " call Dret("netrw#NetRead :3 getcwd<".getcwd().">") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 743 | return |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 744 | endif |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 745 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 746 | " ============ |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 747 | " NetRead: Perform Protocol-Based Read {{{3 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 748 | " =========================== |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 749 | if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 |
| 750 | echo "(netrw) Processing your read request..." |
| 751 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 752 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 753 | "......................................... |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 754 | " NetRead: (rcp) NetRead Method #1 {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 755 | if b:netrw_method == 1 " read with rcp |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 756 | " call Decho("read via rcp (method #1)") |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 757 | " ER: nothing done with g:netrw_uid yet? |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 758 | " ER: on Win2K" rcp machine[.user]:file tmpfile |
| 759 | " ER: if machine contains '.' adding .user is required (use $USERNAME) |
| 760 | " ER: the tmpfile is full path: rcp sees C:\... as host C |
| 761 | if s:netrw_has_nt_rcp == 1 |
| 762 | if exists("g:netrw_uid") && ( g:netrw_uid != "" ) |
| 763 | let uid_machine = g:netrw_machine .'.'. g:netrw_uid |
| 764 | else |
| 765 | " Any way needed it machine contains a '.' |
| 766 | let uid_machine = g:netrw_machine .'.'. $USERNAME |
| 767 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 768 | else |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 769 | if exists("g:netrw_uid") && ( g:netrw_uid != "" ) |
| 770 | let uid_machine = g:netrw_uid .'@'. g:netrw_machine |
| 771 | else |
| 772 | let uid_machine = g:netrw_machine |
| 773 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 774 | endif |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 775 | " call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".shellescape(uid_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1)) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 776 | exe s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".shellescape(uid_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 777 | let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 778 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 779 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 780 | "......................................... |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 781 | " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 782 | elseif b:netrw_method == 2 " read with ftp + <.netrc> |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 783 | " call Decho("read via ftp+.netrc (method #2)") |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 784 | let netrw_fname= b:netrw_fname |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 785 | keepj call s:SaveBufVars()|new|keepj call s:RestoreBufVars() |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 786 | let filtbuf= bufnr("%") |
Bram Moolenaar | 8299df9 | 2004-07-10 09:47:34 +0000 | [diff] [blame] | 787 | setlocal ff=unix |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 788 | keepj put =g:netrw_ftpmode |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 789 | " call Decho("filter input: ".getline(line("$"))) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 790 | if exists("g:netrw_ftpextracmd") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 791 | keepj put =g:netrw_ftpextracmd |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 792 | " call Decho("filter input: ".getline(line("$"))) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 793 | endif |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 794 | call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile) |
| 795 | " call Decho("filter input: ".getline(line("$"))) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 796 | if exists("g:netrw_port") && g:netrw_port != "" |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 797 | " call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)) |
| 798 | exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 799 | else |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 800 | " call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)) |
| 801 | exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 802 | endif |
| 803 | " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) |
Bram Moolenaar | 83bab71 | 2005-08-01 21:58:57 +0000 | [diff] [blame] | 804 | if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying ' |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 805 | let debugkeep = &debug |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 806 | setlocal debug=msg |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 807 | keepj call netrw#ErrorMsg(s:ERROR,getline(1),4) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 808 | let &debug = debugkeep |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 809 | endif |
Bram Moolenaar | ed39e1d | 2008-08-09 17:55:22 +0000 | [diff] [blame] | 810 | call s:SaveBufVars() |
| 811 | bd! |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 812 | if bufname("%") == "" && getline("$") == "" && line('$') == 1 |
| 813 | " needed when one sources a file in a nolbl setting window via ftp |
Bram Moolenaar | ed39e1d | 2008-08-09 17:55:22 +0000 | [diff] [blame] | 814 | q! |
| 815 | endif |
| 816 | call s:RestoreBufVars() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 817 | let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 818 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 819 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 820 | "......................................... |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 821 | " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 822 | elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname |
| 823 | " Construct execution string (four lines) which will be passed through filter |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 824 | " call Decho("read via ftp+mipf (method #3)") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 825 | let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 826 | keepj call s:SaveBufVars()|new|keepj call s:RestoreBufVars() |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 827 | let filtbuf= bufnr("%") |
Bram Moolenaar | 8299df9 | 2004-07-10 09:47:34 +0000 | [diff] [blame] | 828 | setlocal ff=unix |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 829 | if exists("g:netrw_port") && g:netrw_port != "" |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 830 | keepj put ='open '.g:netrw_machine.' '.g:netrw_port |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 831 | " call Decho("filter input: ".getline('.')) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 832 | else |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 833 | keepj put ='open '.g:netrw_machine |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 834 | " call Decho("filter input: ".getline('.')) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 835 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 836 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 837 | if exists("g:netrw_ftp") && g:netrw_ftp == 1 |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 838 | keepj put =g:netrw_uid |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 839 | " call Decho("filter input: ".getline('.')) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 840 | keepj put ='\"'.s:netrw_passwd.'\"' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 841 | " call Decho("filter input: ".getline('.')) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 842 | else |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 843 | keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 844 | " call Decho("filter input: ".getline('.')) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 845 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 846 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 847 | if exists("g:netrw_ftpmode") && g:netrw_ftpmode != "" |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 848 | keepj put =g:netrw_ftpmode |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 849 | " call Decho("filter input: ".getline('.')) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 850 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 851 | if exists("g:netrw_ftpextracmd") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 852 | keepj put =g:netrw_ftpextracmd |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 853 | " call Decho("filter input: ".getline('.')) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 854 | endif |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 855 | keepj put ='get \"'.netrw_fname.'\" '.tmpfile |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 856 | " call Decho("filter input: ".getline('.')) |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 857 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 858 | " perform ftp: |
| 859 | " -i : turns off interactive prompting from ftp |
| 860 | " -n unix : DON'T use <.netrc>, even though it exists |
| 861 | " -n win32: quit being obnoxious about password |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 862 | keepj norm! 1Gdd |
| 863 | " call Decho("executing: %!".s:netrw_ftp_cmd." -i -n") |
| 864 | exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i -n" |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 865 | " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) |
| 866 | if getline(1) !~ "^$" |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 867 | " call Decho("error<".getline(1).">") |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 868 | if !exists("g:netrw_quiet") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 869 | call netrw#ErrorMsg(s:ERROR,getline(1),5) |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 870 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 871 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 872 | call s:SaveBufVars()|bd!|call s:RestoreBufVars() |
| 873 | let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 874 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 875 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 876 | "......................................... |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 877 | " NetRead: (scp) NetRead Method #4 {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 878 | elseif b:netrw_method == 4 " read with scp |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 879 | " call Decho("read via scp (method #4)") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 880 | if exists("g:netrw_port") && g:netrw_port != "" |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame] | 881 | let useport= " ".g:netrw_scpport." ".g:netrw_port |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 882 | else |
| 883 | let useport= "" |
| 884 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 885 | " call Decho("exe ".s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1)) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 886 | exe s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 887 | let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 888 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 889 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 890 | "......................................... |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 891 | " NetRead: (http) NetRead Method #5 (wget) {{{3 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 892 | elseif b:netrw_method == 5 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 893 | " call Decho("read via http (method #5)") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 894 | if g:netrw_http_cmd == "" |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 895 | if !exists("g:netrw_quiet") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 896 | call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6) |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 897 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 898 | " call Dret("netrw#NetRead :4 getcwd<".getcwd().">") |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 899 | return |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 900 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 901 | |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 902 | if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd") |
| 903 | " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 904 | " call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)") |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 905 | if exists("g:netrw_http_xcmd") |
| 906 | " 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)) |
| 907 | exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape("http://".g:netrw_machine.b:netrw_fname,1)." ".g:netrw_http_xcmd." ".shellescape(tmpfile,1) |
| 908 | else |
| 909 | " call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape("http://".g:netrw_machine.b:netrw_fname,1)) |
| 910 | exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape("http://".g:netrw_machine.b:netrw_fname,1) |
| 911 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 912 | let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 913 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 914 | else |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 915 | " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 916 | " call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)") |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 917 | let netrw_html= substitute(b:netrw_fname,"#.*$","","") |
| 918 | let netrw_tag = substitute(b:netrw_fname,"^.*#","","") |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 919 | " call Decho("netrw_html<".netrw_html.">") |
| 920 | " call Decho("netrw_tag <".netrw_tag.">") |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 921 | " call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape("http://".g:netrw_machine.netrw_html,1)) |
| 922 | exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape("http://".g:netrw_machine.netrw_html,1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 923 | let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 924 | " call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/') |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 925 | exe 'keepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>" |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 926 | endif |
| 927 | let b:netrw_lastfile = choice |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 928 | setlocal ro |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 929 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 930 | "......................................... |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 931 | " NetRead: (dav) NetRead Method #6 {{{3 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 932 | elseif b:netrw_method == 6 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 933 | " call Decho("read via cadaver (method #6)") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 934 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 935 | if !executable(g:netrw_dav_cmd) |
| 936 | call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73) |
| 937 | " call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable") |
| 938 | return |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 939 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 940 | if g:netrw_dav_cmd =~ "curl" |
| 941 | " call Decho("exe ".s:netrw_silentxfer."!".g:netrw_dav_cmd." ".shellescape("dav://".g:netrw_machine.b:netrw_fname,1)." ".shellescape(tmpfile,1)) |
| 942 | exe s:netrw_silentxfer."!".g:netrw_dav_cmd." ".shellescape("dav://".g:netrw_machine.b:netrw_fname,1)." ".shellescape(tmpfile,1) |
| 943 | else |
| 944 | " Construct execution string (four lines) which will be passed through filter |
| 945 | let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) |
| 946 | new |
| 947 | setlocal ff=unix |
| 948 | if exists("g:netrw_port") && g:netrw_port != "" |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 949 | keepj put ='open '.g:netrw_machine.' '.g:netrw_port |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 950 | else |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 951 | keepj put ='open '.g:netrw_machine |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 952 | endif |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 953 | keepj put ='user '.g:netrw_uid.' '.s:netrw_passwd |
| 954 | keepj put ='get '.netrw_fname.' '.tmpfile |
| 955 | keepj put ='quit' |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 956 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 957 | " perform cadaver operation: |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 958 | keepj norm! 1Gdd |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 959 | " call Decho("executing: %!".g:netrw_dav_cmd) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 960 | exe s:netrw_silentxfer."%!".g:netrw_dav_cmd |
| 961 | bd! |
| 962 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 963 | let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 964 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 965 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 966 | "......................................... |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 967 | " NetRead: (rsync) NetRead Method #7 {{{3 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 968 | elseif b:netrw_method == 7 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 969 | " call Decho("read via rsync (method #7)") |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 970 | " call Decho("exe ".s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1)) |
| 971 | exe s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 972 | let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 973 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 974 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 975 | "......................................... |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 976 | " NetRead: (fetch) NetRead Method #8 {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 977 | " fetch://[user@]host[:http]/path |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 978 | elseif b:netrw_method == 8 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 979 | " call Decho("read via fetch (method #8)") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 980 | if g:netrw_fetch_cmd == "" |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 981 | if !exists("g:netrw_quiet") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 982 | keepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7) |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 983 | endif |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 984 | " call Dret("NetRead") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 985 | endif |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 986 | if exists("g:netrw_option") && g:netrw_option == ":https\=" |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 987 | let netrw_option= "http" |
| 988 | else |
| 989 | let netrw_option= "ftp" |
| 990 | endif |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 991 | " call Decho("read via fetch for ".netrw_option) |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 992 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 993 | if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != "" |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 994 | " 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)) |
| 995 | 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 Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 996 | else |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 997 | " call Decho("exe ".s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".shellescape(tmpfile,1)." ".shellescape(netrw_option."://".g:netrw_machine."/".b:netrw_fname,1)) |
| 998 | exe s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".shellescape(tmpfile,1)." ".shellescape(netrw_option."://".g:netrw_machine."/".b:netrw_fname,1) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 999 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1000 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1001 | let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1002 | let b:netrw_lastfile = choice |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1003 | setlocal ro |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1004 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1005 | "......................................... |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1006 | " NetRead: (sftp) NetRead Method #9 {{{3 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 1007 | elseif b:netrw_method == 9 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1008 | " call Decho("read via sftp (method #9)") |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 1009 | " call Decho("exe ".s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".tmpfile) |
| 1010 | exe s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".tmpfile |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1011 | let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1012 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1013 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1014 | "......................................... |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1015 | " NetRead: Complain {{{3 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 1016 | else |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1017 | call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1018 | endif |
| 1019 | endwhile |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1020 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1021 | " NetRead: cleanup {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1022 | if exists("b:netrw_method") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1023 | " call Decho("cleanup b:netrw_method and b:netrw_fname") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1024 | unlet b:netrw_method |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1025 | unlet b:netrw_fname |
| 1026 | endif |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 1027 | if s:FileReadable(tmpfile) && tmpfile !~ '.tar.bz2$' && tmpfile !~ '.tar.gz$' && tmpfile !~ '.zip' && tmpfile !~ '.tar' && readcmd != 't' && tmpfile !~ '.tar.xz$' && tmpfile !~ '.txz' |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1028 | " call Decho("cleanup by deleting tmpfile<".tmpfile.">") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1029 | keepj call s:NetrwDelete(tmpfile) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1030 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1031 | keepj call s:NetrwOptionRestore("w:") |
Bram Moolenaar | 8299df9 | 2004-07-10 09:47:34 +0000 | [diff] [blame] | 1032 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1033 | " call Dret("netrw#NetRead :5 getcwd<".getcwd().">") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1034 | endfun |
| 1035 | |
| 1036 | " ------------------------------------------------------------------------ |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1037 | " netrw#NetWrite: responsible for writing a file over the net {{{2 |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 1038 | fun! netrw#NetWrite(...) range |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1039 | " call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw) |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1040 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1041 | " NetWrite: option handling {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1042 | let mod= 0 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1043 | call s:NetrwOptionSave("w:") |
| 1044 | call s:NetrwSafeOptions() |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1045 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1046 | " NetWrite: Get Temporary Filename {{{3 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1047 | let tmpfile= s:GetTempfile("") |
| 1048 | if tmpfile == "" |
| 1049 | " call Dret("netrw#NetWrite : unable to get a tempfile!") |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 1050 | return |
| 1051 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1052 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1053 | if a:0 == 0 |
| 1054 | let ichoice = 0 |
| 1055 | else |
| 1056 | let ichoice = 1 |
| 1057 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1058 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1059 | let curbufname= expand("%") |
| 1060 | " call Decho("curbufname<".curbufname.">") |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 1061 | if &binary |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1062 | " For binary writes, always write entire file. |
| 1063 | " (line numbers don't really make sense for that). |
| 1064 | " Also supports the writing of tar and zip files. |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1065 | " call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)) |
| 1066 | exe "sil keepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1067 | elseif g:netrw_cygwin |
| 1068 | " write (selected portion of) file to temporary |
| 1069 | let cygtmpfile= substitute(tmpfile,'/cygdrive/\(.\)','\1:','') |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1070 | " call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1071 | exe "sil keepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile) |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 1072 | else |
| 1073 | " write (selected portion of) file to temporary |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1074 | " call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1075 | exe "sil keepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile) |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 1076 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1077 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1078 | if curbufname == "" |
| 1079 | " if the file is [No Name], and one attempts to Nwrite it, the buffer takes |
| 1080 | " on the temporary file's name. Deletion of the temporary file during |
| 1081 | " cleanup then causes an error message. |
| 1082 | 0file! |
| 1083 | endif |
| 1084 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1085 | " NetWrite: while choice loop: {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1086 | while ichoice <= a:0 |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1087 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1088 | " Process arguments: {{{4 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1089 | " attempt to repeat with previous host-file-etc |
| 1090 | if exists("b:netrw_lastfile") && a:0 == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1091 | " call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1092 | let choice = b:netrw_lastfile |
| 1093 | let ichoice= ichoice + 1 |
| 1094 | else |
| 1095 | exe "let choice= a:" . ichoice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1096 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1097 | " Reconstruct Choice if choice starts with '"' |
| 1098 | if match(choice,"?") == 0 |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 1099 | echomsg 'NetWrite Usage:"' |
| 1100 | echomsg ':Nwrite machine:path uses rcp' |
| 1101 | echomsg ':Nwrite "machine path" uses ftp with <.netrc>' |
| 1102 | echomsg ':Nwrite "machine id password path" uses ftp' |
| 1103 | echomsg ':Nwrite dav://[user@]machine/path uses cadaver' |
| 1104 | echomsg ':Nwrite fetch://[user@]machine/path uses fetch' |
| 1105 | echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)' |
| 1106 | echomsg ':Nwrite rcp://machine/path uses rcp' |
| 1107 | echomsg ':Nwrite rsync://[user@]machine/path uses rsync' |
| 1108 | echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp' |
| 1109 | echomsg ':Nwrite sftp://[user@]machine/path uses sftp' |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1110 | sleep 4 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1111 | break |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1112 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1113 | elseif match(choice,"^\"") != -1 |
| 1114 | if match(choice,"\"$") != -1 |
| 1115 | " case "..." |
| 1116 | let choice=strpart(choice,1,strlen(choice)-2) |
| 1117 | else |
| 1118 | " case "... ... ..." |
| 1119 | let choice = strpart(choice,1,strlen(choice)-1) |
| 1120 | let wholechoice = "" |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1121 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1122 | while match(choice,"\"$") == -1 |
| 1123 | let wholechoice= wholechoice . " " . choice |
| 1124 | let ichoice = ichoice + 1 |
| 1125 | if choice > a:0 |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 1126 | if !exists("g:netrw_quiet") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1127 | call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13) |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 1128 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1129 | " call Dret("netrw#NetWrite") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1130 | return |
| 1131 | endif |
| 1132 | let choice= a:{ichoice} |
| 1133 | endwhile |
| 1134 | let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1) |
| 1135 | endif |
| 1136 | endif |
| 1137 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1138 | let ichoice= ichoice + 1 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1139 | " call Decho("choice<" . choice . "> ichoice=".ichoice) |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1140 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1141 | " Determine method of write (ftp, rcp, etc) {{{4 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1142 | keepj call s:NetrwMethod(choice) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1143 | if !exists("b:netrw_method") || b:netrw_method < 0 |
| 1144 | " call Dfunc("netrw#NetWrite : unsupported method") |
| 1145 | return |
| 1146 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1147 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1148 | " ============= |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1149 | " NetWrite: Perform Protocol-Based Write {{{3 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 1150 | " ============================ |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 1151 | if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 |
| 1152 | echo "(netrw) Processing your write request..." |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1153 | " call Decho("(netrw) Processing your write request...") |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 1154 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1155 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1156 | "......................................... |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1157 | " NetWrite: (rcp) NetWrite Method #1 {{{3 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 1158 | if b:netrw_method == 1 |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 1159 | " call Decho("write via rcp (method #1)") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1160 | if s:netrw_has_nt_rcp == 1 |
| 1161 | if exists("g:netrw_uid") && ( g:netrw_uid != "" ) |
| 1162 | let uid_machine = g:netrw_machine .'.'. g:netrw_uid |
| 1163 | else |
| 1164 | let uid_machine = g:netrw_machine .'.'. $USERNAME |
| 1165 | endif |
| 1166 | else |
| 1167 | if exists("g:netrw_uid") && ( g:netrw_uid != "" ) |
| 1168 | let uid_machine = g:netrw_uid .'@'. g:netrw_machine |
| 1169 | else |
| 1170 | let uid_machine = g:netrw_machine |
| 1171 | endif |
| 1172 | endif |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 1173 | " call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".shellescape(tmpfile,1)." ".shellescape(uid_machine.":".b:netrw_fname,1)) |
| 1174 | exe s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".shellescape(tmpfile,1)." ".shellescape(uid_machine.":".b:netrw_fname,1) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1175 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1176 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1177 | "......................................... |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1178 | " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 1179 | elseif b:netrw_method == 2 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1180 | " call Decho("write via ftp+.netrc (method #2)") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1181 | let netrw_fname = b:netrw_fname |
| 1182 | |
| 1183 | " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead |
| 1184 | let bhkeep = &l:bh |
| 1185 | let curbuf = bufnr("%") |
| 1186 | setlocal bh=hide |
| 1187 | enew |
| 1188 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1189 | " call Decho("filter input window#".winnr()) |
Bram Moolenaar | 8299df9 | 2004-07-10 09:47:34 +0000 | [diff] [blame] | 1190 | setlocal ff=unix |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1191 | keepj put =g:netrw_ftpmode |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 1192 | " call Decho("filter input: ".getline('$')) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1193 | if exists("g:netrw_ftpextracmd") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1194 | keepj put =g:netrw_ftpextracmd |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 1195 | " call Decho("filter input: ".getline("$")) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1196 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1197 | keepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"') |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 1198 | " call Decho("filter input: ".getline("$")) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1199 | if exists("g:netrw_port") && g:netrw_port != "" |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1200 | " call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)) |
| 1201 | exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1202 | else |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1203 | " call Decho("filter input window#".winnr()) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1204 | " call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)) |
| 1205 | exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1206 | endif |
| 1207 | " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) |
| 1208 | if getline(1) !~ "^$" |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 1209 | if !exists("g:netrw_quiet") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1210 | keepj call netrw#ErrorMsg(s:ERROR,getline(1),14) |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 1211 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1212 | let mod=1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1213 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1214 | |
| 1215 | " remove enew buffer (quietly) |
| 1216 | let filtbuf= bufnr("%") |
| 1217 | exe curbuf."b!" |
| 1218 | let &l:bh = bhkeep |
| 1219 | exe filtbuf."bw!" |
| 1220 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1221 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1222 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1223 | "......................................... |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1224 | " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 1225 | elseif b:netrw_method == 3 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1226 | " Construct execution string (three or more lines) which will be passed through filter |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1227 | " call Decho("read via ftp+mipf (method #3)") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1228 | let netrw_fname = b:netrw_fname |
| 1229 | let bhkeep = &l:bh |
| 1230 | |
| 1231 | " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead |
| 1232 | let curbuf = bufnr("%") |
| 1233 | setlocal bh=hide |
| 1234 | enew |
Bram Moolenaar | 8299df9 | 2004-07-10 09:47:34 +0000 | [diff] [blame] | 1235 | setlocal ff=unix |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1236 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1237 | if exists("g:netrw_port") && g:netrw_port != "" |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1238 | keepj put ='open '.g:netrw_machine.' '.g:netrw_port |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1239 | " call Decho("filter input: ".getline('.')) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1240 | else |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1241 | keepj put ='open '.g:netrw_machine |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1242 | " call Decho("filter input: ".getline('.')) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1243 | endif |
| 1244 | if exists("g:netrw_ftp") && g:netrw_ftp == 1 |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1245 | keepj put =g:netrw_uid |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1246 | " call Decho("filter input: ".getline('.')) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1247 | keepj put ='\"'.s:netrw_passwd.'\"' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1248 | " call Decho("filter input: ".getline('.')) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1249 | else |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1250 | keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1251 | " call Decho("filter input: ".getline('.')) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1252 | endif |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1253 | keepj put =g:netrw_ftpmode |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1254 | " call Decho("filter input: ".getline('$')) |
| 1255 | if exists("g:netrw_ftpextracmd") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1256 | keepj put =g:netrw_ftpextracmd |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1257 | " call Decho("filter input: ".getline("$")) |
| 1258 | endif |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1259 | keepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1260 | " call Decho("filter input: ".getline('.')) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1261 | " save choice/id/password for future use |
| 1262 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1263 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1264 | " perform ftp: |
| 1265 | " -i : turns off interactive prompting from ftp |
| 1266 | " -n unix : DON'T use <.netrc>, even though it exists |
| 1267 | " -n win32: quit being obnoxious about password |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1268 | keepj norm! 1Gdd |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1269 | " call Decho("executing: %!".s:netrw_ftp_cmd." -i -n") |
| 1270 | exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i -n" |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1271 | " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) |
| 1272 | if getline(1) !~ "^$" |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 1273 | if !exists("g:netrw_quiet") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1274 | call netrw#ErrorMsg(s:ERROR,getline(1),15) |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 1275 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1276 | let mod=1 |
| 1277 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1278 | |
| 1279 | " remove enew buffer (quietly) |
| 1280 | let filtbuf= bufnr("%") |
| 1281 | exe curbuf."b!" |
| 1282 | let &l:bh= bhkeep |
| 1283 | exe filtbuf."bw!" |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1284 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1285 | "......................................... |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1286 | " NetWrite: (scp) NetWrite Method #4 {{{3 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 1287 | elseif b:netrw_method == 4 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1288 | " call Decho("write via scp (method #4)") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1289 | if exists("g:netrw_port") && g:netrw_port != "" |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 1290 | let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1291 | else |
| 1292 | let useport= "" |
| 1293 | endif |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 1294 | " call Decho("exe ".s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)) |
| 1295 | exe s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1296 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1297 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1298 | "......................................... |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1299 | " NetWrite: (http) NetWrite Method #5 {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1300 | elseif b:netrw_method == 5 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1301 | " call Decho("write via http (method #5)") |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 1302 | if !exists("g:netrw_quiet") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1303 | call netrw#ErrorMsg(s:ERROR,"currently <netrw.vim> does not support writing using http:",16) |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 1304 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1305 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1306 | "......................................... |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1307 | " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 1308 | elseif b:netrw_method == 6 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1309 | " call Decho("write via cadaver (method #6)") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1310 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1311 | " Construct execution string (four lines) which will be passed through filter |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1312 | let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape) |
| 1313 | let bhkeep = &l:bh |
| 1314 | |
| 1315 | " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead |
| 1316 | let curbuf = bufnr("%") |
| 1317 | setlocal bh=hide |
| 1318 | enew |
| 1319 | |
Bram Moolenaar | 8299df9 | 2004-07-10 09:47:34 +0000 | [diff] [blame] | 1320 | setlocal ff=unix |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1321 | if exists("g:netrw_port") && g:netrw_port != "" |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1322 | keepj put ='open '.g:netrw_machine.' '.g:netrw_port |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1323 | else |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1324 | keepj put ='open '.g:netrw_machine |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1325 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1326 | if exists("g:netrw_uid") && exists("s:netrw_passwd") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1327 | keepj put ='user '.g:netrw_uid.' '.s:netrw_passwd |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1328 | endif |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1329 | keepj put ='put '.tmpfile.' '.netrw_fname |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1330 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1331 | " perform cadaver operation: |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1332 | keepj norm! 1Gdd |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1333 | " call Decho("executing: %!".g:netrw_dav_cmd) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1334 | exe s:netrw_silentxfer."%!".g:netrw_dav_cmd |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1335 | |
| 1336 | " remove enew buffer (quietly) |
| 1337 | let filtbuf= bufnr("%") |
| 1338 | exe curbuf."b!" |
| 1339 | let &l:bh = bhkeep |
| 1340 | exe filtbuf."bw!" |
| 1341 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1342 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1343 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1344 | "......................................... |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1345 | " NetWrite: (rsync) NetWrite Method #7 {{{3 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 1346 | elseif b:netrw_method == 7 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1347 | " call Decho("write via rsync (method #7)") |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 1348 | " call Decho("executing: !".g:netrw_rsync_cmd." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)) |
| 1349 | exe s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1350 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1351 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1352 | "......................................... |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1353 | " NetWrite: (sftp) NetWrite Method #9 {{{3 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 1354 | elseif b:netrw_method == 9 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1355 | " call Decho("read via sftp (method #9)") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1356 | let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1357 | if exists("g:netrw_uid") && ( g:netrw_uid != "" ) |
| 1358 | let uid_machine = g:netrw_uid .'@'. g:netrw_machine |
| 1359 | else |
| 1360 | let uid_machine = g:netrw_machine |
| 1361 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1362 | |
| 1363 | " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead |
| 1364 | let bhkeep = &l:bh |
| 1365 | let curbuf = bufnr("%") |
| 1366 | setlocal bh=hide |
| 1367 | enew |
| 1368 | |
Bram Moolenaar | 8299df9 | 2004-07-10 09:47:34 +0000 | [diff] [blame] | 1369 | setlocal ff=unix |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1370 | call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1371 | " call Decho("filter input: ".getline('.')) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 1372 | " call Decho("executing: %!".g:netrw_sftp_cmd.' '.shellescape(uid_machine,1)) |
| 1373 | exe s:netrw_silentxfer."%!".g:netrw_sftp_cmd.' '.shellescape(uid_machine,1) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1374 | let filtbuf= bufnr("%") |
| 1375 | exe curbuf."b!" |
| 1376 | let &l:bh = bhkeep |
| 1377 | exe filtbuf."bw!" |
| 1378 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1379 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1380 | "......................................... |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1381 | " NetWrite: Complain {{{3 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 1382 | else |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1383 | call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1384 | let leavemod= 1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1385 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1386 | endwhile |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1387 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1388 | " NetWrite: Cleanup: {{{3 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1389 | " call Decho("cleanup") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1390 | if s:FileReadable(tmpfile) |
| 1391 | " call Decho("tmpfile<".tmpfile."> readable, will now delete it") |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 1392 | call s:NetrwDelete(tmpfile) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1393 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1394 | call s:NetrwOptionRestore("w:") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1395 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1396 | if a:firstline == 1 && a:lastline == line("$") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1397 | " restore modifiability; usually equivalent to set nomod |
| 1398 | let &mod= mod |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1399 | elseif !exists("leavemod") |
| 1400 | " indicate that the buffer has not been modified since last written |
| 1401 | set nomod |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1402 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1403 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1404 | " call Dret("netrw#NetWrite") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1405 | endfun |
| 1406 | |
| 1407 | " --------------------------------------------------------------------- |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1408 | " netrw#NetSource: source a remotely hosted vim script {{{2 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1409 | " uses NetRead to get a copy of the file into a temporarily file, |
| 1410 | " then sources that file, |
| 1411 | " then removes that file. |
| 1412 | fun! netrw#NetSource(...) |
| 1413 | " call Dfunc("netrw#NetSource() a:0=".a:0) |
| 1414 | if a:0 > 0 && a:1 == '?' |
| 1415 | " give help |
| 1416 | echomsg 'NetSource Usage:' |
| 1417 | echomsg ':Nsource dav://machine[:port]/path uses cadaver' |
| 1418 | echomsg ':Nsource fetch://machine/path uses fetch' |
| 1419 | echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>' |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 1420 | echomsg ':Nsource http[s]://[user@]machine/path uses http wget' |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1421 | echomsg ':Nsource rcp://[user@]machine/path uses rcp' |
| 1422 | echomsg ':Nsource rsync://machine[:port]/path uses rsync' |
| 1423 | echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp' |
| 1424 | echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp' |
| 1425 | sleep 4 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1426 | else |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1427 | let i= 1 |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1428 | while i <= a:0 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1429 | call netrw#NetRead(3,a:{i}) |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 1430 | " call Decho("(netrw#NetSource) s:netread_tmpfile<".s:netrw_tmpfile.">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1431 | if s:FileReadable(s:netrw_tmpfile) |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 1432 | " call Decho("(netrw#NetSource) exe so ".fnameescape(s:netrw_tmpfile)) |
| 1433 | exe "so ".fnameescape(s:netrw_tmpfile) |
| 1434 | " call Decho("(netrw#NetSource) delete(".s:netrw_tmpfile.")") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1435 | call delete(s:netrw_tmpfile) |
| 1436 | unlet s:netrw_tmpfile |
| 1437 | else |
| 1438 | call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48) |
| 1439 | endif |
| 1440 | let i= i + 1 |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1441 | endwhile |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1442 | endif |
| 1443 | " call Dret("netrw#NetSource") |
| 1444 | endfun |
| 1445 | |
| 1446 | " =========================================== |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1447 | " s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1448 | " readcmd == %r : replace buffer with newly read file |
| 1449 | " == 0r : read file at top of buffer |
| 1450 | " == r : read file after current line |
| 1451 | " == t : leave file in temporary form (ie. don't read into buffer) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1452 | fun! s:NetrwGetFile(readcmd, tfile, method) |
| 1453 | " call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1454 | |
| 1455 | " readcmd=='t': simply do nothing |
| 1456 | if a:readcmd == 't' |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 1457 | " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1458 | " call Dret("NetrwGetFile : skip read of <".a:tfile.">") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1459 | return |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1460 | endif |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 1461 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1462 | " get name of remote filename (ie. url and all) |
| 1463 | let rfile= bufname("%") |
| 1464 | " call Decho("rfile<".rfile.">") |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 1465 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1466 | if exists("*NetReadFixup") |
| 1467 | " for the use of NetReadFixup (not otherwise used internally) |
| 1468 | let line2= line("$") |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 1469 | endif |
| 1470 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1471 | if a:readcmd[0] == '%' |
| 1472 | " get file into buffer |
| 1473 | " call Decho("get file into buffer") |
| 1474 | |
| 1475 | " rename the current buffer to the temp file (ie. tfile) |
| 1476 | if g:netrw_cygwin |
| 1477 | let tfile= substitute(a:tfile,'/cygdrive/\(.\)','\1:','') |
| 1478 | else |
| 1479 | let tfile= a:tfile |
| 1480 | endif |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 1481 | " call Decho("exe sil! keepalt file ".fnameescape(tfile)) |
| 1482 | exe "sil! keepalt file ".fnameescape(tfile) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1483 | |
| 1484 | " edit temporary file (ie. read the temporary file in) |
| 1485 | if rfile =~ '\.zip$' |
| 1486 | " call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)") |
| 1487 | call zip#Browse(tfile) |
| 1488 | elseif rfile =~ '\.tar$' |
| 1489 | " call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)") |
| 1490 | call tar#Browse(tfile) |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 1491 | elseif rfile =~ '\.tar\.gz$' |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1492 | " call Decho("handling remote gzip-compressed tar file") |
| 1493 | call tar#Browse(tfile) |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 1494 | elseif rfile =~ '\.tar\.bz2$' |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1495 | " call Decho("handling remote bz2-compressed tar file") |
| 1496 | call tar#Browse(tfile) |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 1497 | elseif rfile =~ '\.tar\.xz$' |
| 1498 | " call Decho("handling remote xz-compressed tar file") |
| 1499 | call tar#Browse(tfile) |
| 1500 | elseif rfile =~ '\.txz$' |
| 1501 | " call Decho("handling remote xz-compressed tar file (.txz)") |
| 1502 | call tar#Browse(tfile) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1503 | else |
| 1504 | " call Decho("edit temporary file") |
| 1505 | e! |
| 1506 | endif |
| 1507 | |
| 1508 | " rename buffer back to remote filename |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 1509 | " call Decho("exe sil! keepalt file ".fnameescape(rfile)) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1510 | exe "sil! keepj keepalt file ".fnameescape(rfile) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1511 | filetype detect |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1512 | " call Dredir("renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">","ls!") |
| 1513 | let line1 = 1 |
| 1514 | let line2 = line("$") |
| 1515 | |
| 1516 | elseif s:FileReadable(a:tfile) |
| 1517 | " read file after current line |
| 1518 | " call Decho("read file<".a:tfile."> after current line") |
| 1519 | let curline = line(".") |
| 1520 | let lastline= line("$") |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 1521 | " call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1522 | exe "keepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1523 | let line1= curline + 1 |
| 1524 | let line2= line("$") - lastline + 1 |
| 1525 | |
| 1526 | else |
| 1527 | " not readable |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 1528 | " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1529 | " call Decho("tfile<".a:tfile."> not readable") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1530 | keepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1531 | " call Dret("NetrwGetFile : tfile<".a:tfile."> not readable") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1532 | return |
| 1533 | endif |
| 1534 | |
| 1535 | " User-provided (ie. optional) fix-it-up command |
| 1536 | if exists("*NetReadFixup") |
| 1537 | " call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1538 | keepj call NetReadFixup(a:method, line1, line2) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1539 | " else " Decho |
| 1540 | " call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")") |
| 1541 | endif |
| 1542 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1543 | if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1544 | " update the Buffers menu |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1545 | keepj call s:UpdateBuffersMenu() |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1546 | endif |
| 1547 | |
| 1548 | " call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> tfile<".a:tfile."> readable=".s:FileReadable(a:tfile)) |
| 1549 | |
| 1550 | " make sure file is being displayed |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1551 | " redraw! |
| 1552 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 1553 | " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1554 | " call Dret("NetrwGetFile") |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 1555 | endfun |
| 1556 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1557 | " ------------------------------------------------------------------------ |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1558 | " s:NetrwMethod: determine method of transfer {{{2 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1559 | " Input: |
| 1560 | " choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file] |
| 1561 | " Output: |
| 1562 | " b:netrw_method= 1: rcp |
| 1563 | " 2: ftp + <.netrc> |
| 1564 | " 3: ftp + machine, id, password, and [path]filename |
| 1565 | " 4: scp |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 1566 | " 5: http[s] (wget) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1567 | " 6: dav |
| 1568 | " 7: rsync |
| 1569 | " 8: fetch |
| 1570 | " 9: sftp |
| 1571 | " g:netrw_machine= hostname |
| 1572 | " b:netrw_fname = filename |
| 1573 | " g:netrw_port = optional port number (for ftp) |
| 1574 | " g:netrw_choice = copy of input url (choice) |
| 1575 | fun! s:NetrwMethod(choice) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1576 | " call Dfunc("NetrwMethod(a:choice<".a:choice.">)") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1577 | |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 1578 | " sanity check: choice should have at least three slashes in it |
| 1579 | if strlen(substitute(a:choice,'[^/]','','g')) < 3 |
| 1580 | call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78) |
| 1581 | let b:netrw_method = -1 |
| 1582 | " call Dret("NetrwMethod : incorrect url format<".a:choice.">") |
| 1583 | return |
| 1584 | endif |
| 1585 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1586 | " record current g:netrw_machine, if any |
| 1587 | " curmachine used if protocol == ftp and no .netrc |
| 1588 | if exists("g:netrw_machine") |
| 1589 | let curmachine= g:netrw_machine |
| 1590 | " call Decho("curmachine<".curmachine.">") |
| 1591 | else |
| 1592 | let curmachine= "N O T A HOST" |
| 1593 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1594 | if exists("g:netrw_port") |
| 1595 | let netrw_port= g:netrw_port |
| 1596 | endif |
| 1597 | |
| 1598 | " insure that netrw_ftp_cmd starts off every method determination |
| 1599 | " with the current g:netrw_ftp_cmd |
| 1600 | let s:netrw_ftp_cmd= g:netrw_ftp_cmd |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1601 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1602 | " initialization |
| 1603 | let b:netrw_method = 0 |
| 1604 | let g:netrw_machine = "" |
| 1605 | let b:netrw_fname = "" |
| 1606 | let g:netrw_port = "" |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1607 | let g:netrw_choice = a:choice |
| 1608 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1609 | " Patterns: |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1610 | " mipf : a:machine a:id password filename Use ftp |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1611 | " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd |
| 1612 | " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1613 | " rcpurm : rcp://[user@]host/filename Use rcp |
| 1614 | " rcphf : [user@]host:filename Use rcp |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1615 | " scpurm : scp://[user@]host[[#:]port]/filename Use scp |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 1616 | " httpurm : http[s]://[user@]host/filename Use wget |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1617 | " davurm : dav[s]://host[:port]/path Use cadaver/curl |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1618 | " rsyncurm : rsync://host[:port]/path Use rsync |
| 1619 | " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http) |
| 1620 | " sftpurm : sftp://[user@]host/filename Use scp |
| 1621 | let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$' |
| 1622 | let mf = '^\(\S\+\)\s\+\(\S\+\)$' |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 1623 | " let ftpurm = '^ftp://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$' |
| 1624 | " let rcpurm = '^rcp://\%(\([^/@]\{-}\)@\)\=\([^/]\{-}\)/\(.*\)$' |
| 1625 | " let fetchurm = '^fetch://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$' |
| 1626 | let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$' |
| 1627 | let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$' |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1628 | let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$' |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 1629 | let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$' |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 1630 | let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1631 | let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$' |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1632 | let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$' |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 1633 | let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$' |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1634 | let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$' |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1635 | |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1636 | " call Decho("determine method:") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1637 | " Determine Method |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1638 | " Method#1: rcp://user@hostname/...path-to-file {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1639 | if match(a:choice,rcpurm) == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1640 | " call Decho("rcp://...") |
Bram Moolenaar | 83bab71 | 2005-08-01 21:58:57 +0000 | [diff] [blame] | 1641 | let b:netrw_method = 1 |
| 1642 | let userid = substitute(a:choice,rcpurm,'\1',"") |
| 1643 | let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"") |
| 1644 | let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1645 | if userid != "" |
| 1646 | let g:netrw_uid= userid |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1647 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1648 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1649 | " Method#4: scp://user@hostname/...path-to-file {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1650 | elseif match(a:choice,scpurm) == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1651 | " call Decho("scp://...") |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 1652 | let b:netrw_method = 4 |
Bram Moolenaar | 83bab71 | 2005-08-01 21:58:57 +0000 | [diff] [blame] | 1653 | let g:netrw_machine = substitute(a:choice,scpurm,'\1',"") |
| 1654 | let g:netrw_port = substitute(a:choice,scpurm,'\2',"") |
| 1655 | let b:netrw_fname = substitute(a:choice,scpurm,'\3',"") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1656 | |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 1657 | " Method#5: http[s]://user@hostname/...path-to-file {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1658 | elseif match(a:choice,httpurm) == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1659 | " call Decho("http://...") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1660 | let b:netrw_method = 5 |
| 1661 | let g:netrw_machine= substitute(a:choice,httpurm,'\1',"") |
| 1662 | let b:netrw_fname = substitute(a:choice,httpurm,'\2',"") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1663 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1664 | " Method#6: dav://hostname[:port]/..path-to-file.. {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1665 | elseif match(a:choice,davurm) == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1666 | " call Decho("dav://...") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1667 | let b:netrw_method= 6 |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 1668 | if a:choice =~ 'davs:' |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1669 | let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"") |
| 1670 | else |
| 1671 | let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"") |
| 1672 | endif |
| 1673 | let b:netrw_fname = substitute(a:choice,davurm,'\3',"") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1674 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1675 | " Method#7: rsync://user@hostname/...path-to-file {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1676 | elseif match(a:choice,rsyncurm) == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1677 | " call Decho("rsync://...") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1678 | let b:netrw_method = 7 |
| 1679 | let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"") |
| 1680 | let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1681 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1682 | " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1683 | elseif match(a:choice,ftpurm) == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1684 | " call Decho("ftp://...") |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 1685 | let userid = substitute(a:choice,ftpurm,'\2',"") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1686 | let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"") |
| 1687 | let g:netrw_port = substitute(a:choice,ftpurm,'\4',"") |
| 1688 | let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1689 | " call Decho("g:netrw_machine<".g:netrw_machine.">") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1690 | if userid != "" |
| 1691 | let g:netrw_uid= userid |
| 1692 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1693 | if curmachine != g:netrw_machine |
| 1694 | if exists("s:netrw_passwd") |
| 1695 | " if there's a change in hostname, require password re-entry |
| 1696 | unlet s:netrw_passwd |
| 1697 | endif |
| 1698 | if exists("netrw_port") |
| 1699 | unlet netrw_port |
| 1700 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1701 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1702 | if exists("g:netrw_uid") && exists("s:netrw_passwd") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1703 | let b:netrw_method = 3 |
| 1704 | else |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1705 | if (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~ '-[sS]:' |
| 1706 | " call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">") |
| 1707 | " call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">") |
| 1708 | if g:netrw_ftp_cmd =~ '-[sS]:\S*MACHINE\>' |
| 1709 | let machine = substitute(g:netrw_machine,'\([^.]\+\)\.\S*','\1','') |
| 1710 | let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',machine.".ftp",'') |
| 1711 | " call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">") |
| 1712 | endif |
| 1713 | let b:netrw_method= 2 |
| 1714 | elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc |
| 1715 | " call Decho("using <".expand("$HOME/.netrc")."> (readable)") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1716 | let b:netrw_method= 2 |
| 1717 | else |
| 1718 | if !exists("g:netrw_uid") || g:netrw_uid == "" |
| 1719 | call NetUserPass() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1720 | elseif !exists("s:netrw_passwd") || s:netrw_passwd == "" |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1721 | call NetUserPass(g:netrw_uid) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1722 | " else just use current g:netrw_uid and s:netrw_passwd |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1723 | endif |
| 1724 | let b:netrw_method= 3 |
| 1725 | endif |
| 1726 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1727 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1728 | " Method#8: fetch {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1729 | elseif match(a:choice,fetchurm) == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1730 | " call Decho("fetch://...") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1731 | let b:netrw_method = 8 |
| 1732 | let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"") |
| 1733 | let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"") |
| 1734 | let b:netrw_option = substitute(a:choice,fetchurm,'\4',"") |
| 1735 | let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1736 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1737 | " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1738 | elseif match(a:choice,mipf) == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1739 | " call Decho("(ftp) host id pass file") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1740 | let b:netrw_method = 3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1741 | let g:netrw_machine = substitute(a:choice,mipf,'\1',"") |
| 1742 | let g:netrw_uid = substitute(a:choice,mipf,'\2',"") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1743 | let s:netrw_passwd = substitute(a:choice,mipf,'\3',"") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1744 | let b:netrw_fname = substitute(a:choice,mipf,'\4',"") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1745 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1746 | " Method#3: Issue an ftp: "hostname [path/]filename" {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1747 | elseif match(a:choice,mf) == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1748 | " call Decho("(ftp) host file") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1749 | if exists("g:netrw_uid") && exists("s:netrw_passwd") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1750 | let b:netrw_method = 3 |
| 1751 | let g:netrw_machine = substitute(a:choice,mf,'\1',"") |
| 1752 | let b:netrw_fname = substitute(a:choice,mf,'\2',"") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1753 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1754 | elseif s:FileReadable(expand("$HOME/.netrc")) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1755 | let b:netrw_method = 2 |
| 1756 | let g:netrw_machine = substitute(a:choice,mf,'\1',"") |
| 1757 | let b:netrw_fname = substitute(a:choice,mf,'\2',"") |
| 1758 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1759 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1760 | " Method#9: sftp://user@hostname/...path-to-file {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1761 | elseif match(a:choice,sftpurm) == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1762 | " call Decho("sftp://...") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1763 | let b:netrw_method = 9 |
| 1764 | let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"") |
| 1765 | let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1766 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1767 | " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1768 | elseif match(a:choice,rcphf) == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1769 | " call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1770 | let b:netrw_method = 1 |
| 1771 | let userid = substitute(a:choice,rcphf,'\2',"") |
| 1772 | let g:netrw_machine = substitute(a:choice,rcphf,'\3',"") |
| 1773 | let b:netrw_fname = substitute(a:choice,rcphf,'\4',"") |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1774 | " call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">") |
| 1775 | " call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">") |
| 1776 | " call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">") |
| 1777 | " call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1778 | if userid != "" |
| 1779 | let g:netrw_uid= userid |
| 1780 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1781 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1782 | " Cannot Determine Method {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1783 | else |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 1784 | if !exists("g:netrw_quiet") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1785 | call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45) |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 1786 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1787 | let b:netrw_method = -1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1788 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1789 | "}}}3 |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 1790 | |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 1791 | if g:netrw_port != "" |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1792 | " remove any leading [:#] from port number |
| 1793 | let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','') |
| 1794 | elseif exists("netrw_port") |
| 1795 | " retain port number as implicit for subsequent ftp operations |
| 1796 | let g:netrw_port= netrw_port |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 1797 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1798 | |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1799 | " call Decho("a:choice <".a:choice.">") |
| 1800 | " call Decho("b:netrw_method <".b:netrw_method.">") |
| 1801 | " call Decho("g:netrw_machine<".g:netrw_machine.">") |
| 1802 | " call Decho("g:netrw_port <".g:netrw_port.">") |
| 1803 | " if exists("g:netrw_uid") "Decho |
| 1804 | " call Decho("g:netrw_uid <".g:netrw_uid.">") |
| 1805 | " endif "Decho |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1806 | " if exists("s:netrw_passwd") "Decho |
| 1807 | " call Decho("s:netrw_passwd <".s:netrw_passwd.">") |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1808 | " endif "Decho |
| 1809 | " call Decho("b:netrw_fname <".b:netrw_fname.">") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1810 | " call Dret("NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1811 | endfun |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1812 | |
| 1813 | " ------------------------------------------------------------------------ |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1814 | " NetReadFixup: this sort of function is typically written by the user {{{2 |
| 1815 | " to handle extra junk that their system's ftp dumps |
| 1816 | " into the transfer. This function is provided as an |
| 1817 | " example and as a fix for a Windows 95 problem: in my |
| 1818 | " experience, win95's ftp always dumped four blank lines |
| 1819 | " at the end of the transfer. |
| 1820 | if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp |
| 1821 | fun! NetReadFixup(method, line1, line2) |
| 1822 | " call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1823 | |
| 1824 | " sanity checks -- attempt to convert inputs to integers |
| 1825 | let method = a:method + 0 |
| 1826 | let line1 = a:line1 + 0 |
| 1827 | let line2 = a:line2 + 0 |
| 1828 | if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0 |
| 1829 | " call Dret("NetReadFixup") |
| 1830 | return |
| 1831 | endif |
| 1832 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1833 | if method == 3 " ftp (no <.netrc>) |
| 1834 | let fourblanklines= line2 - 3 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1835 | if fourblanklines >= line1 |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1836 | exe "sil keepj ".fourblanklines.",".line2."g/^\s*$/d" |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1837 | call histdel("/",-1) |
| 1838 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1839 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 1840 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1841 | " call Dret("NetReadFixup") |
| 1842 | endfun |
| 1843 | endif |
| 1844 | |
| 1845 | " --------------------------------------------------------------------- |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 1846 | " NetUserPass: set username and password for subsequent ftp transfer {{{2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1847 | " Usage: :call NetUserPass() -- will prompt for userid and password |
| 1848 | " :call NetUserPass("uid") -- will prompt for password |
| 1849 | " :call NetUserPass("uid","password") -- sets global userid and password |
| 1850 | fun! NetUserPass(...) |
| 1851 | |
| 1852 | " get/set userid |
| 1853 | if a:0 == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1854 | " call Dfunc("NetUserPass(a:0<".a:0.">)") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1855 | if !exists("g:netrw_uid") || g:netrw_uid == "" |
| 1856 | " via prompt |
| 1857 | let g:netrw_uid= input('Enter username: ') |
| 1858 | endif |
| 1859 | else " from command line |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1860 | " call Dfunc("NetUserPass(a:1<".a:1.">)") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1861 | let g:netrw_uid= a:1 |
| 1862 | endif |
| 1863 | |
| 1864 | " get password |
| 1865 | if a:0 <= 1 " via prompt |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1866 | " call Decho("a:0=".a:0." case <=1:") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1867 | let s:netrw_passwd= inputsecret("Enter Password: ") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1868 | else " from command line |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1869 | " call Decho("a:0=".a:0." case >1: a:2<".a:2.">") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1870 | let s:netrw_passwd=a:2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1871 | endif |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 1872 | |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1873 | " call Dret("NetUserPass") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1874 | endfun |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1875 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1876 | " =========================================== |
| 1877 | " Shared Browsing Support: {{{1 |
| 1878 | " =========================================== |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1879 | |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 1880 | " --------------------------------------------------------------------- |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1881 | " s:NetrwMaps: {{{2 |
| 1882 | fun! s:NetrwMaps(islocal) |
| 1883 | " call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">") |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 1884 | |
| 1885 | " set up Rexplore and [ 2-leftmouse-click -or- c-leftmouse ] |
| 1886 | " call Decho("set up Rexplore command") |
| 1887 | com! Rexplore call s:NetrwRexplore(w:netrw_rexlocal,exists("w:netrw_rexdir")? w:netrw_rexdir : ".") |
| 1888 | if g:netrw_mousemaps && g:netrw_retmap |
| 1889 | " call Decho("set up Rexplore 2-leftmouse") |
| 1890 | if !hasmapto("<Plug>NetrwReturn") |
| 1891 | if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$' |
| 1892 | " call Decho("making map for 2-leftmouse") |
| 1893 | nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn |
| 1894 | elseif maparg("<c-leftmouse>","n") == "" |
| 1895 | " call Decho("making map for c-leftmouse") |
| 1896 | nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn |
| 1897 | endif |
| 1898 | endif |
| 1899 | nno <silent> <Plug>NetrwReturn :Rexplore<cr> |
| 1900 | " call Decho("made <Plug>NetrwReturn map") |
| 1901 | endif |
| 1902 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1903 | if a:islocal |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 1904 | " call Decho("make local maps") |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 1905 | " local normal-mode maps |
| 1906 | nnoremap <buffer> <silent> a :call <SID>NetrwHide(1)<cr> |
| 1907 | nnoremap <buffer> <silent> % :call <SID>NetrwOpenFile(1)<cr> |
| 1908 | nnoremap <buffer> <silent> c :exe "keepjumps lcd ".fnameescape(b:netrw_curdir)<cr> |
| 1909 | nnoremap <buffer> <silent> C :let g:netrw_chgwin= winnr()<cr> |
| 1910 | nnoremap <buffer> <silent> <cr> :call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr> |
| 1911 | nnoremap <buffer> <silent> d :call <SID>NetrwMakeDir("")<cr> |
| 1912 | nnoremap <buffer> <silent> - :exe "norm! 0"<bar>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,'../'))<cr> |
| 1913 | nnoremap <buffer> <silent> gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr> |
| 1914 | nnoremap <buffer> <silent> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr> |
| 1915 | nnoremap <buffer> <silent> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr> |
| 1916 | nnoremap <buffer> <silent> gh :<c-u>call <SID>NetrwHidden(1)<cr> |
| 1917 | nnoremap <buffer> <silent> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr> |
| 1918 | nnoremap <buffer> <silent> I :call <SID>NetrwBannerCtrl(1)<cr> |
| 1919 | nnoremap <buffer> <silent> i :call <SID>NetrwListStyle(1)<cr> |
| 1920 | nnoremap <buffer> <silent> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr> |
| 1921 | nnoremap <buffer> <silent> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr> |
| 1922 | nnoremap <buffer> <silent> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr> |
| 1923 | nnoremap <buffer> <silent> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr> |
| 1924 | nnoremap <buffer> <silent> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr> |
| 1925 | nnoremap <buffer> <silent> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr> |
| 1926 | nnoremap <buffer> <silent> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr> |
| 1927 | nnoremap <buffer> <silent> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr> |
| 1928 | nnoremap <buffer> <silent> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr> |
| 1929 | nnoremap <buffer> <silent> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr> |
| 1930 | nnoremap <buffer> <silent> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr> |
| 1931 | nnoremap <buffer> <silent> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr> |
| 1932 | nnoremap <buffer> <silent> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr> |
| 1933 | nnoremap <buffer> <silent> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr> |
| 1934 | nnoremap <buffer> <silent> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr> |
| 1935 | nnoremap <buffer> <silent> mx :<c-u>call <SID>NetrwMarkFileExe(1)<cr> |
| 1936 | nnoremap <buffer> <silent> mX :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr> |
| 1937 | nnoremap <buffer> <silent> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr> |
| 1938 | nnoremap <buffer> <silent> O :call <SID>NetrwObtain(1)<cr> |
| 1939 | nnoremap <buffer> <silent> o :call <SID>NetrwSplit(3)<cr> |
| 1940 | nnoremap <buffer> <silent> p :call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr> |
| 1941 | nnoremap <buffer> <silent> P :call <SID>NetrwPrevWinOpen(1)<cr> |
| 1942 | nnoremap <buffer> <silent> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr> |
| 1943 | nnoremap <buffer> <silent> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr> |
| 1944 | 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> |
| 1945 | nnoremap <buffer> <silent> s :call <SID>NetrwSortStyle(1)<cr> |
| 1946 | nnoremap <buffer> <silent> S :call <SID>NetSortSequence(1)<cr> |
| 1947 | nnoremap <buffer> <silent> T :call <SID>NetrwSplit(4)<bar>norm! gT<cr> |
| 1948 | nnoremap <buffer> <silent> t :call <SID>NetrwSplit(4)<cr> |
| 1949 | nnoremap <buffer> <silent> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr> |
| 1950 | nnoremap <buffer> <silent> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr> |
| 1951 | nnoremap <buffer> <silent> v :call <SID>NetrwSplit(5)<cr> |
| 1952 | nnoremap <buffer> <silent> x :call netrw#NetrwBrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr> |
| 1953 | " local insert-mode maps |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1954 | inoremap <buffer> <silent> a <c-o>:call <SID>NetrwHide(1)<cr> |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1955 | inoremap <buffer> <silent> c <c-o>:exe "keepjumps lcd ".fnameescape(b:netrw_curdir)<cr> |
| 1956 | inoremap <buffer> <silent> C <c-o>:let g:netrw_chgwin= winnr()<cr> |
| 1957 | inoremap <buffer> <silent> % <c-o>:call <SID>NetrwOpenFile(1)<cr> |
| 1958 | inoremap <buffer> <silent> - <c-o>:exe "norm! 0"<bar>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,'../'))<cr> |
| 1959 | inoremap <buffer> <silent> <cr> <c-o>:call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr> |
| 1960 | inoremap <buffer> <silent> d <c-o>:call <SID>NetrwMakeDir("")<cr> |
| 1961 | inoremap <buffer> <silent> gb <c-o>:<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr> |
| 1962 | inoremap <buffer> <silent> gh <c-o>:<c-u>call <SID>NetrwHidden(1)<cr> |
| 1963 | inoremap <buffer> <silent> gp <c-o>:<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr> |
| 1964 | inoremap <buffer> <silent> I <c-o>:call <SID>NetrwBannerCtrl(1)<cr> |
| 1965 | inoremap <buffer> <silent> i <c-o>:call <SID>NetrwListStyle(1)<cr> |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1966 | inoremap <buffer> <silent> mb <c-o>:<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr> |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1967 | inoremap <buffer> <silent> mB <c-o>:<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr> |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1968 | inoremap <buffer> <silent> mc <c-o>:<c-u>call <SID>NetrwMarkFileCopy(1)<cr> |
| 1969 | inoremap <buffer> <silent> md <c-o>:<c-u>call <SID>NetrwMarkFileDiff(1)<cr> |
| 1970 | inoremap <buffer> <silent> me <c-o>:<c-u>call <SID>NetrwMarkFileEdit(1)<cr> |
| 1971 | inoremap <buffer> <silent> mf <c-o>:<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr> |
| 1972 | inoremap <buffer> <silent> mg <c-o>:<c-u>call <SID>NetrwMarkFileGrep(1)<cr> |
| 1973 | inoremap <buffer> <silent> mh <c-o>:<c-u>call <SID>NetrwMarkHideSfx(1)<cr> |
| 1974 | inoremap <buffer> <silent> mm <c-o>:<c-u>call <SID>NetrwMarkFileMove(1)<cr> |
| 1975 | inoremap <buffer> <silent> mp <c-o>:<c-u>call <SID>NetrwMarkFilePrint(1)<cr> |
| 1976 | inoremap <buffer> <silent> mr <c-o>:<c-u>call <SID>NetrwMarkFileRegexp(1)<cr> |
| 1977 | inoremap <buffer> <silent> ms <c-o>:<c-u>call <SID>NetrwMarkFileSource(1)<cr> |
| 1978 | inoremap <buffer> <silent> mT <c-o>:<c-u>call <SID>NetrwMarkFileTag(1)<cr> |
| 1979 | inoremap <buffer> <silent> mt <c-o>:<c-u>call <SID>NetrwMarkFileTgt(1)<cr> |
| 1980 | inoremap <buffer> <silent> mu <c-o>:<c-u>call <SID>NetrwUnMarkFile(1)<cr> |
| 1981 | inoremap <buffer> <silent> mx <c-o>:<c-u>call <SID>NetrwMarkFileExe(1)<cr> |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 1982 | inoremap <buffer> <silent> mX <c-o>:<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr> |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1983 | inoremap <buffer> <silent> mz <c-o>:<c-u>call <SID>NetrwMarkFileCompress(1)<cr> |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1984 | inoremap <buffer> <silent> O <c-o>:call <SID>NetrwObtain(1)<cr> |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1985 | inoremap <buffer> <silent> o <c-o>:call <SID>NetrwSplit(3)<cr> |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1986 | inoremap <buffer> <silent> p <c-o>:call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr> |
| 1987 | inoremap <buffer> <silent> P <c-o>:call <SID>NetrwPrevWinOpen(1)<cr> |
| 1988 | inoremap <buffer> <silent> qb <c-o>:<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr> |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1989 | inoremap <buffer> <silent> qf <c-o>:<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr> |
| 1990 | 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> |
| 1991 | inoremap <buffer> <silent> s <c-o>:call <SID>NetrwSortStyle(1)<cr> |
| 1992 | inoremap <buffer> <silent> S <c-o>:call <SID>NetSortSequence(1)<cr> |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1993 | inoremap <buffer> <silent> T <c-o>:call <SID>NetrwSplit(4)<bar>norm! gT<cr> |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1994 | inoremap <buffer> <silent> t <c-o>:call <SID>NetrwSplit(4)<cr> |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1995 | inoremap <buffer> <silent> u <c-o>:<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr> |
| 1996 | inoremap <buffer> <silent> U <c-o>:<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr> |
| 1997 | inoremap <buffer> <silent> v <c-o>:call <SID>NetrwSplit(5)<cr> |
| 1998 | inoremap <buffer> <silent> x <c-o>:call netrw#NetrwBrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr> |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 1999 | if !hasmapto('<Plug>NetrwHideEdit') |
| 2000 | nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2001 | imap <buffer> <unique> <c-h> <Plug>NetrwHideEdit |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2002 | endif |
| 2003 | nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr> |
| 2004 | if !hasmapto('<Plug>NetrwRefresh') |
| 2005 | nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2006 | imap <buffer> <unique> <c-l> <Plug>NetrwRefresh |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2007 | endif |
| 2008 | nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,'./'))<cr> |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2009 | if s:didstarstar || !mapcheck("<s-down>","n") |
| 2010 | nnoremap <buffer> <silent> <s-down> :Nexplore<cr> |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2011 | inoremap <buffer> <silent> <s-down> :Nexplore<cr> |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2012 | endif |
| 2013 | if s:didstarstar || !mapcheck("<s-up>","n") |
| 2014 | nnoremap <buffer> <silent> <s-up> :Pexplore<cr> |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2015 | inoremap <buffer> <silent> <s-up> :Pexplore<cr> |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2016 | endif |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 2017 | let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2018 | if g:netrw_mousemaps == 1 |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 2019 | nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse |
| 2020 | nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(1)<cr> |
| 2021 | nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse |
| 2022 | nno <buffer> <silent> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(1)<cr> |
| 2023 | nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse |
| 2024 | nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr> |
| 2025 | nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse |
| 2026 | nmap <buffer> <silent> <Plug>Netrw2Leftmouse - |
| 2027 | imap <buffer> <leftmouse> <Plug>ILeftmouse |
| 2028 | ino <buffer> <silent> <Plug>ILeftmouse <c-o><leftmouse><c-o>:call <SID>NetrwLeftmouse(1)<cr> |
| 2029 | imap <buffer> <middlemouse> <Plug>IMiddlemouse |
| 2030 | ino <buffer> <silent> <Plug>IMiddlemouse <c-o><leftmouse><c-o>:call <SID>NetrwPrevWinOpen(1)<cr> |
| 2031 | imap <buffer> <s-leftmouse> <Plug>ISLeftmouse |
| 2032 | ino <buffer> <silent> <Plug>ISLeftmouse <c-o><leftmouse><c-o>:call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr> |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 2033 | exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>' |
| 2034 | exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>' |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2035 | exe 'inoremap <buffer> <silent> <rightmouse> <c-o><leftmouse><c-o>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2036 | endif |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 2037 | exe 'nnoremap <buffer> <silent> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>' |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 2038 | exe 'nnoremap <buffer> <silent> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>' |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 2039 | exe 'nnoremap <buffer> <silent> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2040 | exe 'nnoremap <buffer> <silent> <Leader>m :call <SID>NetrwMakeDir("")<cr>' |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2041 | exe 'vnoremap <buffer> <silent> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>' |
| 2042 | exe 'vnoremap <buffer> <silent> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>' |
| 2043 | exe 'vnoremap <buffer> <silent> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>' |
| 2044 | exe 'inoremap <buffer> <silent> <del> <c-o>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>' |
| 2045 | exe 'inoremap <buffer> <silent> D <c-o>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>' |
| 2046 | exe 'inoremap <buffer> <silent> R <c-o>:call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>' |
| 2047 | exe 'inoremap <buffer> <silent> <Leader>m <c-o>:call <SID>NetrwMakeDir("")<cr>' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2048 | nnoremap <buffer> <F1> :he netrw-quickhelp<cr> |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 2049 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2050 | else " remote |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 2051 | " call Decho("make remote maps") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2052 | call s:RemotePathAnalysis(b:netrw_curdir) |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 2053 | " remote normal-mode maps |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2054 | nnoremap <buffer> <silent> <cr> :call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr> |
| 2055 | nnoremap <buffer> <silent> <c-l> :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr> |
| 2056 | nnoremap <buffer> <silent> - :exe "norm! 0"<bar>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,'../'))<cr> |
| 2057 | nnoremap <buffer> <silent> a :call <SID>NetrwHide(0)<cr> |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2058 | nnoremap <buffer> <silent> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr> |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2059 | nnoremap <buffer> <silent> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr> |
| 2060 | nnoremap <buffer> <silent> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr> |
| 2061 | nnoremap <buffer> <silent> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr> |
| 2062 | nnoremap <buffer> <silent> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr> |
| 2063 | nnoremap <buffer> <silent> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr> |
| 2064 | nnoremap <buffer> <silent> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr> |
| 2065 | nnoremap <buffer> <silent> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr> |
| 2066 | nnoremap <buffer> <silent> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr> |
| 2067 | nnoremap <buffer> <silent> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr> |
| 2068 | nnoremap <buffer> <silent> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr> |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2069 | nnoremap <buffer> <silent> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr> |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 2070 | nnoremap <buffer> <silent> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr> |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2071 | nnoremap <buffer> <silent> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr> |
| 2072 | nnoremap <buffer> <silent> mx :<c-u>call <SID>NetrwMarkFileExe(0)<cr> |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 2073 | nnoremap <buffer> <silent> mX :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr> |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2074 | nnoremap <buffer> <silent> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr> |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2075 | nnoremap <buffer> <silent> gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_cur)<cr> |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2076 | nnoremap <buffer> <silent> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr> |
| 2077 | nnoremap <buffer> <silent> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr> |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2078 | nnoremap <buffer> <silent> gh :<c-u>call <SID>NetrwHidden(0)<cr> |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2079 | nnoremap <buffer> <silent> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr> |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2080 | nnoremap <buffer> <silent> C :let g:netrw_chgwin= winnr()<cr> |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2081 | nnoremap <buffer> <silent> i :call <SID>NetrwListStyle(0)<cr> |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2082 | nnoremap <buffer> <silent> I :call <SID>NetrwBannerCtrl(1)<cr> |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2083 | nnoremap <buffer> <silent> o :call <SID>NetrwSplit(0)<cr> |
| 2084 | nnoremap <buffer> <silent> O :call <SID>NetrwObtain(0)<cr> |
| 2085 | nnoremap <buffer> <silent> p :call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr> |
| 2086 | nnoremap <buffer> <silent> P :call <SID>NetrwPrevWinOpen(0)<cr> |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2087 | nnoremap <buffer> <silent> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr> |
| 2088 | nnoremap <buffer> <silent> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr> |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2089 | nnoremap <buffer> <silent> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr> |
| 2090 | 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> |
| 2091 | nnoremap <buffer> <silent> s :call <SID>NetrwSortStyle(0)<cr> |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2092 | nnoremap <buffer> <silent> S :call <SID>NetSortSequence(0)<cr> |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2093 | nnoremap <buffer> <silent> t :call <SID>NetrwSplit(1)<cr> |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2094 | nnoremap <buffer> <silent> T :call <SID>NetrwSplit(1)<bar>norm! gT<cr> |
| 2095 | nnoremap <buffer> <silent> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr> |
| 2096 | nnoremap <buffer> <silent> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr> |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2097 | nnoremap <buffer> <silent> v :call <SID>NetrwSplit(2)<cr> |
| 2098 | nnoremap <buffer> <silent> x :call netrw#NetrwBrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr> |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 2099 | nnoremap <buffer> <silent> % :call <SID>NetrwOpenFile(0)<cr> |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 2100 | " remote insert-mode maps |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2101 | inoremap <buffer> <silent> <cr> <c-o>:call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr> |
| 2102 | inoremap <buffer> <silent> <c-l> <c-o>:call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr> |
| 2103 | inoremap <buffer> <silent> - <c-o>:exe "norm! 0"<bar>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,'../'))<cr> |
| 2104 | inoremap <buffer> <silent> a <c-o>:call <SID>NetrwHide(0)<cr> |
| 2105 | inoremap <buffer> <silent> mb <c-o>:<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr> |
| 2106 | inoremap <buffer> <silent> mc <c-o>:<c-u>call <SID>NetrwMarkFileCopy(0)<cr> |
| 2107 | inoremap <buffer> <silent> md <c-o>:<c-u>call <SID>NetrwMarkFileDiff(0)<cr> |
| 2108 | inoremap <buffer> <silent> me <c-o>:<c-u>call <SID>NetrwMarkFileEdit(0)<cr> |
| 2109 | inoremap <buffer> <silent> mf <c-o>:<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr> |
| 2110 | inoremap <buffer> <silent> mg <c-o>:<c-u>call <SID>NetrwMarkFileGrep(0)<cr> |
| 2111 | inoremap <buffer> <silent> mh <c-o>:<c-u>call <SID>NetrwMarkHideSfx(0)<cr> |
| 2112 | inoremap <buffer> <silent> mm <c-o>:<c-u>call <SID>NetrwMarkFileMove(0)<cr> |
| 2113 | inoremap <buffer> <silent> mp <c-o>:<c-u>call <SID>NetrwMarkFilePrint(0)<cr> |
| 2114 | inoremap <buffer> <silent> mr <c-o>:<c-u>call <SID>NetrwMarkFileRegexp(0)<cr> |
| 2115 | inoremap <buffer> <silent> ms <c-o>:<c-u>call <SID>NetrwMarkFileSource(0)<cr> |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2116 | inoremap <buffer> <silent> mt <c-o>:<c-u>call <SID>NetrwMarkFileTgt(0)<cr> |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 2117 | inoremap <buffer> <silent> mT <c-o>:<c-u>call <SID>NetrwMarkFileTag(0)<cr> |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2118 | inoremap <buffer> <silent> mu <c-o>:<c-u>call <SID>NetrwUnMarkFile(0)<cr> |
| 2119 | inoremap <buffer> <silent> mx <c-o>:<c-u>call <SID>NetrwMarkFileExe(0)<cr> |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 2120 | inoremap <buffer> <silent> mX <c-o>:<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr> |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2121 | inoremap <buffer> <silent> mz <c-o>:<c-u>call <SID>NetrwMarkFileCompress(0)<cr> |
| 2122 | inoremap <buffer> <silent> gb <c-o>:<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_cur)<cr> |
| 2123 | inoremap <buffer> <silent> gh <c-o>:<c-u>call <SID>NetrwHidden(0)<cr> |
| 2124 | inoremap <buffer> <silent> gp <c-o>:<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr> |
| 2125 | inoremap <buffer> <silent> C <c-o>:let g:netrw_chgwin= winnr()<cr> |
| 2126 | inoremap <buffer> <silent> i <c-o>:call <SID>NetrwListStyle(0)<cr> |
| 2127 | inoremap <buffer> <silent> I <c-o>:call <SID>NetrwBannerCtrl(1)<cr> |
| 2128 | inoremap <buffer> <silent> o <c-o>:call <SID>NetrwSplit(0)<cr> |
| 2129 | inoremap <buffer> <silent> O <c-o>:call <SID>NetrwObtain(0)<cr> |
| 2130 | inoremap <buffer> <silent> p <c-o>:call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr> |
| 2131 | inoremap <buffer> <silent> P <c-o>:call <SID>NetrwPrevWinOpen(0)<cr> |
| 2132 | inoremap <buffer> <silent> qb <c-o>:<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr> |
| 2133 | inoremap <buffer> <silent> mB <c-o>:<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr> |
| 2134 | inoremap <buffer> <silent> qf <c-o>:<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr> |
| 2135 | 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> |
| 2136 | inoremap <buffer> <silent> s <c-o>:call <SID>NetrwSortStyle(0)<cr> |
| 2137 | inoremap <buffer> <silent> S <c-o>:call <SID>NetSortSequence(0)<cr> |
| 2138 | inoremap <buffer> <silent> t <c-o>:call <SID>NetrwSplit(1)<cr> |
| 2139 | inoremap <buffer> <silent> T <c-o>:call <SID>NetrwSplit(1)<bar>norm! gT<cr> |
| 2140 | inoremap <buffer> <silent> u <c-o>:<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr> |
| 2141 | inoremap <buffer> <silent> U <c-o>:<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr> |
| 2142 | inoremap <buffer> <silent> v <c-o>:call <SID>NetrwSplit(2)<cr> |
| 2143 | inoremap <buffer> <silent> x <c-o>:call netrw#NetrwBrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr> |
| 2144 | inoremap <buffer> <silent> % <c-o>:call <SID>NetrwOpenFile(0)<cr> |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2145 | if !hasmapto('<Plug>NetrwHideEdit') |
| 2146 | nmap <buffer> <c-h> <Plug>NetrwHideEdit |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2147 | imap <buffer> <c-h> <Plug>NetrwHideEdit |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2148 | endif |
| 2149 | nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr> |
| 2150 | if !hasmapto('<Plug>NetrwRefresh') |
| 2151 | nmap <buffer> <c-l> <Plug>NetrwRefresh |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2152 | imap <buffer> <c-l> <Plug>NetrwRefresh |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2153 | endif |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 2154 | |
| 2155 | let mapsafepath = escape(s:path, s:netrw_map_escape) |
| 2156 | let mapsafeusermach = escape(s:user.s:machine, s:netrw_map_escape) |
| 2157 | |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 2158 | nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr> |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2159 | if g:netrw_mousemaps == 1 |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 2160 | nmap <leftmouse> <Plug>NetrwLeftmouse |
| 2161 | nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(0)<cr> |
| 2162 | nmap <middlemouse> <Plug>NetrwMiddlemouse |
| 2163 | nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(0)<cr> |
| 2164 | nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse |
| 2165 | nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr> |
| 2166 | nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse |
| 2167 | nmap <buffer> <silent> <Plug>Netrw2Leftmouse - |
| 2168 | imap <buffer> <leftmouse> <Plug>ILeftmouse |
| 2169 | ino <buffer> <silent> <Plug>ILeftmouse <c-o><leftmouse><c-o>:call <SID>NetrwLeftmouse(0)<cr> |
| 2170 | imap <buffer> <middlemouse> <Plug>IMiddlemouse |
| 2171 | ino <buffer> <silent> <Plug>IMiddlemouse <c-o><leftmouse><c-o>:call <SID>NetrwPrevWinOpen(0)<cr> |
| 2172 | imap <buffer> <s-leftmouse> <Plug>ISLeftmouse |
| 2173 | ino <buffer> <silent> <Plug>ISLeftmouse <c-o><leftmouse><c-o>:call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr> |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 2174 | exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>' |
| 2175 | exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>' |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2176 | exe 'inoremap <buffer> <silent> <rightmouse> <c-o><leftmouse><c-o>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2177 | endif |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 2178 | exe 'nnoremap <buffer> <silent> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>' |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2179 | exe 'nnoremap <buffer> <silent> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>' |
| 2180 | exe 'nnoremap <buffer> <silent> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>' |
| 2181 | exe 'nnoremap <buffer> <silent> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>' |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 2182 | exe 'vnoremap <buffer> <silent> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>' |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2183 | exe 'vnoremap <buffer> <silent> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>' |
| 2184 | exe 'vnoremap <buffer> <silent> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>' |
| 2185 | exe 'inoremap <buffer> <silent> <del> <c-o>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>' |
| 2186 | exe 'inoremap <buffer> <silent> d <c-o>:call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>' |
| 2187 | exe 'inoremap <buffer> <silent> D <c-o>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>' |
| 2188 | exe 'inoremap <buffer> <silent> R <c-o>:call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>' |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 2189 | nnoremap <buffer> <F1> :he netrw-quickhelp<cr> |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2190 | inoremap <buffer> <F1> <c-o>:he netrw-quickhelp<cr> |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2191 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2192 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2193 | keepj call s:SetRexDir(a:islocal,b:netrw_curdir) |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 2194 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2195 | " call Dret("s:NetrwMaps") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2196 | endfun |
| 2197 | |
| 2198 | " --------------------------------------------------------------------- |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2199 | " s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2 |
| 2200 | fun! s:ExplorePatHls(pattern) |
| 2201 | " call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)") |
| 2202 | let repat= substitute(a:pattern,'^**/\{1,2}','','') |
| 2203 | " call Decho("repat<".repat.">") |
| 2204 | let repat= escape(repat,'][.\') |
| 2205 | " call Decho("repat<".repat.">") |
| 2206 | let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>' |
| 2207 | " call Dret("s:ExplorePatHls repat<".repat.">") |
| 2208 | return repat |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2209 | endfun |
| 2210 | |
| 2211 | " --------------------------------------------------------------------- |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2212 | " s:NetrwBookHistHandler: {{{2 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2213 | " 0: (user: <mb>) bookmark current directory |
| 2214 | " 1: (user: <gb>) change to the bookmarked directory |
| 2215 | " 2: (user: <qb>) list bookmarks |
| 2216 | " 3: (browsing) record current directory history |
| 2217 | " 4: (user: <u>) go up (previous) bookmark |
| 2218 | " 5: (user: <U>) go down (next) bookmark |
| 2219 | " 6: (user: <mB>) delete bookmark |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2220 | fun! s:NetrwBookHistHandler(chg,curdir) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2221 | " call Dfunc("s:NetrwBookHistHandler(chg=".a:chg." curdir<".a:curdir.">) cnt=".v:count." histcnt=".g:netrw_dirhist_cnt." histmax=".g:netrw_dirhistmax) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2222 | |
| 2223 | if a:chg == 0 |
| 2224 | " bookmark the current directory |
| 2225 | " call Decho("(user: <b>) bookmark the current directory") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2226 | if !exists("g:netrw_bookmarklist") |
| 2227 | let g:netrw_bookmarklist= [] |
| 2228 | endif |
| 2229 | if index(g:netrw_bookmarklist,a:curdir) == -1 |
| 2230 | " curdir not currently in g:netrw_bookmarklist, so include it |
| 2231 | call add(g:netrw_bookmarklist,a:curdir) |
| 2232 | call sort(g:netrw_bookmarklist) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2233 | endif |
| 2234 | echo "bookmarked the current directory" |
| 2235 | |
| 2236 | elseif a:chg == 1 |
| 2237 | " change to the bookmarked directory |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2238 | " call Decho("(user: <".v:count."mb>) change to the bookmarked directory") |
| 2239 | if exists("g:netrw_bookmarklist[v:count-1]") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2240 | exe "keepj e ".fnameescape(g:netrw_bookmarklist[v:count-1]) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2241 | else |
| 2242 | echomsg "Sorry, bookmark#".v:count." doesn't exist!" |
| 2243 | endif |
| 2244 | |
| 2245 | elseif a:chg == 2 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2246 | " redraw! |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2247 | let didwork= 0 |
| 2248 | " list user's bookmarks |
| 2249 | " call Decho("(user: <q>) list user's bookmarks") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2250 | if exists("g:netrw_bookmarklist") |
| 2251 | " call Decho('list '.len(g:netrw_bookmarklist).' bookmarks') |
| 2252 | let cnt= 1 |
| 2253 | for bmd in g:netrw_bookmarklist |
| 2254 | " call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1]) |
| 2255 | echo "Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1] |
| 2256 | let didwork = 1 |
| 2257 | let cnt = cnt + 1 |
| 2258 | endfor |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2259 | endif |
| 2260 | |
| 2261 | " list directory history |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2262 | let cnt = g:netrw_dirhist_cnt |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2263 | let first = 1 |
| 2264 | let histcnt = 0 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2265 | if g:netrw_dirhistmax > 0 |
| 2266 | while ( first || cnt != g:netrw_dirhist_cnt ) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2267 | " call Decho("first=".first." cnt=".cnt." dirhist_cnt=".g:netrw_dirhist_cnt) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2268 | let histcnt= histcnt + 1 |
| 2269 | if exists("g:netrw_dirhist_{cnt}") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2270 | " call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt}) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2271 | echo "Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt} |
| 2272 | let didwork= 1 |
| 2273 | endif |
| 2274 | let first = 0 |
| 2275 | let cnt = ( cnt - 1 ) % g:netrw_dirhistmax |
| 2276 | if cnt < 0 |
| 2277 | let cnt= cnt + g:netrw_dirhistmax |
| 2278 | endif |
| 2279 | endwhile |
| 2280 | else |
| 2281 | let g:netrw_dirhist_cnt= 0 |
| 2282 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2283 | if didwork |
| 2284 | call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
| 2285 | endif |
| 2286 | |
| 2287 | elseif a:chg == 3 |
| 2288 | " saves most recently visited directories (when they differ) |
| 2289 | " call Decho("(browsing) record curdir history") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2290 | if !exists("g:netrw_dirhist_cnt") || !exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}") || g:netrw_dirhist_{g:netrw_dirhist_cnt} != a:curdir |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2291 | if g:netrw_dirhistmax > 0 |
| 2292 | let g:netrw_dirhist_cnt = ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax |
| 2293 | let g:netrw_dirhist_{g:netrw_dirhist_cnt} = a:curdir |
| 2294 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2295 | " call Decho("save dirhist#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2296 | endif |
| 2297 | |
| 2298 | elseif a:chg == 4 |
| 2299 | " u: change to the previous directory stored on the history list |
| 2300 | " call Decho("(user: <u>) chg to prev dir from history") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2301 | if g:netrw_dirhistmax > 0 |
| 2302 | let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt - 1 ) % g:netrw_dirhistmax |
| 2303 | if g:netrw_dirhist_cnt < 0 |
| 2304 | let g:netrw_dirhist_cnt= g:netrw_dirhist_cnt + g:netrw_dirhistmax |
| 2305 | endif |
| 2306 | else |
| 2307 | let g:netrw_dirhist_cnt= 0 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2308 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2309 | if exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}") |
| 2310 | " call Decho("changedir u#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2311 | if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir") |
| 2312 | setlocal ma noro |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2313 | " call Decho("setlocal ma noro") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2314 | sil! keepj %d |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2315 | setlocal nomod |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2316 | " call Decho("setlocal nomod") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2317 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2318 | " " call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt})) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2319 | exe "keepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt}) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2320 | else |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2321 | if g:netrw_dirhistmax > 0 |
| 2322 | let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax |
| 2323 | else |
| 2324 | let g:netrw_dirhist_cnt= 0 |
| 2325 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2326 | echo "Sorry, no predecessor directory exists yet" |
| 2327 | endif |
| 2328 | |
| 2329 | elseif a:chg == 5 |
| 2330 | " U: change to the subsequent directory stored on the history list |
| 2331 | " call Decho("(user: <U>) chg to next dir from history") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2332 | if g:netrw_dirhistmax > 0 |
| 2333 | let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax |
| 2334 | if exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2335 | " call Decho("changedir U#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2336 | if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir") |
| 2337 | setlocal ma noro |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2338 | " call Decho("setlocal ma noro") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2339 | sil! keepj %d |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2340 | " call Decho("removed all lines from buffer (%d)") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2341 | setlocal nomod |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2342 | " call Decho("setlocal nomod") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2343 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2344 | " call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt})) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2345 | exe "keepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt}) |
| 2346 | else |
| 2347 | let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt - 1 ) % g:netrw_dirhistmax |
| 2348 | if g:netrw_dirhist_cnt < 0 |
| 2349 | let g:netrw_dirhist_cnt= g:netrw_dirhist_cnt + g:netrw_dirhistmax |
| 2350 | endif |
| 2351 | echo "Sorry, no successor directory exists yet" |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2352 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2353 | else |
| 2354 | let g:netrw_dirhist_cnt= 0 |
| 2355 | echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")" |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2356 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2357 | |
| 2358 | elseif a:chg == 6 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2359 | " delete the v:count'th bookmark |
| 2360 | " call Decho("delete bookmark#".v:count."<".g:netrw_bookmarklist[v:count-1].">") |
| 2361 | let savefile= s:NetrwHome()."/.netrwbook" |
| 2362 | if filereadable(savefile) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2363 | keepj call s:NetrwBookHistSave() " done here to merge bookmarks first |
| 2364 | keepj call delete(savefile) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2365 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2366 | keepj call remove(g:netrw_bookmarklist,v:count-1) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2367 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2368 | call s:NetrwBookmarkMenu() |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2369 | " call Dret("s:NetrwBookHistHandler") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2370 | endfun |
| 2371 | |
| 2372 | " --------------------------------------------------------------------- |
| 2373 | " s:NetrwBookHistRead: this function reads bookmarks and history {{{2 |
| 2374 | " Sister function: s:NetrwBookHistSave() |
| 2375 | fun! s:NetrwBookHistRead() |
| 2376 | " call Dfunc("s:NetrwBookHistRead()") |
| 2377 | if !exists("s:netrw_initbookhist") |
| 2378 | let home = s:NetrwHome() |
| 2379 | let savefile= home."/.netrwbook" |
| 2380 | if filereadable(savefile) |
| 2381 | " call Decho("sourcing .netrwbook") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2382 | exe "keepj so ".savefile |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2383 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2384 | if g:netrw_dirhistmax > 0 |
| 2385 | let savefile= home."/.netrwhist" |
| 2386 | if filereadable(savefile) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2387 | " call Decho("sourcing .netrwhist") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2388 | exe "keepj so ".savefile |
| 2389 | endif |
| 2390 | let s:netrw_initbookhist= 1 |
| 2391 | au VimLeave * call s:NetrwBookHistSave() |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2392 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2393 | endif |
| 2394 | " call Dret("s:NetrwBookHistRead") |
| 2395 | endfun |
| 2396 | |
| 2397 | " --------------------------------------------------------------------- |
| 2398 | " s:NetrwBookHistSave: this function saves bookmarks and history {{{2 |
| 2399 | " Sister function: s:NetrwBookHistRead() |
| 2400 | " I used to do this via viminfo but that appears to |
| 2401 | " be unreliable for long-term storage |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2402 | fun! s:NetrwBookHistSave() |
| 2403 | " call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2404 | if g:netrw_dirhistmax <= 0 |
| 2405 | " call Dret("s:NetrwBookHistSave : dirhistmax=".g:netrw_dirhistmax) |
| 2406 | return |
| 2407 | endif |
| 2408 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2409 | let savefile= s:NetrwHome()."/.netrwhist" |
| 2410 | 1split |
| 2411 | call s:NetrwEnew() |
| 2412 | setlocal cino= com= cpo-=aA fo=nroql2 tw=0 report=10000 noswf |
| 2413 | setlocal nocin noai noci magic nospell nohid wig= noaw |
| 2414 | setlocal ma noro write |
| 2415 | if exists("&acd") | setlocal noacd | endif |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 2416 | sil! keepj keepalt %d |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2417 | |
| 2418 | " save .netrwhist -- no attempt to merge |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2419 | sil! file .netrwhist |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2420 | call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax) |
| 2421 | call setline(2,"let g:netrw_dirhist_cnt =".g:netrw_dirhist_cnt) |
| 2422 | let lastline = line("$") |
| 2423 | let cnt = 1 |
| 2424 | while cnt <= g:netrw_dirhist_cnt |
| 2425 | call setline((cnt+lastline),'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'") |
| 2426 | let cnt= cnt + 1 |
| 2427 | endwhile |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2428 | exe "sil! w! ".savefile |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2429 | |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2430 | sil keepj %d |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2431 | if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] |
| 2432 | " merge and write .netrwbook |
| 2433 | let savefile= s:NetrwHome()."/.netrwbook" |
| 2434 | |
| 2435 | if filereadable(savefile) |
| 2436 | let booklist= deepcopy(g:netrw_bookmarklist) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2437 | exe "sil keepj so ".savefile |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2438 | for bdm in booklist |
| 2439 | if index(g:netrw_bookmarklist,bdm) == -1 |
| 2440 | call add(g:netrw_bookmarklist,bdm) |
| 2441 | endif |
| 2442 | endfor |
| 2443 | call sort(g:netrw_bookmarklist) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2444 | exe "sil! w! ".savefile |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2445 | endif |
| 2446 | |
| 2447 | " construct and save .netrwbook |
| 2448 | call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist)) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2449 | exe "sil! w! ".savefile |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2450 | endif |
| 2451 | let bgone= bufnr("%") |
| 2452 | q! |
| 2453 | exe bgone."bwipe!" |
| 2454 | |
| 2455 | " call Dret("s:NetrwBookHistSave") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2456 | endfun |
| 2457 | |
| 2458 | " --------------------------------------------------------------------- |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2459 | " s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2 |
| 2460 | " list of the contents of a local or remote directory. It is assumed that the |
| 2461 | " g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted |
| 2462 | " with the requested remote hostname first. |
| 2463 | fun! s:NetrwBrowse(islocal,dirname) |
| 2464 | if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2465 | " call Dfunc("s:NetrwBrowse(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".w:netrw_liststyle." ".g:loaded_netrw." buf#".bufnr("%")."<".bufname("%")."> win#".winnr()) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2466 | " call Decho("tab#".tabpagenr()." win#".winnr()) |
| 2467 | " call Dredir("ls!") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2468 | if !exists("s:netrw_initbookhist") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2469 | keepj call s:NetrwBookHistRead() |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2470 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2471 | |
| 2472 | " simplify the dirname (especially for ".."s in dirnames) |
| 2473 | if a:dirname !~ '^\a\+://' |
| 2474 | let dirname= simplify(a:dirname) |
| 2475 | else |
| 2476 | let dirname= a:dirname |
| 2477 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2478 | |
| 2479 | if exists("s:netrw_skipbrowse") |
| 2480 | unlet s:netrw_skipbrowse |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 2481 | " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2482 | " call Dret("s:NetrwBrowse : s:netrw_skipbrowse=".s:netrw_skipbrowse) |
| 2483 | return |
| 2484 | endif |
| 2485 | if !exists("*shellescape") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2486 | keepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2487 | " call Dret("s:NetrwBrowse : missing shellescape()") |
| 2488 | return |
| 2489 | endif |
| 2490 | if !exists("*fnameescape") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2491 | keepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2492 | " call Dret("s:NetrwBrowse : missing fnameescape()") |
| 2493 | return |
| 2494 | endif |
| 2495 | |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 2496 | call s:NetrwOptionSave("w:") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2497 | |
| 2498 | " re-instate any marked files |
| 2499 | if exists("s:netrwmarkfilelist_{bufnr('%')}") |
| 2500 | " call Decho("clearing marked files") |
| 2501 | exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/" |
| 2502 | endif |
| 2503 | |
| 2504 | if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep |
| 2505 | " call Decho("handle w:netrw_acdkeep:") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2506 | " call Decho("keepjumps lcd ".fnameescape(dirname)." (due to w:netrw_acdkeep=".w:netrw_acdkeep." - acd=".&acd.")") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2507 | exe 'keepj lcd '.fnameescape(dirname) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2508 | call s:NetrwSafeOptions() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2509 | " call Decho("getcwd<".getcwd().">") |
| 2510 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2511 | elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2512 | " looks like a regular file, attempt transfer |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2513 | " call Decho("attempt transfer as regular file<".dirname.">") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2514 | |
| 2515 | " remove any filetype indicator from end of dirname, except for the {{{3 |
| 2516 | " "this is a directory" indicator (/). |
| 2517 | " There shouldn't be one of those here, anyway. |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2518 | let path= substitute(dirname,'[*=@|]\r\=$','','e') |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2519 | " call Decho("new path<".path.">") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2520 | call s:RemotePathAnalysis(dirname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2521 | |
| 2522 | " remote-read the requested file into current buffer {{{3 |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2523 | keepj mark ' |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2524 | call s:NetrwEnew(dirname) |
| 2525 | call s:NetrwSafeOptions() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2526 | setlocal ma noro |
| 2527 | " call Decho("setlocal ma noro") |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 2528 | let b:netrw_curdir = dirname |
| 2529 | let url = s:method."://".s:user.s:machine.(s:port ? ":".s:port : "")."/".s:path |
| 2530 | " call Decho("exe sil! keepalt file ".fnameescape(url)." (bt=".&bt.")") |
| 2531 | exe "sil! keepj keepalt file ".fnameescape(url) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2532 | exe "sil! keepj keepalt doau BufReadPre ".fnameescape(s:fname) |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 2533 | sil call netrw#NetRead(2,url) |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 2534 | if s:path !~ '.tar.bz2$' && s:path !~ '.tar.gz' && s:path !~ '.tar.xz' && s:path !~ '.txz' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2535 | " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2536 | exe "sil keepj keepalt doau BufReadPost ".fnameescape(s:fname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2537 | endif |
| 2538 | |
| 2539 | " save certain window-oriented variables into buffer-oriented variables {{{3 |
| 2540 | call s:SetBufWinVars() |
| 2541 | call s:NetrwOptionRestore("w:") |
| 2542 | setlocal ma nomod |
| 2543 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 2544 | " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2545 | " call Dret("s:NetrwBrowse : file<".s:fname.">") |
| 2546 | return |
| 2547 | endif |
| 2548 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2549 | " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2550 | call s:UseBufWinVars() |
| 2551 | |
| 2552 | " set up some variables {{{3 |
| 2553 | let b:netrw_browser_active = 1 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2554 | let dirname = dirname |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2555 | let s:last_sort_by = g:netrw_sort_by |
| 2556 | |
| 2557 | " set up menu {{{3 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2558 | keepj call s:NetrwMenu(1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2559 | |
| 2560 | " set up buffer {{{3 |
| 2561 | let reusing= s:NetrwGetBuffer(a:islocal,dirname) |
| 2562 | " maintain markfile highlighting |
| 2563 | if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != "" |
| 2564 | " call Decho("bufnr(%)=".bufnr('%')) |
| 2565 | " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/") |
| 2566 | exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/" |
| 2567 | else |
| 2568 | " call Decho("2match none") |
| 2569 | 2match none |
| 2570 | endif |
| 2571 | if reusing |
| 2572 | call s:NetrwOptionRestore("w:") |
| 2573 | setlocal noma nomod nowrap |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 2574 | " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2575 | " call Dret("s:NetrwBrowse : re-using buffer") |
| 2576 | return |
| 2577 | endif |
| 2578 | |
| 2579 | " set b:netrw_curdir to the new directory name {{{3 |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2580 | " call Decho("set b:netrw_curdir to the new directory name: (buf#".bufnr("%").")") |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 2581 | let b:netrw_curdir= dirname |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2582 | if b:netrw_curdir =~ '[/\\]$' |
| 2583 | let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e') |
| 2584 | endif |
| 2585 | if b:netrw_curdir == '' |
| 2586 | if has("amiga") |
| 2587 | " On the Amiga, the empty string connotes the current directory |
| 2588 | let b:netrw_curdir= getcwd() |
| 2589 | else |
| 2590 | " under unix, when the root directory is encountered, the result |
| 2591 | " from the preceding substitute is an empty string. |
| 2592 | let b:netrw_curdir= '/' |
| 2593 | endif |
| 2594 | endif |
| 2595 | if !a:islocal && b:netrw_curdir !~ '/$' |
| 2596 | let b:netrw_curdir= b:netrw_curdir.'/' |
| 2597 | endif |
| 2598 | " call Decho("b:netrw_curdir<".b:netrw_curdir.">") |
| 2599 | |
| 2600 | " ------------ |
| 2601 | " (local only) {{{3 |
| 2602 | " ------------ |
| 2603 | if a:islocal |
| 2604 | " call Decho("local only:") |
| 2605 | |
| 2606 | " Set up ShellCmdPost handling. Append current buffer to browselist |
| 2607 | call s:LocalFastBrowser() |
| 2608 | |
| 2609 | " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3 |
| 2610 | if !g:netrw_keepdir |
| 2611 | " call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd) |
| 2612 | " call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist")) |
| 2613 | if !exists("&l:acd") || !&l:acd |
| 2614 | " call Decho('exe keepjumps lcd '.fnameescape(b:netrw_curdir)) |
| 2615 | try |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2616 | exe 'keepj lcd '.fnameescape(b:netrw_curdir) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2617 | catch /^Vim\%((\a\+)\)\=:E472/ |
| 2618 | call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".b:netrw_curdir."> (permissions?)",61) |
| 2619 | if exists("w:netrw_prvdir") |
| 2620 | let b:netrw_curdir= w:netrw_prvdir |
| 2621 | else |
| 2622 | call s:NetrwOptionRestore("w:") |
| 2623 | setlocal noma nomod nowrap |
| 2624 | let b:netrw_curdir= dirname |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 2625 | " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2626 | " call Dret("s:NetrwBrowse : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">") |
| 2627 | return |
| 2628 | endif |
| 2629 | endtry |
| 2630 | endif |
| 2631 | endif |
| 2632 | |
| 2633 | " -------------------------------- |
| 2634 | " remote handling: {{{3 |
| 2635 | " -------------------------------- |
| 2636 | else |
| 2637 | " call Decho("remote only:") |
| 2638 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2639 | " analyze dirname and g:netrw_list_cmd {{{4 |
| 2640 | " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist")."> dirname<".dirname.">") |
| 2641 | if dirname =~ "^NetrwTreeListing\>" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2642 | let dirname= b:netrw_curdir |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2643 | " call Decho("(dirname was ".dirname.") dirname<".dirname.">") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2644 | elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir") |
| 2645 | let dirname= substitute(b:netrw_curdir,'\\','/','g') |
| 2646 | if dirname !~ '/$' |
| 2647 | let dirname= dirname.'/' |
| 2648 | endif |
| 2649 | let b:netrw_curdir = dirname |
| 2650 | " call Decho("(liststyle is TREELIST) dirname<".dirname.">") |
| 2651 | else |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2652 | let dirname = substitute(dirname,'\\','/','g') |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2653 | " call Decho("(normal) dirname<".dirname.">") |
| 2654 | endif |
| 2655 | |
| 2656 | let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$' |
| 2657 | if dirname !~ dirpat |
| 2658 | if !exists("g:netrw_quiet") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2659 | keepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2660 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2661 | keepj call s:NetrwOptionRestore("w:") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2662 | setlocal noma nomod nowrap |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 2663 | " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2664 | " call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">") |
| 2665 | return |
| 2666 | endif |
| 2667 | let b:netrw_curdir= dirname |
| 2668 | " call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)") |
| 2669 | endif " (additional remote handling) |
| 2670 | |
| 2671 | " ----------------------- |
| 2672 | " Directory Listing: {{{3 |
| 2673 | " ----------------------- |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2674 | keepj call s:NetrwMaps(a:islocal) |
| 2675 | keepj call s:PerformListing(a:islocal) |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 2676 | if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2677 | let &l:bexpr= "netrw#NetrwBalloonHelp()" |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 2678 | " call Decho("set up balloon help: l:bexpr=".&l:bexpr) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2679 | set beval |
| 2680 | endif |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 2681 | call s:NetrwOptionRestore("w:") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2682 | |
| 2683 | " The s:LocalBrowseShellCmdRefresh() function is called by an autocmd |
| 2684 | " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow, medium speed). |
| 2685 | " However, s:NetrwBrowse() causes the ShellCmdPost event itself to fire once; setting |
| 2686 | " the variable below avoids that second refresh of the screen. The s:LocalBrowseShellCmdRefresh() |
| 2687 | " function gets called due to that autocmd; it notices that the following variable is set |
| 2688 | " and skips the refresh and sets s:locbrowseshellcmd to zero. Oct 13, 2008 |
| 2689 | let s:locbrowseshellcmd= 1 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2690 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 2691 | " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2692 | " call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2693 | return |
| 2694 | endfun |
| 2695 | |
| 2696 | " --------------------------------------------------------------------- |
| 2697 | " s:NetrwFileInfo: supports qf (query for file information) {{{2 |
| 2698 | fun! s:NetrwFileInfo(islocal,fname) |
| 2699 | " call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">)") |
| 2700 | if a:islocal |
| 2701 | if (has("unix") || has("macunix")) && executable("/bin/ls") |
| 2702 | if exists("b:netrw_curdir") |
| 2703 | " call Decho('using ls with b:netrw_curdir<'.b:netrw_curdir.'>') |
| 2704 | if b:netrw_curdir =~ '/$' |
| 2705 | echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir.a:fname)) |
| 2706 | else |
| 2707 | echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir."/".a:fname)) |
| 2708 | endif |
| 2709 | else |
| 2710 | " call Decho('using ls '.a:fname." using cwd<".getcwd().">") |
| 2711 | echo system("/bin/ls -lsad ".shellescape(a:fname)) |
| 2712 | endif |
| 2713 | else |
| 2714 | " use vim functions to return information about file below cursor |
| 2715 | " call Decho("using vim functions to query for file info") |
| 2716 | if !isdirectory(a:fname) && !filereadable(a:fname) && a:fname =~ '[*@/]' |
| 2717 | let fname= substitute(a:fname,".$","","") |
| 2718 | else |
| 2719 | let fname= a:fname |
| 2720 | endif |
| 2721 | let t = getftime(fname) |
| 2722 | let sz = getfsize(fname) |
| 2723 | echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)) |
| 2724 | " call Decho(fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname))) |
| 2725 | endif |
| 2726 | else |
| 2727 | echo "sorry, \"qf\" not supported yet for remote files" |
| 2728 | endif |
| 2729 | " call Dret("s:NetrwFileInfo") |
| 2730 | endfun |
| 2731 | |
| 2732 | " --------------------------------------------------------------------- |
| 2733 | " s:NetrwGetBuffer: {{{2 |
| 2734 | " returns 0=cleared buffer |
| 2735 | " 1=re-used buffer |
| 2736 | fun! s:NetrwGetBuffer(islocal,dirname) |
| 2737 | " call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle) |
| 2738 | let dirname= a:dirname |
| 2739 | |
| 2740 | " re-use buffer if possible {{{3 |
| 2741 | " call Decho("--re-use a buffer if possible--") |
| 2742 | if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST |
| 2743 | " find NetrwTreeList buffer if there is one |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2744 | " call Decho("find NetrwTreeList buffer if there is one") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2745 | if exists("w:netrw_treebufnr") && w:netrw_treebufnr > 0 |
| 2746 | " call Decho(" re-use w:netrw_treebufnr=".w:netrw_treebufnr) |
| 2747 | let eikeep= &ei |
| 2748 | set ei=all |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 2749 | exe "sil! b ".w:netrw_treebufnr |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2750 | let &ei= eikeep |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2751 | " call Dret("s:NetrwGetBuffer : bufnum#".w:netrw_treebufnr."<NetrwTreeListing>") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2752 | return |
| 2753 | endif |
| 2754 | let bufnum= -1 |
| 2755 | " call Decho(" liststyle=TREE but w:netrw_treebufnr doesn't exist") |
| 2756 | |
| 2757 | else |
| 2758 | " find buffer number of buffer named precisely the same as dirname {{{3 |
| 2759 | " call Decho("--find buffer numnber of buffer named precisely the same as dirname--") |
| 2760 | " call Dredir("ls!") |
| 2761 | |
| 2762 | " get dirname and associated buffer number |
| 2763 | let bufnum = bufnr(escape(dirname,'\')) |
| 2764 | " call Decho(" find buffer<".dirname.">'s number ") |
| 2765 | " call Decho(" bufnr(dirname<".escape(dirname,'\').">)=".bufnum) |
| 2766 | |
| 2767 | if bufnum < 0 && dirname !~ '/$' |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2768 | " try appending a trailing / |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2769 | " call Decho(" try appending a trailing / to dirname<".dirname.">") |
| 2770 | let bufnum= bufnr(escape(dirname.'/','\')) |
| 2771 | if bufnum > 0 |
| 2772 | let dirname= dirname.'/' |
| 2773 | endif |
| 2774 | endif |
| 2775 | |
| 2776 | if bufnum < 0 && dirname =~ '/$' |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2777 | " try removing a trailing / |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2778 | " call Decho(" try removing a trailing / from dirname<".dirname.">") |
| 2779 | let bufnum= bufnr(escape(substitute(dirname,'/$','',''),'\')) |
| 2780 | if bufnum > 0 |
| 2781 | let dirname= substitute(dirname,'/$','','') |
| 2782 | endif |
| 2783 | endif |
| 2784 | |
| 2785 | " call Decho(" findbuf1: bufnum=bufnr('".dirname."')=".bufnum." bufname(".bufnum.")<".bufname(bufnum)."> (initial)") |
| 2786 | " note: !~ was used just below, but that means using ../ to go back would match (ie. abc/def/ and abc/ matches) |
| 2787 | if bufnum > 0 && bufname(bufnum) != dirname && bufname(bufnum) != '.' |
| 2788 | " handle approximate matches |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2789 | " call Decho(" handling approx match: bufnum#".bufnum."<".bufname(bufnum)."> approx-dirname<".dirname.">") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2790 | let ibuf = 1 |
| 2791 | let buflast = bufnr("$") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2792 | " call Decho(" findbuf2: buflast=bufnr($)=".buflast) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2793 | while ibuf <= buflast |
| 2794 | let bname= substitute(bufname(ibuf),'\\','/','g') |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 2795 | let bname= substitute(bname,'.\zs/$','','') |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2796 | " call Decho(" findbuf3: while [ibuf=",ibuf."]<=[buflast=".buflast."]: dirname<".dirname."> bname=bufname(".ibuf.")<".bname.">") |
| 2797 | if bname != '' && dirname =~ '/'.bname.'/\=$' && dirname !~ '^/' |
| 2798 | " bname is not empty |
| 2799 | " dirname ends with bname, |
| 2800 | " dirname doesn't start with /, so its not a absolute path |
| 2801 | " call Decho(" findbuf3a: passes test 1 : dirname<".dirname.'> =~ /'.bname.'/\=$ && dirname !~ ^/') |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2802 | break |
| 2803 | endif |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2804 | if bname =~ '^'.dirname.'/\=$' |
| 2805 | " bname begins with dirname |
| 2806 | " call Decho(' findbuf3b: passes test 2 : bname<'.bname.'>=~^'.dirname.'/\=$') |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2807 | break |
| 2808 | endif |
| 2809 | if dirname =~ '^'.bname.'/$' |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2810 | " call Decho(' findbuf3c: passes test 3 : dirname<'.dirname.'>=~^'.bname.'/$') |
| 2811 | break |
| 2812 | endif |
| 2813 | if bname != '' && dirname =~ '/'.bname.'$' && bname == bufname("%") && line("$") == 1 |
| 2814 | " call Decho(' findbuf3d: passes test 4 : dirname<'.dirname.'>=~ /'.bname.'$') |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 2815 | break |
| 2816 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2817 | let ibuf= ibuf + 1 |
| 2818 | endwhile |
| 2819 | if ibuf > buflast |
| 2820 | let bufnum= -1 |
| 2821 | else |
| 2822 | let bufnum= ibuf |
| 2823 | endif |
| 2824 | " call Decho(" findbuf4: bufnum=".bufnum." (ibuf=".ibuf." buflast=".buflast.")") |
| 2825 | endif |
| 2826 | endif |
| 2827 | |
| 2828 | " get enew buffer and name it -or- re-use buffer {{{3 |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 2829 | sil! keepj mark ' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2830 | if bufnum < 0 || !bufexists(bufnum) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2831 | " call Decho("--get enew buffer and name it (bufexists([bufnum=".bufnum."])=".bufexists(bufnum).")") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2832 | call s:NetrwEnew(dirname) |
| 2833 | " call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)") |
| 2834 | " name the buffer |
| 2835 | if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST |
| 2836 | " Got enew buffer; transform into a NetrwTreeListing |
| 2837 | " call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --") |
| 2838 | if !exists("s:netrw_treelistnum") |
| 2839 | let s:netrw_treelistnum= 1 |
| 2840 | else |
| 2841 | let s:netrw_treelistnum= s:netrw_treelistnum + 1 |
| 2842 | endif |
| 2843 | let w:netrw_treebufnr= bufnr("%") |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 2844 | " call Decho(" exe sil! keepalt file NetrwTreeListing ".fnameescape(s:netrw_treelistnum)) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2845 | exe 'sil! keepalt file NetrwTreeListing\ '.fnameescape(s:netrw_treelistnum) |
| 2846 | set bt=nofile noswf |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2847 | nnoremap <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr> |
| 2848 | nnoremap <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr> |
| 2849 | nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[')<cr> |
| 2850 | nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']')<cr> |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2851 | " call Decho(" tree listing#".s:netrw_treelistnum." bufnr=".w:netrw_treebufnr) |
| 2852 | else |
| 2853 | " let v:errmsg= "" " Decho |
| 2854 | let escdirname= fnameescape(dirname) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2855 | " call Decho(" errmsg<".v:errmsg."> bufnr(escdirname<".escdirname.">)=".bufnr(escdirname)." bufname()<".bufname(bufnr(escdirname)).">") |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 2856 | " call Decho(' exe sil! keepalt file '.escdirname) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2857 | " let v:errmsg= "" " Decho |
| 2858 | exe 'sil! keepalt file '.escdirname |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2859 | " call Decho(" errmsg<".v:errmsg."> bufnr(".escdirname.")=".bufnr(escdirname)."<".bufname(bufnr(escdirname)).">") |
| 2860 | endif |
| 2861 | " call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">") |
| 2862 | |
| 2863 | else " Re-use the buffer |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2864 | " call Decho("--re-use buffer#".bufnum." (bufexists([bufnum=".bufnum."])=".bufexists(bufnum).")") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2865 | let eikeep= &ei |
| 2866 | set ei=all |
| 2867 | if getline(2) =~ '^" Netrw Directory Listing' |
| 2868 | " call Decho(" re-use buffer#".bufnum."<".((bufnum > 0)? bufname(bufnum) : "")."> using: keepalt b ".bufnum) |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 2869 | exe "sil! keepalt b ".bufnum |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2870 | else |
| 2871 | " call Decho(" reusing buffer#".bufnum."<".((bufnum > 0)? bufname(bufnum) : "")."> using: b ".bufnum) |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 2872 | exe "sil! b ".bufnum |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2873 | endif |
| 2874 | if bufname("%") == '.' |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 2875 | " call Decho("exe sil! keepalt file ".fnameescape(getcwd())) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2876 | exe "sil! keepalt file ".fnameescape(getcwd()) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2877 | endif |
| 2878 | let &ei= eikeep |
| 2879 | if line("$") <= 1 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2880 | keepj call s:NetrwListSettings(a:islocal) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2881 | " call Dret("s:NetrwGetBuffer 0 : re-using buffer#".bufnr("%").", but its empty, so refresh it") |
| 2882 | return 0 |
| 2883 | elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST |
| 2884 | " call Decho("--re-use tree listing--") |
| 2885 | " call Decho(" clear buffer<".expand("%")."> with :%d") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2886 | sil keepj %d |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2887 | keepj call s:NetrwListSettings(a:islocal) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2888 | " call Dret("s:NetrwGetBuffer 0 : re-using buffer#".bufnr("%").", but treelist mode always needs a refresh") |
| 2889 | return 0 |
| 2890 | else |
| 2891 | " call Dret("s:NetrwGetBuffer 1 : buf#".bufnr("%")) |
| 2892 | return 1 |
| 2893 | endif |
| 2894 | endif |
| 2895 | |
| 2896 | " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3 |
| 2897 | " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast) |
| 2898 | " slow 0 D D Deleting a buffer implies it will not be re-used (slow) |
| 2899 | " med 1 D H |
| 2900 | " fast 2 H H |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2901 | " call Decho("--do netrw settings: make this buffer#".bufnr("%")." not-a-file, modifiable, not line-numbered, etc--") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2902 | let fname= expand("%") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2903 | keepj call s:NetrwListSettings(a:islocal) |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 2904 | " call Decho("exe sil! keepalt file ".fnameescape(fname)) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2905 | exe "sil! keepj keepalt file ".fnameescape(fname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2906 | |
| 2907 | " delete all lines from buffer {{{3 |
| 2908 | " call Decho("--delete all lines from buffer--") |
| 2909 | " call Decho(" clear buffer<".expand("%")."> with :%d") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2910 | sil! keepalt keepj %d |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2911 | |
| 2912 | " call Dret("s:NetrwGetBuffer 0 : buf#".bufnr("%")) |
| 2913 | return 0 |
| 2914 | endfun |
| 2915 | |
| 2916 | " --------------------------------------------------------------------- |
| 2917 | " s:NetrwGetcwd: get the current directory. {{{2 |
| 2918 | " Change backslashes to forward slashes, if any. |
| 2919 | " If doesc is true, escape certain troublesome characters |
| 2920 | fun! s:NetrwGetcwd(doesc) |
| 2921 | " call Dfunc("NetrwGetcwd(doesc=".a:doesc.")") |
| 2922 | let curdir= substitute(getcwd(),'\\','/','ge') |
| 2923 | if curdir !~ '[\/]$' |
| 2924 | let curdir= curdir.'/' |
| 2925 | endif |
| 2926 | if a:doesc |
| 2927 | let curdir= fnameescape(curdir) |
| 2928 | endif |
| 2929 | " call Dret("NetrwGetcwd <".curdir.">") |
| 2930 | return curdir |
| 2931 | endfun |
| 2932 | |
| 2933 | " --------------------------------------------------------------------- |
| 2934 | " s:NetrwGetWord: it gets the directory/file named under the cursor {{{2 |
| 2935 | fun! s:NetrwGetWord() |
| 2936 | " call Dfunc("s:NetrwGetWord() line#".line(".")." liststyle=".g:netrw_liststyle." virtcol=".virtcol(".")) |
| 2937 | call s:UseBufWinVars() |
| 2938 | |
| 2939 | " insure that w:netrw_liststyle is set up |
| 2940 | if !exists("w:netrw_liststyle") |
| 2941 | if exists("g:netrw_liststyle") |
| 2942 | let w:netrw_liststyle= g:netrw_liststyle |
| 2943 | else |
| 2944 | let w:netrw_liststyle= s:THINLIST |
| 2945 | endif |
| 2946 | " call Decho("w:netrw_liststyle=".w:netrw_liststyle) |
| 2947 | endif |
| 2948 | |
| 2949 | if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt |
| 2950 | " Active Banner support |
| 2951 | " call Decho("active banner handling") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2952 | keepj norm! 0 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2953 | let dirname= "./" |
| 2954 | let curline= getline('.') |
| 2955 | |
| 2956 | if curline =~ '"\s*Sorted by\s' |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2957 | keepj norm s |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2958 | let s:netrw_skipbrowse= 1 |
| 2959 | echo 'Pressing "s" also works' |
| 2960 | |
| 2961 | elseif curline =~ '"\s*Sort sequence:' |
| 2962 | let s:netrw_skipbrowse= 1 |
| 2963 | echo 'Press "S" to edit sorting sequence' |
| 2964 | |
| 2965 | elseif curline =~ '"\s*Quick Help:' |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2966 | keepj norm ? |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2967 | let s:netrw_skipbrowse= 1 |
| 2968 | echo 'Pressing "?" also works' |
| 2969 | |
| 2970 | elseif curline =~ '"\s*\%(Hiding\|Showing\):' |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2971 | keepj norm a |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2972 | let s:netrw_skipbrowse= 1 |
| 2973 | echo 'Pressing "a" also works' |
| 2974 | |
| 2975 | elseif line("$") > w:netrw_bannercnt |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2976 | exe 'sil keepj '.w:netrw_bannercnt |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2977 | endif |
| 2978 | |
| 2979 | elseif w:netrw_liststyle == s:THINLIST |
| 2980 | " call Decho("thin column handling") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2981 | keepj norm! 0 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2982 | let dirname= getline('.') |
| 2983 | |
| 2984 | elseif w:netrw_liststyle == s:LONGLIST |
| 2985 | " call Decho("long column handling") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 2986 | keepj norm! 0 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 2987 | let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e') |
| 2988 | |
| 2989 | elseif w:netrw_liststyle == s:TREELIST |
| 2990 | " call Decho("treelist handling") |
| 2991 | let dirname= substitute(getline('.'),'^\(| \)*','','e') |
| 2992 | |
| 2993 | else |
| 2994 | " call Decho("obtain word from wide listing") |
| 2995 | let dirname= getline('.') |
| 2996 | |
| 2997 | if !exists("b:netrw_cpf") |
| 2998 | let b:netrw_cpf= 0 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 2999 | exe 'sil keepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif' |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3000 | call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3001 | " call Decho("computed cpf=".b:netrw_cpf) |
| 3002 | endif |
| 3003 | |
| 3004 | " call Decho("buf#".bufnr("%")."<".bufname("%").">") |
| 3005 | let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf |
| 3006 | " call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt) |
| 3007 | " call Decho("1: dirname<".dirname.">") |
| 3008 | if filestart == 0 |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3009 | keepj norm! 0ma |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3010 | else |
| 3011 | call cursor(line("."),filestart+1) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3012 | keepj norm! ma |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3013 | endif |
| 3014 | let rega= @a |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 3015 | let eofname= filestart + b:netrw_cpf + 1 |
| 3016 | if eofname <= col("$") |
| 3017 | call cursor(line("."),filestart+b:netrw_cpf+1) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3018 | keepj norm! "ay`a |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 3019 | else |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3020 | keepj norm! "ay$ |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 3021 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3022 | let dirname = @a |
| 3023 | let @a = rega |
| 3024 | " call Decho("2: dirname<".dirname.">") |
| 3025 | let dirname= substitute(dirname,'\s\+$','','e') |
| 3026 | " call Decho("3: dirname<".dirname.">") |
| 3027 | endif |
| 3028 | |
| 3029 | " symlinks are indicated by a trailing "@". Remove it before further processing. |
| 3030 | let dirname= substitute(dirname,"@$","","") |
| 3031 | |
| 3032 | " executables are indicated by a trailing "*". Remove it before further processing. |
| 3033 | let dirname= substitute(dirname,"\*$","","") |
| 3034 | |
| 3035 | " call Dret("s:NetrwGetWord <".dirname.">") |
| 3036 | return dirname |
| 3037 | endfun |
| 3038 | |
| 3039 | " --------------------------------------------------------------------- |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3040 | " s:NetrwListSettings: make standard settings for a netrw listing {{{2 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3041 | fun! s:NetrwListSettings(islocal) |
| 3042 | " call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")") |
| 3043 | let fname= bufname("%") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3044 | " call Decho("setlocal bt=nofile nobl ma nonu nowrap noro") |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 3045 | setlocal bt=nofile nobl ma nonu nowrap noro |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 3046 | " call Decho("exe sil! keepalt file ".fnameescape(fname)) |
| 3047 | exe "sil! keepalt file ".fnameescape(fname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3048 | if g:netrw_use_noswf |
| 3049 | setlocal noswf |
| 3050 | endif |
| 3051 | " call Dredir("ls!") |
| 3052 | " call Decho("exe setlocal ts=".g:netrw_maxfilenamelen) |
| 3053 | exe "setlocal ts=".g:netrw_maxfilenamelen |
| 3054 | setlocal isk+=.,~,- |
| 3055 | if g:netrw_fastbrowse > a:islocal |
| 3056 | setlocal bh=hide |
| 3057 | else |
| 3058 | setlocal bh=delete |
| 3059 | endif |
| 3060 | " call Dret("s:NetrwListSettings") |
| 3061 | endfun |
| 3062 | |
| 3063 | " --------------------------------------------------------------------- |
| 3064 | " s:NetrwListStyle: {{{2 |
| 3065 | " islocal=0: remote browsing |
| 3066 | " =1: local browsing |
| 3067 | fun! s:NetrwListStyle(islocal) |
| 3068 | " call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle) |
| 3069 | let fname = s:NetrwGetWord() |
| 3070 | if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif |
| 3071 | let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST |
| 3072 | " call Decho("fname<".fname.">") |
| 3073 | " call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle) |
| 3074 | " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">") |
| 3075 | |
| 3076 | if w:netrw_liststyle == s:THINLIST |
| 3077 | " use one column listing |
| 3078 | " call Decho("use one column list") |
| 3079 | let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge') |
| 3080 | |
| 3081 | elseif w:netrw_liststyle == s:LONGLIST |
| 3082 | " use long list |
| 3083 | " call Decho("use long list") |
| 3084 | let g:netrw_list_cmd = g:netrw_list_cmd." -l" |
| 3085 | |
| 3086 | elseif w:netrw_liststyle == s:WIDELIST |
| 3087 | " give wide list |
| 3088 | " call Decho("use wide list") |
| 3089 | let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge') |
| 3090 | |
| 3091 | elseif w:netrw_liststyle == s:TREELIST |
| 3092 | " call Decho("use tree list") |
| 3093 | let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge') |
| 3094 | |
| 3095 | else |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3096 | keepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3097 | let g:netrw_liststyle = s:THINLIST |
| 3098 | let w:netrw_liststyle = g:netrw_liststyle |
| 3099 | let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge') |
| 3100 | endif |
| 3101 | setlocal ma noro |
| 3102 | " call Decho("setlocal ma noro") |
| 3103 | |
| 3104 | " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh |
| 3105 | " call Decho("clear buffer<".expand("%")."> with :%d") |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 3106 | sil! keepj %d |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3107 | " following prevents tree listing buffer from being marked "modified" |
| 3108 | setlocal nomod |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3109 | |
| 3110 | " refresh the listing |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3111 | " call Decho("refresh the listing") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3112 | let svpos= netrw#NetrwSavePosn() |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3113 | keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) |
| 3114 | keepj call netrw#NetrwRestorePosn(svpos) |
| 3115 | keepj call s:NetrwCursor() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3116 | |
| 3117 | " keep cursor on the filename |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 3118 | sil! keepj $ |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3119 | let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc') |
| 3120 | " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A')) |
| 3121 | if result <= 0 && exists("w:netrw_bannercnt") |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 3122 | exe "sil! keepj ".w:netrw_bannercnt |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3123 | endif |
| 3124 | |
| 3125 | " call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : "")) |
| 3126 | endfun |
| 3127 | |
| 3128 | " --------------------------------------------------------------------- |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3129 | " s:NetrwBannerCtrl: toggles the display of the banner {{{2 |
| 3130 | fun! s:NetrwBannerCtrl(islocal) |
| 3131 | " call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner) |
| 3132 | |
| 3133 | " toggle the banner (enable/suppress) |
| 3134 | let g:netrw_banner= !g:netrw_banner |
| 3135 | |
| 3136 | " refresh the listing |
| 3137 | let svpos= netrw#NetrwSavePosn() |
| 3138 | call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) |
| 3139 | |
| 3140 | " keep cursor on the filename |
| 3141 | let fname= s:NetrwGetWord() |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3142 | sil keepj $ |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3143 | let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc') |
| 3144 | " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A')) |
| 3145 | if result <= 0 && exists("w:netrw_bannercnt") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3146 | exe "keepj ".w:netrw_bannercnt |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3147 | endif |
| 3148 | " call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner) |
| 3149 | endfun |
| 3150 | |
| 3151 | " --------------------------------------------------------------------- |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3152 | " s:NetrwBookmarkMenu: Uses menu priorities {{{2 |
| 3153 | " .2.[cnt] for bookmarks, and |
| 3154 | " .3.[cnt] for history |
| 3155 | " (see s:NetrwMenu()) |
| 3156 | fun! s:NetrwBookmarkMenu() |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3157 | if !exists("s:netrw_menucnt") |
| 3158 | return |
| 3159 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3160 | " call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhist_cnt." menucnt=".s:netrw_menucnt) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3161 | |
| 3162 | " the following test assures that gvim is running, has menus available, and has menus enabled. |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3163 | if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3164 | if exists("g:NetrwTopLvlMenu") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3165 | " call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3166 | exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks' |
| 3167 | exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete' |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3168 | endif |
| 3169 | if !exists("s:netrw_initbookhist") |
| 3170 | call s:NetrwBookHistRead() |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3171 | endif |
| 3172 | |
| 3173 | " show bookmarked places |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3174 | if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] |
| 3175 | let cnt= 1 |
| 3176 | for bmd in g:netrw_bookmarklist |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3177 | " call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3178 | let bmd= escape(bmd,g:netrw_menu_escape) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3179 | |
| 3180 | " show bookmarks for goto menu |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3181 | exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>" |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3182 | |
| 3183 | " show bookmarks for deletion menu |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3184 | exe 'sil! menu '.g:NetrwMenuPriority.".8.2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete.'.bmd.' '.cnt."mB" |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3185 | let cnt= cnt + 1 |
| 3186 | endfor |
| 3187 | |
| 3188 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3189 | |
| 3190 | " show directory browsing history |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3191 | if g:netrw_dirhistmax > 0 |
| 3192 | let cnt = g:netrw_dirhist_cnt |
| 3193 | let first = 1 |
| 3194 | let histcnt = 0 |
| 3195 | while ( first || cnt != g:netrw_dirhist_cnt ) |
| 3196 | let histcnt = histcnt + 1 |
| 3197 | let priority = g:netrw_dirhist_cnt + histcnt |
| 3198 | if exists("g:netrw_dirhist_{cnt}") |
| 3199 | let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape) |
| 3200 | " call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir) |
| 3201 | exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>" |
| 3202 | endif |
| 3203 | let first = 0 |
| 3204 | let cnt = ( cnt - 1 ) % g:netrw_dirhistmax |
| 3205 | if cnt < 0 |
| 3206 | let cnt= cnt + g:netrw_dirhistmax |
| 3207 | endif |
| 3208 | endwhile |
| 3209 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3210 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3211 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3212 | " call Dret("NetrwBookmarkMenu") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3213 | endfun |
| 3214 | |
| 3215 | " --------------------------------------------------------------------- |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3216 | " s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2 |
| 3217 | " directory and a new directory name. Also, if the |
| 3218 | " "new directory name" is actually a file, |
| 3219 | " NetrwBrowseChgDir() edits the file. |
| 3220 | fun! s:NetrwBrowseChgDir(islocal,newdir,...) |
| 3221 | " 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 Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3222 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3223 | if !exists("b:netrw_curdir") |
| 3224 | " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called |
| 3225 | " and the current window is the NetrwMessage window. |
| 3226 | " call Decho("(NetrwBrowseChgDir) b:netrw_curdir doesn't exist!") |
| 3227 | " call Decho("getcwd<".getcwd().">") |
| 3228 | " call Dredir("ls!") |
| 3229 | " call Dret("s:NetrwBrowseChgDir") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3230 | return |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3231 | endif |
| 3232 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3233 | keepj call s:NetrwOptionSave("s:") |
| 3234 | keepj call s:NetrwSafeOptions() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3235 | let nbcd_curpos = netrw#NetrwSavePosn() |
| 3236 | let s:nbcd_curpos_{bufnr('%')} = nbcd_curpos |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3237 | if (has("win32") || has("win95") || has("win64") || has("win16")) |
| 3238 | let dirname = substitute(b:netrw_curdir,'\\','/','ge') |
| 3239 | else |
| 3240 | let dirname= b:netrw_curdir |
| 3241 | endif |
| 3242 | let newdir = a:newdir |
| 3243 | let dolockout = 0 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3244 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3245 | " set up o/s-dependent directory recognition pattern |
| 3246 | if has("amiga") |
| 3247 | let dirpat= '[\/:]$' |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3248 | else |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3249 | let dirpat= '[\/]$' |
| 3250 | endif |
| 3251 | " call Decho("dirname<".dirname."> dirpat<".dirpat.">") |
| 3252 | |
| 3253 | if dirname !~ dirpat |
| 3254 | " apparently vim is "recognizing" that it is in a directory and |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3255 | " is removing the trailing "/". Bad idea, so let's put it back. |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3256 | let dirname= dirname.'/' |
| 3257 | " call Decho("adjusting dirname<".dirname.">") |
| 3258 | endif |
| 3259 | |
| 3260 | if newdir !~ dirpat |
| 3261 | " ------------ |
| 3262 | " edit a file: |
| 3263 | " ------------ |
| 3264 | " call Decho('case "handling a file": newdir<'.newdir.'> !~ dirpat<'.dirpat.">") |
| 3265 | if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)' |
| 3266 | let dirname= s:NetrwTreeDir() |
| 3267 | if dirname =~ '/$' |
| 3268 | let dirname= dirname.newdir |
| 3269 | else |
| 3270 | let dirname= s:NetrwTreeDir()."/".newdir |
| 3271 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3272 | " call Decho("dirname<".dirname.">") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3273 | " call Decho("tree listing") |
| 3274 | elseif newdir =~ '^\(/\|\a:\)' |
| 3275 | let dirname= newdir |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3276 | else |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3277 | let dirname= s:ComposePath(dirname,newdir) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3278 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3279 | " call Decho("handling a file: dirname<".dirname."> (a:0=".a:0.")") |
| 3280 | " this lets NetrwBrowseX avoid the edit |
| 3281 | if a:0 < 1 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3282 | " call Decho("set up windows for editing<".fnameescape(dirname)."> didsplit=".(exists("s:didsplit")? s:didsplit : "doesn't exist")) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3283 | keepj call s:NetrwOptionRestore("s:") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3284 | if !exists("s:didsplit") |
| 3285 | if g:netrw_browse_split == 1 |
| 3286 | new |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3287 | if !&ea |
| 3288 | wincmd _ |
| 3289 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3290 | elseif g:netrw_browse_split == 2 |
| 3291 | rightb vert new |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3292 | if !&ea |
| 3293 | wincmd | |
| 3294 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3295 | elseif g:netrw_browse_split == 3 |
| 3296 | tabnew |
| 3297 | elseif g:netrw_browse_split == 4 |
| 3298 | if s:NetrwPrevWinOpen(2) == 3 |
| 3299 | " call Dret("s:NetrwBrowseChgDir") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3300 | return |
| 3301 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3302 | else |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3303 | " handling a file, didn't split, so remove menu |
| 3304 | " call Decho("handling a file+didn't split, so remove menu") |
| 3305 | call s:NetrwMenu(0) |
| 3306 | " optional change to window |
| 3307 | if g:netrw_chgwin >= 1 |
| 3308 | exe "keepjumps ".g:netrw_chgwin."wincmd w" |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3309 | endif |
| 3310 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3311 | endif |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 3312 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3313 | " the point where netrw actually edits the (local) file |
| 3314 | " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will |
| 3315 | if a:islocal |
| 3316 | " call Decho("edit local file: exe e! ".fnameescape(dirname)) |
| 3317 | exe "e! ".fnameescape(dirname) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3318 | else |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3319 | " call Decho("remote file: NetrwBrowse will edit it") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3320 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3321 | let dolockout= 1 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3322 | |
| 3323 | " handle g:Netrw_funcref -- call external-to-netrw functions |
| 3324 | " This code will handle g:Netrw_funcref as an individual function reference |
| 3325 | " or as a list of function references. It will ignore anything that's not |
| 3326 | " a function reference. See :help Funcref for information about function references. |
| 3327 | if exists("g:Netrw_funcref") |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 3328 | " call Decho("handle optional Funcrefs") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3329 | if type(g:Netrw_funcref) == 2 |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 3330 | " call Decho("handling a g:Netrw_funcref") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3331 | keepj call g:Netrw_funcref() |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3332 | elseif type(g:Netrw_funcref) == 3 |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 3333 | " call Decho("handling a list of g:Netrw_funcrefs") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3334 | for Fncref in g:Netrw_funcref |
| 3335 | if type(FncRef) == 2 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3336 | keepj call FncRef() |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3337 | endif |
| 3338 | endfor |
| 3339 | endif |
| 3340 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3341 | endif |
| 3342 | |
| 3343 | elseif newdir =~ '^/' |
| 3344 | " --------------------------------- |
| 3345 | " just go to the new directory spec |
| 3346 | " --------------------------------- |
| 3347 | " call Decho('case "just go to new directory spec": newdir<'.newdir.'>') |
| 3348 | let dirname= newdir |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3349 | keepj call s:SetRexDir(a:islocal,dirname) |
| 3350 | keepj call s:NetrwOptionRestore("s:") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3351 | |
| 3352 | elseif newdir == './' |
| 3353 | " -------------------------- |
| 3354 | " refresh the directory list |
| 3355 | " -------------------------- |
| 3356 | " call Decho('case "refresh directory listing": newdir == "./"') |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3357 | keepj call s:SetRexDir(a:islocal,dirname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3358 | |
| 3359 | elseif newdir == '../' |
| 3360 | " ------------------- |
| 3361 | " go up one directory |
| 3362 | " ------------------- |
| 3363 | " call Decho('case "go up one directory": newdir == "../"') |
| 3364 | |
| 3365 | if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") |
| 3366 | " force a refresh |
| 3367 | " call Decho("clear buffer<".expand("%")."> with :%d") |
| 3368 | setlocal noro ma |
| 3369 | " call Decho("setlocal noro ma") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3370 | keepj %d |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3371 | endif |
| 3372 | |
| 3373 | if has("amiga") |
| 3374 | " amiga |
| 3375 | " call Decho('case "go up one directory": newdir == "../" and amiga') |
| 3376 | if a:islocal |
| 3377 | let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','') |
| 3378 | let dirname= substitute(dirname,'/$','','') |
| 3379 | else |
| 3380 | let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','') |
| 3381 | endif |
| 3382 | " call Decho("amiga: dirname<".dirname."> (go up one dir)") |
| 3383 | |
| 3384 | else |
| 3385 | " unix or cygwin |
| 3386 | " call Decho('case "go up one directory": newdir == "../" and unix or cygwin') |
| 3387 | if a:islocal |
| 3388 | let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','') |
| 3389 | if dirname == "" |
| 3390 | let dirname= '/' |
| 3391 | endif |
| 3392 | else |
| 3393 | let dirname= substitute(dirname,'^\(\a\+://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','') |
| 3394 | endif |
| 3395 | " call Decho("unix: dirname<".dirname."> (go up one dir)") |
| 3396 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3397 | keepj call s:SetRexDir(a:islocal,dirname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3398 | |
| 3399 | elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") |
| 3400 | " call Decho('case liststyle is TREELIST and w:netrw_treedict exists') |
| 3401 | " force a refresh (for TREELIST, wait for NetrwTreeDir() to force the refresh) |
| 3402 | setlocal noro ma |
| 3403 | " call Decho("setlocal noro ma") |
| 3404 | if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")) |
| 3405 | " call Decho("clear buffer<".expand("%")."> with :%d") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3406 | keepj %d |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3407 | endif |
| 3408 | let treedir = s:NetrwTreeDir() |
| 3409 | let s:treecurpos = nbcd_curpos |
| 3410 | let haskey= 0 |
| 3411 | " call Decho("w:netrw_treedict<".string(w:netrw_treedict).">") |
| 3412 | |
| 3413 | " search treedict for tree dir as-is |
| 3414 | if has_key(w:netrw_treedict,treedir) |
| 3415 | " call Decho('....searched for treedir<'.treedir.'> : found it!') |
| 3416 | let haskey= 1 |
| 3417 | else |
| 3418 | " call Decho('....searched for treedir<'.treedir.'> : not found') |
| 3419 | endif |
| 3420 | |
| 3421 | " search treedict for treedir with a / appended |
| 3422 | if !haskey && treedir !~ '/$' |
| 3423 | if has_key(w:netrw_treedict,treedir."/") |
| 3424 | let treedir= treedir."/" |
| 3425 | " call Decho('....searched.for treedir<'.treedir.'> found it!') |
| 3426 | let haskey = 1 |
| 3427 | else |
| 3428 | " call Decho('....searched for treedir<'.treedir.'/> : not found') |
| 3429 | endif |
| 3430 | endif |
| 3431 | |
| 3432 | " search treedict for treedir with any trailing / elided |
| 3433 | if !haskey && treedir =~ '/$' |
| 3434 | let treedir= substitute(treedir,'/$','','') |
| 3435 | if has_key(w:netrw_treedict,treedir) |
| 3436 | " call Decho('....searched.for treedir<'.treedir.'> found it!') |
| 3437 | let haskey = 1 |
| 3438 | else |
| 3439 | " call Decho('....searched for treedir<'.treedir.'> : not found') |
| 3440 | endif |
| 3441 | endif |
| 3442 | |
| 3443 | if haskey |
| 3444 | " close tree listing for selected subdirectory |
| 3445 | " call Decho("closing selected subdirectory<".dirname.">") |
| 3446 | call remove(w:netrw_treedict,treedir) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3447 | " call Decho("removed entry<".treedir."> from treedict") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3448 | " call Decho("yielding treedict<".string(w:netrw_treedict).">") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3449 | let dirname= w:netrw_treetop |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3450 | else |
| 3451 | " go down one directory |
| 3452 | let dirname= substitute(treedir,'/*$','/','') |
| 3453 | " call Decho("go down one dir: treedir<".treedir.">") |
| 3454 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3455 | keepj call s:SetRexDir(a:islocal,dirname) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3456 | let s:treeforceredraw = 1 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3457 | |
| 3458 | else |
| 3459 | " go down one directory |
| 3460 | let dirname= s:ComposePath(dirname,newdir) |
| 3461 | " call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3462 | keepj call s:SetRexDir(a:islocal,dirname) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3463 | endif |
| 3464 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3465 | keepj call s:NetrwOptionRestore("s:") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3466 | if dolockout |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 3467 | " call Decho("filewritable(dirname<".dirname.">)=".filewritable(dirname)) |
| 3468 | if filewritable(dirname) |
| 3469 | " call Decho("doing modification lockout settings: ma nomod noro") |
| 3470 | setlocal ma nomod noro |
| 3471 | else |
| 3472 | " call Decho("doing modification lockout settings: ma nomod ro") |
| 3473 | setlocal ma nomod ro |
| 3474 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3475 | " call Decho("setlocal ma nomod noro") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3476 | endif |
| 3477 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3478 | " call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">") |
| 3479 | return dirname |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3480 | endfun |
| 3481 | |
| 3482 | " --------------------------------------------------------------------- |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3483 | " s:NetrwBrowseX: (implements "x") executes a special "viewer" script or program for the {{{2 |
| 3484 | " given filename; typically this means given their extension. |
| 3485 | " 0=local, 1=remote |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3486 | fun! netrw#NetrwBrowseX(fname,remote) |
| 3487 | " call Dfunc("NetrwBrowseX(fname<".a:fname."> remote=".a:remote.")") |
| 3488 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3489 | " special core dump handler |
| 3490 | if a:fname =~ '/core\(\.\d\+\)\=$' |
| 3491 | if exists("g:Netrw_corehandler") |
| 3492 | if type(g:Netrw_corehandler) == 2 |
| 3493 | " g:Netrw_corehandler is a function reference (see :help Funcref) |
| 3494 | " call Decho("g:Netrw_corehandler is a funcref") |
| 3495 | call g:Netrw_corehandler(a:fname) |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3496 | elseif type(g:Netrw_corehandler) == 3) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3497 | " g:Netrw_corehandler is a List of function references (see :help Funcref) |
| 3498 | " call Decho("g:Netrw_corehandler is a List") |
| 3499 | for Fncref in g:Netrw_corehandler |
| 3500 | if type(FncRef) == 2 |
| 3501 | call FncRef(a:fname) |
| 3502 | endif |
| 3503 | endfor |
| 3504 | endif |
| 3505 | " call Dret("NetrwBrowseX : coredump handler invoked") |
| 3506 | return |
| 3507 | endif |
| 3508 | endif |
| 3509 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3510 | " set up the filename |
| 3511 | " (lower case the extension, make a local copy of a remote file) |
| 3512 | let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e') |
| 3513 | if has("win32") || has("win95") || has("win64") || has("win16") |
| 3514 | let exten= substitute(exten,'^.*$','\L&\E','') |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3515 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3516 | " call Decho("exten<".exten.">") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3517 | |
| 3518 | " seems kde systems often have gnome-open due to dependencies, even though |
| 3519 | " gnome-open's subsidiary display tools are largely absent. Kde systems |
| 3520 | " usually have "kdeinit" running, though... (tnx Mikolaj Machowski) |
| 3521 | if !exists("s:haskdeinit") |
| 3522 | if has("unix") |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 3523 | let s:haskdeinit= system("ps -e") =~ 'kdeinit' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3524 | if v:shell_error |
| 3525 | let s:haskdeinit = 0 |
| 3526 | endif |
| 3527 | else |
| 3528 | let s:haskdeinit= 0 |
| 3529 | endif |
| 3530 | " call Decho("setting s:haskdeinit=".s:haskdeinit) |
| 3531 | endif |
| 3532 | |
| 3533 | if a:remote == 1 |
| 3534 | " create a local copy |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3535 | " call Decho("a:remote=".a:remote.": create a local copy of <".a:fname.">") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3536 | setlocal bh=delete |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3537 | call netrw#NetRead(3,a:fname) |
| 3538 | " attempt to rename tempfile |
| 3539 | let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','') |
| 3540 | let newname= substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','') |
| 3541 | " call Decho("basename<".basename.">") |
| 3542 | " call Decho("newname <".newname.">") |
| 3543 | if rename(s:netrw_tmpfile,newname) == 0 |
| 3544 | " renaming succeeded |
| 3545 | let fname= newname |
| 3546 | else |
| 3547 | " renaming failed |
| 3548 | let fname= s:netrw_tmpfile |
| 3549 | endif |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 3550 | else |
| 3551 | let fname= a:fname |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3552 | " special ~ handler for local |
| 3553 | if fname =~ '^\~' && expand("$HOME") != "" |
| 3554 | " call Decho('invoking special ~ handler') |
| 3555 | let fname= substitute(fname,'^\~',expand("$HOME"),'') |
| 3556 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3557 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3558 | " call Decho("fname<".fname.">") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3559 | " call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten)) |
| 3560 | |
| 3561 | " set up redirection |
| 3562 | if &srr =~ "%s" |
| 3563 | if (has("win32") || has("win95") || has("win64") || has("win16")) |
| 3564 | let redir= substitute(&srr,"%s","nul","") |
| 3565 | else |
| 3566 | let redir= substitute(&srr,"%s","/dev/null","") |
| 3567 | endif |
| 3568 | elseif (has("win32") || has("win95") || has("win64") || has("win16")) |
| 3569 | let redir= &srr . "nul" |
| 3570 | else |
| 3571 | let redir= &srr . "/dev/null" |
| 3572 | endif |
| 3573 | " call Decho("redir{".redir."} srr{".&srr."}") |
| 3574 | |
| 3575 | " extract any viewing options. Assumes that they're set apart by quotes. |
| 3576 | if exists("g:netrw_browsex_viewer") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3577 | " call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3578 | if g:netrw_browsex_viewer =~ '\s' |
| 3579 | let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','') |
| 3580 | let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." " |
| 3581 | let oviewer = '' |
| 3582 | let cnt = 1 |
| 3583 | while !executable(viewer) && viewer != oviewer |
| 3584 | let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','') |
| 3585 | let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." " |
| 3586 | let cnt = cnt + 1 |
| 3587 | let oviewer = viewer |
| 3588 | " call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">") |
| 3589 | endwhile |
| 3590 | else |
| 3591 | let viewer = g:netrw_browsex_viewer |
| 3592 | let viewopt = "" |
| 3593 | endif |
| 3594 | " call Decho("viewer<".viewer."> viewopt<".viewopt.">") |
| 3595 | endif |
| 3596 | |
| 3597 | " execute the file handler |
| 3598 | if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-' |
| 3599 | " call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">") |
| 3600 | let ret= netrwFileHandlers#Invoke(exten,fname) |
| 3601 | |
| 3602 | elseif exists("g:netrw_browsex_viewer") && executable(viewer) |
| 3603 | " call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3604 | " call Decho("exe sil !".viewer." ".viewopt.shellescape(fname,1).redir) |
| 3605 | exe "sil !".viewer." ".viewopt.shellescape(fname,1).redir |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3606 | let ret= v:shell_error |
| 3607 | |
| 3608 | elseif has("win32") || has("win64") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3609 | if executable("start") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3610 | " call Decho('exe sil !start rundll32 url.dll,FileProtocolHandler '.shellescape(fname,1)) |
| 3611 | exe 'sil !start rundll32 url.dll,FileProtocolHandler '.shellescape(fname,1) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3612 | elseif executable("rundll32") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3613 | " call Decho('exe sil !rundll32 url.dll,FileProtocolHandler '.shellescape(fname,1)) |
| 3614 | exe 'sil !rundll32 url.dll,FileProtocolHandler '.shellescape(fname,1) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3615 | else |
| 3616 | call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74) |
| 3617 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3618 | call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
| 3619 | let ret= v:shell_error |
| 3620 | |
| 3621 | elseif has("unix") && executable("gnome-open") && !s:haskdeinit |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3622 | " call Decho("exe sil !gnome-open ".shellescape(fname,1)." ".redir) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3623 | exe "sil !gnome-open ".shellescape(fname,1).redir |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3624 | let ret= v:shell_error |
| 3625 | |
| 3626 | elseif has("unix") && executable("kfmclient") && s:haskdeinit |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3627 | " call Decho("exe sil !kfmclient exec ".shellescape(fname,1)." ".redir) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3628 | exe "sil !kfmclient exec ".shellescape(fname,1)." ".redir |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3629 | let ret= v:shell_error |
| 3630 | |
| 3631 | elseif has("macunix") && executable("open") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3632 | " call Decho("exe sil !open ".shellescape(fname,1)." ".redir) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3633 | exe "sil !open ".shellescape(fname,1)." ".redir |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3634 | let ret= v:shell_error |
| 3635 | |
| 3636 | else |
| 3637 | " netrwFileHandlers#Invoke() always returns 0 |
| 3638 | let ret= netrwFileHandlers#Invoke(exten,fname) |
| 3639 | endif |
| 3640 | |
| 3641 | " if unsuccessful, attempt netrwFileHandlers#Invoke() |
| 3642 | if ret |
| 3643 | let ret= netrwFileHandlers#Invoke(exten,fname) |
| 3644 | endif |
| 3645 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 3646 | " restoring redraw! after external file handlers |
| 3647 | redraw! |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3648 | |
| 3649 | " cleanup: remove temporary file, |
| 3650 | " delete current buffer if success with handler, |
| 3651 | " return to prior buffer (directory listing) |
| 3652 | " Feb 12, 2008: had to de-activiate removal of |
| 3653 | " temporary file because it wasn't getting seen. |
| 3654 | " if a:remote == 1 && fname != a:fname |
| 3655 | " call Decho("deleting temporary file<".fname.">") |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 3656 | " call s:NetrwDelete(fname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3657 | " endif |
| 3658 | |
| 3659 | if a:remote == 1 |
| 3660 | setlocal bh=delete bt=nofile |
| 3661 | if g:netrw_use_noswf |
| 3662 | setlocal noswf |
| 3663 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3664 | exe "sil! keepj norm! \<c-o>" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3665 | " redraw! |
| 3666 | endif |
| 3667 | |
| 3668 | " call Dret("NetrwBrowseX") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3669 | endfun |
| 3670 | |
| 3671 | " --------------------------------------------------------------------- |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3672 | " s:NetrwChgPerm: (implements "gp") change file permission {{{2 |
| 3673 | fun! s:NetrwChgPerm(islocal,curdir) |
| 3674 | " call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)") |
| 3675 | call inputsave() |
| 3676 | let newperm= input("Enter new permission: ") |
| 3677 | call inputrestore() |
| 3678 | let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',shellescape(expand("<cfile>")),'') |
| 3679 | let chgperm= substitute(chgperm,'\<PERM\>',shellescape(newperm),'') |
| 3680 | " call Decho("chgperm<".chgperm.">") |
| 3681 | call system(chgperm) |
| 3682 | if v:shell_error != 0 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3683 | keepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3684 | endif |
| 3685 | if a:islocal |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3686 | keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3687 | endif |
| 3688 | " call Dret("s:NetrwChgPerm") |
| 3689 | endfun |
| 3690 | |
| 3691 | " --------------------------------------------------------------------- |
| 3692 | " s:NetrwClearExplore: clear explore variables (if any) {{{2 |
| 3693 | fun! s:NetrwClearExplore() |
| 3694 | " call Dfunc("s:NetrwClearExplore()") |
| 3695 | 2match none |
| 3696 | if exists("s:explore_match") |unlet s:explore_match |endif |
| 3697 | if exists("s:explore_indx") |unlet s:explore_indx |endif |
| 3698 | if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif |
| 3699 | if exists("s:dirstarstar") |unlet s:dirstarstar |endif |
| 3700 | if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif |
| 3701 | if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif |
| 3702 | if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif |
| 3703 | if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif |
| 3704 | if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif |
| 3705 | " redraw! |
| 3706 | echo " " |
| 3707 | echo " " |
| 3708 | " call Dret("s:NetrwClearExplore") |
| 3709 | endfun |
| 3710 | |
| 3711 | " --------------------------------------------------------------------- |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3712 | " netrw#Explore: launch the local browser in the directory of the current file {{{2 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3713 | " indx: == -1: Nexplore |
| 3714 | " == -2: Pexplore |
| 3715 | " == +: this is overloaded: |
| 3716 | " * If Nexplore/Pexplore is in use, then this refers to the |
| 3717 | " indx'th item in the w:netrw_explore_list[] of items which |
| 3718 | " matched the */pattern **/pattern *//pattern **//pattern |
| 3719 | " * If Hexplore or Vexplore, then this will override |
| 3720 | " g:netrw_winsize to specify the qty of rows or columns the |
| 3721 | " newly split window should have. |
| 3722 | " dosplit==0: the window will be split iff the current file has been modified |
| 3723 | " dosplit==1: the window will be split before running the local browser |
| 3724 | " style == 0: Explore style == 1: Explore! |
| 3725 | " == 2: Hexplore style == 3: Hexplore! |
| 3726 | " == 4: Vexplore style == 5: Vexplore! |
| 3727 | " == 6: Texplore |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3728 | fun! netrw#Explore(indx,dosplit,style,...) |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame] | 3729 | " call Dfunc("netrw#Explore(indx=".a:indx." dosplit=".a:dosplit." style=".a:style.",a:1<".a:1.">) &modified=".&modified." a:0=".a:0) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3730 | if !exists("b:netrw_curdir") |
| 3731 | let b:netrw_curdir= getcwd() |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame] | 3732 | " call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3733 | endif |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3734 | let curdir = simplify(b:netrw_curdir) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3735 | let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e') |
| 3736 | " call Decho("curdir<".curdir."> curfiledir<".curfiledir.">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3737 | |
| 3738 | " save registers |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3739 | sil! let keepregstar = @* |
| 3740 | sil! let keepregplus = @+ |
| 3741 | sil! let keepregslash= @/ |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3742 | |
| 3743 | " if dosplit or file has been modified |
| 3744 | if a:dosplit || &modified || a:style == 6 |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3745 | " call Decho("case dosplit=".a:dosplit." modified=".&modified." a:style=".a:style.": dosplit or file has been modified") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3746 | call s:SaveWinVars() |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 3747 | let winsz= g:netrw_winsize |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3748 | if a:indx > 0 |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 3749 | let winsz= a:indx |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3750 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3751 | |
| 3752 | if a:style == 0 " Explore, Sexplore |
| 3753 | " call Decho("style=0: Explore or Sexplore") |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3754 | let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 3755 | exe winsz."wincmd s" |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3756 | |
| 3757 | elseif a:style == 1 "Explore!, Sexplore! |
| 3758 | " call Decho("style=1: Explore! or Sexplore!") |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3759 | let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 3760 | exe winsz."wincmd v" |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3761 | |
| 3762 | elseif a:style == 2 " Hexplore |
| 3763 | " call Decho("style=2: Hexplore") |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3764 | let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 3765 | exe "bel ".winsz."wincmd s" |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3766 | |
| 3767 | elseif a:style == 3 " Hexplore! |
| 3768 | " call Decho("style=3: Hexplore!") |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3769 | let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 3770 | exe "abo ".winsz."wincmd s" |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3771 | |
| 3772 | elseif a:style == 4 " Vexplore |
| 3773 | " call Decho("style=4: Vexplore") |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3774 | let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 3775 | exe "lefta ".winsz."wincmd v" |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3776 | |
| 3777 | elseif a:style == 5 " Vexplore! |
| 3778 | " call Decho("style=5: Vexplore!") |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3779 | let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 3780 | exe "rightb ".winsz."wincmd v" |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3781 | |
| 3782 | elseif a:style == 6 " Texplore |
| 3783 | call s:SaveBufVars() |
| 3784 | " call Decho("style = 6: Texplore") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3785 | exe "tabnew ".fnameescape(curdir) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3786 | call s:RestoreBufVars() |
| 3787 | endif |
| 3788 | call s:RestoreWinVars() |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3789 | " else " Decho |
| 3790 | " call Decho("case a:dosplit=".a:dosplit." AND modified=".&modified." AND a:style=".a:style." is not 6") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3791 | endif |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3792 | keepj norm! 0 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3793 | |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame] | 3794 | if a:0 > 0 |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3795 | " call Decho("case [a:0=".a:0."] > 0") |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame] | 3796 | if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)) |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3797 | " call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3798 | let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),'')) |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3799 | " call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)") |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame] | 3800 | elseif a:1 == '.' |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3801 | " call Decho("..case a:1<".a:1.">: matches .") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3802 | let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd()) |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame] | 3803 | if dirname !~ '/$' |
| 3804 | let dirname= dirname."/" |
| 3805 | endif |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3806 | " call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")") |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame] | 3807 | elseif a:1 =~ '\$' |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3808 | " call Decho("..case a:1<".a:1.">: matches ending $") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3809 | let dirname= simplify(expand(a:1)) |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3810 | " call Decho("..using user-specified dirname<".dirname."> with $env-var") |
| 3811 | elseif a:1 !~ '^\*\{1,2}/' |
| 3812 | " call Decho("..case a:1<".a:1.">: other, not pattern or filepattern") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3813 | let dirname= simplify(a:1) |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3814 | " call Decho("..using user-specified dirname<".dirname.">") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3815 | else |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3816 | " call Decho("..case a:1: pattern or filepattern") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3817 | let dirname= a:1 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3818 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3819 | else |
| 3820 | " clear explore |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3821 | " call Decho("case a:0=".a:0.": clearing Explore list") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3822 | call s:NetrwClearExplore() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3823 | " call Dret("netrw#Explore : cleared list") |
| 3824 | return |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3825 | endif |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3826 | |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3827 | " call Decho("dirname<".dirname.">") |
| 3828 | if dirname =~ '\.\./\=$' |
| 3829 | let dirname= simplify(fnamemodify(dirname,':p:h')) |
| 3830 | elseif dirname =~ '\.\.' || dirname == '.' |
| 3831 | let dirname= simplify(fnamemodify(dirname,':p')) |
| 3832 | endif |
| 3833 | " call Decho("dirname<".dirname."> (after simplify)") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3834 | |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3835 | if dirname =~ '^\*//' |
| 3836 | " starpat=1: Explore *//pattern (current directory only search for files containing pattern) |
| 3837 | " call Decho("case Explore *//pattern") |
| 3838 | let pattern= substitute(dirname,'^\*//\(.*\)$','\1','') |
| 3839 | let starpat= 1 |
| 3840 | " call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">") |
| 3841 | if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif |
| 3842 | |
| 3843 | elseif dirname =~ '^\*\*//' |
| 3844 | " starpat=2: Explore **//pattern (recursive descent search for files containing pattern) |
| 3845 | " call Decho("case Explore **//pattern") |
| 3846 | let pattern= substitute(dirname,'^\*\*//','','') |
| 3847 | let starpat= 2 |
| 3848 | " call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">") |
| 3849 | |
| 3850 | elseif dirname =~ '/\*\*/' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3851 | " handle .../**/.../filepat |
| 3852 | " call Decho("case Explore .../**/.../filepat") |
| 3853 | let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','') |
| 3854 | if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && (has("win32") || has("win95") || has("win64") || has("win16"))) |
| 3855 | let b:netrw_curdir = prefixdir |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3856 | else |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3857 | let b:netrw_curdir= getcwd().'/'.prefixdir |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3858 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3859 | let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','') |
| 3860 | let starpat= 4; |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3861 | " call Decho("..pwd<".getcwd()."> dirname<".dirname.">") |
| 3862 | " call Decho("..case Explore ../**/../filepat (starpat=".starpat.")") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3863 | |
| 3864 | elseif dirname =~ '^\*/' |
| 3865 | " starpat=3: Explore */filepat (search in current directory for filenames matching filepat) |
| 3866 | let starpat= 3 |
| 3867 | " call Decho("case Explore */filepat (starpat=".starpat.")") |
| 3868 | |
| 3869 | elseif dirname=~ '^\*\*/' |
| 3870 | " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat) |
| 3871 | let starpat= 4 |
| 3872 | " call Decho("case Explore **/filepat (starpat=".starpat.")") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3873 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3874 | else |
| 3875 | let starpat= 0 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3876 | " call Decho("default case: starpat=".starpat) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3877 | endif |
| 3878 | |
| 3879 | if starpat == 0 && a:indx >= 0 |
| 3880 | " [Explore Hexplore Vexplore Sexplore] [dirname] |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3881 | " call Decho("case starpat==0 && a:indx=".a:indx.": dirname<".dirname."> Explore Hexplore Vexplore Sexplore") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3882 | if dirname == "" |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3883 | let dirname= curfiledir |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3884 | " call Decho("..empty dirname, using current file's directory<".dirname.">") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3885 | endif |
| 3886 | if dirname =~ '^scp:' || dirname =~ '^ftp:' |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3887 | " call Decho("..calling NetrwBrowse(0,dirname<".dirname.">)") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3888 | call s:NetrwBrowse(0,dirname) |
| 3889 | else |
| 3890 | if dirname == ""|let dirname= getcwd()|endif |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3891 | " call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3892 | call netrw#LocalBrowseCheck(dirname) |
| 3893 | endif |
| 3894 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3895 | " call Decho("curdir<".curdir.">") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3896 | if has("win32") || has("win95") || has("win64") || has("win16") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3897 | keepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW') |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3898 | else |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3899 | keepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW') |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3900 | endif |
| 3901 | |
| 3902 | " starpat=1: Explore *//pattern (current directory only search for files containing pattern) |
| 3903 | " starpat=2: Explore **//pattern (recursive descent search for files containing pattern) |
| 3904 | " starpat=3: Explore */filepat (search in current directory for filenames matching filepat) |
| 3905 | " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat) |
| 3906 | elseif a:indx <= 0 |
| 3907 | " Nexplore, Pexplore, Explore: handle starpat |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3908 | " call Decho("case a:indx<=0: Nexplore, Pexplore, <s-down>, <s-up> starpat=".starpat." a:indx=".a:indx) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3909 | if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir") |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3910 | " call Decho("..set up <s-up> and <s-down> maps") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3911 | let s:didstarstar= 1 |
| 3912 | nnoremap <buffer> <silent> <s-up> :Pexplore<cr> |
| 3913 | nnoremap <buffer> <silent> <s-down> :Nexplore<cr> |
| 3914 | endif |
| 3915 | |
| 3916 | if has("path_extra") |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3917 | " call Decho("..starpat=".starpat.": has +path_extra") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3918 | if !exists("w:netrw_explore_indx") |
| 3919 | let w:netrw_explore_indx= 0 |
| 3920 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3921 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3922 | let indx = a:indx |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3923 | " call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3924 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3925 | if indx == -1 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3926 | " Nexplore |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3927 | " call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3928 | if !exists("w:netrw_explore_list") " sanity check |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3929 | keepj call netrw#ErrorMsg(s:WARNING,"using Nexplore or <s-down> improperly; see help for netrw-starstar",40) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3930 | sil! let @* = keepregstar |
| 3931 | sil! let @+ = keepregstar |
| 3932 | sil! let @/ = keepregslash |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3933 | " call Dret("netrw#Explore") |
| 3934 | return |
| 3935 | endif |
| 3936 | let indx= w:netrw_explore_indx |
| 3937 | if indx < 0 | let indx= 0 | endif |
| 3938 | if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif |
| 3939 | let curfile= w:netrw_explore_list[indx] |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3940 | " call Decho("....indx=".indx." curfile<".curfile.">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3941 | while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx] |
| 3942 | let indx= indx + 1 |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3943 | " call Decho("....indx=".indx." (Nexplore while loop)") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3944 | endwhile |
| 3945 | if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3946 | " call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3947 | |
| 3948 | elseif indx == -2 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3949 | " Pexplore |
| 3950 | " call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3951 | if !exists("w:netrw_explore_list") " sanity check |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3952 | keepj call netrw#ErrorMsg(s:WARNING,"using Pexplore or <s-up> improperly; see help for netrw-starstar",41) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3953 | sil! let @* = keepregstar |
| 3954 | sil! let @+ = keepregstar |
| 3955 | sil! let @/ = keepregslash |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3956 | " call Dret("netrw#Explore") |
| 3957 | return |
| 3958 | endif |
| 3959 | let indx= w:netrw_explore_indx |
| 3960 | if indx < 0 | let indx= 0 | endif |
| 3961 | if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif |
| 3962 | let curfile= w:netrw_explore_list[indx] |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3963 | " call Decho("....indx=".indx." curfile<".curfile.">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3964 | while indx >= 0 && curfile == w:netrw_explore_list[indx] |
| 3965 | let indx= indx - 1 |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3966 | " call Decho("....indx=".indx." (Pexplore while loop)") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3967 | endwhile |
| 3968 | if indx < 0 | let indx= 0 | endif |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3969 | " call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3970 | |
| 3971 | else |
| 3972 | " Explore -- initialize |
| 3973 | " build list of files to Explore with Nexplore/Pexplore |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3974 | " call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 3975 | keepj call s:NetrwClearExplore() |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3976 | let w:netrw_explore_indx= 0 |
| 3977 | if !exists("b:netrw_curdir") |
| 3978 | let b:netrw_curdir= getcwd() |
| 3979 | endif |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3980 | " call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3981 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3982 | " switch on starpat to build the w:netrw_explore_list of files |
| 3983 | if starpat == 1 |
| 3984 | " starpat=1: Explore *//pattern (current directory only search for files containing pattern) |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3985 | " call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls) |
| 3986 | " call Decho("....pattern<".pattern.">") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3987 | try |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 3988 | exe "keepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*" |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 3989 | catch /^Vim\%((\a\+)\)\=:E480/ |
| 3990 | call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76) |
| 3991 | " call Dret("netrw#Explore : unable to find pattern<".pattern.">") |
| 3992 | return |
| 3993 | endtry |
| 3994 | let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)')) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3995 | if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif |
| 3996 | |
| 3997 | elseif starpat == 2 |
| 3998 | " starpat=2: Explore **//pattern (recursive descent search for files containing pattern) |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 3999 | " call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)") |
| 4000 | " call Decho("....pattern<".pattern.">") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4001 | try |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 4002 | exe "sil keepj noautocmd vimgrep /".pattern."/gj "."**/*" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4003 | catch /^Vim\%((\a\+)\)\=:E480/ |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4004 | call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4005 | if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4006 | sil! let @* = keepregstar |
| 4007 | sil! let @+ = keepregstar |
| 4008 | sil! let @/ = keepregslash |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4009 | " call Dret("netrw#Explore : no files matched pattern") |
| 4010 | return |
| 4011 | endtry |
| 4012 | let s:netrw_curdir = b:netrw_curdir |
| 4013 | let w:netrw_explore_list = getqflist() |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4014 | let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)')) |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 4015 | if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4016 | |
| 4017 | elseif starpat == 3 |
| 4018 | " starpat=3: Explore */filepat (search in current directory for filenames matching filepat) |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 4019 | " call Decho("..case starpat=".starpat.": build */filepat list (curdir-only srch filenames matching filepat) &hls=".&hls) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4020 | let filepat= substitute(dirname,'^\*/','','') |
| 4021 | let filepat= substitute(filepat,'^[%#<]','\\&','') |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 4022 | " call Decho("....b:netrw_curdir<".b:netrw_curdir.">") |
| 4023 | " call Decho("....filepat<".filepat.">") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4024 | let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n')) |
| 4025 | if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4026 | |
| 4027 | elseif starpat == 4 |
| 4028 | " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat) |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 4029 | " call Decho("..case starpat=".starpat.": build **/filepat list (recursive descent srch filenames matching filepat) &hls=".&hls) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4030 | let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n')) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4031 | if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif |
| 4032 | endif " switch on starpat to build w:netrw_explore_list |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4033 | |
| 4034 | let w:netrw_explore_listlen = len(w:netrw_explore_list) |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 4035 | " call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">") |
| 4036 | " call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4037 | |
| 4038 | if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/') |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4039 | keepj call netrw#ErrorMsg(s:WARNING,"no files matched",42) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 4040 | sil! let @* = keepregstar |
| 4041 | sil! let @+ = keepregstar |
| 4042 | sil! let @/ = keepregslash |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4043 | " call Dret("netrw#Explore : no files matched") |
| 4044 | return |
| 4045 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4046 | endif " if indx ... endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4047 | |
| 4048 | " NetrwStatusLine support - for exploring support |
| 4049 | let w:netrw_explore_indx= indx |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 4050 | " call Decho("....w:netrw_explore_list<".join(w:netrw_explore_list,',')."> len=".w:netrw_explore_listlen) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4051 | |
| 4052 | " wrap the indx around, but issue a note |
| 4053 | if indx >= w:netrw_explore_listlen || indx < 0 |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 4054 | " call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4055 | let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0 |
| 4056 | let w:netrw_explore_indx= indx |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4057 | keepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4058 | endif |
| 4059 | |
| 4060 | exe "let dirfile= w:netrw_explore_list[".indx."]" |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 4061 | " call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4062 | let newdir= substitute(dirfile,'/[^/]*$','','e') |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 4063 | " call Decho("....newdir<".newdir.">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4064 | |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 4065 | " call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4066 | call netrw#LocalBrowseCheck(newdir) |
| 4067 | if !exists("w:netrw_liststyle") |
| 4068 | let w:netrw_liststyle= g:netrw_liststyle |
| 4069 | endif |
| 4070 | if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 4071 | keepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4072 | else |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 4073 | keepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4074 | endif |
| 4075 | let w:netrw_explore_mtchcnt = indx + 1 |
| 4076 | let w:netrw_explore_bufnr = bufnr("%") |
| 4077 | let w:netrw_explore_line = line(".") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4078 | keepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}') |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 4079 | " call Decho("....explore: mtchcnt=".w:netrw_explore_mtchcnt." bufnr=".w:netrw_explore_bufnr." line#".w:netrw_explore_line) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4080 | |
| 4081 | else |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 4082 | " call Decho("..your vim does not have +path_extra") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4083 | if !exists("g:netrw_quiet") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4084 | keepj call netrw#ErrorMsg(s:WARNING,"your vim needs the +path_extra feature for Exploring with **!",44) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4085 | endif |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 4086 | sil! let @* = keepregstar |
| 4087 | sil! let @+ = keepregstar |
| 4088 | sil! let @/ = keepregslash |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4089 | " call Dret("netrw#Explore : missing +path_extra") |
| 4090 | return |
| 4091 | endif |
| 4092 | |
| 4093 | else |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 4094 | " call Decho("..default case: Explore newdir<".dirname.">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4095 | if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/' |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 4096 | sil! unlet w:netrw_treedict |
| 4097 | sil! unlet w:netrw_treetop |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4098 | endif |
| 4099 | let newdir= dirname |
| 4100 | if !exists("b:netrw_curdir") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4101 | keepj call netrw#LocalBrowseCheck(getcwd()) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4102 | else |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4103 | keepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir)) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4104 | endif |
| 4105 | endif |
| 4106 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4107 | " visual display of **/ **// */ Exploration files |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4108 | " call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist")) |
| 4109 | " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4110 | if exists("w:netrw_explore_indx") && exists("b:netrw_curdir") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4111 | " call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-")) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4112 | if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir |
| 4113 | " only update match list if current directory isn't the same as before |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4114 | " call Decho("only update match list if current directory not the same as before") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4115 | let s:explore_prvdir = b:netrw_curdir |
| 4116 | let s:explore_match = "" |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4117 | let dirlen = s:Strlen(b:netrw_curdir) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4118 | if b:netrw_curdir !~ '/$' |
| 4119 | let dirlen= dirlen + 1 |
| 4120 | endif |
| 4121 | let prvfname= "" |
| 4122 | for fname in w:netrw_explore_list |
| 4123 | " call Decho("fname<".fname.">") |
| 4124 | if fname =~ '^'.b:netrw_curdir |
| 4125 | if s:explore_match == "" |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4126 | let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4127 | else |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4128 | let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4129 | endif |
| 4130 | elseif fname !~ '^/' && fname != prvfname |
| 4131 | if s:explore_match == "" |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4132 | let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4133 | else |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4134 | let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4135 | endif |
| 4136 | endif |
| 4137 | let prvfname= fname |
| 4138 | endfor |
| 4139 | " call Decho("explore_match<".s:explore_match.">") |
| 4140 | exe "2match netrwMarkFile /".s:explore_match."/" |
| 4141 | endif |
| 4142 | echo "<s-up>==Pexplore <s-down>==Nexplore" |
| 4143 | else |
| 4144 | 2match none |
| 4145 | if exists("s:explore_match") | unlet s:explore_match | endif |
| 4146 | if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif |
| 4147 | echo " " |
| 4148 | " call Decho("cleared explore match list") |
| 4149 | endif |
| 4150 | |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 4151 | sil! let @* = keepregstar |
| 4152 | sil! let @+ = keepregstar |
| 4153 | sil! let @/ = keepregslash |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4154 | " call Dret("netrw#Explore : @/<".@/.">") |
| 4155 | endfun |
| 4156 | |
| 4157 | " --------------------------------------------------------------------- |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4158 | " s:NetrwExploreListUniq: {{{2 |
| 4159 | fun! s:NetrwExploreListUniq(explist) |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 4160 | " call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4161 | |
| 4162 | " this assumes that the list is already sorted |
| 4163 | let newexplist= [] |
| 4164 | for member in a:explist |
| 4165 | if !exists("uniqmember") || member != uniqmember |
| 4166 | let uniqmember = member |
| 4167 | let newexplist = newexplist + [ member ] |
| 4168 | endif |
| 4169 | endfor |
| 4170 | |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 4171 | " call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4172 | return newexplist |
| 4173 | endfun |
| 4174 | |
| 4175 | " --------------------------------------------------------------------- |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4176 | " s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2 |
| 4177 | fun! s:NetrwForceChgDir(islocal,newdir) |
| 4178 | " call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)") |
| 4179 | if a:newdir !~ '/$' |
| 4180 | " ok, looks like force is needed to get directory-style treatment |
| 4181 | if a:newdir =~ '@$' |
| 4182 | let newdir= substitute(a:newdir,'@$','/','') |
| 4183 | elseif a:newdir =~ '[*=|\\]$' |
| 4184 | let newdir= substitute(a:newdir,'.$','/','') |
| 4185 | else |
| 4186 | let newdir= a:newdir.'/' |
| 4187 | endif |
| 4188 | " call Decho("adjusting newdir<".newdir."> due to gd") |
| 4189 | else |
| 4190 | " should already be getting treatment as a directory |
| 4191 | let newdir= a:newdir |
| 4192 | endif |
| 4193 | call s:NetrwBrowseChgDir(a:islocal,newdir) |
| 4194 | call s:NetrwBrowse(a:islocal,newdir) |
| 4195 | " call Dret("s:NetrwForceChgDir") |
| 4196 | endfun |
| 4197 | |
| 4198 | " --------------------------------------------------------------------- |
| 4199 | " s:NetrwForceFile: (gf support) Force treatment as a file {{{2 |
| 4200 | fun! s:NetrwForceFile(islocal,newfile) |
| 4201 | " " call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newdir.">)") |
| 4202 | if a:newfile =~ '[/@*=|\\]$' |
| 4203 | let newfile= substitute(a:newfile,'.$','','') |
| 4204 | else |
| 4205 | let newfile= a:newfile |
| 4206 | endif |
| 4207 | call s:NetrwBrowseChgDir(a:islocal,newfile) |
| 4208 | " call Dret("s:NetrwForceFile") |
| 4209 | endfun |
| 4210 | |
| 4211 | " --------------------------------------------------------------------- |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4212 | " s:NetrwHide: this function is invoked by the "a" map for browsing {{{2 |
| 4213 | " and switches the hiding mode. The actual hiding is done by |
| 4214 | " s:NetrwListHide(). |
| 4215 | " g:netrw_hide= 0: show all |
| 4216 | " 1: show not-hidden files |
| 4217 | " 2: show hidden files only |
| 4218 | fun! s:NetrwHide(islocal) |
| 4219 | " call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide) |
| 4220 | let svpos= netrw#NetrwSavePosn() |
| 4221 | |
| 4222 | if exists("s:netrwmarkfilelist_{bufnr('%')}") |
| 4223 | " call Decho(((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">") |
| 4224 | " call Decho("g:netrw_list_hide<".g:netrw_list_hide.">") |
| 4225 | |
| 4226 | " hide the files in the markfile list |
| 4227 | for fname in s:netrwmarkfilelist_{bufnr("%")} |
| 4228 | " call Decho("match(g:netrw_list_hide<".g:netrw_list_hide.'> fname<\<'.fname.'\>>)='.match(g:netrw_list_hide,'\<'.fname.'\>')." isk=".&isk) |
| 4229 | if match(g:netrw_list_hide,'\<'.fname.'\>') != -1 |
| 4230 | " remove fname from hiding list |
| 4231 | let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','') |
| 4232 | let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g') |
| 4233 | let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','') |
| 4234 | " call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">") |
| 4235 | else |
| 4236 | " append fname to hiding list |
| 4237 | if exists("g:netrw_list_hide") && g:netrw_list_hide != "" |
| 4238 | let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>' |
| 4239 | else |
| 4240 | let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>' |
| 4241 | endif |
| 4242 | " call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">") |
| 4243 | endif |
| 4244 | endfor |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4245 | keepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4246 | let g:netrw_hide= 1 |
| 4247 | |
| 4248 | else |
| 4249 | |
| 4250 | " switch between show-all/show-not-hidden/show-hidden |
| 4251 | let g:netrw_hide=(g:netrw_hide+1)%3 |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 4252 | exe "keepj norm! 0" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4253 | if g:netrw_hide && g:netrw_list_hide == "" |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4254 | keepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4255 | " call Dret("NetrwHide") |
| 4256 | return |
| 4257 | endif |
| 4258 | endif |
| 4259 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4260 | keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) |
| 4261 | keepj call netrw#NetrwRestorePosn(svpos) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4262 | " call Dret("NetrwHide") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4263 | endfun |
| 4264 | |
| 4265 | " --------------------------------------------------------------------- |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4266 | " s:NetrwHidden: invoked by "gh" {{{2 |
| 4267 | fun! s:NetrwHidden(islocal) |
| 4268 | " call Dfunc("s:NetrwHidden()") |
| 4269 | " save current position |
| 4270 | let svpos= netrw#NetrwSavePosn() |
| 4271 | |
| 4272 | if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+' |
| 4273 | " remove pattern from hiding list |
| 4274 | let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','') |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4275 | elseif s:Strlen(g:netrw_list_hide) >= 1 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4276 | let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+' |
| 4277 | else |
| 4278 | let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+' |
| 4279 | endif |
| 4280 | |
| 4281 | " refresh screen and return to saved position |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4282 | keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) |
| 4283 | keepj call netrw#NetrwRestorePosn(svpos) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4284 | " call Dret("s:NetrwHidden") |
| 4285 | endfun |
| 4286 | |
| 4287 | " --------------------------------------------------------------------- |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4288 | " s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2 |
| 4289 | fun! s:NetrwHome() |
| 4290 | if exists("g:netrw_home") |
| 4291 | let home= g:netrw_home |
| 4292 | else |
| 4293 | " go to vim plugin home |
| 4294 | for home in split(&rtp,',') + [''] |
| 4295 | if isdirectory(home) && filewritable(home) | break | endif |
| 4296 | let basehome= substitute(home,'[/\\]\.vim$','','') |
| 4297 | if isdirectory(basehome) && filewritable(basehome) |
| 4298 | let home= basehome."/.vim" |
| 4299 | break |
| 4300 | endif |
| 4301 | endfor |
| 4302 | if home == "" |
| 4303 | " just pick the first directory |
| 4304 | let home= substitute(&rtp,',.*$','','') |
| 4305 | endif |
| 4306 | if (has("win32") || has("win95") || has("win64") || has("win16")) |
| 4307 | let home= substitute(home,'/','\\','g') |
| 4308 | endif |
| 4309 | endif |
| 4310 | " insure that the home directory exists |
| 4311 | if !isdirectory(home) |
| 4312 | if exists("g:netrw_mkdir") |
| 4313 | call system(g:netrw_mkdir." ".shellescape(home)) |
| 4314 | else |
| 4315 | call mkdir(home) |
| 4316 | endif |
| 4317 | endif |
| 4318 | let g:netrw_home= home |
| 4319 | return home |
| 4320 | endfun |
| 4321 | |
| 4322 | " --------------------------------------------------------------------- |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4323 | " s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2 |
| 4324 | fun! s:NetrwLeftmouse(islocal) |
| 4325 | " call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 4326 | |
| 4327 | " check if the status bar was clicked on instead of a file/directory name |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4328 | while getchar(0) != 0 |
| 4329 | "clear the input stream |
| 4330 | endwhile |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 4331 | call feedkeys("\<LeftMouse>") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4332 | let c = getchar() |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 4333 | let mouse_lnum = v:mouse_lnum |
| 4334 | let wlastline = line('w$') |
| 4335 | let lastline = line('$') |
| 4336 | " call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr()) |
| 4337 | " call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0)) |
| 4338 | if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr() |
| 4339 | " appears to be a status bar leftmouse click |
| 4340 | " call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click") |
| 4341 | return |
| 4342 | endif |
| 4343 | if v:mouse_col != col('.') |
| 4344 | " call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click") |
| 4345 | return |
| 4346 | endif |
| 4347 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4348 | if a:islocal |
| 4349 | if exists("b:netrw_curdir") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4350 | keepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord())) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4351 | endif |
| 4352 | else |
| 4353 | if exists("b:netrw_curdir") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4354 | keepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord())) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4355 | endif |
| 4356 | endif |
| 4357 | " call Dret("s:NetrwLeftmouse") |
| 4358 | endfun |
| 4359 | |
| 4360 | " --------------------------------------------------------------------- |
| 4361 | " s:NetrwListHide: uses [range]g~...~d to delete files that match comma {{{2 |
| 4362 | " separated patterns given in g:netrw_list_hide |
| 4363 | fun! s:NetrwListHide() |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4364 | " call Dfunc("NetrwListHide() g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4365 | |
| 4366 | " find a character not in the "hide" string to use as a separator for :g and :v commands |
| 4367 | " How-it-works: take the hiding command, convert it into a range. Duplicate |
| 4368 | " characters don't matter. Remove all such characters from the '/~...90' |
| 4369 | " string. Use the first character left as a separator character. |
| 4370 | let listhide= g:netrw_list_hide |
| 4371 | let sep = strpart(substitute('/~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1) |
| 4372 | " call Decho("sep=".sep) |
| 4373 | |
| 4374 | while listhide != "" |
| 4375 | if listhide =~ ',' |
| 4376 | let hide = substitute(listhide,',.*$','','e') |
| 4377 | let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e') |
| 4378 | else |
| 4379 | let hide = listhide |
| 4380 | let listhide = "" |
| 4381 | endif |
| 4382 | |
| 4383 | " Prune the list by hiding any files which match |
| 4384 | if g:netrw_hide == 1 |
| 4385 | " call Decho("hiding<".hide."> listhide<".listhide.">") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 4386 | exe 'sil keepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4387 | elseif g:netrw_hide == 2 |
| 4388 | " call Decho("showing<".hide."> listhide<".listhide.">") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 4389 | exe 'sil keepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4390 | endif |
| 4391 | endwhile |
| 4392 | if g:netrw_hide == 2 |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 4393 | exe 'sil keepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d' |
| 4394 | exe 'sil keepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4395 | endif |
| 4396 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4397 | " remove any blank lines that have somehow remained. |
| 4398 | " This seems to happen under Windows. |
| 4399 | exe 'sil! keepj 1,$g@^\s*$@d' |
| 4400 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4401 | " call Dret("NetrwListHide") |
| 4402 | endfun |
| 4403 | |
| 4404 | " --------------------------------------------------------------------- |
| 4405 | " NetrwHideEdit: allows user to edit the file/directory hiding list |
| 4406 | fun! s:NetrwHideEdit(islocal) |
| 4407 | " call Dfunc("NetrwHideEdit(islocal=".a:islocal.")") |
| 4408 | |
| 4409 | " save current cursor position |
| 4410 | let svpos= netrw#NetrwSavePosn() |
| 4411 | |
| 4412 | " get new hiding list from user |
| 4413 | call inputsave() |
| 4414 | let newhide= input("Edit Hiding List: ",g:netrw_list_hide) |
| 4415 | call inputrestore() |
| 4416 | let g:netrw_list_hide= newhide |
| 4417 | " call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">") |
| 4418 | |
| 4419 | " refresh the listing |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4420 | sil keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./")) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4421 | |
| 4422 | " restore cursor position |
| 4423 | call netrw#NetrwRestorePosn(svpos) |
| 4424 | |
| 4425 | " call Dret("NetrwHideEdit") |
| 4426 | endfun |
| 4427 | |
| 4428 | " --------------------------------------------------------------------- |
| 4429 | " NetSortSequence: allows user to edit the sorting sequence |
| 4430 | fun! s:NetSortSequence(islocal) |
| 4431 | " call Dfunc("NetSortSequence(islocal=".a:islocal.")") |
| 4432 | |
| 4433 | let svpos= netrw#NetrwSavePosn() |
| 4434 | call inputsave() |
| 4435 | let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence) |
| 4436 | call inputrestore() |
| 4437 | |
| 4438 | " refresh the listing |
| 4439 | let g:netrw_sort_sequence= newsortseq |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4440 | keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) |
| 4441 | keepj call netrw#NetrwRestorePosn(svpos) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4442 | |
| 4443 | " call Dret("NetSortSequence") |
| 4444 | endfun |
| 4445 | |
| 4446 | " --------------------------------------------------------------------- |
| 4447 | " s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2 |
| 4448 | fun! s:NetrwMakeDir(usrhost) |
| 4449 | " call Dfunc("NetrwMakeDir(usrhost<".a:usrhost.">)") |
| 4450 | |
| 4451 | " get name of new directory from user. A bare <CR> will skip. |
| 4452 | " if its currently a directory, also request will be skipped, but with |
| 4453 | " a message. |
| 4454 | call inputsave() |
| 4455 | let newdirname= input("Please give directory name: ") |
| 4456 | call inputrestore() |
| 4457 | " call Decho("newdirname<".newdirname.">") |
| 4458 | |
| 4459 | if newdirname == "" |
| 4460 | " call Dret("NetrwMakeDir : user aborted with bare <cr>") |
| 4461 | return |
| 4462 | endif |
| 4463 | |
| 4464 | if a:usrhost == "" |
| 4465 | " call Decho("local mkdir") |
| 4466 | |
| 4467 | " Local mkdir: |
| 4468 | " sanity checks |
| 4469 | let fullnewdir= b:netrw_curdir.'/'.newdirname |
| 4470 | " call Decho("fullnewdir<".fullnewdir.">") |
| 4471 | if isdirectory(fullnewdir) |
| 4472 | if !exists("g:netrw_quiet") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4473 | keepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4474 | endif |
| 4475 | " call Dret("NetrwMakeDir : directory<".newdirname."> exists previously") |
| 4476 | return |
| 4477 | endif |
| 4478 | if s:FileReadable(fullnewdir) |
| 4479 | if !exists("g:netrw_quiet") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4480 | keepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4481 | endif |
| 4482 | " call Dret("NetrwMakeDir : file<".newdirname."> exists previously") |
| 4483 | return |
| 4484 | endif |
| 4485 | |
| 4486 | " requested new local directory is neither a pre-existing file or |
| 4487 | " directory, so make it! |
| 4488 | if exists("*mkdir") |
| 4489 | call mkdir(fullnewdir,"p") |
| 4490 | else |
| 4491 | let netrw_origdir= s:NetrwGetcwd(1) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 4492 | exe 'keepj lcd '.fnameescape(b:netrw_curdir) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4493 | " call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4494 | " call Decho("exe sil! !".g:netrw_local_mkdir.' '.shellescape(newdirname,1)) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 4495 | exe "sil! !".g:netrw_local_mkdir.' '.shellescape(newdirname,1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4496 | if !g:netrw_keepdir |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 4497 | exe 'keepj lcd '.fnameescape(netrw_origdir) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4498 | " call Decho("netrw_keepdir=".g:netrw_keepdir.": keepjumps lcd ".fnameescape(netrw_origdir)." getcwd<".getcwd().">") |
| 4499 | endif |
| 4500 | endif |
| 4501 | |
| 4502 | if v:shell_error == 0 |
| 4503 | " refresh listing |
| 4504 | " call Decho("refresh listing") |
| 4505 | let svpos= netrw#NetrwSavePosn() |
| 4506 | call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./')) |
| 4507 | call netrw#NetrwRestorePosn(svpos) |
| 4508 | elseif !exists("g:netrw_quiet") |
| 4509 | call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26) |
| 4510 | endif |
| 4511 | " redraw! |
| 4512 | |
| 4513 | elseif !exists("b:netrw_method") || b:netrw_method == 4 |
| 4514 | " Remote mkdir: |
| 4515 | " call Decho("remote mkdir") |
| 4516 | let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd) |
| 4517 | let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4518 | " call Decho("exe sil! !".mkdircmd." ".shellescape(newdirname,1)) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 4519 | exe "sil! !".mkdircmd." ".shellescape(newdirname,1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4520 | if v:shell_error == 0 |
| 4521 | " refresh listing |
| 4522 | let svpos= netrw#NetrwSavePosn() |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4523 | keepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./')) |
| 4524 | keepj call netrw#NetrwRestorePosn(svpos) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4525 | elseif !exists("g:netrw_quiet") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4526 | keepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4527 | endif |
| 4528 | " redraw! |
| 4529 | |
| 4530 | elseif b:netrw_method == 2 |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 4531 | let svpos= netrw#NetrwSavePosn() |
| 4532 | call s:NetrwRemoteFtpCmd("",g:netrw_remote_mkdir.' "'.newdirname.'"') |
| 4533 | keepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./')) |
| 4534 | keepj call netrw#NetrwRestorePosn(svpos) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4535 | elseif b:netrw_method == 3 |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 4536 | let svpos= netrw#NetrwSavePosn() |
| 4537 | call s:NetrwRemoteFtpCmd("",g:netrw_remote_mkdir.' "'.newdirname.'"') |
| 4538 | keepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./')) |
| 4539 | keepj call netrw#NetrwRestorePosn(svpos) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4540 | endif |
| 4541 | |
| 4542 | " call Dret("NetrwMakeDir") |
| 4543 | endfun |
| 4544 | |
| 4545 | " --------------------------------------------------------------------- |
| 4546 | " s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2 |
| 4547 | " mark and unmark files. If a markfile list exists, |
| 4548 | " then the rename and delete functions will use it instead |
| 4549 | " of whatever may happen to be under the cursor at that |
| 4550 | " moment. When the mouse and gui are available, |
| 4551 | " shift-leftmouse may also be used to mark files. |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 4552 | " |
| 4553 | " Creates two lists |
| 4554 | " s:netrwmarkfilelist -- holds complete paths to all marked files |
| 4555 | " s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr()) |
| 4556 | " |
| 4557 | " Creates a marked file match string |
| 4558 | " s:netrwmarfilemtch_# -- used with 2match to display marked files |
| 4559 | " |
Bram Moolenaar | ed39e1d | 2008-08-09 17:55:22 +0000 | [diff] [blame] | 4560 | " Creates a buffer version of islocal |
| 4561 | " b:netrw_islocal |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4562 | fun! s:NetrwMarkFile(islocal,fname) |
| 4563 | " call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)") |
| 4564 | let curbufnr= bufnr("%") |
| 4565 | let curdir = b:netrw_curdir |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4566 | let trailer = '[@=|\/\*]\=\>' |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4567 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4568 | if exists("s:netrwmarkfilelist_{curbufnr}") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4569 | " markfile list pre-exists |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4570 | " call Decho("starting s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">") |
| 4571 | " call Decho("starting s:netrwmarkfilemtch_{curbufnr}<".s:netrwmarkfilemtch_{curbufnr}.">") |
Bram Moolenaar | ed39e1d | 2008-08-09 17:55:22 +0000 | [diff] [blame] | 4572 | let b:netrw_islocal= a:islocal |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4573 | |
| 4574 | if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1 |
Bram Moolenaar | ed39e1d | 2008-08-09 17:55:22 +0000 | [diff] [blame] | 4575 | " append filename to buffer's markfilelist |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4576 | " call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">") |
| 4577 | call add(s:netrwmarkfilelist_{curbufnr},a:fname) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4578 | let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|\<'.escape(a:fname,g:netrw_markfileesc."'".g:netrw_markfileesc."'").trailer |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4579 | |
| 4580 | else |
Bram Moolenaar | ed39e1d | 2008-08-09 17:55:22 +0000 | [diff] [blame] | 4581 | " remove filename from buffer's markfilelist |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4582 | " call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">") |
| 4583 | call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname') |
| 4584 | if s:netrwmarkfilelist_{curbufnr} == [] |
| 4585 | " local markfilelist is empty; remove it entirely |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4586 | " call Decho("markfile list now empty") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4587 | call s:NetrwUnmarkList(curbufnr,curdir) |
| 4588 | else |
| 4589 | " rebuild match list to display markings correctly |
| 4590 | " call Decho("rebuild s:netrwmarkfilemtch_".curbufnr) |
| 4591 | let s:netrwmarkfilemtch_{curbufnr}= "" |
| 4592 | let first = 1 |
| 4593 | for fname in s:netrwmarkfilelist_{curbufnr} |
| 4594 | if first |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4595 | let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\<'.escape(fname,g:netrw_markfileesc."'".g:netrw_markfileesc."'").trailer |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4596 | else |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4597 | let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|\<'.escape(fname,g:netrw_markfileesc."'".g:netrw_markfileesc."'").trailer |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4598 | endif |
| 4599 | let first= 0 |
| 4600 | endfor |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 4601 | " call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4602 | endif |
| 4603 | endif |
| 4604 | |
| 4605 | else |
| 4606 | " initialize new markfilelist |
| 4607 | |
| 4608 | " call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr) |
| 4609 | let s:netrwmarkfilelist_{curbufnr}= [] |
| 4610 | call add(s:netrwmarkfilelist_{curbufnr},a:fname) |
| 4611 | " call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">") |
| 4612 | |
| 4613 | " build initial markfile matching pattern |
| 4614 | if a:fname =~ '/$' |
| 4615 | let s:netrwmarkfilemtch_{curbufnr}= '\<'.escape(a:fname,g:netrw_markfileesc) |
| 4616 | else |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4617 | let s:netrwmarkfilemtch_{curbufnr}= '\<'.escape(a:fname,g:netrw_markfileesc).trailer |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4618 | endif |
| 4619 | " call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">") |
| 4620 | endif |
| 4621 | |
| 4622 | " handle global markfilelist |
| 4623 | if exists("s:netrwmarkfilelist") |
| 4624 | let dname= s:ComposePath(b:netrw_curdir,a:fname) |
| 4625 | if index(s:netrwmarkfilelist,dname) == -1 |
| 4626 | " append new filename to global markfilelist |
| 4627 | call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname)) |
| 4628 | " call Decho("append filename<".a:fname."> to global markfilelist<".string(s:netrwmarkfilelist).">") |
| 4629 | else |
| 4630 | " remove new filename from global markfilelist |
| 4631 | " call Decho("filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")") |
| 4632 | call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"') |
| 4633 | " call Decho("ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">") |
| 4634 | if s:netrwmarkfilelist == [] |
| 4635 | unlet s:netrwmarkfilelist |
| 4636 | endif |
| 4637 | endif |
| 4638 | else |
| 4639 | " initialize new global-directory markfilelist |
| 4640 | let s:netrwmarkfilelist= [] |
| 4641 | call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname)) |
| 4642 | " call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">") |
| 4643 | endif |
| 4644 | |
| 4645 | " set up 2match'ing to netrwmarkfilemtch list |
| 4646 | if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != "" |
| 4647 | " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4648 | if exists("g:did_drchip_netrwlist_syntax") |
| 4649 | exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/" |
| 4650 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4651 | else |
| 4652 | " call Decho("2match none") |
| 4653 | 2match none |
| 4654 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4655 | " call Dret("s:NetrwMarkFile : s:netrwmarkfilelist_".curbufnr."<".(exists("s:netrwmarkfilelist_{curbufnr}")? string(s:netrwmarkfilelist_{curbufnr}) : " doesn't exist").">") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4656 | endfun |
| 4657 | |
| 4658 | " --------------------------------------------------------------------- |
| 4659 | " s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2 |
| 4660 | " compress/decompress files using the programs |
| 4661 | " in g:netrw_compress and g:netrw_uncompress, |
| 4662 | " using g:netrw_compress_suffix to know which to |
| 4663 | " do. By default: |
| 4664 | " g:netrw_compress = "gzip" |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 4665 | " g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"} |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4666 | fun! s:NetrwMarkFileCompress(islocal) |
| 4667 | " call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")") |
| 4668 | let svpos = netrw#NetrwSavePosn() |
| 4669 | let curdir = b:netrw_curdir |
| 4670 | let curbufnr = bufnr("%") |
| 4671 | |
| 4672 | if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress") |
| 4673 | for fname in s:netrwmarkfilelist_{curbufnr} |
| 4674 | " for every filename in the marked list |
| 4675 | for sfx in sort(keys(g:netrw_decompress)) |
| 4676 | if fname =~ '\'.sfx.'$' |
| 4677 | " fname has a suffix indicating that its compressed; apply associated decompression routine |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4678 | let exe= netrw#WinPath(g:netrw_decompress[sfx]) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4679 | " call Decho("fname<".fname."> is compressed so decompress with <".exe.">") |
| 4680 | if a:islocal |
| 4681 | if g:netrw_keepdir |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 4682 | let fname= shellescape(s:ComposePath(curdir,fname)) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4683 | endif |
| 4684 | else |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 4685 | let fname= shellescape(b:netrw_curdir.fname,1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4686 | endif |
| 4687 | if executable(exe) |
| 4688 | if a:islocal |
| 4689 | call system(exe." ".fname) |
| 4690 | else |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4691 | keepj call s:RemoteSystem(exe." ".fname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4692 | endif |
| 4693 | else |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4694 | keepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4695 | endif |
| 4696 | break |
| 4697 | endif |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 4698 | unlet sfx |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4699 | endfor |
| 4700 | if exists("exe") |
| 4701 | unlet exe |
| 4702 | elseif a:islocal |
| 4703 | " fname not a compressed file, so compress it |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4704 | call system(netrw#WinPath(g:netrw_compress)." ".shellescape(s:ComposePath(b:netrw_curdir,fname))) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4705 | else |
| 4706 | " fname not a compressed file, so compress it |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4707 | keepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".shellescape(fname)) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4708 | endif |
| 4709 | endfor |
| 4710 | call s:NetrwUnmarkList(curbufnr,curdir) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4711 | keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) |
| 4712 | keepj call netrw#NetrwRestorePosn(svpos) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4713 | endif |
| 4714 | " call Dret("s:NetrwMarkFileCompress") |
| 4715 | endfun |
| 4716 | |
| 4717 | " --------------------------------------------------------------------- |
| 4718 | " s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2 |
| 4719 | " If no marked files, then set up directory as the |
| 4720 | " target. Currently does not support copying entire |
| 4721 | " directories. Uses the local-buffer marked file list. |
| 4722 | " Returns 1=success (used by NetrwMarkFileMove()) |
| 4723 | " 0=failure |
| 4724 | fun! s:NetrwMarkFileCopy(islocal) |
| 4725 | " call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---').">") |
| 4726 | |
| 4727 | " sanity checks |
| 4728 | if !exists("s:netrwmarkfilelist_{bufnr('%')}") || empty(s:netrwmarkfilelist_{bufnr('%')}) |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 4729 | keepj call netrw#ErrorMsg(s:ERROR,"there are no marked files in this window (:help netrw-mf)",66) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4730 | " call Dret("s:NetrwMarkFileCopy 0") |
| 4731 | return 0 |
| 4732 | endif |
| 4733 | " call Decho("sanity chk passed: s:netrwmarkfilelist_".bufnr('%')."<".string(s:netrwmarkfilelist_{bufnr('%')})) |
| 4734 | if !exists("s:netrwmftgt") |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 4735 | keepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4736 | " call Dret("s:NetrwMarkFileCopy 0") |
| 4737 | return 0 |
| 4738 | endif |
| 4739 | " call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">") |
| 4740 | let curdir = b:netrw_curdir |
| 4741 | let curbufnr = bufnr("%") |
| 4742 | |
| 4743 | if a:islocal && s:netrwmftgt_islocal |
| 4744 | " Copy marked files, local directory to local directory |
| 4745 | " call Decho("copy from local to local") |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 4746 | let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"shellescape(b:netrw_curdir.\"/\".v:val)")) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4747 | " call Decho("system(".g:netrw_localcopycmd." ".args." ".shellescape(s:netrwmftgt).")") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4748 | call system(netrw#WinPath(g:netrw_localcopycmd)." ".args." ".shellescape(s:netrwmftgt)) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4749 | |
| 4750 | elseif a:islocal && !s:netrwmftgt_islocal |
| 4751 | " Copy marked files, local directory to remote directory |
| 4752 | " call Decho("copy from local to remote") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4753 | keepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4754 | |
| 4755 | elseif !a:islocal && s:netrwmftgt_islocal |
| 4756 | " call Decho("copy from remote to local") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4757 | keepj call netrw#NetrwObtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4758 | |
| 4759 | elseif !a:islocal && !s:netrwmftgt_islocal |
| 4760 | " call Decho("copy from remote to remote") |
| 4761 | let curdir = getcwd() |
| 4762 | let tmpdir = s:GetTempfile("") |
| 4763 | if tmpdir !~ '/' |
| 4764 | let tmpdir= curdir."/".tmpdir |
| 4765 | endif |
| 4766 | if exists("*mkdir") |
| 4767 | call mkdir(tmpdir) |
| 4768 | else |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 4769 | exe "sil! !".g:netrw_local_mkdir.' '.shellescape(tmpdir,1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4770 | endif |
| 4771 | if isdirectory(tmpdir) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 4772 | exe "keepj lcd ".fnameescape(tmpdir) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4773 | keepj call netrw#NetrwObtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir) |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 4774 | let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")') |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4775 | keepj call s:NetrwUpload(localfiles,s:netrwmftgt) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4776 | if getcwd() == tmpdir |
| 4777 | for fname in s:netrwmarkfilelist_{bufnr('%')} |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4778 | keepj call s:NetrwDelete(fname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4779 | endfor |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 4780 | exe "keepj lcd ".fnameescape(curdir) |
| 4781 | exe "sil !".g:netrw_local_rmdir." ".shellescape(tmpdir,1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4782 | else |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 4783 | exe "keepj lcd ".fnameescape(curdir) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4784 | endif |
| 4785 | endif |
| 4786 | endif |
| 4787 | |
| 4788 | " ------- |
| 4789 | " cleanup |
| 4790 | " ------- |
| 4791 | " call Decho("cleanup") |
| 4792 | |
| 4793 | " remove markings from local buffer |
| 4794 | call s:NetrwUnmarkList(curbufnr,curdir) |
| 4795 | |
| 4796 | " refresh buffers |
| 4797 | if !s:netrwmftgt_islocal |
| 4798 | call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt) |
| 4799 | endif |
| 4800 | if a:islocal |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4801 | keepj call s:NetrwRefreshDir(a:islocal,curdir) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4802 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4803 | if g:netrw_fastbrowse <= 1 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4804 | keepj call s:LocalBrowseShellCmdRefresh() |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4805 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4806 | |
| 4807 | " call Dret("s:NetrwMarkFileCopy 1") |
| 4808 | return 1 |
| 4809 | endfun |
| 4810 | |
| 4811 | " --------------------------------------------------------------------- |
| 4812 | " s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2 |
| 4813 | " invoke vim's diff mode on the marked files. |
| 4814 | " Either two or three files can be so handled. |
| 4815 | " Uses the global marked file list. |
| 4816 | fun! s:NetrwMarkFileDiff(islocal) |
| 4817 | " call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">") |
| 4818 | let curbufnr= bufnr("%") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4819 | |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 4820 | if exists("s:netrwmarkfilelist_{curbufnr}") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4821 | let cnt = 0 |
| 4822 | let curdir = b:netrw_curdir |
| 4823 | for fname in s:netrwmarkfilelist |
| 4824 | let cnt= cnt + 1 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4825 | if cnt == 1 |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 4826 | " call Decho("diffthis: fname<".fname.">") |
| 4827 | exe "e ".fnameescape(fname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4828 | diffthis |
| 4829 | elseif cnt == 2 || cnt == 3 |
| 4830 | vsplit |
| 4831 | wincmd l |
| 4832 | " call Decho("diffthis: ".fname) |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 4833 | exe "e ".fnameescape(fname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4834 | diffthis |
| 4835 | else |
| 4836 | break |
| 4837 | endif |
| 4838 | endfor |
| 4839 | call s:NetrwUnmarkList(curbufnr,curdir) |
| 4840 | endif |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 4841 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4842 | " call Dret("s:NetrwMarkFileDiff") |
| 4843 | endfun |
| 4844 | |
| 4845 | " --------------------------------------------------------------------- |
| 4846 | " s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2 |
| 4847 | " Uses global markfilelist |
| 4848 | fun! s:NetrwMarkFileEdit(islocal) |
| 4849 | " call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")") |
| 4850 | |
| 4851 | let curdir = b:netrw_curdir |
| 4852 | let curbufnr = bufnr("%") |
| 4853 | if exists("s:netrwmarkfilelist_{curbufnr}") |
| 4854 | call s:SetRexDir(a:islocal,curdir) |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 4855 | let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)")) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4856 | " unmark markedfile list |
| 4857 | " call s:NetrwUnmarkList(curbufnr,curdir) |
| 4858 | call s:NetrwUnmarkAll() |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4859 | " call Decho("exe sil args ".flist) |
| 4860 | exe "sil args ".flist |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4861 | endif |
| 4862 | |
| 4863 | " call Dret("s:NetrwMarkFileEdit") |
| 4864 | endfun |
| 4865 | |
| 4866 | " --------------------------------------------------------------------- |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 4867 | " s:NetrwMarkFileExe: (invoked by mx) execute arbitrary system command on marked files, one at a time {{{2 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4868 | " Uses the local marked-file list. |
| 4869 | fun! s:NetrwMarkFileExe(islocal) |
| 4870 | " call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.")") |
| 4871 | let svpos = netrw#NetrwSavePosn() |
| 4872 | let curdir = b:netrw_curdir |
| 4873 | let curbufnr = bufnr("%") |
| 4874 | |
| 4875 | if exists("s:netrwmarkfilelist_{curbufnr}") |
| 4876 | " get the command |
| 4877 | call inputsave() |
| 4878 | let cmd= input("Enter command: ","","file") |
| 4879 | call inputrestore() |
| 4880 | " call Decho("cmd<".cmd.">") |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 4881 | if cmd == "" |
| 4882 | " " call Dret("s:NetrwMarkFileExe : early exit, empty command") |
| 4883 | return |
| 4884 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4885 | |
| 4886 | " apply command to marked files. Substitute: filename -> % |
| 4887 | " If no %, then append a space and the filename to the command |
| 4888 | for fname in s:netrwmarkfilelist_{curbufnr} |
| 4889 | if a:islocal |
| 4890 | if g:netrw_keepdir |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4891 | let fname= shellescape(netrw#WinPath(s:ComposePath(curdir,fname))) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4892 | endif |
| 4893 | else |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 4894 | let fname= shellescape(netrw#WinPath(b:netrw_curdir.fname)) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4895 | endif |
| 4896 | if cmd =~ '%' |
| 4897 | let xcmd= substitute(cmd,'%',fname,'g') |
| 4898 | else |
| 4899 | let xcmd= cmd.' '.fname |
| 4900 | endif |
| 4901 | if a:islocal |
| 4902 | " call Decho("local: xcmd<".xcmd.">") |
| 4903 | let ret= system(xcmd) |
| 4904 | else |
| 4905 | " call Decho("remote: xcmd<".xcmd.">") |
| 4906 | let ret= s:RemoteSystem(xcmd) |
| 4907 | endif |
| 4908 | if v:shell_error < 0 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4909 | keepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4910 | break |
| 4911 | else |
| 4912 | echo ret |
| 4913 | endif |
| 4914 | endfor |
| 4915 | |
| 4916 | " unmark marked file list |
| 4917 | call s:NetrwUnmarkList(curbufnr,curdir) |
| 4918 | |
| 4919 | " refresh the listing |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4920 | keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) |
| 4921 | keepj call netrw#NetrwRestorePosn(svpos) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4922 | else |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4923 | keepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4924 | endif |
| 4925 | |
| 4926 | " call Dret("s:NetrwMarkFileExe") |
| 4927 | endfun |
| 4928 | |
| 4929 | " --------------------------------------------------------------------- |
| 4930 | " s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix |
| 4931 | " as the marked file(s) (toggles suffix presence) |
| 4932 | " Uses the local marked file list. |
| 4933 | fun! s:NetrwMarkHideSfx(islocal) |
| 4934 | " call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")") |
| 4935 | let svpos = netrw#NetrwSavePosn() |
| 4936 | let curbufnr = bufnr("%") |
| 4937 | |
| 4938 | " s:netrwmarkfilelist_{curbufnr}: the List of marked files |
| 4939 | if exists("s:netrwmarkfilelist_{curbufnr}") |
| 4940 | |
| 4941 | for fname in s:netrwmarkfilelist_{curbufnr} |
| 4942 | " call Decho("s:NetrwMarkFileCopy: fname<".fname.">") |
| 4943 | " construct suffix pattern |
| 4944 | if fname =~ '\.' |
| 4945 | let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','') |
| 4946 | else |
| 4947 | let sfxpat= '^\%(\%(\.\)\@!.\)*$' |
| 4948 | endif |
| 4949 | " determine if its in the hiding list or not |
| 4950 | let inhidelist= 0 |
| 4951 | if g:netrw_list_hide != "" |
| 4952 | let itemnum = 0 |
| 4953 | let hidelist= split(g:netrw_list_hide,',') |
| 4954 | for hidepat in hidelist |
| 4955 | if sfxpat == hidepat |
| 4956 | let inhidelist= 1 |
| 4957 | break |
| 4958 | endif |
| 4959 | let itemnum= itemnum + 1 |
| 4960 | endfor |
| 4961 | endif |
| 4962 | " call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">") |
| 4963 | if inhidelist |
| 4964 | " remove sfxpat from list |
| 4965 | call remove(hidelist,itemnum) |
| 4966 | let g:netrw_list_hide= join(hidelist,",") |
| 4967 | elseif g:netrw_list_hide != "" |
| 4968 | " append sfxpat to non-empty list |
| 4969 | let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat |
| 4970 | else |
| 4971 | " set hiding list to sfxpat |
| 4972 | let g:netrw_list_hide= sfxpat |
| 4973 | endif |
| 4974 | endfor |
| 4975 | |
| 4976 | " refresh the listing |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4977 | keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) |
| 4978 | keepj call netrw#NetrwRestorePosn(svpos) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4979 | else |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 4980 | keepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4981 | endif |
| 4982 | |
| 4983 | " call Dret("s:NetrwMarkHideSfx") |
| 4984 | endfun |
| 4985 | |
| 4986 | " --------------------------------------------------------------------- |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 4987 | " s:NetrwMarkFileVimCmd: (invoked by mX) execute arbitrary vim command on marked files, one at a time {{{2 |
| 4988 | " Uses the local marked-file list. |
| 4989 | fun! s:NetrwMarkFileVimCmd(islocal) |
| 4990 | " call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")") |
| 4991 | let svpos = netrw#NetrwSavePosn() |
| 4992 | let curdir = b:netrw_curdir |
| 4993 | let curbufnr = bufnr("%") |
| 4994 | |
| 4995 | if exists("s:netrwmarkfilelist_{curbufnr}") |
| 4996 | " get the command |
| 4997 | call inputsave() |
| 4998 | let cmd= input("Enter vim command: ","","file") |
| 4999 | call inputrestore() |
| 5000 | " call Decho("cmd<".cmd.">") |
| 5001 | if cmd == "" |
| 5002 | " " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command") |
| 5003 | return |
| 5004 | endif |
| 5005 | |
| 5006 | " apply command to marked files. Substitute: filename -> % |
| 5007 | " If no %, then append a space and the filename to the command |
| 5008 | for fname in s:netrwmarkfilelist_{curbufnr} |
| 5009 | " call Decho("fname<".fname.">") |
| 5010 | if a:islocal |
| 5011 | 1split |
| 5012 | exe "sil! keepalt e ".fnameescape(fname) |
| 5013 | " call Decho("local<".fname.">: exe ".cmd) |
| 5014 | exe cmd |
| 5015 | exe "sil! keepalt wq!" |
| 5016 | else |
| 5017 | " COMBAK -- not supported yet |
| 5018 | " call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET") |
| 5019 | echo "sorry, \"mX\" not supported yet for remote files" |
| 5020 | endif |
| 5021 | endfor |
| 5022 | |
| 5023 | " unmark marked file list |
| 5024 | call s:NetrwUnmarkList(curbufnr,curdir) |
| 5025 | |
| 5026 | " refresh the listing |
| 5027 | keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) |
| 5028 | keepj call netrw#NetrwRestorePosn(svpos) |
| 5029 | else |
| 5030 | keepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59) |
| 5031 | endif |
| 5032 | |
| 5033 | " call Dret("s:NetrwMarkFileVimCmd") |
| 5034 | endfun |
| 5035 | |
| 5036 | " --------------------------------------------------------------------- |
| 5037 | " s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix |
| 5038 | " as the marked file(s) (toggles suffix presence) |
| 5039 | " Uses the local marked file list. |
| 5040 | fun! s:NetrwMarkHideSfx(islocal) |
| 5041 | " call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")") |
| 5042 | let svpos = netrw#NetrwSavePosn() |
| 5043 | let curbufnr = bufnr("%") |
| 5044 | |
| 5045 | " s:netrwmarkfilelist_{curbufnr}: the List of marked files |
| 5046 | if exists("s:netrwmarkfilelist_{curbufnr}") |
| 5047 | |
| 5048 | for fname in s:netrwmarkfilelist_{curbufnr} |
| 5049 | " call Decho("s:NetrwMarkFileCopy: fname<".fname.">") |
| 5050 | " construct suffix pattern |
| 5051 | if fname =~ '\.' |
| 5052 | let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','') |
| 5053 | else |
| 5054 | let sfxpat= '^\%(\%(\.\)\@!.\)*$' |
| 5055 | endif |
| 5056 | " determine if its in the hiding list or not |
| 5057 | let inhidelist= 0 |
| 5058 | if g:netrw_list_hide != "" |
| 5059 | let itemnum = 0 |
| 5060 | let hidelist= split(g:netrw_list_hide,',') |
| 5061 | for hidepat in hidelist |
| 5062 | if sfxpat == hidepat |
| 5063 | let inhidelist= 1 |
| 5064 | break |
| 5065 | endif |
| 5066 | let itemnum= itemnum + 1 |
| 5067 | endfor |
| 5068 | endif |
| 5069 | " call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">") |
| 5070 | if inhidelist |
| 5071 | " remove sfxpat from list |
| 5072 | call remove(hidelist,itemnum) |
| 5073 | let g:netrw_list_hide= join(hidelist,",") |
| 5074 | elseif g:netrw_list_hide != "" |
| 5075 | " append sfxpat to non-empty list |
| 5076 | let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat |
| 5077 | else |
| 5078 | " set hiding list to sfxpat |
| 5079 | let g:netrw_list_hide= sfxpat |
| 5080 | endif |
| 5081 | endfor |
| 5082 | |
| 5083 | " refresh the listing |
| 5084 | keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) |
| 5085 | keepj call netrw#NetrwRestorePosn(svpos) |
| 5086 | else |
| 5087 | keepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59) |
| 5088 | endif |
| 5089 | |
| 5090 | " call Dret("s:NetrwMarkHideSfx") |
| 5091 | endfun |
| 5092 | |
| 5093 | " --------------------------------------------------------------------- |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5094 | " s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2 |
| 5095 | " Uses the global markfilelist |
| 5096 | fun! s:NetrwMarkFileGrep(islocal) |
| 5097 | " call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")") |
| 5098 | let svpos = netrw#NetrwSavePosn() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5099 | let curbufnr = bufnr("%") |
| 5100 | |
| 5101 | if exists("s:netrwmarkfilelist") |
| 5102 | " call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">") |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 5103 | let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)")) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5104 | call s:NetrwUnmarkAll() |
| 5105 | |
| 5106 | " ask user for pattern |
| 5107 | call inputsave() |
| 5108 | let pat= input("Enter pattern: ","") |
| 5109 | call inputrestore() |
| 5110 | if pat !~ '^\s' |
| 5111 | if pat !~ '^/' |
| 5112 | let pat= '/'.pat.'/' |
| 5113 | endif |
| 5114 | let pat= " ".pat |
| 5115 | endif |
| 5116 | |
| 5117 | " use vimgrep for both local and remote |
| 5118 | " call Decho("exe vimgrep".pat." ".netrwmarkfilelist) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 5119 | try |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5120 | exe "keepj noautocmd vimgrep".pat." ".netrwmarkfilelist |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 5121 | catch /^Vim\%((\a\+)\)\=:E480/ |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5122 | keepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 5123 | " call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pattern.">") |
| 5124 | return |
| 5125 | endtry |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5126 | |
| 5127 | 2match none |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5128 | keepj call netrw#NetrwRestorePosn(svpos) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5129 | endif |
| 5130 | |
| 5131 | " call Dret("s:NetrwMarkFileGrep") |
| 5132 | endfun |
| 5133 | |
| 5134 | " --------------------------------------------------------------------- |
| 5135 | " s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2 |
| 5136 | " uses the global marked file list |
| 5137 | " s:netrwmfloc= 0: target directory is remote |
| 5138 | " = 1: target directory is local |
| 5139 | fun! s:NetrwMarkFileMove(islocal) |
| 5140 | " call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")") |
| 5141 | let curdir = b:netrw_curdir |
| 5142 | let curbufnr = bufnr("%") |
| 5143 | |
| 5144 | " sanity check |
| 5145 | if !exists("s:netrwmarkfilelist_{bufnr('%')}") || empty(s:netrwmarkfilelist_{bufnr('%')}) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5146 | keepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5147 | " call Dret("s:NetrwMarkFileMove") |
| 5148 | return |
| 5149 | endif |
| 5150 | " call Decho("sanity chk passed: s:netrwmarkfilelist_".bufnr('%')."<".string(s:netrwmarkfilelist_{bufnr('%')})) |
| 5151 | if !exists("s:netrwmftgt") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5152 | keepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5153 | " call Dret("s:NetrwMarkFileCopy 0") |
| 5154 | return 0 |
| 5155 | endif |
| 5156 | " call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">") |
| 5157 | |
| 5158 | if a:islocal && s:netrwmftgt_islocal |
| 5159 | " move: local -> local |
| 5160 | " call Decho("move from local to local") |
| 5161 | " call Decho("(s:NetrwMarkFileMove) local to local move") |
| 5162 | if executable(g:netrw_localmovecmd) |
| 5163 | for fname in s:netrwmarkfilelist_{bufnr("%")} |
| 5164 | " call Decho("system(".g:netrw_localmovecmd." ".shellescape(fname)." ".shellescape(s:netrwmftgt).")") |
| 5165 | let ret= system(g:netrw_localmovecmd." ".shellescape(fname)." ".shellescape(s:netrwmftgt)) |
| 5166 | if v:shell_error < 0 |
| 5167 | call netrw#ErrorMsg(s:ERROR,"command<".g:netrw_localmovecmd."> failed, aborting",54) |
| 5168 | break |
| 5169 | endif |
| 5170 | endfor |
| 5171 | else |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5172 | keepj call netrw#ErrorMsg(s:ERROR,"command<".g:netrw_localmovecmd."> is not executable!",57) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5173 | endif |
| 5174 | |
| 5175 | elseif a:islocal && !s:netrwmftgt_islocal |
| 5176 | " move: local -> remote |
| 5177 | " call Decho("move from local to remote") |
| 5178 | " call Decho("copy") |
| 5179 | let mflist= s:netrwmarkfilelist_{bufnr("%")} |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5180 | keepj call s:NetrwMarkFileCopy(a:islocal) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5181 | " call Decho("remove") |
| 5182 | for fname in mflist |
| 5183 | let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','') |
| 5184 | let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1) |
| 5185 | endfor |
| 5186 | unlet mflist |
| 5187 | |
| 5188 | elseif !a:islocal && s:netrwmftgt_islocal |
| 5189 | " move: remote -> local |
| 5190 | " call Decho("move from remote to local") |
| 5191 | " call Decho("copy") |
| 5192 | let mflist= s:netrwmarkfilelist_{bufnr("%")} |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5193 | keepj call s:NetrwMarkFileCopy(a:islocal) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5194 | " call Decho("remove") |
| 5195 | for fname in mflist |
| 5196 | let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','') |
| 5197 | let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1) |
| 5198 | endfor |
| 5199 | unlet mflist |
| 5200 | |
| 5201 | elseif !a:islocal && !s:netrwmftgt_islocal |
| 5202 | " move: remote -> remote |
| 5203 | " call Decho("move from remote to remote") |
| 5204 | " call Decho("copy") |
| 5205 | let mflist= s:netrwmarkfilelist_{bufnr("%")} |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5206 | keepj call s:NetrwMarkFileCopy(a:islocal) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5207 | " call Decho("remove") |
| 5208 | for fname in mflist |
| 5209 | let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','') |
| 5210 | let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1) |
| 5211 | endfor |
| 5212 | unlet mflist |
| 5213 | endif |
| 5214 | |
| 5215 | " ------- |
| 5216 | " cleanup |
| 5217 | " ------- |
| 5218 | " call Decho("cleanup") |
| 5219 | |
| 5220 | " remove markings from local buffer |
| 5221 | call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer |
| 5222 | |
| 5223 | " refresh buffers |
| 5224 | if !s:netrwmftgt_islocal |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5225 | " call Decho("refresh netrwmftgt<".s:netrwmftgt.">") |
| 5226 | keepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5227 | endif |
| 5228 | if a:islocal |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5229 | " call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">") |
| 5230 | keepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5231 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 5232 | if g:netrw_fastbrowse <= 1 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5233 | " call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh") |
| 5234 | keepj call s:LocalBrowseShellCmdRefresh() |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 5235 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5236 | |
| 5237 | " call Dret("s:NetrwMarkFileMove") |
| 5238 | endfun |
| 5239 | |
| 5240 | " --------------------------------------------------------------------- |
| 5241 | " s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2 |
| 5242 | " using the hardcopy command. Local marked-file list only. |
| 5243 | fun! s:NetrwMarkFilePrint(islocal) |
| 5244 | " call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")") |
| 5245 | let curbufnr= bufnr("%") |
| 5246 | if exists("s:netrwmarkfilelist_{curbufnr}") |
| 5247 | let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr} |
| 5248 | let curdir = b:netrw_curdir |
| 5249 | call s:NetrwUnmarkList(curbufnr,curdir) |
| 5250 | for fname in netrwmarkfilelist |
| 5251 | if a:islocal |
| 5252 | if g:netrw_keepdir |
| 5253 | let fname= s:ComposePath(curdir,fname) |
| 5254 | endif |
| 5255 | else |
| 5256 | let fname= curdir.fname |
| 5257 | endif |
| 5258 | 1split |
| 5259 | " the autocmds will handle both local and remote files |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5260 | " call Decho("exe sil e ".escape(fname,' ')) |
| 5261 | exe "sil e ".fnameescape(fname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5262 | " call Decho("hardcopy") |
| 5263 | hardcopy |
| 5264 | q |
| 5265 | endfor |
| 5266 | 2match none |
| 5267 | endif |
| 5268 | " call Dret("s:NetrwMarkFilePrint") |
| 5269 | endfun |
| 5270 | |
| 5271 | " --------------------------------------------------------------------- |
| 5272 | " s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2 |
| 5273 | " files when given a regexp (for which a prompt is |
| 5274 | " issued). |
| 5275 | fun! s:NetrwMarkFileRegexp(islocal) |
| 5276 | " call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")") |
| 5277 | |
| 5278 | " get the regular expression |
| 5279 | call inputsave() |
| 5280 | let regexp= input("Enter regexp: ","","file") |
| 5281 | call inputrestore() |
| 5282 | |
| 5283 | if a:islocal |
| 5284 | " get the matching list of files using local glob() |
| 5285 | " call Decho("handle local regexp") |
| 5286 | let dirname = escape(b:netrw_curdir,g:netrw_glob_escape) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 5287 | let files = glob(s:ComposePath(dirname,regexp)) |
| 5288 | " call Decho("files<".files.">") |
| 5289 | let filelist= split(files,"\n") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5290 | |
| 5291 | " mark the list of files |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 5292 | for fname in filelist |
| 5293 | " call Decho("fname<".fname.">") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5294 | keepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','','')) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 5295 | endfor |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5296 | |
| 5297 | else |
| 5298 | " call Decho("handle remote regexp") |
| 5299 | |
| 5300 | " convert displayed listing into a filelist |
| 5301 | let eikeep = &ei |
| 5302 | let areg = @a |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5303 | sil keepj %y a |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5304 | set ei=all ma |
| 5305 | " call Decho("set ei=all ma") |
| 5306 | 1split |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5307 | keepj call s:NetrwEnew() |
| 5308 | keepj call s:NetrwSafeOptions() |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5309 | sil keepj norm! "ap |
| 5310 | keepj 2 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5311 | let bannercnt= search('^" =====','W') |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5312 | exe "sil keepj 1,".bannercnt."d" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5313 | set bt=nofile |
| 5314 | if g:netrw_liststyle == s:LONGLIST |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5315 | sil keepj %s/\s\{2,}\S.*$//e |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 5316 | call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5317 | elseif g:netrw_liststyle == s:WIDELIST |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5318 | sil keepj %s/\s\{2,}/\r/ge |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 5319 | call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5320 | elseif g:netrw_liststyle == s:TREELIST |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5321 | sil keepj %s/^| //e |
| 5322 | sil! keepj g/^ .*$/d |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 5323 | call histdel("/",-1) |
| 5324 | call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5325 | endif |
| 5326 | " convert regexp into the more usual glob-style format |
| 5327 | let regexp= substitute(regexp,'\*','.*','g') |
| 5328 | " call Decho("regexp<".regexp.">") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5329 | exe "sil! keepj v/".escape(regexp,'/')."/d" |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 5330 | call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5331 | let filelist= getline(1,line("$")) |
| 5332 | q! |
| 5333 | for filename in filelist |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5334 | keepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','','')) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5335 | endfor |
| 5336 | unlet filelist |
| 5337 | let @a = areg |
| 5338 | let &ei = eikeep |
| 5339 | endif |
| 5340 | |
| 5341 | " call Dret("s:NetrwMarkFileRegexp") |
| 5342 | endfun |
| 5343 | |
| 5344 | " --------------------------------------------------------------------- |
| 5345 | " s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2 |
| 5346 | " Uses the local marked file list. |
| 5347 | fun! s:NetrwMarkFileSource(islocal) |
| 5348 | " call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")") |
| 5349 | let curbufnr= bufnr("%") |
| 5350 | if exists("s:netrwmarkfilelist_{curbufnr}") |
| 5351 | let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")} |
| 5352 | let curdir = b:netrw_curdir |
| 5353 | call s:NetrwUnmarkList(curbufnr,curdir) |
| 5354 | for fname in netrwmarkfilelist |
| 5355 | if a:islocal |
| 5356 | if g:netrw_keepdir |
| 5357 | let fname= s:ComposePath(curdir,fname) |
| 5358 | endif |
| 5359 | else |
| 5360 | let fname= curdir.fname |
| 5361 | endif |
| 5362 | " the autocmds will handle sourcing both local and remote files |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 5363 | " call Decho("exe so ".fnameescape(fname)) |
| 5364 | exe "so ".fnameescape(fname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5365 | endfor |
| 5366 | 2match none |
| 5367 | endif |
| 5368 | " call Dret("s:NetrwMarkFileSource") |
| 5369 | endfun |
| 5370 | |
| 5371 | " --------------------------------------------------------------------- |
| 5372 | " s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2 |
| 5373 | " Uses the global markfilelist |
| 5374 | fun! s:NetrwMarkFileTag(islocal) |
| 5375 | " call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")") |
| 5376 | let svpos = netrw#NetrwSavePosn() |
| 5377 | let curdir = b:netrw_curdir |
| 5378 | let curbufnr = bufnr("%") |
| 5379 | |
| 5380 | if exists("s:netrwmarkfilelist") |
| 5381 | " call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">") |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 5382 | let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "shellescape(v:val,".!a:islocal.")")) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5383 | call s:NetrwUnmarkAll() |
| 5384 | |
| 5385 | if a:islocal |
| 5386 | if executable(g:netrw_ctags) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5387 | " call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")") |
| 5388 | call system(g:netrw_ctags." ".netrwmarkfilelist) |
| 5389 | else |
| 5390 | call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51) |
| 5391 | endif |
| 5392 | else |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 5393 | let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5394 | call netrw#NetrwObtain(a:islocal,"tags") |
| 5395 | let curdir= b:netrw_curdir |
| 5396 | 1split |
| 5397 | e tags |
| 5398 | let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','') |
| 5399 | " call Decho("curdir<".curdir."> path<".path.">") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5400 | exe 'keepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e' |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 5401 | call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5402 | wq! |
| 5403 | endif |
| 5404 | 2match none |
| 5405 | call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) |
| 5406 | call netrw#NetrwRestorePosn(svpos) |
| 5407 | endif |
| 5408 | |
| 5409 | " call Dret("s:NetrwMarkFileTag") |
| 5410 | endfun |
| 5411 | |
| 5412 | " --------------------------------------------------------------------- |
| 5413 | " s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2 |
| 5414 | " Sets up two variables, |
| 5415 | " s:netrwmftgt : holds the target directory |
| 5416 | " s:netrwmftgt_islocal : 0=target directory is remote |
| 5417 | " 1=target directory is local |
| 5418 | fun! s:NetrwMarkFileTgt(islocal) |
| 5419 | " call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")") |
| 5420 | let svpos = netrw#NetrwSavePosn() |
| 5421 | let curdir = b:netrw_curdir |
| 5422 | let hadtgt = exists("s:netrwmftgt") |
| 5423 | if !exists("w:netrw_bannercnt") |
| 5424 | let w:netrw_bannercnt= b:netrw_bannercnt |
| 5425 | endif |
| 5426 | |
| 5427 | " set up target |
| 5428 | if line(".") < w:netrw_bannercnt |
| 5429 | " if cursor in banner region, use b:netrw_curdir for the target |
| 5430 | let s:netrwmftgt= b:netrw_curdir |
| 5431 | " call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">") |
| 5432 | |
| 5433 | else |
| 5434 | " get word under cursor. |
| 5435 | " * If directory, use it for the target. |
| 5436 | " * If file, use b:netrw_curdir for the target |
| 5437 | let curword= s:NetrwGetWord() |
| 5438 | let tgtdir = s:ComposePath(curdir,curword) |
| 5439 | if a:islocal && isdirectory(tgtdir) |
| 5440 | let s:netrwmftgt = tgtdir |
| 5441 | " call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">") |
| 5442 | elseif !a:islocal && tgtdir =~ '/$' |
| 5443 | let s:netrwmftgt = tgtdir |
| 5444 | " call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">") |
| 5445 | else |
| 5446 | let s:netrwmftgt = curdir |
| 5447 | " call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">") |
| 5448 | endif |
| 5449 | endif |
| 5450 | if a:islocal |
| 5451 | " simplify the target (eg. /abc/def/../ghi -> /abc/ghi) |
| 5452 | let s:netrwmftgt= simplify(s:netrwmftgt) |
| 5453 | " call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">") |
| 5454 | endif |
| 5455 | if g:netrw_cygwin |
| 5456 | let s:netrwmftgt= substitute(system("cygpath ".shellescape(s:netrwmftgt)),'\n$','','') |
| 5457 | let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','') |
| 5458 | endif |
| 5459 | let s:netrwmftgt_islocal= a:islocal |
| 5460 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 5461 | if g:netrw_fastbrowse <= 1 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5462 | call s:LocalBrowseShellCmdRefresh() |
| 5463 | endif |
| 5464 | call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) |
| 5465 | call netrw#NetrwRestorePosn(svpos) |
| 5466 | if !hadtgt |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5467 | sil! keepj norm! j |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5468 | endif |
| 5469 | |
| 5470 | " call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">") |
| 5471 | endfun |
| 5472 | |
| 5473 | " --------------------------------------------------------------------- |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 5474 | " s:NetrwOpenFile: query user for a filename and open it {{{2 |
| 5475 | fun! s:NetrwOpenFile(islocal) |
| 5476 | " call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")") |
| 5477 | call inputsave() |
| 5478 | let fname= input("Enter filename: ") |
| 5479 | call inputrestore() |
| 5480 | if fname !~ '[/\\]' |
| 5481 | if exists("b:netrw_curdir") |
| 5482 | if exists("g:netrw_quiet") |
| 5483 | let netrw_quiet_keep = g:netrw_quiet |
| 5484 | endif |
| 5485 | let g:netrw_quiet = 1 |
| 5486 | if b:netrw_curdir =~ '/$' |
| 5487 | exe "e ".fnameescape(b:netrw_curdir.fname) |
| 5488 | else |
| 5489 | exe "e ".fnameescape(b:netrw_curdir."/".fname) |
| 5490 | endif |
| 5491 | if exists("netrw_quiet_keep") |
| 5492 | let g:netrw_quiet= netrw_quiet_keep |
| 5493 | else |
| 5494 | unlet g:netrw_quiet |
| 5495 | endif |
| 5496 | endif |
| 5497 | else |
| 5498 | exe "e ".fnameescape(fname) |
| 5499 | endif |
| 5500 | " call Dret("s:NetrwOpenFile") |
| 5501 | endfun |
| 5502 | |
| 5503 | " --------------------------------------------------------------------- |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5504 | " s:NetrwUnmarkList: delete local marked file lists and remove their contents from the global marked-file list {{{2 |
| 5505 | fun! s:NetrwUnmarkList(curbufnr,curdir) |
| 5506 | " call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)") |
| 5507 | |
| 5508 | " remove all files in local marked-file list from global list |
| 5509 | if exists("s:netrwmarkfilelist_{a:curbufnr}") |
| 5510 | for mfile in s:netrwmarkfilelist_{a:curbufnr} |
| 5511 | let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile |
| 5512 | let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile |
| 5513 | call remove(s:netrwmarkfilelist,idx) " remove from global list |
| 5514 | endfor |
| 5515 | if s:netrwmarkfilelist == [] |
| 5516 | unlet s:netrwmarkfilelist |
| 5517 | endif |
| 5518 | |
| 5519 | " getting rid of the local marked-file lists is easy |
| 5520 | unlet s:netrwmarkfilelist_{a:curbufnr} |
| 5521 | endif |
| 5522 | if exists("s:netrwmarkfilemtch_{a:curbufnr}") |
| 5523 | unlet s:netrwmarkfilemtch_{a:curbufnr} |
| 5524 | endif |
| 5525 | 2match none |
| 5526 | " call Dret("s:NetrwUnmarkList") |
| 5527 | endfun |
| 5528 | |
| 5529 | " --------------------------------------------------------------------- |
| 5530 | " s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2 |
| 5531 | fun! s:NetrwUnmarkAll() |
| 5532 | " call Dfunc("s:NetrwUnmarkAll()") |
| 5533 | if exists("s:netrwmarkfilelist") |
| 5534 | unlet s:netrwmarkfilelist |
| 5535 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5536 | sil call s:NetrwUnmarkAll2() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5537 | 2match none |
| 5538 | " call Dret("s:NetrwUnmarkAll") |
| 5539 | endfun |
| 5540 | |
| 5541 | " --------------------------------------------------------------------- |
| 5542 | " s:NetrwUnmarkAll2: {{{2 |
| 5543 | fun! s:NetrwUnmarkAll2() |
| 5544 | " call Dfunc("s:NetrwUnmarkAll2()") |
| 5545 | redir => netrwmarkfilelist_let |
| 5546 | let |
| 5547 | redir END |
| 5548 | let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list |
| 5549 | call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_ |
| 5550 | call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to |
| 5551 | for flist in netrwmarkfilelist_list |
| 5552 | let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','') |
| 5553 | unlet s:netrwmarkfilelist_{curbufnr} |
| 5554 | unlet s:netrwmarkfilemtch_{curbufnr} |
| 5555 | endfor |
| 5556 | " call Dret("s:NetrwUnmarkAll2") |
| 5557 | endfun |
| 5558 | |
| 5559 | " --------------------------------------------------------------------- |
| 5560 | " s:NetrwUnMarkFile: {{{2 |
| 5561 | fun! s:NetrwUnMarkFile(islocal) |
| 5562 | " call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")") |
| 5563 | let svpos = netrw#NetrwSavePosn() |
| 5564 | let curbufnr = bufnr("%") |
| 5565 | |
| 5566 | " unmark marked file list (although I expect s:NetrwUpload() |
| 5567 | " to do it, I'm just making sure) |
| 5568 | if exists("s:netrwmarkfilelist_{bufnr('%')}") |
| 5569 | " call Decho("unlet'ing: s:netrwmarkfile[list|mtch]_".bufnr("%")) |
| 5570 | unlet s:netrwmarkfilelist |
| 5571 | unlet s:netrwmarkfilelist_{curbufnr} |
| 5572 | unlet s:netrwmarkfilemtch_{curbufnr} |
| 5573 | 2match none |
| 5574 | endif |
| 5575 | |
| 5576 | " call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) |
| 5577 | call netrw#NetrwRestorePosn(svpos) |
| 5578 | " call Dret("s:NetrwUnMarkFile") |
| 5579 | endfun |
| 5580 | |
| 5581 | " --------------------------------------------------------------------- |
| 5582 | " s:NetrwMenu: generates the menu for gvim and netrw {{{2 |
| 5583 | fun! s:NetrwMenu(domenu) |
| 5584 | |
| 5585 | if !exists("g:NetrwMenuPriority") |
| 5586 | let g:NetrwMenuPriority= 80 |
| 5587 | endif |
| 5588 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5589 | if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5590 | " call Dfunc("NetrwMenu(domenu=".a:domenu.")") |
| 5591 | |
| 5592 | if !exists("s:netrw_menu_enabled") && a:domenu |
| 5593 | " call Decho("initialize menu") |
| 5594 | let s:netrw_menu_enabled= 1 |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5595 | exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>' |
| 5596 | exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :' |
| 5597 | exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -' |
| 5598 | exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x' |
| 5599 | exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb' |
| 5600 | exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u' |
| 5601 | exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U' |
| 5602 | exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb' |
| 5603 | exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'" |
| 5604 | exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S' |
| 5605 | exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh" |
| 5606 | exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>" |
| 5607 | exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>" |
| 5608 | exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D' |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 5609 | exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %' |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5610 | exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>" |
| 5611 | exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p' |
| 5612 | exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P' |
| 5613 | exe 'sil! menu '.g:NetrwMenuPriority.'.11.4 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Window<tab>o o' |
| 5614 | exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v' |
| 5615 | exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore ' |
| 5616 | exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */' |
| 5617 | exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/' |
| 5618 | exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//' |
| 5619 | exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//' |
| 5620 | exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>' |
| 5621 | exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>' |
| 5622 | exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d' |
| 5623 | exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf' |
| 5624 | exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr' |
| 5625 | exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a' |
| 5626 | exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc' |
| 5627 | exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D' |
| 5628 | exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md' |
| 5629 | exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me' |
| 5630 | exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx' |
| 5631 | exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm' |
| 5632 | exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O' |
| 5633 | exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp' |
| 5634 | exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R' |
| 5635 | exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt' |
| 5636 | exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT' |
| 5637 | exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz' |
| 5638 | exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O' |
| 5639 | exe 'sil! menu '.g:NetrwMenuPriority.'.16.1 '.g:NetrwTopLvlMenu.'Style.Listing\ Style\ (thin-long-wide-tree)<tab>i i' |
| 5640 | exe 'sil! menu '.g:NetrwMenuPriority.'.16.2 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show<tab>a a' |
| 5641 | exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r" |
| 5642 | exe 'sil! menu '.g:NetrwMenuPriority.'.16.4 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method\ (name-time-size)<tab>s s' |
| 5643 | exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R' |
| 5644 | exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c' |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 5645 | call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5646 | let s:netrw_menucnt= 28 |
| 5647 | |
| 5648 | elseif !a:domenu |
| 5649 | let s:netrwcnt = 0 |
| 5650 | let curwin = winnr() |
| 5651 | windo if getline(2) =~ "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif |
| 5652 | exe curwin."wincmd w" |
| 5653 | |
| 5654 | if s:netrwcnt <= 1 |
| 5655 | " call Decho("clear menus") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5656 | exe 'sil! unmenu '.g:NetrwTopLvlMenu |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5657 | " call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*') |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5658 | sil! unlet s:netrw_menu_enabled |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5659 | endif |
| 5660 | endif |
| 5661 | " call Dret("NetrwMenu") |
| 5662 | endif |
| 5663 | |
| 5664 | endfun |
| 5665 | |
| 5666 | " --------------------------------------------------------------------- |
| 5667 | " s:NetrwObtain: obtain file under cursor or from markfile list {{{2 |
| 5668 | " Used by the O maps (as <SID>NetrwObtain()) |
| 5669 | fun! s:NetrwObtain(islocal) |
| 5670 | " call Dfunc("NetrwObtain(islocal=".a:islocal.")") |
| 5671 | |
| 5672 | if exists("s:netrwmarkfilelist_{bufnr('%')}") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 5673 | let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\+://' |
| 5674 | call netrw#NetrwObtain(islocal,s:netrwmarkfilelist_{bufnr('%')}) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5675 | call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir) |
| 5676 | else |
| 5677 | call netrw#NetrwObtain(a:islocal,expand("<cWORD>")) |
| 5678 | endif |
| 5679 | |
| 5680 | " call Dret("NetrwObtain") |
| 5681 | endfun |
| 5682 | |
| 5683 | " --------------------------------------------------------------------- |
| 5684 | " netrw#NetrwObtain: {{{2 |
| 5685 | " netrw#NetrwObtain(islocal,fname[,tgtdirectory]) |
| 5686 | " islocal=0 obtain from remote source |
| 5687 | " =1 obtain from local source |
| 5688 | " fname : a filename or a list of filenames |
| 5689 | " tgtdir : optional place where files are to go (not present, uses getcwd()) |
| 5690 | fun! netrw#NetrwObtain(islocal,fname,...) |
| 5691 | " call Dfunc("netrw#NetrwObtain(islocal=".a:islocal." fname<".((type(a:fname) == 1)? a:fname : string(a:fname)).">) a:0=".a:0) |
| 5692 | " NetrwStatusLine support - for obtaining support |
| 5693 | |
| 5694 | if type(a:fname) == 1 |
| 5695 | let fnamelist= [ a:fname ] |
| 5696 | elseif type(a:fname) == 3 |
| 5697 | let fnamelist= a:fname |
| 5698 | else |
| 5699 | call netrw#ErrorMsg(s:ERROR,"attempting to use NetrwObtain on something not a filename or a list",62) |
| 5700 | " call Dret("netrw#NetrwObtain") |
| 5701 | return |
| 5702 | endif |
| 5703 | " call Decho("fnamelist<".string(fnamelist).">") |
| 5704 | if a:0 > 0 |
| 5705 | let tgtdir= a:1 |
| 5706 | else |
| 5707 | let tgtdir= getcwd() |
| 5708 | endif |
| 5709 | " call Decho("tgtdir<".tgtdir.">") |
| 5710 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 5711 | if exists("b:netrw_islocal") && b:netrw_islocal |
Bram Moolenaar | ed39e1d | 2008-08-09 17:55:22 +0000 | [diff] [blame] | 5712 | " obtain a file from local b:netrw_curdir to (local) tgtdir |
| 5713 | " call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5714 | if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir |
| 5715 | let topath= s:ComposePath(tgtdir,"") |
| 5716 | if (has("win32") || has("win95") || has("win64") || has("win16")) |
| 5717 | " transfer files one at time |
Bram Moolenaar | ed39e1d | 2008-08-09 17:55:22 +0000 | [diff] [blame] | 5718 | " call Decho("transfer files one at a time") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5719 | for fname in fnamelist |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 5720 | " call Decho("system(".g:netrw_localcopycmd." ".shellescape(fname)." ".shellescape(topath).")") |
| 5721 | call system(g:netrw_localcopycmd." ".shellescape(fname)." ".shellescape(topath)) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5722 | endfor |
| 5723 | else |
| 5724 | " transfer files with one command |
Bram Moolenaar | ed39e1d | 2008-08-09 17:55:22 +0000 | [diff] [blame] | 5725 | " call Decho("transfer files with one command") |
| 5726 | let filelist= join(map(deepcopy(fnamelist),"shellescape(v:val)")) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5727 | " call Decho("system(".g:netrw_localcopycmd." ".filelist." ".shellescape(topath).")") |
| 5728 | call system(g:netrw_localcopycmd." ".filelist." ".shellescape(topath)) |
| 5729 | endif |
| 5730 | elseif !exists("b:netrw_curdir") |
| 5731 | call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36) |
| 5732 | else |
| 5733 | call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37) |
| 5734 | endif |
| 5735 | |
| 5736 | else |
Bram Moolenaar | ed39e1d | 2008-08-09 17:55:22 +0000 | [diff] [blame] | 5737 | " obtain files from remote b:netrw_curdir to local tgtdir |
| 5738 | " call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5739 | if type(a:fname) == 1 |
| 5740 | call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname) |
| 5741 | endif |
| 5742 | call s:NetrwMethod(b:netrw_curdir) |
| 5743 | |
| 5744 | if b:netrw_method == 4 |
| 5745 | " obtain file using scp |
| 5746 | " call Decho("obtain via scp (method#4)") |
| 5747 | if exists("g:netrw_port") && g:netrw_port != "" |
| 5748 | let useport= " ".g:netrw_scpport." ".g:netrw_port |
| 5749 | else |
| 5750 | let useport= "" |
| 5751 | endif |
| 5752 | if b:netrw_fname =~ '/' |
| 5753 | let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','') |
| 5754 | else |
| 5755 | let path= "" |
| 5756 | endif |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 5757 | let filelist= join(map(deepcopy(fnamelist),'shellescape(g:netrw_machine.":".path.v:val,1)')) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 5758 | " call Decho("exe ".s:netrw_silentxfer."!".g:netrw_scp_cmd.shellescape(useport,1)." ".filelist." ".shellescape(tgtdir,1)) |
| 5759 | exe s:netrw_silentxfer."!".g:netrw_scp_cmd.shellescape(useport,1)." ".filelist." ".shellescape(tgtdir,1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5760 | |
| 5761 | elseif b:netrw_method == 2 |
| 5762 | " obtain file using ftp + .netrc |
| 5763 | " call Decho("obtain via ftp+.netrc (method #2)") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5764 | call s:SaveBufVars()|sil keepjumps new|call s:RestoreBufVars() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5765 | let tmpbufnr= bufnr("%") |
| 5766 | setlocal ff=unix |
| 5767 | if exists("g:netrw_ftpmode") && g:netrw_ftpmode != "" |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5768 | keepj put =g:netrw_ftpmode |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5769 | " call Decho("filter input: ".getline('$')) |
| 5770 | endif |
| 5771 | |
| 5772 | if exists("b:netrw_fname") && b:netrw_fname != "" |
| 5773 | call setline(line("$")+1,'cd "'.b:netrw_fname.'"') |
| 5774 | " call Decho("filter input: ".getline('$')) |
| 5775 | endif |
| 5776 | |
| 5777 | if exists("g:netrw_ftpextracmd") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5778 | keepj put =g:netrw_ftpextracmd |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5779 | " call Decho("filter input: ".getline('$')) |
| 5780 | endif |
| 5781 | for fname in fnamelist |
| 5782 | call setline(line("$")+1,'get "'.fname.'"') |
| 5783 | " call Decho("filter input: ".getline('$')) |
| 5784 | endfor |
| 5785 | if exists("g:netrw_port") && g:netrw_port != "" |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5786 | " call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)) |
| 5787 | exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5788 | else |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5789 | " call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)) |
| 5790 | exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5791 | endif |
| 5792 | " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) |
| 5793 | if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying ' |
| 5794 | let debugkeep= &debug |
| 5795 | setlocal debug=msg |
| 5796 | call netrw#ErrorMsg(s:ERROR,getline(1),4) |
| 5797 | let &debug= debugkeep |
| 5798 | endif |
| 5799 | |
| 5800 | elseif b:netrw_method == 3 |
| 5801 | " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc) |
| 5802 | " call Decho("obtain via ftp+mipf (method #3)") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5803 | call s:SaveBufVars()|sil keepjumps new|call s:RestoreBufVars() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5804 | let tmpbufnr= bufnr("%") |
| 5805 | setlocal ff=unix |
| 5806 | |
| 5807 | if exists("g:netrw_port") && g:netrw_port != "" |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5808 | keepj put ='open '.g:netrw_machine.' '.g:netrw_port |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5809 | " call Decho("filter input: ".getline('$')) |
| 5810 | else |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5811 | keepj put ='open '.g:netrw_machine |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5812 | " call Decho("filter input: ".getline('$')) |
| 5813 | endif |
| 5814 | |
| 5815 | if exists("g:netrw_ftp") && g:netrw_ftp == 1 |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5816 | keepj put =g:netrw_uid |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5817 | " call Decho("filter input: ".getline('$')) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5818 | keepj put ='\"'.s:netrw_passwd.'\"' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5819 | " call Decho("filter input: ".getline('$')) |
| 5820 | else |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5821 | keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5822 | " call Decho("filter input: ".getline('$')) |
| 5823 | endif |
| 5824 | |
| 5825 | if exists("g:netrw_ftpmode") && g:netrw_ftpmode != "" |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5826 | keepj put =g:netrw_ftpmode |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5827 | " call Decho("filter input: ".getline('$')) |
| 5828 | endif |
| 5829 | |
| 5830 | if exists("b:netrw_fname") && b:netrw_fname != "" |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5831 | keepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"') |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5832 | " call Decho("filter input: ".getline('$')) |
| 5833 | endif |
| 5834 | |
| 5835 | if exists("g:netrw_ftpextracmd") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5836 | keepj put =g:netrw_ftpextracmd |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5837 | " call Decho("filter input: ".getline('$')) |
| 5838 | endif |
| 5839 | |
| 5840 | if exists("g:netrw_ftpextracmd") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5841 | keepj put =g:netrw_ftpextracmd |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5842 | " call Decho("filter input: ".getline('$')) |
| 5843 | endif |
| 5844 | for fname in fnamelist |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5845 | keepj call setline(line("$")+1,'get "'.fname.'"') |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5846 | endfor |
| 5847 | " call Decho("filter input: ".getline('$')) |
| 5848 | |
| 5849 | " perform ftp: |
| 5850 | " -i : turns off interactive prompting from ftp |
| 5851 | " -n unix : DON'T use <.netrc>, even though it exists |
| 5852 | " -n win32: quit being obnoxious about password |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 5853 | keepj norm! 1Gdd |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5854 | " call Decho("executing: %!".s:netrw_ftp_cmd." -i -n") |
| 5855 | exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i -n" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5856 | " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) |
| 5857 | if getline(1) !~ "^$" |
| 5858 | " call Decho("error<".getline(1).">") |
| 5859 | if !exists("g:netrw_quiet") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5860 | keepj call netrw#ErrorMsg(s:ERROR,getline(1),5) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5861 | endif |
| 5862 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 5863 | elseif !exists("b:netrw_method") || b:netrw_method < 0 |
| 5864 | " call Dfunc("netrw#NetrwObtain : unsupported method") |
| 5865 | return |
| 5866 | endif |
| 5867 | |
| 5868 | " restore status line |
| 5869 | if type(a:fname) == 1 && exists("s:netrw_users_stl") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5870 | keepj call s:SetupNetrwStatusLine(s:netrw_users_stl) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5871 | endif |
| 5872 | |
| 5873 | endif |
| 5874 | |
| 5875 | " cleanup |
| 5876 | if exists("tmpbufnr") |
| 5877 | if bufnr("%") != tmpbufnr |
| 5878 | exe tmpbufnr."bw!" |
| 5879 | else |
| 5880 | q! |
| 5881 | endif |
| 5882 | endif |
| 5883 | |
| 5884 | " call Dret("netrw#NetrwObtain") |
| 5885 | endfun |
| 5886 | |
| 5887 | " --------------------------------------------------------------------- |
| 5888 | " s:NetrwPrevWinOpen: open file/directory in previous window. {{{2 |
| 5889 | " If there's only one window, then the window will first be split. |
| 5890 | " Returns: |
| 5891 | " choice = 0 : didn't have to choose |
| 5892 | " choice = 1 : saved modified file in window first |
| 5893 | " choice = 2 : didn't save modified file, opened window |
| 5894 | " choice = 3 : cancel open |
| 5895 | fun! s:NetrwPrevWinOpen(islocal) |
| 5896 | " call Dfunc("NetrwPrevWinOpen(islocal=".a:islocal.")") |
| 5897 | |
| 5898 | " grab a copy of the b:netrw_curdir to pass it along to newly split windows |
| 5899 | let curdir = b:netrw_curdir |
| 5900 | |
| 5901 | " get last window number and the word currently under the cursor |
| 5902 | let lastwinnr = winnr("$") |
| 5903 | let curword = s:NetrwGetWord() |
| 5904 | let choice = 0 |
| 5905 | " call Decho("lastwinnr=".lastwinnr." curword<".curword.">") |
| 5906 | |
| 5907 | let didsplit = 0 |
| 5908 | if lastwinnr == 1 |
| 5909 | " if only one window, open a new one first |
| 5910 | " call Decho("only one window, so open a new one (g:netrw_alto=".g:netrw_alto.")") |
| 5911 | if g:netrw_preview |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 5912 | let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize |
| 5913 | " call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s") |
| 5914 | exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5915 | else |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 5916 | let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize |
| 5917 | " call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s") |
| 5918 | exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5919 | endif |
| 5920 | let didsplit = 1 |
| 5921 | |
| 5922 | else |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5923 | keepj call s:SaveBufVars() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5924 | " call Decho("wincmd p") |
| 5925 | wincmd p |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5926 | keepj call s:RestoreBufVars() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5927 | " if the previous window's buffer has been changed (is modified), |
| 5928 | " and it doesn't appear in any other extant window, then ask the |
| 5929 | " user if s/he wants to abandon modifications therein. |
| 5930 | let bnr = winbufnr(0) |
| 5931 | let bnrcnt = 0 |
| 5932 | if &mod |
| 5933 | " call Decho("detected: prev window's buffer has been modified: bnr=".bnr." winnr#".winnr()) |
| 5934 | let eikeep= &ei |
| 5935 | set ei=all |
| 5936 | windo if winbufnr(0) == bnr | let bnrcnt=bnrcnt+1 | endif |
| 5937 | exe bnr."wincmd p" |
| 5938 | let &ei= eikeep |
| 5939 | " call Decho("bnr=".bnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr#".winnr()) |
| 5940 | if bnrcnt == 1 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 5941 | let bufname = bufname(winbufnr(winnr())) |
| 5942 | let choice = confirm("Save modified file<".bufname.">?","&Yes\n&No\n&Cancel") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5943 | " call Decho("bufname<".bufname."> choice=".choice." winnr#".winnr()) |
| 5944 | |
| 5945 | if choice == 1 |
| 5946 | " Yes -- write file & then browse |
| 5947 | let v:errmsg= "" |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5948 | sil w |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5949 | if v:errmsg != "" |
| 5950 | call netrw#ErrorMsg(s:ERROR,"unable to write <".bufname.">!",30) |
| 5951 | if didsplit |
| 5952 | q |
| 5953 | else |
| 5954 | wincmd p |
| 5955 | endif |
| 5956 | " call Dret("NetrwPrevWinOpen ".choice." : unable to write <".bufname.">") |
| 5957 | return choice |
| 5958 | endif |
| 5959 | |
| 5960 | elseif choice == 2 |
| 5961 | " No -- don't worry about changed file, just browse anyway |
| 5962 | setlocal nomod |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 5963 | keepj call netrw#ErrorMsg(s:WARNING,bufname." changes to ".bufname." abandoned",31) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 5964 | wincmd p |
| 5965 | |
| 5966 | else |
| 5967 | " Cancel -- don't do this |
| 5968 | if didsplit |
| 5969 | q |
| 5970 | else |
| 5971 | wincmd p |
| 5972 | endif |
| 5973 | " call Dret("NetrwPrevWinOpen ".choice." : cancelled") |
| 5974 | return choice |
| 5975 | endif |
| 5976 | endif |
| 5977 | endif |
| 5978 | endif |
| 5979 | |
| 5980 | " restore b:netrw_curdir (window split/enew may have lost it) |
| 5981 | let b:netrw_curdir= curdir |
| 5982 | if a:islocal < 2 |
| 5983 | if a:islocal |
| 5984 | call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword)) |
| 5985 | else |
| 5986 | call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword)) |
| 5987 | endif |
| 5988 | endif |
| 5989 | " call Dret("NetrwPrevWinOpen ".choice) |
| 5990 | return choice |
| 5991 | endfun |
| 5992 | |
| 5993 | " --------------------------------------------------------------------- |
| 5994 | " s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2 |
| 5995 | " Always assumed to be local -> remote |
| 5996 | " call s:NetrwUpload(filename, target) |
| 5997 | " call s:NetrwUpload(filename, target, fromdirectory) |
| 5998 | fun! s:NetrwUpload(fname,tgt,...) |
| 5999 | " call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0) |
| 6000 | |
| 6001 | if a:tgt =~ '^\a\+://' |
| 6002 | let tgtdir= substitute(a:tgt,'^\a\+://[^/]\+/\(.\{-}\)$','\1','') |
| 6003 | else |
| 6004 | let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','') |
| 6005 | endif |
| 6006 | " call Decho("tgtdir<".tgtdir.">") |
| 6007 | |
| 6008 | if a:0 > 0 |
| 6009 | let fromdir= a:1 |
| 6010 | else |
| 6011 | let fromdir= getcwd() |
| 6012 | endif |
| 6013 | " call Decho("fromdir<".fromdir.">") |
| 6014 | |
| 6015 | if type(a:fname) == 1 |
| 6016 | " handle uploading a single file using NetWrite |
| 6017 | " call Decho("handle uploading a single file via NetWrite") |
| 6018 | 1split |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 6019 | " call Decho("exe e ".fnameescape(a:fname)) |
| 6020 | exe "e ".fnameescape(a:fname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6021 | " call Decho("now locally editing<".expand("%").">, has ".line("$")." lines") |
| 6022 | if a:tgt =~ '/$' |
| 6023 | let wfname= substitute(a:fname,'^.*/','','') |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 6024 | " call Decho("exe w! ".fnameescape(wfname)) |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 6025 | exe "w! ".fnameescape(a:tgt.wfname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6026 | else |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 6027 | " call Decho("writing local->remote: exe w ".fnameescape(a:tgt)) |
| 6028 | exe "w ".fnameescape(a:tgt) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6029 | " call Decho("done writing local->remote") |
| 6030 | endif |
| 6031 | q! |
| 6032 | |
| 6033 | elseif type(a:fname) == 3 |
| 6034 | " handle uploading a list of files via scp |
| 6035 | " call Decho("handle uploading a list of files via scp") |
| 6036 | let curdir= getcwd() |
| 6037 | if a:tgt =~ '^scp:' |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6038 | exe "keepjumps sil lcd ".fnameescape(fromdir) |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 6039 | let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')}) |
| 6040 | let args = join(map(filelist,"shellescape(v:val, 1)")) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6041 | if exists("g:netrw_port") && g:netrw_port != "" |
| 6042 | let useport= " ".g:netrw_scpport." ".g:netrw_port |
| 6043 | else |
| 6044 | let useport= "" |
| 6045 | endif |
| 6046 | let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','') |
| 6047 | let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','') |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 6048 | " call Decho("exe ".s:netrw_silentxfer."!".g:netrw_scp_cmd.shellescape(useport,1)." ".args." ".shellescape(machine.":".tgt,1)) |
| 6049 | exe s:netrw_silentxfer."!".g:netrw_scp_cmd.shellescape(useport,1)." ".args." ".shellescape(machine.":".tgt,1) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6050 | exe "keepjumps sil lcd ".fnameescape(curdir) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6051 | |
| 6052 | elseif a:tgt =~ '^ftp:' |
| 6053 | call s:NetrwMethod(a:tgt) |
| 6054 | |
| 6055 | if b:netrw_method == 2 |
| 6056 | " handle uploading a list of files via ftp+.netrc |
| 6057 | let netrw_fname = b:netrw_fname |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6058 | sil keepj new |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6059 | " call Decho("filter input window#".winnr()) |
| 6060 | |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6061 | keepj put =g:netrw_ftpmode |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6062 | " call Decho("filter input: ".getline('$')) |
| 6063 | |
| 6064 | if exists("g:netrw_ftpextracmd") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6065 | keepj put =g:netrw_ftpextracmd |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6066 | " call Decho("filter input: ".getline('$')) |
| 6067 | endif |
| 6068 | |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6069 | keepj call setline(line("$")+1,'lcd "'.fromdir.'"') |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6070 | " call Decho("filter input: ".getline('$')) |
| 6071 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6072 | if tgtdir == "" |
| 6073 | let tgtdir= '/' |
| 6074 | endif |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6075 | keepj call setline(line("$")+1,'cd "'.tgtdir.'"') |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6076 | " call Decho("filter input: ".getline('$')) |
| 6077 | |
| 6078 | for fname in a:fname |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6079 | keepj call setline(line("$")+1,'put "'.fname.'"') |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6080 | " call Decho("filter input: ".getline('$')) |
| 6081 | endfor |
| 6082 | |
| 6083 | if exists("g:netrw_port") && g:netrw_port != "" |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6084 | " call Decho("executing: ".s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)) |
| 6085 | exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6086 | else |
| 6087 | " call Decho("filter input window#".winnr()) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6088 | " call Decho("executing: ".s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)) |
| 6089 | exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6090 | endif |
| 6091 | " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6092 | sil keepj g/Local directory now/d |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6093 | call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6094 | if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying ' |
| 6095 | call netrw#ErrorMsg(s:ERROR,getline(1),14) |
| 6096 | else |
| 6097 | bw!|q |
| 6098 | endif |
| 6099 | |
| 6100 | elseif b:netrw_method == 3 |
| 6101 | " upload with ftp + machine, id, passwd, and fname (ie. no .netrc) |
| 6102 | let netrw_fname= b:netrw_fname |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6103 | keepj call s:SaveBufVars()|sil keepj new|keepj call s:RestoreBufVars() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6104 | let tmpbufnr= bufnr("%") |
| 6105 | setlocal ff=unix |
| 6106 | |
| 6107 | if exists("g:netrw_port") && g:netrw_port != "" |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6108 | keepj put ='open '.g:netrw_machine.' '.g:netrw_port |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6109 | " call Decho("filter input: ".getline('$')) |
| 6110 | else |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6111 | keepj put ='open '.g:netrw_machine |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6112 | " call Decho("filter input: ".getline('$')) |
| 6113 | endif |
| 6114 | |
| 6115 | if exists("g:netrw_ftp") && g:netrw_ftp == 1 |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6116 | keepj put =g:netrw_uid |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6117 | " call Decho("filter input: ".getline('$')) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6118 | keepj call setline(line("$")+1,'"'.s:netrw_passwd.'"') |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6119 | " call Decho("filter input: ".getline('$')) |
| 6120 | else |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6121 | keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6122 | " call Decho("filter input: ".getline('$')) |
| 6123 | endif |
| 6124 | |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6125 | keepj call setline(line("$")+1,'lcd "'.fromdir.'"') |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6126 | " call Decho("filter input: ".getline('$')) |
| 6127 | |
| 6128 | if exists("b:netrw_fname") && b:netrw_fname != "" |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6129 | keepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"') |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6130 | " call Decho("filter input: ".getline('$')) |
| 6131 | endif |
| 6132 | |
| 6133 | if exists("g:netrw_ftpextracmd") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6134 | keepj put =g:netrw_ftpextracmd |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6135 | " call Decho("filter input: ".getline('$')) |
| 6136 | endif |
| 6137 | |
| 6138 | for fname in a:fname |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6139 | keepj call setline(line("$")+1,'put "'.fname.'"') |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6140 | " call Decho("filter input: ".getline('$')) |
| 6141 | endfor |
| 6142 | |
| 6143 | " perform ftp: |
| 6144 | " -i : turns off interactive prompting from ftp |
| 6145 | " -n unix : DON'T use <.netrc>, even though it exists |
| 6146 | " -n win32: quit being obnoxious about password |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6147 | keepj norm! 1Gdd |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6148 | " call Decho("executing: ".s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i -n") |
| 6149 | exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i -n" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6150 | " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6151 | sil keepj g/Local directory now/d |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6152 | call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6153 | if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying ' |
| 6154 | let debugkeep= &debug |
| 6155 | setlocal debug=msg |
| 6156 | call netrw#ErrorMsg(s:ERROR,getline(1),15) |
| 6157 | let &debug = debugkeep |
| 6158 | let mod = 1 |
| 6159 | else |
| 6160 | bw!|q |
| 6161 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6162 | elseif !exists("b:netrw_method") || b:netrw_method < 0 |
| 6163 | " call Dfunc("netrw#NetrwUpload : unsupported method") |
| 6164 | return |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6165 | endif |
| 6166 | else |
| 6167 | call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63) |
| 6168 | endif |
| 6169 | endif |
| 6170 | |
| 6171 | " call Dret("s:NetrwUpload") |
| 6172 | endfun |
| 6173 | |
| 6174 | " --------------------------------------------------------------------- |
| 6175 | " s:NetrwPreview: {{{2 |
| 6176 | fun! s:NetrwPreview(path) range |
| 6177 | " call Dfunc("NetrwPreview(path<".a:path.">)") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6178 | keepj call s:NetrwOptionSave("s:") |
| 6179 | keepj call s:NetrwSafeOptions() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6180 | if has("quickfix") |
| 6181 | if !isdirectory(a:path) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6182 | if g:netrw_preview && !g:netrw_alto |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 6183 | let pvhkeep = &pvh |
| 6184 | let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize |
| 6185 | let &pvh = winwidth(0) - winsz |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6186 | endif |
| 6187 | exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path) |
| 6188 | if exists("pvhkeep") |
| 6189 | let &pvh= pvhkeep |
| 6190 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6191 | elseif !exists("g:netrw_quiet") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6192 | keepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6193 | endif |
| 6194 | elseif !exists("g:netrw_quiet") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6195 | keepj call netrw#ErrorMsg(s:WARNING,"sorry, to preview your vim needs the quickfix feature compiled in",39) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6196 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6197 | keepj call s:NetrwOptionRestore("s:") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6198 | " call Dret("NetrwPreview") |
| 6199 | endfun |
| 6200 | |
| 6201 | " --------------------------------------------------------------------- |
| 6202 | " s:NetrwRefresh: {{{2 |
| 6203 | fun! s:NetrwRefresh(islocal,dirname) |
| 6204 | " call Dfunc("NetrwRefresh(islocal<".a:islocal.">,dirname=".a:dirname.") hide=".g:netrw_hide." sortdir=".g:netrw_sort_direction) |
| 6205 | " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first. |
| 6206 | " NetrwBrowseChgDir() may clear the display; hence a NetrwSavePosn() may not work if its placed here. |
| 6207 | " Also, NetrwBrowseChgDir() now does a NetrwSavePosn() itself. |
| 6208 | setlocal ma noro |
| 6209 | " call Decho("setlocal ma noro") |
| 6210 | " call Decho("clear buffer<".expand("%")."> with :%d") |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6211 | sil! keepj %d |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6212 | if a:islocal |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6213 | keepj call netrw#LocalBrowseCheck(a:dirname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6214 | else |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6215 | keepj call s:NetrwBrowse(a:islocal,a:dirname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6216 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6217 | keepj call netrw#NetrwRestorePosn() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6218 | |
| 6219 | " restore file marks |
| 6220 | if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != "" |
| 6221 | " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/") |
| 6222 | exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/" |
| 6223 | else |
| 6224 | " call Decho("2match none") |
| 6225 | 2match none |
| 6226 | endif |
| 6227 | |
| 6228 | " redraw! |
| 6229 | " call Dret("NetrwRefresh") |
| 6230 | endfun |
| 6231 | |
| 6232 | " --------------------------------------------------------------------- |
| 6233 | " s:NetrwRefreshDir: refreshes a directory by name {{{2 |
| 6234 | " Called by NetrwMarkFileCopy() |
| 6235 | " Interfaces to s:NetrwRefresh() and s:LocalBrowseShellCmdRefresh() |
| 6236 | fun! s:NetrwRefreshDir(islocal,dirname) |
| 6237 | " call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) fastbrowse=".g:netrw_fastbrowse) |
| 6238 | if g:netrw_fastbrowse == 0 |
| 6239 | " slowest mode (keep buffers refreshed, local or remote) |
| 6240 | " call Decho("slowest mode: keep buffers refreshed, local or remote") |
| 6241 | let tgtwin= bufwinnr(a:dirname) |
| 6242 | " call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin) |
| 6243 | |
| 6244 | if tgtwin > 0 |
| 6245 | " tgtwin is being displayed, so refresh it |
| 6246 | let curwin= winnr() |
| 6247 | " call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")") |
| 6248 | exe tgtwin."wincmd w" |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6249 | keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6250 | exe curwin."wincmd w" |
| 6251 | |
| 6252 | elseif bufnr(a:dirname) > 0 |
| 6253 | let bn= bufnr(a:dirname) |
| 6254 | " call Decho("bd bufnr(".a:dirname.")=".bn) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6255 | exe "sil bd ".bn |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6256 | endif |
| 6257 | |
| 6258 | elseif g:netrw_fastbrowse <= 1 |
| 6259 | " call Decho("medium-speed mode: refresh local buffers only") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6260 | keepj call s:LocalBrowseShellCmdRefresh() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6261 | endif |
| 6262 | " call Dret("s:NetrwRefreshDir") |
| 6263 | endfun |
| 6264 | |
| 6265 | " --------------------------------------------------------------------- |
| 6266 | " s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2 |
| 6267 | " What this function does is to compute a priority for the patterns |
| 6268 | " in the g:netrw_sort_sequence. It applies a substitute to any |
| 6269 | " "files" that satisfy each pattern, putting the priority / in |
| 6270 | " front. An "*" pattern handles the default priority. |
| 6271 | fun! s:NetrwSetSort() |
| 6272 | " call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt) |
| 6273 | if w:netrw_liststyle == s:LONGLIST |
| 6274 | let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge') |
| 6275 | else |
| 6276 | let seqlist = g:netrw_sort_sequence |
| 6277 | endif |
| 6278 | " sanity check -- insure that * appears somewhere |
| 6279 | if seqlist == "" |
| 6280 | let seqlist= '*' |
| 6281 | elseif seqlist !~ '\*' |
| 6282 | let seqlist= seqlist.',*' |
| 6283 | endif |
| 6284 | let priority = 1 |
| 6285 | while seqlist != "" |
| 6286 | if seqlist =~ ',' |
| 6287 | let seq = substitute(seqlist,',.*$','','e') |
| 6288 | let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e') |
| 6289 | else |
| 6290 | let seq = seqlist |
| 6291 | let seqlist = "" |
| 6292 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6293 | if priority < 10 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6294 | let spriority= "00".priority.g:netrw_sepchr |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6295 | elseif priority < 100 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6296 | let spriority= "0".priority.g:netrw_sepchr |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6297 | else |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6298 | let spriority= priority.g:netrw_sepchr |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6299 | endif |
| 6300 | " call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">") |
| 6301 | |
| 6302 | " sanity check |
| 6303 | if w:netrw_bannercnt > line("$") |
| 6304 | " apparently no files were left after a Hiding pattern was used |
| 6305 | " call Dret("SetSort : no files left after hiding") |
| 6306 | return |
| 6307 | endif |
| 6308 | if seq == '*' |
| 6309 | let starpriority= spriority |
| 6310 | else |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6311 | exe 'sil keepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/' |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6312 | call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6313 | " sometimes multiple sorting patterns will match the same file or directory. |
| 6314 | " The following substitute is intended to remove the excess matches. |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6315 | 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 Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6316 | keepj call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6317 | endif |
| 6318 | let priority = priority + 1 |
| 6319 | endwhile |
| 6320 | if exists("starpriority") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6321 | exe 'sil keepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/' |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6322 | keepj call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6323 | endif |
| 6324 | |
| 6325 | " Following line associated with priority -- items that satisfy a priority |
| 6326 | " pattern get prefixed by ###/ which permits easy sorting by priority. |
| 6327 | " Sometimes files can satisfy multiple priority patterns -- only the latest |
| 6328 | " priority pattern needs to be retained. So, at this point, these excess |
| 6329 | " priority prefixes need to be removed, but not directories that happen to |
| 6330 | " be just digits themselves. |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6331 | exe 'sil keepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e' |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6332 | keepj call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6333 | |
| 6334 | " call Dret("SetSort") |
| 6335 | endfun |
| 6336 | |
| 6337 | " ===================================================================== |
| 6338 | " s:NetrwSortStyle: change sorting style (name - time - size) and refresh display {{{2 |
| 6339 | fun! s:NetrwSortStyle(islocal) |
| 6340 | " call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6341 | keepj call s:NetrwSaveWordPosn() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6342 | let svpos= netrw#NetrwSavePosn() |
| 6343 | |
| 6344 | let g:netrw_sort_by= (g:netrw_sort_by =~ 'n')? 'time' : (g:netrw_sort_by =~ 't')? 'size' : 'name' |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6345 | keepj norm! 0 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6346 | keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) |
| 6347 | keepj call netrw#NetrwRestorePosn(svpos) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6348 | |
| 6349 | " call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">") |
| 6350 | endfun |
| 6351 | |
| 6352 | " --------------------------------------------------------------------- |
| 6353 | " s:NetrwSplit: mode {{{2 |
| 6354 | " =0 : net and o |
| 6355 | " =1 : net and t |
| 6356 | " =2 : net and v |
| 6357 | " =3 : local and o |
| 6358 | " =4 : local and t |
| 6359 | " =5 : local and v |
| 6360 | fun! s:NetrwSplit(mode) |
| 6361 | " call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv) |
| 6362 | |
| 6363 | call s:SaveWinVars() |
| 6364 | |
| 6365 | if a:mode == 0 |
| 6366 | " remote and o |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 6367 | let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize |
| 6368 | " call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s") |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 6369 | exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6370 | let s:didsplit= 1 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6371 | keepj call s:RestoreWinVars() |
| 6372 | keepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord())) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6373 | unlet s:didsplit |
| 6374 | |
| 6375 | elseif a:mode == 1 |
| 6376 | " remote and t |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6377 | let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord()) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6378 | " call Decho("tabnew") |
| 6379 | tabnew |
| 6380 | let s:didsplit= 1 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6381 | keepj call s:RestoreWinVars() |
| 6382 | keepj call s:NetrwBrowse(0,newdir) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6383 | unlet s:didsplit |
| 6384 | |
| 6385 | elseif a:mode == 2 |
| 6386 | " remote and v |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 6387 | let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize |
| 6388 | " call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v") |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 6389 | exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6390 | let s:didsplit= 1 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6391 | keepj call s:RestoreWinVars() |
| 6392 | keepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord())) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6393 | unlet s:didsplit |
| 6394 | |
| 6395 | elseif a:mode == 3 |
| 6396 | " local and o |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 6397 | let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize |
| 6398 | " call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s") |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 6399 | exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6400 | let s:didsplit= 1 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6401 | keepj call s:RestoreWinVars() |
| 6402 | keepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord())) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6403 | unlet s:didsplit |
| 6404 | |
| 6405 | elseif a:mode == 4 |
| 6406 | " local and t |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6407 | let cursorword = s:NetrwGetWord() |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6408 | let netrw_curdir= s:NetrwTreeDir() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6409 | " call Decho("tabnew") |
| 6410 | tabnew |
| 6411 | let b:netrw_curdir= netrw_curdir |
| 6412 | let s:didsplit= 1 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6413 | keepj call s:RestoreWinVars() |
| 6414 | keepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword)) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6415 | unlet s:didsplit |
| 6416 | |
| 6417 | elseif a:mode == 5 |
| 6418 | " local and v |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 6419 | let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize |
| 6420 | " call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v") |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 6421 | exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6422 | let s:didsplit= 1 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6423 | keepj call s:RestoreWinVars() |
| 6424 | keepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord())) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6425 | unlet s:didsplit |
| 6426 | |
| 6427 | else |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6428 | keepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6429 | endif |
| 6430 | |
| 6431 | " call Dret("s:NetrwSplit") |
| 6432 | endfun |
| 6433 | |
| 6434 | " --------------------------------------------------------------------- |
| 6435 | " NetrwStatusLine: {{{2 |
| 6436 | fun! NetrwStatusLine() |
| 6437 | |
| 6438 | " vvv NetrwStatusLine() debugging vvv |
| 6439 | " let g:stlmsg="" |
| 6440 | " if !exists("w:netrw_explore_bufnr") |
| 6441 | " let g:stlmsg="!X<explore_bufnr>" |
| 6442 | " elseif w:netrw_explore_bufnr != bufnr("%") |
| 6443 | " let g:stlmsg="explore_bufnr!=".bufnr("%") |
| 6444 | " endif |
| 6445 | " if !exists("w:netrw_explore_line") |
| 6446 | " let g:stlmsg=" !X<explore_line>" |
| 6447 | " elseif w:netrw_explore_line != line(".") |
| 6448 | " let g:stlmsg=" explore_line!={line(.)<".line(".").">" |
| 6449 | " endif |
| 6450 | " if !exists("w:netrw_explore_list") |
| 6451 | " let g:stlmsg=" !X<explore_list>" |
| 6452 | " endif |
| 6453 | " ^^^ NetrwStatusLine() debugging ^^^ |
| 6454 | |
| 6455 | 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") |
| 6456 | " restore user's status line |
| 6457 | let &stl = s:netrw_users_stl |
| 6458 | let &laststatus = s:netrw_users_ls |
| 6459 | if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif |
| 6460 | if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif |
| 6461 | return "" |
| 6462 | else |
| 6463 | return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen |
| 6464 | endif |
| 6465 | endfun |
| 6466 | |
| 6467 | " --------------------------------------------------------------------- |
| 6468 | " s:NetrwTreeDir: determine tree directory given current cursor position {{{2 |
| 6469 | " (full path directory with trailing slash returned) |
| 6470 | fun! s:NetrwTreeDir() |
| 6471 | " call Dfunc("NetrwTreeDir() curline#".line(".")."<".getline('.')."> b:netrw_curdir<".b:netrw_curdir."> tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%").">") |
| 6472 | |
| 6473 | let treedir= b:netrw_curdir |
| 6474 | " call Decho("set initial treedir<".treedir.">") |
| 6475 | let s:treecurpos= netrw#NetrwSavePosn() |
| 6476 | |
| 6477 | if w:netrw_liststyle == s:TREELIST |
| 6478 | " call Decho("w:netrrw_liststyle is TREELIST:") |
| 6479 | " call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6480 | |
| 6481 | " extract tree directory if on a line specifying a subdirectory (ie. ends with "/") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6482 | if getline('.') =~ '/$' |
| 6483 | let treedir= substitute(getline('.'),'^\%(| \)*\([^|].\{-}\)$','\1','e') |
| 6484 | else |
| 6485 | let treedir= "" |
| 6486 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6487 | " call Decho("treedir<".treedir.">") |
| 6488 | |
| 6489 | " detect user attempting to close treeroot |
| 6490 | if getline('.') !~ '|' && getline('.') != '..' |
| 6491 | " call Decho("user attempted to close treeroot") |
| 6492 | " now force a refresh |
| 6493 | " call Decho("clear buffer<".expand("%")."> with :%d") |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6494 | sil! keepj %d |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6495 | " call Dret("NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".string(s:treecurpos).">") |
| 6496 | return b:netrw_curdir |
| 6497 | endif |
| 6498 | |
| 6499 | " elide all non-depth information |
| 6500 | let depth = substitute(getline('.'),'^\(\%(| \)*\)[^|].\{-}$','\1','e') |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6501 | " call Decho("depth<".depth."> 1st subst (non-depth info removed)") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6502 | |
| 6503 | " elide first depth |
| 6504 | let depth = substitute(depth,'^| ','','') |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6505 | " call Decho("depth<".depth."> 2nd subst (first depth removed)") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6506 | |
| 6507 | " construct treedir by searching backwards at correct depth |
| 6508 | " call Decho("constructing treedir<".treedir."> depth<".depth.">") |
| 6509 | while depth != "" && search('^'.depth.'[^|].\{-}/$','bW') |
| 6510 | let dirname= substitute(getline('.'),'^\(| \)*','','e') |
| 6511 | let treedir= dirname.treedir |
| 6512 | let depth = substitute(depth,'^| ','','') |
| 6513 | " call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">") |
| 6514 | endwhile |
| 6515 | if w:netrw_treetop =~ '/$' |
| 6516 | let treedir= w:netrw_treetop.treedir |
| 6517 | else |
| 6518 | let treedir= w:netrw_treetop.'/'.treedir |
| 6519 | endif |
| 6520 | " call Decho("bufnr(.)=".bufnr("%")." line($)=".line("$")." line(.)=".line(".")) |
| 6521 | endif |
| 6522 | let treedir= substitute(treedir,'//$','/','') |
| 6523 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6524 | " call Dret("NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".string(s:treecurpos).">") |
| 6525 | return treedir |
| 6526 | endfun |
| 6527 | |
| 6528 | " --------------------------------------------------------------------- |
| 6529 | " s:NetrwTreeDisplay: recursive tree display {{{2 |
| 6530 | fun! s:NetrwTreeDisplay(dir,depth) |
| 6531 | " call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)") |
| 6532 | |
| 6533 | " insure that there are no folds |
| 6534 | setlocal nofen |
| 6535 | |
| 6536 | " install ../ and shortdir |
| 6537 | if a:depth == "" |
| 6538 | call setline(line("$")+1,'../') |
| 6539 | " call Decho("setline#".line("$")." ../ (depth is zero)") |
| 6540 | endif |
| 6541 | if a:dir =~ '^\a\+://' |
| 6542 | if a:dir == w:netrw_treetop |
| 6543 | let shortdir= a:dir |
| 6544 | else |
| 6545 | let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e') |
| 6546 | endif |
| 6547 | call setline(line("$")+1,a:depth.shortdir) |
| 6548 | else |
| 6549 | let shortdir= substitute(a:dir,'^.*/','','e') |
| 6550 | call setline(line("$")+1,a:depth.shortdir.'/') |
| 6551 | endif |
| 6552 | " call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">") |
| 6553 | |
| 6554 | " append a / to dir if its missing one |
| 6555 | let dir= a:dir |
| 6556 | if dir !~ '/$' |
| 6557 | let dir= dir.'/' |
| 6558 | endif |
| 6559 | |
| 6560 | " display subtrees (if any) |
| 6561 | let depth= "| ".a:depth |
| 6562 | |
| 6563 | " call Decho("display subtrees with depth<".depth."> and current leaves") |
| 6564 | for entry in w:netrw_treedict[a:dir] |
| 6565 | let direntry= substitute(dir.entry,'/$','','e') |
| 6566 | " call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">") |
| 6567 | if entry =~ '/$' && has_key(w:netrw_treedict,direntry) |
| 6568 | " call Decho("<".direntry."> is a key in treedict - display subtree for it") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6569 | keepj call s:NetrwTreeDisplay(direntry,depth) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6570 | elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/') |
| 6571 | " call Decho("<".direntry."/> is a key in treedict - display subtree for it") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6572 | keepj call s:NetrwTreeDisplay(direntry.'/',depth) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6573 | else |
| 6574 | " call Decho("<".entry."> is not a key in treedict (no subtree)") |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6575 | sil! keepj call setline(line("$")+1,depth.entry) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6576 | endif |
| 6577 | endfor |
| 6578 | " call Dret("NetrwTreeDisplay") |
| 6579 | endfun |
| 6580 | |
| 6581 | " --------------------------------------------------------------------- |
| 6582 | " s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2 |
| 6583 | fun! s:NetrwTreeListing(dirname) |
| 6584 | if w:netrw_liststyle == s:TREELIST |
| 6585 | " call Dfunc("NetrwTreeListing() bufname<".expand("%").">") |
| 6586 | " call Decho("curdir<".a:dirname.">") |
| 6587 | " 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")) |
| 6588 | |
| 6589 | " update the treetop |
| 6590 | " call Decho("update the treetop") |
| 6591 | if !exists("w:netrw_treetop") |
| 6592 | let w:netrw_treetop= a:dirname |
| 6593 | " call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)") |
| 6594 | elseif (w:netrw_treetop =~ ('^'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop)) || a:dirname !~ ('^'.w:netrw_treetop) |
| 6595 | let w:netrw_treetop= a:dirname |
| 6596 | " call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)") |
| 6597 | endif |
| 6598 | |
| 6599 | " insure that we have at least an empty treedict |
| 6600 | if !exists("w:netrw_treedict") |
| 6601 | let w:netrw_treedict= {} |
| 6602 | endif |
| 6603 | |
| 6604 | " update the directory listing for the current directory |
| 6605 | " call Decho("updating dictionary with ".a:dirname.":[..directory listing..]") |
| 6606 | " call Decho("bannercnt=".w:netrw_bannercnt." line($)=".line("$")) |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6607 | exe "sil! keepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6608 | let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$")) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6609 | " call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname])) |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6610 | exe "sil! keepj ".w:netrw_bannercnt.",$d" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6611 | |
| 6612 | " if past banner, record word |
| 6613 | if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt |
| 6614 | let fname= expand("<cword>") |
| 6615 | else |
| 6616 | let fname= "" |
| 6617 | endif |
| 6618 | " call Decho("fname<".fname.">") |
| 6619 | |
| 6620 | " display from treetop on down |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6621 | keepj call s:NetrwTreeDisplay(w:netrw_treetop,"") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6622 | |
| 6623 | " call Dret("NetrwTreeListing : bufname<".expand("%").">") |
| 6624 | endif |
| 6625 | endfun |
| 6626 | |
| 6627 | " --------------------------------------------------------------------- |
| 6628 | " s:NetrwWideListing: {{{2 |
| 6629 | fun! s:NetrwWideListing() |
| 6630 | |
| 6631 | if w:netrw_liststyle == s:WIDELIST |
| 6632 | " call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo) |
| 6633 | " look for longest filename (cpf=characters per filename) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6634 | " cpf: characters per filename |
| 6635 | " fpl: filenames per line |
| 6636 | " fpc: filenames per column |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6637 | setlocal ma noro |
| 6638 | " call Decho("setlocal ma noro") |
| 6639 | let b:netrw_cpf= 0 |
| 6640 | if line("$") >= w:netrw_bannercnt |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6641 | exe 'sil keepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif' |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6642 | keepj call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6643 | else |
| 6644 | " call Dret("NetrwWideListing") |
| 6645 | return |
| 6646 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6647 | let b:netrw_cpf= b:netrw_cpf + 2 |
| 6648 | " call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6649 | |
| 6650 | " determine qty files per line (fpl) |
| 6651 | let w:netrw_fpl= winwidth(0)/b:netrw_cpf |
| 6652 | if w:netrw_fpl <= 0 |
| 6653 | let w:netrw_fpl= 1 |
| 6654 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6655 | " call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6656 | |
| 6657 | " make wide display |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6658 | exe 'sil keepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'s",submatch(0)),"\\")/' |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6659 | keepj call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6660 | let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl |
| 6661 | let newcolstart = w:netrw_bannercnt + fpc |
| 6662 | let newcolend = newcolstart + fpc - 1 |
| 6663 | " call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]") |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6664 | sil! let keepregstar = @* |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6665 | while line("$") >= newcolstart |
| 6666 | if newcolend > line("$") | let newcolend= line("$") | endif |
| 6667 | let newcolqty= newcolend - newcolstart |
| 6668 | exe newcolstart |
| 6669 | if newcolqty == 0 |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6670 | exe "sil! keepj norm! 0\<c-v>$hx".w:netrw_bannercnt."G$p" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6671 | else |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6672 | exe "sil! keepj norm! 0\<c-v>".newcolqty.'j$hx'.w:netrw_bannercnt.'G$p' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6673 | endif |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6674 | exe "sil! keepj ".newcolstart.','.newcolend.'d' |
| 6675 | exe 'sil! keepj '.w:netrw_bannercnt |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6676 | endwhile |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6677 | sil! let @*= keepregstar |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6678 | exe "sil! keepj ".w:netrw_bannercnt.',$s/\s\+$//e' |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6679 | keepj call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6680 | setlocal noma nomod ro |
| 6681 | " call Dret("NetrwWideListing") |
| 6682 | endif |
| 6683 | |
| 6684 | endfun |
| 6685 | |
| 6686 | " --------------------------------------------------------------------- |
| 6687 | " s:PerformListing: {{{2 |
| 6688 | fun! s:PerformListing(islocal) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6689 | " call Dfunc("s:PerformListing(islocal=".a:islocal.") bufnr(%)=".bufnr("%")."<".bufname("%").">") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6690 | |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 6691 | " set up syntax highlighting {{{3 |
| 6692 | " call Decho("set up syntax highlighting") |
| 6693 | if has("syntax") |
| 6694 | if !exists("g:syntax_on") || !g:syntax_on |
| 6695 | " call Decho("but g:syntax_on".(exists("g:syntax_on")? "=".g:syntax_on : "<doesn't exist>")) |
| 6696 | setlocal ft= |
| 6697 | elseif &ft != "netrw" |
| 6698 | setlocal ft=netrw |
| 6699 | endif |
| 6700 | endif |
| 6701 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6702 | keepj call s:NetrwSafeOptions() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6703 | setlocal noro ma |
| 6704 | " call Decho("setlocal noro ma") |
| 6705 | |
| 6706 | " if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho |
| 6707 | " call Decho("(netrw) Processing your browsing request...") |
| 6708 | " endif " Decho |
| 6709 | |
| 6710 | " call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a')) |
| 6711 | if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") |
| 6712 | " force a refresh for tree listings |
| 6713 | " call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d") |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6714 | sil! keepj %d |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6715 | endif |
| 6716 | |
| 6717 | " save current directory on directory history list |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6718 | keepj call s:NetrwBookHistHandler(3,b:netrw_curdir) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6719 | |
| 6720 | " Set up the banner {{{3 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6721 | if g:netrw_banner |
| 6722 | " call Decho("set up banner") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6723 | keepj call setline(1,'" ============================================================================') |
| 6724 | keepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')') |
| 6725 | keepj call setline(3,'" '.b:netrw_curdir) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6726 | let w:netrw_bannercnt= 3 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6727 | keepj exe "sil! keepj ".w:netrw_bannercnt |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6728 | else |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6729 | keepj 1 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6730 | let w:netrw_bannercnt= 1 |
| 6731 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6732 | |
| 6733 | let sortby= g:netrw_sort_by |
| 6734 | if g:netrw_sort_direction =~ "^r" |
| 6735 | let sortby= sortby." reversed" |
| 6736 | endif |
| 6737 | |
| 6738 | " Sorted by... {{{3 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6739 | if g:netrw_banner |
| 6740 | " call Decho("handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">") |
| 6741 | if g:netrw_sort_by =~ "^n" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6742 | " call Decho("directories will be sorted by name") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6743 | " sorted by name |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6744 | keepj put ='\" Sorted by '.sortby |
| 6745 | keepj put ='\" Sort sequence: '.g:netrw_sort_sequence |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6746 | let w:netrw_bannercnt= w:netrw_bannercnt + 2 |
| 6747 | else |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6748 | " call Decho("directories will be sorted by size or time") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6749 | " sorted by size or date |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6750 | keepj put ='\" Sorted by '.sortby |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6751 | let w:netrw_bannercnt= w:netrw_bannercnt + 1 |
| 6752 | endif |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6753 | exe "sil! keepj ".w:netrw_bannercnt |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6754 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6755 | |
| 6756 | " show copy/move target, if any |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6757 | if g:netrw_banner |
| 6758 | if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") |
| 6759 | " call Decho("show copy/move target<".s:netrwmftgt.">") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6760 | keepj put ='' |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6761 | if s:netrwmftgt_islocal |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6762 | sil! keepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)') |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6763 | else |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6764 | sil! keepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)') |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6765 | endif |
| 6766 | let w:netrw_bannercnt= w:netrw_bannercnt + 1 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6767 | else |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6768 | " call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6769 | endif |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6770 | exe "sil! keepj ".w:netrw_bannercnt |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6771 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6772 | |
| 6773 | " Hiding... -or- Showing... {{{3 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6774 | if g:netrw_banner |
| 6775 | " call Decho("handle hiding/showing (g:netrw_hide=".g:netrw_list_hide." g:netrw_list_hide<".g:netrw_list_hide.">)") |
| 6776 | if g:netrw_list_hide != "" && g:netrw_hide |
| 6777 | if g:netrw_hide == 1 |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6778 | keepj put ='\" Hiding: '.g:netrw_list_hide |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6779 | else |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6780 | keepj put ='\" Showing: '.g:netrw_list_hide |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6781 | endif |
| 6782 | let w:netrw_bannercnt= w:netrw_bannercnt + 1 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6783 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6784 | exe "keepjumps ".w:netrw_bannercnt |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6785 | keepj put ='\" Quick Help: <F1>:help -:go up dir D:delete R:rename s:sort-by x:exec' |
| 6786 | keepj put ='\" ============================================================================' |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6787 | let w:netrw_bannercnt= w:netrw_bannercnt + 2 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6788 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6789 | |
| 6790 | " bannercnt should index the line just after the banner |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6791 | if g:netrw_banner |
| 6792 | let w:netrw_bannercnt= w:netrw_bannercnt + 1 |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6793 | exe "sil! keepj ".w:netrw_bannercnt |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6794 | " call Decho("bannercnt=".w:netrw_bannercnt." (should index line just after banner) line($)=".line("$")) |
| 6795 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6796 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6797 | " get list of files |
| 6798 | " call Decho("Get list of files - islocal=".a:islocal) |
| 6799 | if a:islocal |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6800 | keepj call s:LocalListing() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6801 | else " remote |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6802 | keepj call s:NetrwRemoteListing() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6803 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6804 | " call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6805 | |
| 6806 | " manipulate the directory listing (hide, sort) {{{3 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6807 | if !g:netrw_banner || line("$") >= w:netrw_bannercnt |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6808 | " call Decho("manipulate directory listing (hide)") |
| 6809 | " call Decho("g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">") |
| 6810 | if g:netrw_hide && g:netrw_list_hide != "" |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6811 | keepj call s:NetrwListHide() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6812 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6813 | if !g:netrw_banner || line("$") >= w:netrw_bannercnt |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6814 | " call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">") |
| 6815 | |
| 6816 | if g:netrw_sort_by =~ "^n" |
| 6817 | " sort by name |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6818 | keepj call s:NetrwSetSort() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6819 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6820 | if !g:netrw_banner || w:netrw_bannercnt < line("$") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6821 | " call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")") |
| 6822 | if g:netrw_sort_direction =~ 'n' |
| 6823 | " normal direction sorting |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6824 | exe 'sil keepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6825 | else |
| 6826 | " reverse direction sorting |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 6827 | exe 'sil keepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6828 | endif |
| 6829 | endif |
| 6830 | " remove priority pattern prefix |
| 6831 | " call Decho("remove priority pattern prefix") |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6832 | exe 'sil! keepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e' |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6833 | keepj call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6834 | |
| 6835 | elseif a:islocal |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6836 | if !g:netrw_banner || w:netrw_bannercnt < line("$") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6837 | " call Decho("g:netrw_sort_direction=".g:netrw_sort_direction) |
| 6838 | if g:netrw_sort_direction =~ 'n' |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6839 | " call Decho('exe sil keepjumps '.w:netrw_bannercnt.',$sort') |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6840 | exe 'sil! keepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6841 | else |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6842 | " call Decho('exe sil keepjumps '.w:netrw_bannercnt.',$sort!') |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6843 | exe 'sil! keepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6844 | endif |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6845 | exe 'sil! keepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e' |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6846 | keepj call histdel("/",-1) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6847 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6848 | endif |
| 6849 | |
| 6850 | elseif g:netrw_sort_direction =~ 'r' |
| 6851 | " call Decho('reverse the sorted listing') |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6852 | if !g:netrw_banner || w:netrw_bannercnt < line('$') |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6853 | exe 'sil! keepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6854 | call histdel("/",-1) |
| 6855 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6856 | endif |
| 6857 | endif |
| 6858 | |
| 6859 | " convert to wide/tree listing {{{3 |
| 6860 | " call Decho("modify display if wide/tree listing style") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6861 | keepj call s:NetrwWideListing() |
| 6862 | keepj call s:NetrwTreeListing(b:netrw_curdir) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6863 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6864 | if exists("w:netrw_bannercnt") && (line("$") > w:netrw_bannercnt || !g:netrw_banner) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6865 | " place cursor on the top-left corner of the file listing |
| 6866 | " call Decho("place cursor on top-left corner of file listing") |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6867 | exe 'sil! keepj '.w:netrw_bannercnt |
| 6868 | sil! keepj norm! 0 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6869 | endif |
| 6870 | |
| 6871 | " record previous current directory |
| 6872 | let w:netrw_prvdir= b:netrw_curdir |
| 6873 | " call Decho("record netrw_prvdir<".w:netrw_prvdir.">") |
| 6874 | |
| 6875 | " save certain window-oriented variables into buffer-oriented variables {{{3 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6876 | keepj call s:SetBufWinVars() |
| 6877 | keepj call s:NetrwOptionRestore("w:") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6878 | |
| 6879 | " set display to netrw display settings |
| 6880 | " call Decho("set display to netrw display settings (noma nomod etc)") |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6881 | exe "setl ".g:netrw_bufsettings |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6882 | if exists("s:treecurpos") |
| 6883 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6884 | keepj call netrw#NetrwRestorePosn(s:treecurpos) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6885 | unlet s:treecurpos |
| 6886 | endif |
| 6887 | |
| 6888 | " call Dret("s:PerformListing : curpos<".string(getpos(".")).">") |
| 6889 | endfun |
| 6890 | |
| 6891 | " --------------------------------------------------------------------- |
| 6892 | " s:SetupNetrwStatusLine: {{{2 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 6893 | fun! s:SetupNetrwStatusLine(statline) |
| 6894 | " call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)") |
| 6895 | |
| 6896 | if !exists("s:netrw_setup_statline") |
| 6897 | let s:netrw_setup_statline= 1 |
| 6898 | " call Decho("do first-time status line setup") |
| 6899 | |
| 6900 | if !exists("s:netrw_users_stl") |
| 6901 | let s:netrw_users_stl= &stl |
| 6902 | endif |
| 6903 | if !exists("s:netrw_users_ls") |
| 6904 | let s:netrw_users_ls= &laststatus |
| 6905 | endif |
| 6906 | |
| 6907 | " set up User9 highlighting as needed |
| 6908 | let keepa= @a |
| 6909 | redir @a |
| 6910 | try |
| 6911 | hi User9 |
| 6912 | catch /^Vim\%((\a\+)\)\=:E411/ |
| 6913 | if &bg == "dark" |
| 6914 | hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue |
| 6915 | else |
| 6916 | hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue |
| 6917 | endif |
| 6918 | endtry |
| 6919 | redir END |
| 6920 | let @a= keepa |
| 6921 | endif |
| 6922 | |
| 6923 | " set up status line (may use User9 highlighting) |
| 6924 | " insure that windows have a statusline |
| 6925 | " make sure statusline is displayed |
| 6926 | let &stl=a:statline |
| 6927 | setlocal laststatus=2 |
| 6928 | " call Decho("stl=".&stl) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6929 | redraw |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 6930 | |
| 6931 | " call Dret("SetupNetrwStatusLine : stl=".&stl) |
| 6932 | endfun |
| 6933 | |
| 6934 | " --------------------------------------------------------------------- |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6935 | " Remote Directory Browsing Support: {{{1 |
| 6936 | " =========================================== |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 6937 | |
| 6938 | " --------------------------------------------------------------------- |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6939 | " s:NetrwRemoteListing: {{{2 |
| 6940 | fun! s:NetrwRemoteListing() |
| 6941 | " call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">)") |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 6942 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6943 | call s:RemotePathAnalysis(b:netrw_curdir) |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 6944 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6945 | " sanity check: |
| 6946 | if exists("b:netrw_method") && b:netrw_method =~ '[235]' |
| 6947 | " call Decho("b:netrw_method=".b:netrw_method) |
| 6948 | if !executable("ftp") |
| 6949 | if !exists("g:netrw_quiet") |
| 6950 | call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18) |
| 6951 | endif |
| 6952 | call s:NetrwOptionRestore("w:") |
| 6953 | " call Dret("s:NetrwRemoteListing") |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 6954 | return |
| 6955 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6956 | |
| 6957 | elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == '' |
| 6958 | if !exists("g:netrw_quiet") |
| 6959 | if g:netrw_list_cmd == "" |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6960 | keepj call netrw#ErrorMsg(s:ERROR,g:netrw_ssh_cmd." is not executable on your system",47) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6961 | else |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6962 | keepj call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ".g:netrw_list_cmd,19) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6963 | endif |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 6964 | endif |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 6965 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6966 | keepj call s:NetrwOptionRestore("w:") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6967 | " call Dret("s:NetrwRemoteListing") |
| 6968 | return |
| 6969 | endif " (remote handling sanity check) |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 6970 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6971 | if exists("b:netrw_method") |
| 6972 | " call Decho("setting w:netrw_method<".b:netrw_method.">") |
| 6973 | let w:netrw_method= b:netrw_method |
| 6974 | endif |
| 6975 | |
| 6976 | if s:method == "ftp" |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6977 | " use ftp to get remote file listing {{{3 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6978 | " call Decho("use ftp to get remote file listing") |
| 6979 | let s:method = "ftp" |
| 6980 | let listcmd = g:netrw_ftp_list_cmd |
| 6981 | if g:netrw_sort_by =~ '^t' |
| 6982 | let listcmd= g:netrw_ftp_timelist_cmd |
| 6983 | elseif g:netrw_sort_by =~ '^s' |
| 6984 | let listcmd= g:netrw_ftp_sizelist_cmd |
| 6985 | endif |
| 6986 | " call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)") |
| 6987 | call s:NetrwRemoteFtpCmd(s:path,listcmd) |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6988 | " exe "sil! keepalt keepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."))' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6989 | |
| 6990 | if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || w:netrw_liststyle == s:TREELIST |
| 6991 | " shorten the listing |
| 6992 | " call Decho("generate short listing") |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6993 | exe "sil! keepalt keepj ".w:netrw_bannercnt |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6994 | |
| 6995 | " cleanup |
| 6996 | if g:netrw_ftp_browse_reject != "" |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 6997 | exe "sil! keepalt keepj g/".g:netrw_ftp_browse_reject."/keepj d" |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 6998 | keepj call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 6999 | endif |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7000 | sil! keepj %s/\r$//e |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7001 | keepj call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7002 | |
| 7003 | " if there's no ../ listed, then put ./ and ../ in |
| 7004 | let line1= line(".") |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 7005 | exe "sil! keepj ".w:netrw_bannercnt |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7006 | let line2= search('^\.\.\/\%(\s\|$\)','cnW') |
| 7007 | if line2 == 0 |
| 7008 | " call Decho("netrw is putting ./ and ../ into listing") |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 7009 | sil! keepj put='../' |
| 7010 | sil! keepj put='./' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7011 | endif |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 7012 | exe "sil! keepj ".line1 |
| 7013 | sil! keepj norm! 0 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7014 | |
| 7015 | " call Decho("line1=".line1." line2=".line2." line(.)=".line(".")) |
| 7016 | if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup |
| 7017 | " call Decho("M$ ftp cleanup") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7018 | exe 'sil! keepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//' |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7019 | keepj call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7020 | else " normal ftp cleanup |
| 7021 | " call Decho("normal ftp cleanup") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7022 | exe 'sil! keepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e' |
| 7023 | exe "sil! keepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e' |
| 7024 | exe "sil! keepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e' |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7025 | keepj call histdel("/",-1) |
| 7026 | keepj call histdel("/",-1) |
| 7027 | keepj call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7028 | endif |
| 7029 | endif |
| 7030 | |
| 7031 | else |
| 7032 | " use ssh to get remote file listing {{{3 |
| 7033 | " call Decho("use ssh to get remote file listing: s:path<".s:path.">") |
| 7034 | let listcmd= s:MakeSshCmd(g:netrw_list_cmd) |
| 7035 | " call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)") |
| 7036 | if g:netrw_scp_cmd =~ '^pscp' |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7037 | " call Decho("1: exe sil r! ".shellescape(listcmd.s:path, 1)) |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 7038 | exe "sil! keepj r! ".listcmd.shellescape(s:path, 1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7039 | " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 7040 | sil! keepj g/^Listing directory/keepj d |
| 7041 | sil! keepj g/^d[-rwx][-rwx][-rwx]/keepj s+$+/+e |
| 7042 | sil! keepj g/^l[-rwx][-rwx][-rwx]/keepj s+$+@+e |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7043 | keepj call histdel("/",-1) |
| 7044 | keepj call histdel("/",-1) |
| 7045 | keepj call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7046 | if g:netrw_liststyle != s:LONGLIST |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 7047 | sil! keepj g/^[dlsp-][-rwx][-rwx][-rwx]/keepj s/^.*\s\(\S\+\)$/\1/e |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7048 | keepj call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7049 | endif |
| 7050 | else |
| 7051 | if s:path == "" |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7052 | " call Decho("2: exe sil r! ".listcmd) |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 7053 | exe "sil! keepj keepalt r! ".listcmd |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7054 | else |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 7055 | " call Decho("3: exe sil r! ".listcmd.' '.shellescape(fnameescape(s:path),1)) |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 7056 | exe "sil! keepj keepalt r! ".listcmd.' '.shellescape(fnameescape(s:path),1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7057 | " call Decho("listcmd<".listcmd."> path<".s:path.">") |
| 7058 | endif |
| 7059 | endif |
| 7060 | |
| 7061 | " cleanup |
| 7062 | if g:netrw_ftp_browse_reject != "" |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7063 | " call Decho("(cleanup) exe sil! g/".g:netrw_ssh_browse_reject."/keepjumps d") |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 7064 | exe "sil! g/".g:netrw_ssh_browse_reject."/keepj d" |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7065 | keepj call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7066 | endif |
| 7067 | endif |
| 7068 | |
| 7069 | if w:netrw_liststyle == s:LONGLIST |
| 7070 | " do a long listing; these substitutions need to be done prior to sorting {{{3 |
| 7071 | " call Decho("fix long listing:") |
| 7072 | |
| 7073 | if s:method == "ftp" |
| 7074 | " cleanup |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 7075 | exe "sil! keepj ".w:netrw_bannercnt |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7076 | while getline('.') =~ g:netrw_ftp_browse_reject |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 7077 | sil! keepj d |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7078 | endwhile |
| 7079 | " if there's no ../ listed, then put ./ and ../ in |
| 7080 | let line1= line(".") |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 7081 | sil! keepj 1 |
| 7082 | sil! keepj call search('^\.\.\/\%(\s\|$\)','W') |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7083 | let line2= line(".") |
| 7084 | if line2 == 0 |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 7085 | exe 'sil! keepj '.w:netrw_bannercnt."put='./'" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7086 | if b:netrw_curdir != '/' |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 7087 | exe 'sil! keepj '.w:netrw_bannercnt."put='../'" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7088 | endif |
| 7089 | endif |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 7090 | exe "sil! keepj ".line1 |
| 7091 | sil! keepj norm! 0 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7092 | endif |
| 7093 | |
| 7094 | if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup |
| 7095 | " call Decho("M$ ftp site listing cleanup") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7096 | 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 Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7097 | elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") |
| 7098 | " call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$")) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7099 | exe 'sil keepj '.w:netrw_bannercnt.',$s/ -> .*$//e' |
| 7100 | exe 'sil keepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2\t\1/e' |
| 7101 | exe 'sil keepj '.w:netrw_bannercnt |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7102 | keepj call histdel("/",-1) |
| 7103 | keepj call histdel("/",-1) |
| 7104 | keepj call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7105 | endif |
| 7106 | endif |
| 7107 | |
| 7108 | " if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7109 | " exe "keepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."))' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7110 | " endif " Decho |
| 7111 | " call Dret("s:NetrwRemoteListing") |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 7112 | endfun |
| 7113 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7114 | " --------------------------------------------------------------------- |
| 7115 | " s:NetrwRemoteRm: remove/delete a remote file or directory {{{2 |
| 7116 | fun! s:NetrwRemoteRm(usrhost,path) range |
| 7117 | " call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol(".")) |
| 7118 | " call Decho("firstline=".a:firstline." lastline=".a:lastline) |
| 7119 | let svpos= netrw#NetrwSavePosn() |
| 7120 | |
| 7121 | let all= 0 |
| 7122 | if exists("s:netrwmarkfilelist_{bufnr('%')}") |
| 7123 | " remove all marked files |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 7124 | " call Decho("remove all marked files with bufnr#".bufnr("%")) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7125 | for fname in s:netrwmarkfilelist_{bufnr("%")} |
| 7126 | let ok= s:NetrwRemoteRmFile(a:path,fname,all) |
| 7127 | if ok =~ 'q\%[uit]' |
| 7128 | break |
| 7129 | elseif ok =~ 'a\%[ll]' |
| 7130 | let all= 1 |
| 7131 | endif |
| 7132 | endfor |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 7133 | call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7134 | |
| 7135 | else |
| 7136 | " remove files specified by range |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 7137 | " call Decho("remove files specified by range") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7138 | |
| 7139 | " preparation for removing multiple files/directories |
| 7140 | let ctr= a:firstline |
| 7141 | |
| 7142 | " remove multiple files and directories |
| 7143 | while ctr <= a:lastline |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 7144 | exe "keepj ".ctr |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7145 | let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all) |
| 7146 | if ok =~ 'q\%[uit]' |
| 7147 | break |
| 7148 | elseif ok =~ 'a\%[ll]' |
| 7149 | let all= 1 |
| 7150 | endif |
| 7151 | let ctr= ctr + 1 |
| 7152 | endwhile |
| 7153 | endif |
| 7154 | |
| 7155 | " refresh the (remote) directory listing |
| 7156 | " call Decho("refresh remote directory listing") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7157 | keepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./')) |
| 7158 | keepj call netrw#NetrwRestorePosn(svpos) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7159 | |
| 7160 | " call Dret("s:NetrwRemoteRm") |
| 7161 | endfun |
| 7162 | |
| 7163 | " --------------------------------------------------------------------- |
| 7164 | " s:NetrwRemoteRmFile: {{{2 |
| 7165 | fun! s:NetrwRemoteRmFile(path,rmfile,all) |
| 7166 | " call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all) |
| 7167 | |
| 7168 | let all= a:all |
| 7169 | let ok = "" |
| 7170 | |
| 7171 | if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$') |
| 7172 | " attempt to remove file |
| 7173 | " call Decho("attempt to remove file (all=".all.")") |
| 7174 | if !all |
| 7175 | echohl Statement |
| 7176 | " call Decho("case all=0:") |
| 7177 | call inputsave() |
| 7178 | let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ") |
| 7179 | call inputrestore() |
| 7180 | echohl NONE |
| 7181 | if ok == "" |
| 7182 | let ok="no" |
| 7183 | endif |
| 7184 | let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e') |
| 7185 | if ok =~ 'a\%[ll]' |
| 7186 | let all= 1 |
| 7187 | endif |
| 7188 | endif |
| 7189 | |
| 7190 | if all || ok =~ 'y\%[es]' || ok == "" |
| 7191 | " call Decho("case all=".all." or ok<".ok.">".(exists("w:netrw_method")? ': netrw_method='.w:netrw_method : "")) |
| 7192 | if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3) |
| 7193 | " call Decho("case ftp:") |
| 7194 | let path= a:path |
| 7195 | if path =~ '^\a\+://' |
| 7196 | let path= substitute(path,'^\a\+://[^/]\+/','','') |
| 7197 | endif |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 7198 | sil! keepj .,$d |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7199 | call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"') |
| 7200 | else |
| 7201 | " call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">") |
| 7202 | let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd) |
| 7203 | " call Decho("netrw_rm_cmd<".netrw_rm_cmd.">") |
| 7204 | if !exists("b:netrw_curdir") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7205 | keepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7206 | let ok="q" |
| 7207 | else |
| 7208 | let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','') |
| 7209 | " call Decho("netrw_rm_cmd<".netrw_rm_cmd.">") |
| 7210 | " call Decho("remotedir<".remotedir.">") |
| 7211 | " call Decho("rmfile<".a:rmfile.">") |
| 7212 | if remotedir != "" |
| 7213 | let netrw_rm_cmd= netrw_rm_cmd." ".shellescape(fnameescape(remotedir.a:rmfile)) |
| 7214 | else |
| 7215 | let netrw_rm_cmd= netrw_rm_cmd." ".shellescape(fnameescape(a:rmfile)) |
| 7216 | endif |
| 7217 | " call Decho("call system(".netrw_rm_cmd.")") |
| 7218 | let ret= system(netrw_rm_cmd) |
| 7219 | if ret != 0 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7220 | keepj call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7221 | endif |
| 7222 | " call Decho("returned=".ret." errcode=".v:shell_error) |
| 7223 | endif |
| 7224 | endif |
| 7225 | elseif ok =~ 'q\%[uit]' |
| 7226 | " call Decho("ok==".ok) |
| 7227 | break |
| 7228 | endif |
| 7229 | |
| 7230 | else |
| 7231 | " attempt to remove directory |
| 7232 | " call Decho("attempt to remove directory") |
| 7233 | if !all |
| 7234 | call inputsave() |
| 7235 | let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ") |
| 7236 | call inputrestore() |
| 7237 | if ok == "" |
| 7238 | let ok="no" |
| 7239 | endif |
| 7240 | let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e') |
| 7241 | if ok =~ 'a\%[ll]' |
| 7242 | let all= 1 |
| 7243 | endif |
| 7244 | endif |
| 7245 | |
| 7246 | if all || ok =~ 'y\%[es]' || ok == "" |
| 7247 | if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7248 | keepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7249 | else |
| 7250 | let rmfile = substitute(a:path.a:rmfile,'/$','','') |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 7251 | let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.shellescape(netrw#WinPath(rmfile)) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7252 | " call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")") |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7253 | let ret= system(netrw_rmdir_cmd) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7254 | " call Decho("returned=".ret." errcode=".v:shell_error) |
| 7255 | |
| 7256 | if v:shell_error != 0 |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7257 | " call Decho("v:shell_error not 0") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 7258 | let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.shellescape(netrw#WinPath(substitute(rmfile,'[\/]$','','e'))) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7259 | " call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")") |
| 7260 | let ret= system(netrw_rmf_cmd) |
| 7261 | " call Decho("returned=".ret." errcode=".v:shell_error) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7262 | |
| 7263 | if v:shell_error != 0 && !exists("g:netrw_quiet") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7264 | keepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7265 | endif |
| 7266 | endif |
| 7267 | endif |
| 7268 | |
| 7269 | elseif ok =~ 'q\%[uit]' |
| 7270 | break |
| 7271 | endif |
| 7272 | endif |
| 7273 | |
| 7274 | " call Dret("s:NetrwRemoteRmFile ".ok) |
| 7275 | return ok |
| 7276 | endfun |
| 7277 | |
| 7278 | " --------------------------------------------------------------------- |
| 7279 | " s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2 |
| 7280 | " This function assumes that a long listing will be received. Size, time, |
| 7281 | " and reverse sorts will be requested of the server but not otherwise |
| 7282 | " enforced here. |
| 7283 | fun! s:NetrwRemoteFtpCmd(path,listcmd) |
| 7284 | " call Dfunc("NetrwRemoteFtpCmd(path<".a:path."> listcmd<".a:listcmd.">) netrw_method=".w:netrw_method) |
| 7285 | " call Decho("line($)=".line("$")." bannercnt=".w:netrw_bannercnt) |
| 7286 | |
| 7287 | " because WinXX ftp uses unix style input |
| 7288 | let ffkeep= &ff |
| 7289 | setlocal ma ff=unix noro |
| 7290 | " call Decho("setlocal ma ff=unix noro") |
| 7291 | |
| 7292 | " clear off any older non-banner lines |
| 7293 | " note that w:netrw_bannercnt indexes the line after the banner |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7294 | " call Decho('exe sil! keepjumps '.w:netrw_bannercnt.",$d (clear off old non-banner lines)") |
| 7295 | exe "sil! keepjumps ".w:netrw_bannercnt.",$d" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7296 | |
| 7297 | "......................................... |
| 7298 | if w:netrw_method == 2 || w:netrw_method == 5 |
| 7299 | " ftp + <.netrc>: Method #2 |
| 7300 | if a:path != "" |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7301 | keepj put ='cd \"'.a:path.'\"' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7302 | endif |
| 7303 | if exists("g:netrw_ftpextracmd") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7304 | keepj put =g:netrw_ftpextracmd |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7305 | " call Decho("filter input: ".getline('.')) |
| 7306 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7307 | keepj call setline(line("$")+1,a:listcmd) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7308 | " exe "keepjumps ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."))' |
| 7309 | if exists("g:netrw_port") && g:netrw_port != "" |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7310 | " 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 Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 7311 | exe s:netrw_silentxfer." keepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7312 | else |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7313 | " call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)) |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 7314 | exe s:netrw_silentxfer." keepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7315 | endif |
| 7316 | |
| 7317 | "......................................... |
| 7318 | elseif w:netrw_method == 3 |
| 7319 | " ftp + machine,id,passwd,filename: Method #3 |
| 7320 | setlocal ff=unix |
| 7321 | if exists("g:netrw_port") && g:netrw_port != "" |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7322 | keepj put ='open '.g:netrw_machine.' '.g:netrw_port |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7323 | else |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7324 | keepj put ='open '.g:netrw_machine |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7325 | endif |
| 7326 | |
| 7327 | if exists("g:netrw_ftp") && g:netrw_ftp == 1 |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7328 | keepj put =g:netrw_uid |
| 7329 | keepj put ='\"'.s:netrw_passwd.'\"' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7330 | else |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7331 | keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7332 | endif |
| 7333 | |
| 7334 | if a:path != "" |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7335 | keepj put ='cd \"'.a:path.'\"' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7336 | endif |
| 7337 | if exists("g:netrw_ftpextracmd") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7338 | keepj put =g:netrw_ftpextracmd |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7339 | " call Decho("filter input: ".getline('.')) |
| 7340 | endif |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7341 | keepj call setline(line("$")+1,a:listcmd) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7342 | |
| 7343 | " perform ftp: |
| 7344 | " -i : turns off interactive prompting from ftp |
| 7345 | " -n unix : DON'T use <.netrc>, even though it exists |
| 7346 | " -n win32: quit being obnoxious about password |
| 7347 | " exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."))' |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7348 | " call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i -n") |
| 7349 | exe s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i -n" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7350 | |
| 7351 | "......................................... |
| 7352 | else |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7353 | keepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",23) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7354 | endif |
| 7355 | |
| 7356 | " cleanup for Windows |
| 7357 | if has("win32") || has("win95") || has("win64") || has("win16") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7358 | sil! keepj %s/\r$//e |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7359 | keepj call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7360 | endif |
| 7361 | if a:listcmd == "dir" |
| 7362 | " infer directory/link based on the file permission string |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7363 | sil! keepj g/d\%([-r][-w][-x]\)\{3}/keepj s@$@/@ |
| 7364 | sil! keepj g/l\%([-r][-w][-x]\)\{3}/keepj s/$/@/ |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7365 | keepj call histdel("/",-1) |
| 7366 | keepj call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7367 | if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || w:netrw_liststyle == s:TREELIST |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7368 | exe "sil! keepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e' |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7369 | keepj call histdel("/",-1) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7370 | endif |
| 7371 | endif |
| 7372 | |
| 7373 | " ftp's listing doesn't seem to include ./ or ../ |
| 7374 | if !search('^\.\/$\|\s\.\/$','wn') |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7375 | exe 'keepj '.w:netrw_bannercnt |
| 7376 | keepj put ='./' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7377 | endif |
| 7378 | if !search('^\.\.\/$\|\s\.\.\/$','wn') |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7379 | exe 'keepj '.w:netrw_bannercnt |
| 7380 | keepj put ='../' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7381 | endif |
| 7382 | |
| 7383 | " restore settings |
| 7384 | let &ff= ffkeep |
| 7385 | " call Dret("NetrwRemoteFtpCmd") |
| 7386 | endfun |
| 7387 | |
| 7388 | " --------------------------------------------------------------------- |
| 7389 | " s:NetrwRemoteRename: rename a remote file or directory {{{2 |
| 7390 | fun! s:NetrwRemoteRename(usrhost,path) range |
| 7391 | " call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)") |
| 7392 | |
| 7393 | " preparation for removing multiple files/directories |
| 7394 | let svpos = netrw#NetrwSavePosn() |
| 7395 | let ctr = a:firstline |
| 7396 | let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd) |
| 7397 | |
| 7398 | " rename files given by the markfilelist |
| 7399 | if exists("s:netrwmarkfilelist_{bufnr('%')}") |
| 7400 | for oldname in s:netrwmarkfilelist_{bufnr("%")} |
| 7401 | " call Decho("oldname<".oldname.">") |
| 7402 | if exists("subfrom") |
| 7403 | let newname= substitute(oldname,subfrom,subto,'') |
| 7404 | " call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">") |
| 7405 | else |
| 7406 | call inputsave() |
| 7407 | let newname= input("Moving ".oldname." to : ",oldname) |
| 7408 | call inputrestore() |
| 7409 | if newname =~ '^s/' |
| 7410 | let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','') |
| 7411 | let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','') |
| 7412 | let newname = substitute(oldname,subfrom,subto,'') |
| 7413 | " call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">") |
| 7414 | endif |
| 7415 | endif |
| 7416 | |
| 7417 | if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7418 | keepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7419 | else |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7420 | let oldname= shellescape(a:path.oldname) |
| 7421 | let newname= shellescape(a:path.newname) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 7422 | " call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")") |
| 7423 | let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7424 | endif |
| 7425 | |
| 7426 | endfor |
| 7427 | call s:NetrwUnMarkFile(1) |
| 7428 | |
| 7429 | else |
| 7430 | |
| 7431 | " attempt to rename files/directories |
| 7432 | while ctr <= a:lastline |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7433 | exe "keepj ".ctr |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7434 | |
| 7435 | let oldname= s:NetrwGetWord() |
| 7436 | " call Decho("oldname<".oldname.">") |
| 7437 | |
| 7438 | call inputsave() |
| 7439 | let newname= input("Moving ".oldname." to : ",oldname) |
| 7440 | call inputrestore() |
| 7441 | |
| 7442 | if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3) |
| 7443 | call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname) |
| 7444 | else |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7445 | let oldname= shellescape(a:path.oldname) |
| 7446 | let newname= shellescape(a:path.newname) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 7447 | " call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")") |
| 7448 | let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7449 | endif |
| 7450 | |
| 7451 | let ctr= ctr + 1 |
| 7452 | endwhile |
| 7453 | endif |
| 7454 | |
| 7455 | " refresh the directory |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7456 | keepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./')) |
| 7457 | keepj call netrw#NetrwRestorePosn(svpos) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7458 | |
| 7459 | " call Dret("NetrwRemoteRename") |
| 7460 | endfun |
| 7461 | |
| 7462 | " --------------------------------------------------------------------- |
| 7463 | " Local Directory Browsing Support: {{{1 |
| 7464 | " ========================================== |
| 7465 | |
| 7466 | " --------------------------------------------------------------------- |
| 7467 | " netrw#LocalBrowseCheck: {{{2 |
| 7468 | fun! netrw#LocalBrowseCheck(dirname) |
| 7469 | " unfortunate interaction -- split window debugging can't be |
| 7470 | " used here, must use D-echoRemOn or D-echoTabOn -- the BufEnter |
| 7471 | " event triggers another call to LocalBrowseCheck() when attempts |
| 7472 | " to write to the DBG buffer are made. |
| 7473 | " The &ft == "netrw" test was installed because the BufEnter event |
| 7474 | " would hit when re-entering netrw windows, creating unexpected |
| 7475 | " refreshes (and would do so in the middle of NetrwSaveOptions(), too) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 7476 | " call Decho("netrw#LocalBrowseCheck: isdir<".a:dirname.">=".isdirectory(a:dirname).((exists("s:treeforceredraw")? " treeforceredraw" : ""))) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7477 | " call Dredir("LocalBrowseCheck","ls!")|redraw!|sleep 3 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7478 | if isdirectory(a:dirname) |
| 7479 | " call Decho(" ft<".&ft."> b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : " doesn't exist")."> dirname<".a:dirname.">"." line($)=".line("$")) |
| 7480 | if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7481 | sil! keepj call s:NetrwBrowse(1,a:dirname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7482 | elseif &ft == "netrw" && line("$") == 1 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7483 | sil! keepj call s:NetrwBrowse(1,a:dirname) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 7484 | elseif exists("s:treeforceredraw") |
| 7485 | unlet s:treeforceredraw |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7486 | sil! keepj call s:NetrwBrowse(1,a:dirname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7487 | endif |
| 7488 | endif |
| 7489 | " not a directory, ignore it |
| 7490 | endfun |
| 7491 | |
| 7492 | " --------------------------------------------------------------------- |
| 7493 | " s:LocalListing: does the job of "ls" for local directories {{{2 |
| 7494 | fun! s:LocalListing() |
| 7495 | " call Dfunc("s:LocalListing()") |
| 7496 | " call Decho("&ma=".&ma) |
| 7497 | " call Decho("&mod=".&mod) |
| 7498 | " call Decho("&ro=".&ro) |
| 7499 | " call Decho("bufname(%)<".bufname("%").">") |
| 7500 | |
| 7501 | " if exists("b:netrw_curdir") |call Decho('b:netrw_curdir<'.b:netrw_curdir.">") |else|call Decho("b:netrw_curdir doesn't exist") |endif |
| 7502 | " 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 |
| 7503 | |
| 7504 | " get the list of files contained in the current directory |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7505 | let dirname = b:netrw_curdir |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 7506 | let dirnamelen = s:Strlen(b:netrw_curdir) |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 7507 | let filelist = glob(s:ComposePath(fnameescape(dirname),"*")) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7508 | " call Decho("glob(dirname<".dirname."/*>)=".filelist) |
| 7509 | if filelist != "" |
| 7510 | let filelist= filelist."\n" |
| 7511 | endif |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 7512 | let filelist= filelist.glob(s:ComposePath(fnameescape(dirname),".*")) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7513 | " call Decho("glob(dirname<".dirname."/.*>)=".filelist) |
| 7514 | |
| 7515 | " Coding choice: either elide ./ if present |
| 7516 | " or include ./ if not present |
| 7517 | if filelist =~ '[\\/]\.[\\/]\=\(\n\|$\)' |
| 7518 | " elide /path/. from glob() entries if present |
| 7519 | " call Decho("elide /path/. from glob entries if present") |
| 7520 | let filelist = substitute(filelist,'\n','\t','g') |
| 7521 | let filelist = substitute(filelist,'^[^\t]\+[/\\]\.\t','','') |
| 7522 | let filelist = substitute(filelist,'[^\t]\+[/\\]\.$','','') |
| 7523 | let filelist = substitute(filelist,'\t\zs[^\t]\+[/\\]\.\t','','') |
| 7524 | let filelist = substitute(filelist,'\t','\n','g') |
| 7525 | endif |
| 7526 | " call Decho("filelist<".filelist.">") |
| 7527 | if filelist !~ '[\\/]\.\.[\\/]\=\(\n\|$\)' |
| 7528 | " include ../ in the glob() entry if its missing |
| 7529 | " call Decho("forcibly tacking on ..") |
| 7530 | let filelist= filelist."\n".s:ComposePath(b:netrw_curdir,"../") |
| 7531 | " call Decho("filelist<".filelist.">") |
| 7532 | endif |
| 7533 | if b:netrw_curdir == '/' |
| 7534 | " remove .. from filelist when current directory is root directory |
| 7535 | " call Decho("remove .. from filelist") |
| 7536 | let filelist= substitute(filelist,'/\.\.\n','','') |
| 7537 | endif |
| 7538 | " remove multiple contiguous newlines |
| 7539 | let filelist= substitute(filelist,'\n\{2,}','\n','ge') |
| 7540 | if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16")) |
| 7541 | " change all \s to /s |
| 7542 | " call Decho('change all \s to /s') |
| 7543 | let filelist= substitute(filelist,'\','/','g') |
| 7544 | else |
| 7545 | " escape all \s to \\ |
| 7546 | " call Decho('escape all \s to \\') |
| 7547 | let filelist= substitute(filelist,'\','\\','g') |
| 7548 | endif |
| 7549 | |
| 7550 | " call Decho("(before while) dirname<".dirname.">") |
| 7551 | " call Decho("(before while) dirnamelen<".dirnamelen.">") |
| 7552 | " call Decho("(before while) filelist<".filelist.">") |
| 7553 | |
| 7554 | while filelist != "" |
| 7555 | if filelist =~ '\n' |
| 7556 | let filename = substitute(filelist,'\n.*$','','e') |
| 7557 | let filelist = substitute(filelist,'^.\{-}\n\(.*\)$','\1','e') |
| 7558 | else |
| 7559 | let filename = filelist |
| 7560 | let filelist = "" |
| 7561 | endif |
| 7562 | " call Decho(" ") |
| 7563 | " call Decho("(while) filelist<".filelist.">") |
| 7564 | " call Decho("(while) filename<".filename.">") |
| 7565 | |
| 7566 | if getftype(filename) == "link" |
| 7567 | " indicate a symbolic link |
| 7568 | " call Decho("indicate <".filename."> is a symbolic link with trailing @") |
| 7569 | let pfile= filename."@" |
| 7570 | |
| 7571 | elseif getftype(filename) == "socket" |
| 7572 | " indicate a socket |
| 7573 | " call Decho("indicate <".filename."> is a socket with trailing =") |
| 7574 | let pfile= filename."=" |
| 7575 | |
| 7576 | elseif getftype(filename) == "fifo" |
| 7577 | " indicate a fifo |
| 7578 | " call Decho("indicate <".filename."> is a fifo with trailing |") |
| 7579 | let pfile= filename."|" |
| 7580 | |
| 7581 | elseif isdirectory(filename) |
| 7582 | " indicate a directory |
| 7583 | " call Decho("indicate <".filename."> is a directory with trailing /") |
| 7584 | let pfile= filename."/" |
| 7585 | |
| 7586 | elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(filename) |
| 7587 | if (has("win32") || has("win95") || has("win64") || has("win16")) |
| 7588 | if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$' |
| 7589 | " indicate an executable |
| 7590 | " call Decho("indicate <".filename."> is executable with trailing *") |
| 7591 | let pfile= filename."*" |
| 7592 | else |
| 7593 | " normal file |
| 7594 | let pfile= filename |
| 7595 | endif |
| 7596 | elseif executable(filename) |
| 7597 | " indicate an executable |
| 7598 | " call Decho("indicate <".filename."> is executable with trailing *") |
| 7599 | let pfile= filename."*" |
| 7600 | else |
| 7601 | " normal file |
| 7602 | let pfile= filename |
| 7603 | endif |
| 7604 | |
| 7605 | else |
| 7606 | " normal file |
| 7607 | let pfile= filename |
| 7608 | endif |
| 7609 | " call Decho("pfile<".pfile."> (after *@/ appending)") |
| 7610 | |
| 7611 | if pfile =~ '//$' |
| 7612 | let pfile= substitute(pfile,'//$','/','e') |
| 7613 | " call Decho("change // to /: pfile<".pfile.">") |
| 7614 | endif |
| 7615 | let pfile= strpart(pfile,dirnamelen) |
| 7616 | let pfile= substitute(pfile,'^[/\\]','','e') |
| 7617 | " call Decho("filename<".filename.">") |
| 7618 | " call Decho("pfile <".pfile.">") |
| 7619 | |
| 7620 | if w:netrw_liststyle == s:LONGLIST |
| 7621 | let sz = getfsize(filename) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 7622 | let fsz = strpart(" ",1,15-strlen(sz)).sz |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7623 | let pfile= pfile."\t".fsz." ".strftime(g:netrw_timefmt,getftime(filename)) |
| 7624 | " call Decho("sz=".sz." fsz=".fsz) |
| 7625 | endif |
| 7626 | |
| 7627 | if g:netrw_sort_by =~ "^t" |
| 7628 | " sort by time (handles time up to 1 quintillion seconds, US) |
| 7629 | " call Decho("getftime(".filename.")=".getftime(filename)) |
| 7630 | let t = getftime(filename) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 7631 | let ft = strpart("000000000000000000",1,18-strlen(t)).t |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7632 | " call Decho("exe keepjumps put ='".ft.'/'.filename."'") |
| 7633 | let ftpfile= ft.'/'.pfile |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7634 | sil! keepj put=ftpfile |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7635 | |
| 7636 | elseif g:netrw_sort_by =~ "^s" |
| 7637 | " sort by size (handles file sizes up to 1 quintillion bytes, US) |
| 7638 | " call Decho("getfsize(".filename.")=".getfsize(filename)) |
| 7639 | let sz = getfsize(filename) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 7640 | let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7641 | " call Decho("exe keepjumps put ='".fsz.'/'.filename."'") |
| 7642 | let fszpfile= fsz.'/'.pfile |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7643 | sil! keepj put =fszpfile |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7644 | |
| 7645 | else |
| 7646 | " sort by name |
| 7647 | " call Decho("exe keepjumps put ='".pfile."'") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7648 | sil! keepj put=pfile |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7649 | endif |
| 7650 | endwhile |
| 7651 | |
| 7652 | " cleanup any windows mess at end-of-line |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7653 | sil! keepj g/^$/d |
| 7654 | sil! keepj %s/\r$//e |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 7655 | call histdel("/",-1) |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 7656 | exe "setl ts=".g:netrw_maxfilenamelen |
| 7657 | " call Decho("setl ts=".g:netrw_maxfilenamelen) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7658 | |
| 7659 | " call Dret("s:LocalListing") |
| 7660 | endfun |
| 7661 | |
| 7662 | " --------------------------------------------------------------------- |
| 7663 | " s:LocalBrowseShellCmdRefresh: this function is called after a user has {{{2 |
| 7664 | " performed any shell command. The idea is to cause all local-browsing |
| 7665 | " buffers to be refreshed after a user has executed some shell command, |
| 7666 | " on the chance that s/he removed/created a file/directory with it. |
| 7667 | fun! s:LocalBrowseShellCmdRefresh() |
| 7668 | " call Dfunc("LocalBrowseShellCmdRefresh() browselist=".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "empty")." ".tabpagenr("$")." tabs") |
| 7669 | " determine which buffers currently reside in a tab |
| 7670 | if !exists("s:netrw_browselist") |
| 7671 | " call Dret("LocalBrowseShellCmdRefresh : browselist is empty") |
| 7672 | return |
| 7673 | endif |
| 7674 | if !exists("w:netrw_bannercnt") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 7675 | " call Dret("LocalBrowseShellCmdRefresh : don't refresh when focus not on netrw window") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7676 | return |
| 7677 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 7678 | if exists("s:locbrowseshellcmd") |
| 7679 | if s:locbrowseshellcmd |
| 7680 | let s:locbrowseshellcmd= 0 |
| 7681 | " call Dret("LocalBrowseShellCmdRefresh : NetrwBrowse itself caused the refresh") |
| 7682 | return |
| 7683 | endif |
| 7684 | let s:locbrowseshellcmd= 0 |
| 7685 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7686 | let itab = 1 |
| 7687 | let buftablist = [] |
| 7688 | while itab <= tabpagenr("$") |
| 7689 | let buftablist = buftablist + tabpagebuflist() |
| 7690 | let itab = itab + 1 |
| 7691 | tabn |
| 7692 | endwhile |
| 7693 | " call Decho("buftablist".string(buftablist)) |
| 7694 | " call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">") |
| 7695 | " GO through all buffers on netrw_browselist (ie. just local-netrw buffers): |
| 7696 | " | refresh any netrw window |
| 7697 | " | wipe out any non-displaying netrw buffer |
| 7698 | let curwin = winnr() |
| 7699 | let ibl = 0 |
| 7700 | for ibuf in s:netrw_browselist |
| 7701 | " call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf)) |
| 7702 | if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1 |
| 7703 | " wipe out any non-displaying netrw buffer |
| 7704 | " call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7705 | exe "sil! bd ".fnameescape(ibuf) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7706 | call remove(s:netrw_browselist,ibl) |
| 7707 | " call Decho("browselist=".string(s:netrw_browselist)) |
| 7708 | continue |
| 7709 | elseif index(tabpagebuflist(),ibuf) != -1 |
| 7710 | " refresh any netrw buffer |
| 7711 | " call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf)) |
| 7712 | exe bufwinnr(ibuf)."wincmd w" |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7713 | keepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./')) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7714 | endif |
| 7715 | let ibl= ibl + 1 |
| 7716 | endfor |
| 7717 | exe curwin."wincmd w" |
| 7718 | |
| 7719 | " call Dret("LocalBrowseShellCmdRefresh") |
| 7720 | endfun |
| 7721 | |
| 7722 | " --------------------------------------------------------------------- |
| 7723 | " s:NetrwLocalRm: {{{2 |
| 7724 | fun! s:NetrwLocalRm(path) range |
| 7725 | " call Dfunc("s:NetrwLocalRm(path<".a:path.">)") |
| 7726 | " call Decho("firstline=".a:firstline." lastline=".a:lastline) |
| 7727 | |
| 7728 | " preparation for removing multiple files/directories |
| 7729 | let ret = 0 |
| 7730 | let all = 0 |
| 7731 | let svpos = netrw#NetrwSavePosn() |
| 7732 | |
| 7733 | if exists("s:netrwmarkfilelist_{bufnr('%')}") |
| 7734 | " remove all marked files |
| 7735 | " call Decho("remove all marked files") |
| 7736 | for fname in s:netrwmarkfilelist_{bufnr("%")} |
| 7737 | let ok= s:NetrwLocalRmFile(a:path,fname,all) |
| 7738 | if ok =~ 'q\%[uit]' || ok == "no" |
| 7739 | break |
| 7740 | elseif ok =~ 'a\%[ll]' |
| 7741 | let all= 1 |
| 7742 | endif |
| 7743 | endfor |
| 7744 | call s:NetrwUnMarkFile(1) |
| 7745 | |
| 7746 | else |
| 7747 | " remove (multiple) files and directories |
| 7748 | " call Decho("remove files in range [".a:firstline.",".a:lastline."]") |
| 7749 | |
| 7750 | let ctr = a:firstline |
| 7751 | while ctr <= a:lastline |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7752 | exe "keepj ".ctr |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7753 | |
| 7754 | " sanity checks |
| 7755 | if line(".") < w:netrw_bannercnt |
| 7756 | let ctr= ctr + 1 |
| 7757 | continue |
| 7758 | endif |
| 7759 | let curword= s:NetrwGetWord() |
| 7760 | if curword == "./" || curword == "../" |
| 7761 | let ctr= ctr + 1 |
| 7762 | continue |
| 7763 | endif |
| 7764 | let ok= s:NetrwLocalRmFile(a:path,curword,all) |
| 7765 | if ok =~ 'q\%[uit]' || ok == "no" |
| 7766 | break |
| 7767 | elseif ok =~ 'a\%[ll]' |
| 7768 | let all= 1 |
| 7769 | endif |
| 7770 | let ctr= ctr + 1 |
| 7771 | endwhile |
| 7772 | endif |
| 7773 | |
| 7774 | " refresh the directory |
| 7775 | " call Decho("bufname<".bufname("%").">") |
| 7776 | if bufname("%") != "NetrwMessage" |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7777 | keepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./')) |
| 7778 | keepj call netrw#NetrwRestorePosn(svpos) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7779 | endif |
| 7780 | |
| 7781 | " call Dret("s:NetrwLocalRm") |
| 7782 | endfun |
| 7783 | |
| 7784 | " --------------------------------------------------------------------- |
| 7785 | " s:NetrwLocalRmFile: remove file fname given the path {{{2 |
| 7786 | " Give confirmation prompt unless all==1 |
| 7787 | fun! s:NetrwLocalRmFile(path,fname,all) |
| 7788 | " call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all) |
| 7789 | |
| 7790 | let all= a:all |
| 7791 | let ok = "" |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7792 | keepj norm! 0 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7793 | let rmfile= s:ComposePath(a:path,a:fname) |
| 7794 | " call Decho("rmfile<".rmfile.">") |
| 7795 | |
| 7796 | if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$') |
| 7797 | " attempt to remove file |
| 7798 | " call Decho("attempt to remove file<".rmfile.">") |
| 7799 | if !all |
| 7800 | echohl Statement |
| 7801 | call inputsave() |
| 7802 | let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ") |
| 7803 | call inputrestore() |
| 7804 | echohl NONE |
| 7805 | if ok == "" |
| 7806 | let ok="no" |
| 7807 | endif |
| 7808 | " call Decho("response: ok<".ok.">") |
| 7809 | let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e') |
| 7810 | " call Decho("response: ok<".ok."> (after sub)") |
| 7811 | if ok =~ 'a\%[ll]' |
| 7812 | let all= 1 |
| 7813 | endif |
| 7814 | endif |
| 7815 | |
| 7816 | if all || ok =~ 'y\%[es]' || ok == "" |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7817 | let ret= s:NetrwDelete(rmfile) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7818 | " call Decho("errcode=".v:shell_error." ret=".ret) |
| 7819 | endif |
| 7820 | |
| 7821 | else |
| 7822 | " attempt to remove directory |
| 7823 | if !all |
| 7824 | echohl Statement |
| 7825 | call inputsave() |
| 7826 | let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ") |
| 7827 | call inputrestore() |
| 7828 | let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e') |
| 7829 | if ok == "" |
| 7830 | let ok="no" |
| 7831 | endif |
| 7832 | if ok =~ 'a\%[ll]' |
| 7833 | let all= 1 |
| 7834 | endif |
| 7835 | endif |
| 7836 | let rmfile= substitute(rmfile,'[\/]$','','e') |
| 7837 | |
| 7838 | if all || ok =~ 'y\%[es]' || ok == "" |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 7839 | " call Decho("1st attempt: system(netrw#WinPath(".g:netrw_local_rmdir.') '.shellescape(rmfile).')') |
| 7840 | call system(netrw#WinPath(g:netrw_local_rmdir).' '.shellescape(rmfile)) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7841 | " call Decho("v:shell_error=".v:shell_error) |
| 7842 | |
| 7843 | if v:shell_error != 0 |
| 7844 | " call Decho("2nd attempt to remove directory<".rmfile.">") |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7845 | let errcode= s:NetrwDelete(rmfile) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7846 | " call Decho("errcode=".errcode) |
| 7847 | |
| 7848 | if errcode != 0 |
| 7849 | if has("unix") |
| 7850 | " call Decho("3rd attempt to remove directory<".rmfile.">") |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7851 | call system("rm ".shellescape(rmfile)) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7852 | if v:shell_error != 0 && !exists("g:netrw_quiet") |
| 7853 | call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",34) |
| 7854 | let ok="no" |
| 7855 | endif |
| 7856 | elseif !exists("g:netrw_quiet") |
| 7857 | call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",35) |
| 7858 | let ok="no" |
| 7859 | endif |
| 7860 | endif |
| 7861 | endif |
| 7862 | endif |
| 7863 | endif |
| 7864 | |
| 7865 | " call Dret("s:NetrwLocalRmFile ".ok) |
| 7866 | return ok |
| 7867 | endfun |
| 7868 | |
| 7869 | " --------------------------------------------------------------------- |
| 7870 | " s:NetrwLocalRename: rename a remote file or directory {{{2 |
| 7871 | fun! s:NetrwLocalRename(path) range |
| 7872 | " call Dfunc("NetrwLocalRename(path<".a:path.">)") |
| 7873 | |
| 7874 | " preparation for removing multiple files/directories |
| 7875 | let ctr = a:firstline |
| 7876 | let svpos= netrw#NetrwSavePosn() |
| 7877 | |
| 7878 | " rename files given by the markfilelist |
| 7879 | if exists("s:netrwmarkfilelist_{bufnr('%')}") |
| 7880 | for oldname in s:netrwmarkfilelist_{bufnr("%")} |
| 7881 | " call Decho("oldname<".oldname.">") |
| 7882 | if exists("subfrom") |
| 7883 | let newname= substitute(oldname,subfrom,subto,'') |
| 7884 | " call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">") |
| 7885 | else |
| 7886 | call inputsave() |
| 7887 | let newname= input("Moving ".oldname." to : ",oldname) |
| 7888 | call inputrestore() |
| 7889 | if newname =~ '^s/' |
| 7890 | let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','') |
| 7891 | let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','') |
| 7892 | " call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">") |
| 7893 | let newname = substitute(oldname,subfrom,subto,'') |
| 7894 | endif |
| 7895 | endif |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 7896 | call rename(oldname,newname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7897 | endfor |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 7898 | call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7899 | |
| 7900 | else |
| 7901 | |
| 7902 | " attempt to rename files/directories |
| 7903 | while ctr <= a:lastline |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7904 | exe "keepj ".ctr |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7905 | |
| 7906 | " sanity checks |
| 7907 | if line(".") < w:netrw_bannercnt |
| 7908 | let ctr= ctr + 1 |
| 7909 | continue |
| 7910 | endif |
| 7911 | let curword= s:NetrwGetWord() |
| 7912 | if curword == "./" || curword == "../" |
| 7913 | let ctr= ctr + 1 |
| 7914 | continue |
| 7915 | endif |
| 7916 | |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7917 | keepj norm! 0 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7918 | let oldname= s:ComposePath(a:path,curword) |
| 7919 | " call Decho("oldname<".oldname.">") |
| 7920 | |
| 7921 | call inputsave() |
| 7922 | let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e')) |
| 7923 | call inputrestore() |
| 7924 | |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 7925 | call rename(oldname,newname) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7926 | " call Decho("renaming <".oldname."> to <".newname.">") |
| 7927 | |
| 7928 | let ctr= ctr + 1 |
| 7929 | endwhile |
| 7930 | endif |
| 7931 | |
| 7932 | " refresh the directory |
| 7933 | " call Decho("refresh the directory listing") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 7934 | keepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./')) |
| 7935 | keepj call netrw#NetrwRestorePosn(svpos) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7936 | |
| 7937 | " call Dret("NetrwLocalRename") |
| 7938 | endfun |
| 7939 | |
| 7940 | " --------------------------------------------------------------------- |
| 7941 | " s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2 |
| 7942 | " |
| 7943 | " g:netrw_ Directory Is |
| 7944 | " fastbrowse Local Remote |
| 7945 | " slow 0 D D D=Deleting a buffer implies it will not be re-used (slow) |
| 7946 | " med 1 D H H=Hiding a buffer implies it may be re-used (fast) |
| 7947 | " fast 2 H H |
| 7948 | " |
| 7949 | " Deleting a buffer means that it will be re-loaded when examined, hence "slow". |
| 7950 | " Hiding a buffer means that it will be re-used when examined, hence "fast". |
| 7951 | " (re-using a buffer may not be as accurate) |
| 7952 | fun! s:LocalFastBrowser() |
| 7953 | " call Dfunc("LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse) |
| 7954 | |
| 7955 | " initialize browselist, a list of buffer numbers that the local browser has used |
| 7956 | if !exists("s:netrw_browselist") |
| 7957 | " call Decho("initialize s:netrw_browselist") |
| 7958 | let s:netrw_browselist= [] |
| 7959 | endif |
| 7960 | |
| 7961 | " append current buffer to fastbrowse list |
| 7962 | if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1] |
| 7963 | " call Decho("appendng current buffer to browselist") |
| 7964 | call add(s:netrw_browselist,bufnr("%")) |
| 7965 | " call Decho("browselist=".string(s:netrw_browselist)) |
| 7966 | endif |
| 7967 | |
| 7968 | " enable autocmd events to handle refreshing/removing local browser buffers |
| 7969 | " If local browse buffer is currently showing: refresh it |
| 7970 | " If local browse buffer is currently hidden : wipe it |
| 7971 | if !exists("s:netrw_browser_shellcmd") && g:netrw_fastbrowse <= 1 |
| 7972 | " call Decho("setting up local-browser shell command refresh") |
| 7973 | let s:netrw_browser_shellcmd= 1 |
| 7974 | augroup AuNetrwShellCmd |
| 7975 | au! |
| 7976 | if (has("win32") || has("win95") || has("win64") || has("win16")) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 7977 | " call Decho("autocmd: ShellCmdPost * call s:LocalBrowseShellCmdRefresh()") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7978 | au ShellCmdPost * call s:LocalBrowseShellCmdRefresh() |
| 7979 | else |
| 7980 | au ShellCmdPost,FocusGained * call s:LocalBrowseShellCmdRefresh() |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 7981 | " call Decho("autocmd: ShellCmdPost,FocusGained * call s:LocalBrowseShellCmdRefresh()") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 7982 | endif |
| 7983 | augroup END |
| 7984 | endif |
| 7985 | |
| 7986 | " user must have changed fastbrowse to its fast setting, so remove |
| 7987 | " the associated autocmd events |
| 7988 | if g:netrw_fastbrowse > 1 && exists("s:netrw_browser_shellcmd") |
| 7989 | " call Decho("remove AuNetrwShellCmd autcmd group") |
| 7990 | unlet s:netrw_browser_shellcmd |
| 7991 | augroup AuNetrwShellCmd |
| 7992 | au! |
| 7993 | augroup END |
| 7994 | augroup! AuNetrwShellCmd |
| 7995 | endif |
| 7996 | |
| 7997 | " call Dret("LocalFastBrowser : browselist<".string(s:netrw_browselist).">") |
| 7998 | endfun |
| 7999 | |
| 8000 | " --------------------------------------------------------------------- |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8001 | " netrw#FileUrlRead: handles reading file://* files {{{2 |
| 8002 | " Should accept: file://localhost/etc/fstab |
| 8003 | " file:///etc/fstab |
| 8004 | " file:///c:/WINDOWS/clock.avi |
| 8005 | " file:///c|/WINDOWS/clock.avi |
| 8006 | " file://localhost/c:/WINDOWS/clock.avi |
| 8007 | " file://localhost/c|/WINDOWS/clock.avi |
| 8008 | " file://c:/foo.txt |
| 8009 | " file:///c:/foo.txt |
| 8010 | " and %XX (where X is [0-9a-fA-F] is converted into a character with the given hexadecimal value |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8011 | fun! netrw#FileUrlRead(fname) |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8012 | " call Dfunc("netrw#FileUrlRead(fname<".a:fname.">)") |
| 8013 | let fname = a:fname |
| 8014 | if fname =~ '^file://localhost/' |
| 8015 | " call Decho('converting file://localhost/ -to- file:///') |
| 8016 | let fname= substitute(fname,'^file://localhost/','file:///','') |
| 8017 | " call Decho("fname<".fname.">") |
| 8018 | endif |
| 8019 | if (has("win32") || has("win95") || has("win64") || has("win16")) |
| 8020 | if fname =~ '^file:///\=\a[|:]/' |
| 8021 | " call Decho('converting file:///\a|/ -to- file://\a:/') |
| 8022 | let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','') |
| 8023 | " call Decho("fname<".fname.">") |
| 8024 | endif |
| 8025 | endif |
| 8026 | let fname2396 = netrw#RFC2396(fname) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8027 | let fname2396e= fnameescape(fname2396) |
| 8028 | let plainfname= substitute(fname2396,'file://\(.*\)','\1',"") |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8029 | if (has("win32") || has("win95") || has("win64") || has("win16")) |
| 8030 | " call Decho("windows exception for plainfname") |
| 8031 | if plainfname =~ '^/\+\a:' |
| 8032 | " call Decho('removing leading "/"s') |
| 8033 | let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','') |
| 8034 | endif |
| 8035 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8036 | " call Decho("fname2396<".fname2396.">") |
| 8037 | " call Decho("plainfname<".plainfname.">") |
| 8038 | exe "sil doau BufReadPre ".fname2396e |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8039 | exe 'keepj r '.plainfname |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8040 | exe 'file! '.plainfname |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8041 | keepj 1d |
| 8042 | setl nomod |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8043 | " call Dret("netrw#FileUrlRead") |
| 8044 | exe "sil doau BufReadPost ".fname2396e |
| 8045 | endfun |
| 8046 | |
| 8047 | " --------------------------------------------------------------------- |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8048 | " Support Functions: {{{1 |
| 8049 | |
Bram Moolenaar | 488c651 | 2005-08-11 20:09:58 +0000 | [diff] [blame] | 8050 | " --------------------------------------------------------------------- |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8051 | " netrw#ErrorMsg: {{{2 |
| 8052 | " 0=note = s:NOTE |
| 8053 | " 1=warning = s:WARNING |
| 8054 | " 2=error = s:ERROR |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 8055 | " Apr 18, 2011 : max errnum currently is 78 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8056 | fun! netrw#ErrorMsg(level,msg,errnum) |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame] | 8057 | " call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8058 | |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame] | 8059 | if a:level == 1 |
| 8060 | let level= "**warning** (netrw) " |
| 8061 | elseif a:level == 2 |
| 8062 | let level= "**error** (netrw) " |
| 8063 | else |
| 8064 | let level= "**note** (netrw) " |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8065 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8066 | " call Decho("level=".level) |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame] | 8067 | |
| 8068 | if g:netrw_use_errorwindow |
| 8069 | " (default) netrw creates a one-line window to show error/warning |
| 8070 | " messages (reliably displayed) |
| 8071 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8072 | " record current window number for NetrwRestorePosn()'s benefit |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame] | 8073 | let s:winBeforeErr= winnr() |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8074 | " call Decho("s:winBeforeErr=".s:winBeforeErr) |
| 8075 | |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame] | 8076 | " getting messages out reliably is just plain difficult! |
| 8077 | " This attempt splits the current window, creating a one line window. |
| 8078 | if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8079 | " call Decho("write to NetrwMessage buffer") |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame] | 8080 | exe bufwinnr("NetrwMessage")."wincmd w" |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8081 | " call Decho("setl ma noro") |
| 8082 | setl ma noro |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8083 | keepj call setline(line("$")+1,level.a:msg) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8084 | keepj $ |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame] | 8085 | else |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8086 | " call Decho("create a NetrwMessage buffer window") |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame] | 8087 | bo 1split |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 8088 | call s:NetrwEnew() |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8089 | keepj call s:NetrwSafeOptions() |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8090 | setl bt=nofile |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8091 | keepj file NetrwMessage |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8092 | " call Decho("setlocal ma noro") |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8093 | setl ma noro |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame] | 8094 | call setline(line("$"),level.a:msg) |
| 8095 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8096 | " call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr()) |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame] | 8097 | if &fo !~ '[ta]' |
| 8098 | syn clear |
| 8099 | syn match netrwMesgNote "^\*\*note\*\*" |
| 8100 | syn match netrwMesgWarning "^\*\*warning\*\*" |
| 8101 | syn match netrwMesgError "^\*\*error\*\*" |
| 8102 | hi link netrwMesgWarning WarningMsg |
| 8103 | hi link netrwMesgError Error |
| 8104 | endif |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8105 | setl noma ro bh=wipe |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame] | 8106 | |
| 8107 | else |
| 8108 | " (optional) netrw will show messages using echomsg. Even if the |
| 8109 | " message doesn't appear, at least it'll be recallable via :messages |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8110 | " redraw! |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame] | 8111 | if a:level == s:WARNING |
| 8112 | echohl WarningMsg |
| 8113 | elseif a:level == s:ERROR |
| 8114 | echohl Error |
| 8115 | endif |
| 8116 | echomsg level.a:msg |
| 8117 | " call Decho("echomsg ***netrw*** ".a:msg) |
| 8118 | echohl None |
| 8119 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8120 | |
| 8121 | " call Dret("netrw#ErrorMsg") |
| 8122 | endfun |
| 8123 | |
| 8124 | " --------------------------------------------------------------------- |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8125 | " netrw#NetrwRestorePosn: restores the cursor and file position as saved by NetrwSavePosn() {{{2 |
| 8126 | fun! netrw#NetrwRestorePosn(...) |
| 8127 | " 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)) |
| 8128 | let eikeep= &ei |
| 8129 | set ei=all |
| 8130 | if expand("%") == "NetrwMessage" |
| 8131 | exe s:winBeforeErr."wincmd w" |
| 8132 | endif |
| 8133 | |
| 8134 | if a:0 > 0 |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8135 | exe "keepj ".a:1 |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8136 | endif |
| 8137 | |
| 8138 | " restore window |
| 8139 | if exists("w:netrw_winnr") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8140 | " call Decho("restore window: exe sil! ".w:netrw_winnr."wincmd w") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8141 | exe "sil! ".w:netrw_winnr."wincmd w" |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8142 | endif |
| 8143 | if v:shell_error == 0 |
| 8144 | " as suggested by Bram M: redraw on no error |
| 8145 | " allows protocol error messages to remain visible |
| 8146 | " redraw! |
| 8147 | endif |
| 8148 | |
| 8149 | " restore top-of-screen line |
| 8150 | if exists("w:netrw_hline") |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8151 | " call Decho("restore topofscreen: exe keepj norm! ".w:netrw_hline."G0z") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8152 | exe "keepj norm! ".w:netrw_hline."G0z\<CR>" |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8153 | endif |
| 8154 | |
| 8155 | " restore position |
| 8156 | if exists("w:netrw_line") && exists("w:netrw_col") |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8157 | " call Decho("restore posn: exe keepj norm! ".w:netrw_line."G0".w:netrw_col."|") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8158 | exe "keepj norm! ".w:netrw_line."G0".w:netrw_col."\<bar>" |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8159 | endif |
| 8160 | |
| 8161 | let &ei= eikeep |
| 8162 | " call Dret("netrw#NetrwRestorePosn") |
| 8163 | endfun |
| 8164 | |
| 8165 | " --------------------------------------------------------------------- |
| 8166 | " netrw#NetrwSavePosn: saves position of cursor on screen {{{2 |
| 8167 | fun! netrw#NetrwSavePosn() |
| 8168 | " call Dfunc("netrw#NetrwSavePosn()") |
| 8169 | " Save current line and column |
| 8170 | let w:netrw_winnr= winnr() |
| 8171 | let w:netrw_line = line(".") |
| 8172 | let w:netrw_col = virtcol(".") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 8173 | " call Decho("currently, win#".w:netrw_winnr." line#".w:netrw_line." col#".w:netrw_col) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8174 | |
| 8175 | " Save top-of-screen line |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8176 | keepj norm! H0 |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8177 | let w:netrw_hline= line(".") |
| 8178 | |
| 8179 | " set up string holding position parameters |
| 8180 | 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 |
| 8181 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8182 | keepj call netrw#NetrwRestorePosn() |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8183 | " call Dret("netrw#NetrwSavePosn : winnr=".w:netrw_winnr." line=".w:netrw_line." col=".w:netrw_col." hline=".w:netrw_hline) |
| 8184 | return ret |
| 8185 | endfun |
| 8186 | |
| 8187 | " ------------------------------------------------------------------------ |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8188 | " netrw#RFC2396: converts %xx into characters {{{2 |
| 8189 | fun! netrw#RFC2396(fname) |
| 8190 | " call Dfunc("netrw#RFC2396(fname<".a:fname.">)") |
| 8191 | let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t") |
| 8192 | " call Dret("netrw#RFC2396 ".fname) |
| 8193 | return fname |
| 8194 | endfun |
| 8195 | |
| 8196 | " --------------------------------------------------------------------- |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8197 | " s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2 |
| 8198 | fun! s:ComposePath(base,subdir) |
| 8199 | " call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)") |
| 8200 | |
| 8201 | if(has("amiga")) |
| 8202 | " call Decho("amiga") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 8203 | let ec = a:base[s:Strlen(a:base)-1] |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8204 | if ec != '/' && ec != ':' |
| 8205 | let ret = a:base . "/" . a:subdir |
| 8206 | else |
| 8207 | let ret = a:base . a:subdir |
| 8208 | endif |
| 8209 | |
| 8210 | elseif a:subdir =~ '^\a:[/\\][^/\\]' && (has("win32") || has("win95") || has("win64") || has("win16")) |
| 8211 | " call Decho("windows") |
| 8212 | let ret= a:subdir |
| 8213 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 8214 | elseif a:base =~ '^\a:[/\\][^/\\]' && (has("win32") || has("win95") || has("win64") || has("win16")) |
| 8215 | " call Decho("windows") |
| 8216 | if a:base =~ '[/\\]$' |
| 8217 | let ret= a:base.a:subdir |
| 8218 | else |
| 8219 | let ret= a:base."/".a:subdir |
| 8220 | endif |
| 8221 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8222 | elseif a:base =~ '^\a\+://' |
| 8223 | " call Decho("remote linux/macos") |
| 8224 | let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','') |
| 8225 | let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','') |
| 8226 | if a:subdir == '../' |
| 8227 | if curpath =~ '[^/]/[^/]\+/$' |
| 8228 | let curpath= substitute(curpath,'[^/]\+/$','','') |
| 8229 | else |
| 8230 | let curpath="" |
| 8231 | endif |
| 8232 | let ret= urlbase.curpath |
| 8233 | else |
| 8234 | let ret= urlbase.curpath.a:subdir |
| 8235 | endif |
| 8236 | " call Decho("urlbase<".urlbase.">") |
| 8237 | " call Decho("curpath<".curpath.">") |
| 8238 | " call Decho("ret<".ret.">") |
| 8239 | |
| 8240 | else |
| 8241 | " call Decho("local linux/macos") |
| 8242 | let ret = substitute(a:base."/".a:subdir,"//","/","g") |
| 8243 | if a:base =~ '^//' |
| 8244 | " keeping initial '//' for the benefit of network share listing support |
| 8245 | let ret= '/'.ret |
| 8246 | endif |
| 8247 | let ret= simplify(ret) |
| 8248 | endif |
| 8249 | |
| 8250 | " call Dret("s:ComposePath ".ret) |
| 8251 | return ret |
| 8252 | endfun |
| 8253 | |
| 8254 | " --------------------------------------------------------------------- |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8255 | " s:FileReadable: o/s independent filereadable {{{2 |
| 8256 | fun! s:FileReadable(fname) |
| 8257 | " call Dfunc("s:FileReadable(fname<".a:fname.">)") |
| 8258 | |
| 8259 | if g:netrw_cygwin |
| 8260 | let ret= filereadable(substitute(a:fname,'/cygdrive/\(.\)','\1:/','')) |
| 8261 | else |
| 8262 | let ret= filereadable(a:fname) |
| 8263 | endif |
| 8264 | |
| 8265 | " call Dret("s:FileReadable ".ret) |
| 8266 | return ret |
| 8267 | endfun |
| 8268 | |
| 8269 | " --------------------------------------------------------------------- |
| 8270 | " s:GetTempfile: gets a tempname that'll work for various o/s's {{{2 |
| 8271 | " Places correct suffix on end of temporary filename, |
| 8272 | " using the suffix provided with fname |
| 8273 | fun! s:GetTempfile(fname) |
| 8274 | " call Dfunc("s:GetTempfile(fname<".a:fname.">)") |
| 8275 | |
| 8276 | if !exists("b:netrw_tmpfile") |
| 8277 | " get a brand new temporary filename |
| 8278 | let tmpfile= tempname() |
| 8279 | " call Decho("tmpfile<".tmpfile."> : from tempname()") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8280 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8281 | let tmpfile= substitute(tmpfile,'\','/','ge') |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8282 | " call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8283 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8284 | " sanity check -- does the temporary file's directory exist? |
| 8285 | if !isdirectory(substitute(tmpfile,'[^/]\+$','','e')) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8286 | " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8287 | keepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8288 | " call Dret("s:GetTempfile getcwd<".getcwd().">") |
| 8289 | return "" |
| 8290 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8291 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8292 | " let netrw#NetSource() know about the tmpfile |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 8293 | let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#NetrwBrowseX() |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8294 | " call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8295 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8296 | " o/s dependencies |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8297 | if g:netrw_cygwin != 0 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8298 | let tmpfile = substitute(tmpfile,'^\(\a\):','/cygdrive/\1','e') |
| 8299 | elseif has("win32") || has("win95") || has("win64") || has("win16") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8300 | if !exists("+shellslash") || !&ssl |
| 8301 | let tmpfile = substitute(tmpfile,'/','\','g') |
| 8302 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8303 | else |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8304 | let tmpfile = tmpfile |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8305 | endif |
| 8306 | let b:netrw_tmpfile= tmpfile |
| 8307 | " call Decho("o/s dependent fixed tempname<".tmpfile.">") |
| 8308 | else |
| 8309 | " re-use temporary filename |
| 8310 | let tmpfile= b:netrw_tmpfile |
| 8311 | " call Decho("tmpfile<".tmpfile."> re-using") |
| 8312 | endif |
| 8313 | |
| 8314 | " use fname's suffix for the temporary file |
| 8315 | if a:fname != "" |
| 8316 | if a:fname =~ '\.[^./]\+$' |
| 8317 | " call Decho("using fname<".a:fname.">'s suffix") |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 8318 | if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$' |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8319 | let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e') |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 8320 | elseif a:fname =~ '.txz$' |
| 8321 | let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e') |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8322 | else |
| 8323 | let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e') |
| 8324 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8325 | " call Decho("suffix<".suffix.">") |
| 8326 | let tmpfile= substitute(tmpfile,'\.tmp$','','e') |
| 8327 | " call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)") |
| 8328 | let tmpfile .= suffix |
| 8329 | " call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">") |
| 8330 | let s:netrw_tmpfile= tmpfile " supports netrw#NetSource() |
| 8331 | endif |
| 8332 | endif |
| 8333 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8334 | " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8335 | " call Dret("s:GetTempfile <".tmpfile.">") |
| 8336 | return tmpfile |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8337 | endfun |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8338 | |
| 8339 | " --------------------------------------------------------------------- |
| 8340 | " s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2 |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8341 | " a correct command for use with a system() call |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8342 | fun! s:MakeSshCmd(sshcmd) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8343 | " call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8344 | let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user.s:machine,'') |
| 8345 | if exists("g:netrw_port") && g:netrw_port != "" |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame] | 8346 | let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'') |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8347 | elseif exists("s:port") && s:port != "" |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame] | 8348 | let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'') |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8349 | else |
| 8350 | let sshcmd= substitute(sshcmd,"USEPORT ",'','') |
| 8351 | endif |
| 8352 | " call Dret("s:MakeSshCmd <".sshcmd.">") |
| 8353 | return sshcmd |
| 8354 | endfun |
| 8355 | |
| 8356 | " --------------------------------------------------------------------- |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8357 | " s:NetrwBMShow: {{{2 |
| 8358 | fun! s:NetrwBMShow() |
| 8359 | " call Dfunc("s:NetrwBMShow()") |
| 8360 | redir => bmshowraw |
| 8361 | menu |
| 8362 | redir END |
| 8363 | let bmshowlist = split(bmshowraw,'\n') |
| 8364 | if bmshowlist != [] |
| 8365 | let bmshowfuncs= filter(bmshowlist,'v:val =~ "<SNR>\\d\\+_BMShow()"') |
| 8366 | if bmshowfuncs != [] |
| 8367 | let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','') |
| 8368 | if bmshowfunc =~ '^call.*BMShow()' |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8369 | exe "sil! keepj ".bmshowfunc |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8370 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8371 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8372 | endif |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8373 | " call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">") |
| 8374 | endfun |
| 8375 | |
| 8376 | " --------------------------------------------------------------------- |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8377 | " s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2 |
| 8378 | fun! s:NetrwCursor() |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8379 | if !exists("w:netrw_liststyle") |
| 8380 | let w:netrw_liststyle= g:netrw_liststyle |
| 8381 | endif |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8382 | " 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 Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8383 | |
| 8384 | if &ft != "netrw" |
| 8385 | " if the current window isn't a netrw directory listing window, then use user cursorline/column |
| 8386 | " settings. Affects when netrw is used to read/write a file using scp/ftp/etc. |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8387 | " call Decho("case ft!=netrw: use user cul,cuc") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8388 | let &l:cursorline = s:netrw_usercul |
| 8389 | let &l:cursorcolumn = s:netrw_usercuc |
| 8390 | |
| 8391 | elseif g:netrw_cursor == 4 |
| 8392 | " all styles: cursorline, cursorcolumn |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8393 | " call Decho("case g:netrw_cursor==4: setl cul cuc") |
| 8394 | setl cursorline |
| 8395 | setl cursorcolumn |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8396 | |
| 8397 | elseif g:netrw_cursor == 3 |
| 8398 | " thin-long-tree: cursorline, user's cursorcolumn |
| 8399 | " wide : cursorline, cursorcolumn |
| 8400 | if w:netrw_liststyle == s:WIDELIST |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8401 | " call Decho("case g:netrw_cursor==3 and wide: setlocal cul cuc") |
| 8402 | setl cursorline |
| 8403 | setl cursorcolumn |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8404 | else |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8405 | " call Decho("case g:netrw_cursor==3 and not wide: setlocal cul (use user's cuc)") |
| 8406 | setl cursorline |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8407 | let &l:cursorcolumn = s:netrw_usercuc |
| 8408 | endif |
| 8409 | |
| 8410 | elseif g:netrw_cursor == 2 |
| 8411 | " thin-long-tree: cursorline, user's cursorcolumn |
| 8412 | " wide : cursorline, user's cursorcolumn |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8413 | " call Decho("case g:netrw_cursor==2: setlocal cuc (use user's cul)") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8414 | let &l:cursorcolumn = s:netrw_usercuc |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8415 | setl cursorline |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8416 | |
| 8417 | elseif g:netrw_cursor == 1 |
| 8418 | " thin-long-tree: user's cursorline, user's cursorcolumn |
| 8419 | " wide : cursorline, user's cursorcolumn |
| 8420 | let &l:cursorcolumn = s:netrw_usercuc |
| 8421 | if w:netrw_liststyle == s:WIDELIST |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8422 | " call Decho("case g:netrw_cursor==2 and wide: setlocal cul (use user's cuc)") |
| 8423 | set cursorline |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8424 | else |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8425 | " call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8426 | let &l:cursorline = s:netrw_usercul |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8427 | endif |
| 8428 | |
| 8429 | else |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8430 | " all styles: user's cursorline, user's cursorcolumn |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8431 | " call Decho("default: (use user's cul,cuc)") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8432 | let &l:cursorline = s:netrw_usercul |
| 8433 | let &l:cursorcolumn = s:netrw_usercuc |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8434 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8435 | |
| 8436 | " call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8437 | endfun |
| 8438 | |
| 8439 | " --------------------------------------------------------------------- |
| 8440 | " s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2 |
| 8441 | fun! s:RestoreCursorline() |
| 8442 | " call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%")) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8443 | if exists("s:netrw_usercul") |
| 8444 | let &l:cursorline = s:netrw_usercul |
| 8445 | endif |
| 8446 | if exists("s:netrw_usercuc") |
| 8447 | let &l:cursorcolumn = s:netrw_usercuc |
| 8448 | endif |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8449 | " call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn) |
| 8450 | endfun |
| 8451 | |
| 8452 | " --------------------------------------------------------------------- |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8453 | " s:NetrwDelete: Deletes a file. {{{2 |
| 8454 | " Uses Steve Hall's idea to insure that Windows paths stay |
| 8455 | " acceptable. No effect on Unix paths. |
| 8456 | " Examples of use: let result= s:NetrwDelete(path) |
| 8457 | fun! s:NetrwDelete(path) |
| 8458 | " call Dfunc("s:NetrwDelete(path<".a:path.">)") |
| 8459 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 8460 | let path = netrw#WinPath(a:path) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8461 | if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16")) |
| 8462 | if exists("+shellslash") |
| 8463 | let sskeep= &shellslash |
| 8464 | setlocal noshellslash |
| 8465 | let result = delete(path) |
| 8466 | let &shellslash = sskeep |
| 8467 | else |
| 8468 | " call Decho("exe let result= ".a:cmd."('".path."')") |
| 8469 | let result= delete(path) |
| 8470 | endif |
| 8471 | else |
| 8472 | " call Decho("let result= delete(".path.")") |
| 8473 | let result= delete(path) |
| 8474 | endif |
| 8475 | if result < 0 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8476 | keepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8477 | endif |
| 8478 | |
| 8479 | " call Dret("s:NetrwDelete ".result) |
| 8480 | return result |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8481 | endfun |
| 8482 | |
| 8483 | " --------------------------------------------------------------------- |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8484 | " s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 8485 | fun! s:NetrwEnew(...) |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8486 | " call Dfunc("s:NetrwEnew() a:0=".a:0." bufnr($)=".bufnr("$")) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 8487 | " call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8488 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8489 | " grab a function-local-variable copy of buffer variables |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8490 | " call Decho("make function-local copy of netrw variables") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8491 | if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif |
| 8492 | if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif |
| 8493 | if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif |
| 8494 | if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif |
| 8495 | if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif |
| 8496 | if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif |
| 8497 | if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif |
| 8498 | if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif |
| 8499 | if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif |
| 8500 | if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif |
| 8501 | if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif |
| 8502 | if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif |
| 8503 | if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif |
| 8504 | if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif |
| 8505 | if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif |
| 8506 | if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif |
| 8507 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8508 | keepj call s:NetrwOptionRestore("w:") |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8509 | " call Decho("generate a buffer with keepjumps keepalt enew!") |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 8510 | let netrw_keepdiff= &l:diff |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8511 | " COMBAK: Benzinger: using tree mode, vim -o Foo/ file shows Foo/ Foo/ instead. Place return here, problem goes away (beeps result, but who knows) |
| 8512 | " call Dredir("Benzinger 1:","ls!") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8513 | keepj keepalt enew! |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8514 | " call Dredir("Benzinger 2:","ls!") |
| 8515 | " COMBAK: Benzinger: using tree mode, vim -o Foo/ file shows Foo/ Foo/ instead. Place return here, problem remains. |
Bram Moolenaar | 5ac3b1a | 2010-07-27 22:50:36 +0200 | [diff] [blame] | 8516 | let &l:diff= netrw_keepdiff |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8517 | " call Decho("bufnr($)=".bufnr("$")) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8518 | keepj call s:NetrwOptionSave("w:") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8519 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8520 | " copy function-local-variables to buffer variable equivalents |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8521 | " call Decho("copy function-local variables back to buffer netrw variables") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8522 | if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif |
| 8523 | if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif |
| 8524 | if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif |
| 8525 | if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif |
| 8526 | if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif |
| 8527 | if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif |
| 8528 | if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif |
| 8529 | if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif |
| 8530 | if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif |
| 8531 | if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif |
| 8532 | if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif |
| 8533 | if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif |
| 8534 | if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif |
| 8535 | if exists("netrw_method") |let b:netrw_method = netrw_method |endif |
| 8536 | if exists("netrw_option") |let b:netrw_option = netrw_option |endif |
| 8537 | if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif |
| 8538 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 8539 | if a:0 > 0 |
| 8540 | let b:netrw_curdir= a:1 |
| 8541 | if b:netrw_curdir =~ '/$' |
| 8542 | if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST |
| 8543 | file NetrwTreeListing |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8544 | set bt=nowrite noswf |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8545 | nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr> |
| 8546 | nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr> |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 8547 | else |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8548 | exe "sil! keepalt file ".fnameescape(b:netrw_curdir) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 8549 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8550 | endif |
| 8551 | endif |
| 8552 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8553 | " call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#").">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8554 | endfun |
| 8555 | |
| 8556 | " ------------------------------------------------------------------------ |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8557 | " s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2 |
| 8558 | " changed sorting, etc. Also see s:NetrwRestoreWordPosn(). |
| 8559 | fun! s:NetrwSaveWordPosn() |
| 8560 | " call Dfunc("NetrwSaveWordPosn()") |
| 8561 | let s:netrw_saveword= '^'.fnameescape(getline('.')).'$' |
| 8562 | " call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">") |
| 8563 | endfun |
| 8564 | |
| 8565 | " --------------------------------------------------------------------- |
| 8566 | " s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2 |
| 8567 | " changed sorting, etc. Also see s:NetrwSaveWordPosn(). |
| 8568 | fun! s:NetrwRestoreWordPosn() |
| 8569 | " call Dfunc("NetrwRestoreWordPosn()") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8570 | sil! call search(s:netrw_saveword,'w') |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8571 | " call Dret("NetrwRestoreWordPosn") |
| 8572 | endfun |
| 8573 | |
| 8574 | " --------------------------------------------------------------------- |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8575 | " s:RestoreBufVars: {{{2 |
| 8576 | fun! s:RestoreBufVars() |
| 8577 | " call Dfunc("s:RestoreBufVars()") |
| 8578 | |
| 8579 | if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif |
| 8580 | if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif |
| 8581 | if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif |
| 8582 | if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif |
| 8583 | if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif |
| 8584 | if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif |
| 8585 | |
| 8586 | " call Dret("s:RestoreBufVars") |
| 8587 | endfun |
| 8588 | |
| 8589 | " --------------------------------------------------------------------- |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8590 | " s:RemotePathAnalysis: {{{2 |
| 8591 | fun! s:RemotePathAnalysis(dirname) |
Bram Moolenaar | 251e191 | 2011-06-19 05:09:16 +0200 | [diff] [blame] | 8592 | " call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8593 | |
| 8594 | let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$' |
| 8595 | let s:method = substitute(a:dirname,dirpat,'\1','') |
| 8596 | let s:user = substitute(a:dirname,dirpat,'\2','') |
| 8597 | let s:machine = substitute(a:dirname,dirpat,'\3','') |
| 8598 | let s:port = substitute(a:dirname,dirpat,'\4','') |
| 8599 | let s:path = substitute(a:dirname,dirpat,'\5','') |
| 8600 | let s:fname = substitute(a:dirname,'^.*/\ze.','','') |
| 8601 | |
| 8602 | " call Decho("set up s:method <".s:method .">") |
| 8603 | " call Decho("set up s:user <".s:user .">") |
| 8604 | " call Decho("set up s:machine<".s:machine.">") |
| 8605 | " call Decho("set up s:port <".s:port.">") |
| 8606 | " call Decho("set up s:path <".s:path .">") |
| 8607 | " call Decho("set up s:fname <".s:fname .">") |
| 8608 | |
| 8609 | " call Dret("s:RemotePathAnalysis") |
| 8610 | endfun |
| 8611 | |
| 8612 | " --------------------------------------------------------------------- |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8613 | " s:RemoteSystem: runs a command on a remote host using ssh {{{2 |
| 8614 | " Returns status |
| 8615 | " Runs system() on |
| 8616 | " [cd REMOTEDIRPATH;] a:cmd |
| 8617 | " Note that it doesn't do shellescape(a:cmd)! |
| 8618 | fun! s:RemoteSystem(cmd) |
| 8619 | " call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)") |
| 8620 | if !executable(g:netrw_ssh_cmd) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8621 | keepj call netrw#ErrorMsg(s:ERROR,"g:netrw_ssh_cmd<".g:netrw_ssh_cmd."> is not executable!",52) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8622 | elseif !exists("b:netrw_curdir") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8623 | keepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8624 | else |
| 8625 | let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME") |
| 8626 | let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','') |
| 8627 | if remotedir != "" |
| 8628 | let cmd= cmd.' cd '.shellescape(remotedir).";" |
| 8629 | else |
| 8630 | let cmd= cmd.' ' |
| 8631 | endif |
| 8632 | let cmd= cmd.a:cmd |
| 8633 | " call Decho("call system(".cmd.")") |
| 8634 | let ret= system(cmd) |
| 8635 | endif |
| 8636 | " call Dret("s:RemoteSystem ".ret) |
| 8637 | return ret |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8638 | endfun |
| 8639 | |
| 8640 | " --------------------------------------------------------------------- |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8641 | " s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8642 | fun! s:RestoreWinVars() |
| 8643 | " call Dfunc("s:RestoreWinVars()") |
Bram Moolenaar | 488c651 | 2005-08-11 20:09:58 +0000 | [diff] [blame] | 8644 | if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8645 | if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif |
| 8646 | if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif |
| 8647 | if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif |
| 8648 | if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif |
| 8649 | if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif |
| 8650 | if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif |
| 8651 | if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif |
| 8652 | if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif |
| 8653 | if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif |
| 8654 | if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif |
| 8655 | if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif |
| 8656 | if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif |
Bram Moolenaar | 488c651 | 2005-08-11 20:09:58 +0000 | [diff] [blame] | 8657 | if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif |
| 8658 | if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8659 | if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif |
| 8660 | if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif |
| 8661 | if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif |
| 8662 | " call Dret("s:RestoreWinVars") |
Bram Moolenaar | 488c651 | 2005-08-11 20:09:58 +0000 | [diff] [blame] | 8663 | endfun |
| 8664 | |
Bram Moolenaar | 90cfdbe | 2005-08-12 19:59:19 +0000 | [diff] [blame] | 8665 | " --------------------------------------------------------------------- |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8666 | " s:Rexplore: implements returning from a buffer to a netrw directory {{{2 |
| 8667 | " |
| 8668 | " s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap |
| 8669 | " is true) and a command, :Rexplore, which call this function. |
| 8670 | " |
| 8671 | " s:nbcd_curpos_{bufnr('%')} is set up by s:NetrwBrowseChgDir() |
| 8672 | fun! s:NetrwRexplore(islocal,dirname) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8673 | " call Dfunc("s:NetrwRexplore() w:netrw_rexlocal=".w:netrw_rexlocal." w:netrw_rexdir<".w:netrw_rexdir.">") |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8674 | if !exists("w:netrw_rexlocal") |
| 8675 | " call Dret("s:NetrwRexplore() w:netrw_rexlocal doesn't exist") |
| 8676 | return |
| 8677 | endif |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8678 | if w:netrw_rexlocal |
| 8679 | keepj call netrw#LocalBrowseCheck(w:netrw_rexdir) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8680 | else |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8681 | keepj call s:NetrwBrowse(0,w:netrw_rexdir) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8682 | endif |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8683 | if exists("s:initbeval") |
| 8684 | set beval |
| 8685 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8686 | if exists("s:nbcd_curpos_{bufnr('%')}") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8687 | keepj call netrw#NetrwRestorePosn(s:nbcd_curpos_{bufnr('%')}) |
Bram Moolenaar | 1514667 | 2011-10-20 22:22:38 +0200 | [diff] [blame^] | 8688 | " unlet s:nbcd_curpos_{bufnr('%')} |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8689 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 8690 | if exists("s:explore_match") |
| 8691 | exe "2match netrwMarkFile /".s:explore_match."/" |
| 8692 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8693 | " call Dret("s:NetrwRexplore") |
| 8694 | endfun |
| 8695 | |
| 8696 | " --------------------------------------------------------------------- |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8697 | " s:SaveBufVars: {{{2 |
| 8698 | fun! s:SaveBufVars() |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 8699 | " call Dfunc("s:SaveBufVars() buf#".bufnr("%")) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8700 | |
| 8701 | if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif |
| 8702 | if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif |
| 8703 | if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif |
| 8704 | if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif |
| 8705 | if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif |
| 8706 | if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif |
| 8707 | |
| 8708 | " call Dret("s:SaveBufVars") |
| 8709 | endfun |
| 8710 | |
| 8711 | " --------------------------------------------------------------------- |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8712 | " s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8713 | fun! s:SaveWinVars() |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 8714 | " call Dfunc("s:SaveWinVars() win#".winnr()) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8715 | if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif |
| 8716 | if exists("w:netrw_col") |let s:col = w:netrw_col |endif |
| 8717 | if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif |
| 8718 | if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif |
| 8719 | if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif |
| 8720 | if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif |
| 8721 | if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif |
| 8722 | if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif |
| 8723 | if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif |
| 8724 | if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif |
| 8725 | if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif |
| 8726 | if exists("w:netrw_line") |let s:line = w:netrw_line |endif |
| 8727 | if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif |
| 8728 | if exists("w:netrw_method") |let s:method = w:netrw_method |endif |
| 8729 | if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif |
| 8730 | if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif |
| 8731 | if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif |
| 8732 | if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif |
| 8733 | " call Dret("s:SaveWinVars") |
| 8734 | endfun |
| 8735 | |
| 8736 | " --------------------------------------------------------------------- |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8737 | " s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2 |
Bram Moolenaar | 90cfdbe | 2005-08-12 19:59:19 +0000 | [diff] [blame] | 8738 | " To allow separate windows to have their own activities, such as |
| 8739 | " Explore **/pattern, several variables have been made window-oriented. |
| 8740 | " However, when the user splits a browser window (ex: ctrl-w s), these |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 8741 | " variables are not inherited by the new window. SetBufWinVars() and |
Bram Moolenaar | 90cfdbe | 2005-08-12 19:59:19 +0000 | [diff] [blame] | 8742 | " UseBufWinVars() get around that. |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 8743 | fun! s:SetBufWinVars() |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 8744 | " call Dfunc("s:SetBufWinVars() win#".winnr()) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8745 | if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif |
| 8746 | if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif |
| 8747 | if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif |
| 8748 | if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif |
| 8749 | if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif |
| 8750 | if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif |
| 8751 | if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif |
| 8752 | if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif |
| 8753 | if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif |
| 8754 | if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif |
| 8755 | " call Dret("s:SetBufWinVars") |
Bram Moolenaar | 90cfdbe | 2005-08-12 19:59:19 +0000 | [diff] [blame] | 8756 | endfun |
| 8757 | |
| 8758 | " --------------------------------------------------------------------- |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8759 | " s:SetRexDir: set directory for :Rexplore {{{2 |
| 8760 | fun! s:SetRexDir(islocal,dirname) |
| 8761 | " call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">)") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8762 | let w:netrw_rexdir = a:dirname |
| 8763 | let w:netrw_rexlocal = a:islocal |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8764 | " call Dret("s:SetRexDir") |
| 8765 | endfun |
| 8766 | |
| 8767 | " --------------------------------------------------------------------- |
| 8768 | " s:Strlen: this function returns the length of a string, even if its {{{2 |
| 8769 | " using two-byte etc characters. |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 8770 | " Solution from Nicolai Weibull, vim docs (:help strlen()), Tony Mechelynck, |
| 8771 | " and a bit from me. |
| 8772 | " if g:netrw_xstrlen is zero (default), then the builtin strlen() function is used. |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8773 | fun! s:Strlen(x) |
| 8774 | " call Dfunc("s:Strlen(x<".a:x.">") |
| 8775 | if g:netrw_xstrlen == 1 |
| 8776 | " number of codepoints (Latin a + combining circumflex is two codepoints) |
| 8777 | " (comment from TM, solution from NW) |
| 8778 | let ret= strlen(substitute(a:x,'.','c','g')) |
| 8779 | |
| 8780 | elseif g:netrw_xstrlen == 2 |
| 8781 | " number of spacing codepoints (Latin a + combining circumflex is one spacing |
| 8782 | " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.) |
| 8783 | " (comment from TM, solution from TM) |
| 8784 | let ret=strlen(substitute(a:x, '.\Z', 'x', 'g')) |
| 8785 | |
| 8786 | elseif g:netrw_xstrlen == 3 |
| 8787 | " virtual length (counting, for instance, tabs as anything between 1 and |
| 8788 | " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately |
| 8789 | " preceded by lam, one otherwise, etc.) |
| 8790 | " (comment from TM, solution from me) |
| 8791 | let modkeep= &mod |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8792 | exe "keepj norm! o\<esc>" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8793 | call setline(line("."),a:x) |
| 8794 | let ret= virtcol("$") - 1 |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8795 | keepj d |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8796 | let &mod= modkeep |
| 8797 | |
| 8798 | else |
| 8799 | " at least give a decent default |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 8800 | let ret= strlen(a:x) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8801 | endif |
| 8802 | " call Dret("s:Strlen ".ret) |
| 8803 | return ret |
| 8804 | endfun |
| 8805 | |
| 8806 | " --------------------------------------------------------------------- |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8807 | " s:TreeListMove: {{{2 |
| 8808 | fun! s:TreeListMove(dir) |
| 8809 | " call Dfunc("s:TreeListMove(dir<".a:dir.">)") |
| 8810 | let curline = getline('.') |
| 8811 | let prvline = (line(".") > 1)? getline(line(".")-1) : '' |
| 8812 | let nxtline = (line(".") < line("$"))? getline(line(".")+1) : '' |
| 8813 | let curindent= substitute(curline,'^\([| ]*\).\{-}$','\1','') |
| 8814 | let indentm1 = substitute(curindent,'^| ','','') |
| 8815 | " call Decho("prvline <".prvline."> #".line(".")-1) |
| 8816 | " call Decho("curline <".curline."> #".line(".")) |
| 8817 | " call Decho("nxtline <".nxtline."> #".line(".")+1) |
| 8818 | " call Decho("curindent<".curindent.">") |
| 8819 | " call Decho("indentm1 <".indentm1.">") |
| 8820 | |
| 8821 | if curline !~ '/$' |
| 8822 | " call Decho('regfile') |
| 8823 | if a:dir == '[' && prvline != '' |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8824 | keepj norm! 0 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8825 | let nl = search('^'.indentm1.'[^|]','bWe') " search backwards from regular file |
| 8826 | " call Decho("regfile srch back: ".nl) |
| 8827 | elseif a:dir == ']' && nxtline != '' |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8828 | keepj norm! $ |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8829 | let nl = search('^'.indentm1.'[^|]','We') " search forwards from regular file |
| 8830 | " call Decho("regfile srch fwd: ".nl) |
| 8831 | endif |
| 8832 | |
| 8833 | elseif a:dir == '[' && prvline != '' |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8834 | keepj norm! 0 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8835 | let curline= line(".") |
| 8836 | let nl = search('^'.curindent.'[^|]','bWe') " search backwards From directory, same indentation |
| 8837 | " call Decho("dir srch back ind: ".nl) |
| 8838 | if nl != 0 |
| 8839 | if line(".") == curline-1 |
| 8840 | let nl= search('^'.indentm1.'[^|]','bWe') " search backwards from directory, indentation - 1 |
| 8841 | " call Decho("dir srch back ind-1: ".nl) |
| 8842 | endif |
| 8843 | endif |
| 8844 | |
| 8845 | elseif a:dir == ']' && nxtline != '' |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 8846 | keepj norm! $ |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8847 | let curline = line(".") |
| 8848 | let nl = search('^'.curindent.'[^|]','We') " search forwards from directory, same indentation |
| 8849 | " call Decho("dir srch fwd ind: ".nl) |
| 8850 | if nl != 0 |
| 8851 | if line(".") == curline+1 |
| 8852 | let nl= search('^'.indentm1.'[^|]','We') " search forwards from directory, indentation - 1 |
| 8853 | " call Decho("dir srch fwd ind-1: ".nl) |
| 8854 | endif |
| 8855 | endif |
| 8856 | |
| 8857 | endif |
| 8858 | |
| 8859 | " call Dret("s:TreeListMove") |
| 8860 | endfun |
| 8861 | |
| 8862 | " --------------------------------------------------------------------- |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8863 | " s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2 |
| 8864 | " The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function |
| 8865 | " can't be called except via emenu. But due to locale, that menu line may not be called |
| 8866 | " Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway. |
| 8867 | fun! s:UpdateBuffersMenu() |
| 8868 | " call Dfunc("s:UpdateBuffersMenu()") |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8869 | if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8870 | try |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8871 | sil emenu Buffers.Refresh\ menu |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8872 | catch /^Vim\%((\a\+)\)\=:E/ |
| 8873 | let v:errmsg= "" |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8874 | sil keepj call s:NetrwBMShow() |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8875 | endtry |
| 8876 | endif |
| 8877 | " call Dret("s:UpdateBuffersMenu") |
| 8878 | endfun |
| 8879 | |
| 8880 | " --------------------------------------------------------------------- |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8881 | " s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2 |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 8882 | " Matching function to s:SetBufWinVars() |
Bram Moolenaar | 90cfdbe | 2005-08-12 19:59:19 +0000 | [diff] [blame] | 8883 | fun! s:UseBufWinVars() |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8884 | " call Dfunc("s:UseBufWinVars()") |
| 8885 | if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif |
Bram Moolenaar | 90cfdbe | 2005-08-12 19:59:19 +0000 | [diff] [blame] | 8886 | if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif |
| 8887 | if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif |
| 8888 | if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif |
| 8889 | if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif |
| 8890 | if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif |
| 8891 | if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif |
| 8892 | if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif |
| 8893 | if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif |
| 8894 | if exists("b:netrw_explore_list") && !exists("w:netrw_explore_list") |let w:netrw_explore_list = b:netrw_explore_list |endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 8895 | " call Dret("s:UseBufWinVars") |
Bram Moolenaar | 90cfdbe | 2005-08-12 19:59:19 +0000 | [diff] [blame] | 8896 | endfun |
| 8897 | |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 8898 | " --------------------------------------------------------------------- |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 8899 | " netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2 |
| 8900 | fun! netrw#WinPath(path) |
| 8901 | " call Dfunc("netrw#WinPath(path<".a:path.">)") |
| 8902 | if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && (has("win32") || has("win95") || has("win64") || has("win16")) |
| 8903 | " remove cygdrive prefix, if present |
| 8904 | let path = substitute(a:path,'/cygdrive/\(.\)','\1:','') |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8905 | " remove trailing slash (Win95) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 8906 | let path = substitute(path, '\(\\\|/\)$', '', 'g') |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8907 | " remove escaped spaces |
| 8908 | let path = substitute(path, '\ ', ' ', 'g') |
| 8909 | " convert slashes to backslashes |
| 8910 | let path = substitute(path, '/', '\', 'g') |
| 8911 | else |
| 8912 | let path= a:path |
| 8913 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 8914 | " call Dret("netrw#WinPath <".path.">") |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8915 | return path |
| 8916 | endfun |
| 8917 | |
| 8918 | " --------------------------------------------------------------------- |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 8919 | " Settings Restoration: {{{2 |
Bram Moolenaar | 83bab71 | 2005-08-01 21:58:57 +0000 | [diff] [blame] | 8920 | let &cpo= s:keepcpo |
| 8921 | unlet s:keepcpo |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 8922 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8923 | " ------------------------------------------------------------------------ |
Bram Moolenaar | 83bab71 | 2005-08-01 21:58:57 +0000 | [diff] [blame] | 8924 | " Modelines: {{{1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8925 | " vim:ts=8 fdm=marker |