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 | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 3 | " Date: May 05, 2007 |
| 4 | " Version: 109 |
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 | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 7 | " Copyright: Copyright (C) 1999-2007 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 |
| 12 | " *as is* and comes with no warranty of any kind, either |
| 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 | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 16 | " of this software. |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 17 | " COMBAK: worked with tmpfile s:GetTempname() in NetRead() NetWrite() |
| 18 | " !!NEEDS DEBUGGING && TESTING!!! |
| 19 | "redraw!|call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 20 | " |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 21 | " 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] | 22 | " (James 1:22 RSV) |
| 23 | " =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 24 | " Load Once: {{{1 |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 25 | if &cp || exists("g:loaded_netrw") |
| 26 | finish |
| 27 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 28 | if !exists("s:NOTE") |
| 29 | let s:NOTE = 0 |
| 30 | let s:WARNING = 1 |
| 31 | let s:ERROR = 2 |
| 32 | endif |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 33 | let g:loaded_netrw = "v109" |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 34 | if v:version < 700 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 35 | 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] | 36 | finish |
| 37 | endif |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 38 | let s:keepcpo= &cpo |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 39 | setlocal cpo&vim |
| 40 | "DechoTabOn |
| 41 | "call Decho("doing autoload/netrw.vim version ".g:loaded_netrw) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 42 | |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 43 | " ====================== |
| 44 | " Netrw Variables: {{{1 |
| 45 | " ====================== |
| 46 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 47 | " --------------------------------------------------------------------- |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 48 | " Netrw Constants: {{{2 |
| 49 | if !exists("g:NETRW_BOOKMARKMAX") |
| 50 | let g:NETRW_BOOKMARKMAX= 0 |
| 51 | endif |
| 52 | if !exists("g:NETRW_DIRHIST_CNT") |
| 53 | let g:NETRW_DIRHIST_CNT= 0 |
| 54 | endif |
| 55 | if !exists("s:LONGLIST") |
| 56 | let s:THINLIST = 0 |
| 57 | let s:LONGLIST = 1 |
| 58 | let s:WIDELIST = 2 |
| 59 | let s:TREELIST = 3 |
| 60 | let s:MAXLIST = 4 |
| 61 | endif |
| 62 | |
| 63 | " --------------------------------------------------------------------- |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 64 | " Default values for netrw's global protocol variables {{{2 |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 65 | if !exists("g:netrw_dav_cmd") |
| 66 | let g:netrw_dav_cmd = "cadaver" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 67 | endif |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 68 | if !exists("g:netrw_fetch_cmd") |
| 69 | if executable("fetch") |
| 70 | let g:netrw_fetch_cmd = "fetch -o" |
| 71 | else |
| 72 | let g:netrw_fetch_cmd = "" |
| 73 | endif |
| 74 | endif |
| 75 | if !exists("g:netrw_ftp_cmd") |
| 76 | let g:netrw_ftp_cmd = "ftp" |
| 77 | endif |
| 78 | if !exists("g:netrw_http_cmd") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 79 | if executable("curl") |
| 80 | let g:netrw_http_cmd = "curl -o" |
| 81 | elseif executable("wget") |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 82 | let g:netrw_http_cmd = "wget -q -O" |
| 83 | elseif executable("fetch") |
| 84 | let g:netrw_http_cmd = "fetch -o" |
| 85 | else |
| 86 | let g:netrw_http_cmd = "" |
| 87 | endif |
| 88 | endif |
| 89 | if !exists("g:netrw_rcp_cmd") |
| 90 | let g:netrw_rcp_cmd = "rcp" |
| 91 | endif |
| 92 | if !exists("g:netrw_rsync_cmd") |
| 93 | let g:netrw_rsync_cmd = "rsync" |
| 94 | endif |
| 95 | if !exists("g:netrw_scp_cmd") |
| 96 | let g:netrw_scp_cmd = "scp -q" |
| 97 | endif |
| 98 | if !exists("g:netrw_sftp_cmd") |
| 99 | let g:netrw_sftp_cmd = "sftp" |
| 100 | endif |
| 101 | if !exists("g:netrw_ssh_cmd") |
| 102 | let g:netrw_ssh_cmd= "ssh" |
| 103 | endif |
| 104 | |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 105 | if (has("win32") || has("win95") || has("win64") || has("win16")) |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 106 | \ && exists("g:netrw_use_nt_rcp") |
| 107 | \ && g:netrw_use_nt_rcp |
| 108 | \ && executable( $SystemRoot .'/system32/rcp.exe') |
| 109 | let s:netrw_has_nt_rcp = 1 |
| 110 | let s:netrw_rcpmode = '-b' |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 111 | else |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 112 | let s:netrw_has_nt_rcp = 0 |
| 113 | let s:netrw_rcpmode = '' |
| 114 | endif |
| 115 | |
| 116 | " --------------------------------------------------------------------- |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 117 | " Default values for netrw's global variables {{{2 |
| 118 | " Default values - a-c ---------- {{{3 |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 119 | if !exists("g:netrw_alto") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 120 | let g:netrw_alto= &sb |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 121 | endif |
| 122 | if !exists("g:netrw_altv") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 123 | let g:netrw_altv= &spr |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 124 | endif |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 125 | if !exists("g:netrw_browse_split") |
| 126 | let g:netrw_browse_split= 0 |
| 127 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 128 | if !exists("g:netrw_chgwin") |
| 129 | let g:netrw_chgwin = -1 |
| 130 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 131 | if !exists("g:netrw_cygwin") |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 132 | if has("win32") || has("win95") || has("win64") || has("win16") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 133 | if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$' |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 134 | let g:netrw_cygwin= 1 |
| 135 | else |
| 136 | let g:netrw_cygwin= 0 |
| 137 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 138 | else |
| 139 | let g:netrw_cygwin= 0 |
| 140 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 141 | else |
| 142 | let g:netrw_cygwin= 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 143 | endif |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 144 | " Default values - d-f ---------- {{{3 |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 145 | if !exists("g:NETRW_DIRHIST_CNT") |
| 146 | let g:NETRW_DIRHIST_CNT= 0 |
| 147 | endif |
| 148 | if !exists("g:netrw_dirhistmax") |
| 149 | let g:netrw_dirhistmax= 10 |
| 150 | endif |
| 151 | if !exists("g:netrw_ftp_browse_reject") |
| 152 | let 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 | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 153 | endif |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 154 | if !exists("g:netrw_ftp_list_cmd") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 155 | if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin) |
| 156 | let g:netrw_ftp_list_cmd = "ls -lF" |
| 157 | let g:netrw_ftp_timelist_cmd = "ls -tlF" |
| 158 | let g:netrw_ftp_sizelist_cmd = "ls -slF" |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 159 | else |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 160 | let g:netrw_ftp_list_cmd = "dir" |
| 161 | let g:netrw_ftp_timelist_cmd = "dir" |
| 162 | let g:netrw_ftp_sizelist_cmd = "dir" |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 163 | endif |
| 164 | endif |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 165 | if !exists("g:netrw_ftpmode") |
| 166 | let g:netrw_ftpmode= "binary" |
Bram Moolenaar | 6103699 | 2005-10-12 20:54:52 +0000 | [diff] [blame] | 167 | endif |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 168 | " Default values - h-lh ---------- {{{3 |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 169 | if !exists("g:netrw_hide") |
| 170 | let g:netrw_hide= 1 |
Bram Moolenaar | 6103699 | 2005-10-12 20:54:52 +0000 | [diff] [blame] | 171 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 172 | if !exists("g:netrw_ignorenetrc") |
| 173 | if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$' |
| 174 | let g:netrw_ignorenetrc= 1 |
| 175 | else |
| 176 | let g:netrw_ignorenetrc= 0 |
| 177 | endif |
| 178 | endif |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 179 | if !exists("g:netrw_keepdir") |
| 180 | let g:netrw_keepdir= 1 |
| 181 | endif |
| 182 | if !exists("g:netrw_list_cmd") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 183 | if g:netrw_scp_cmd =~ '^pscp' && executable("pscp") |
| 184 | " provide a 'pscp' listing command |
| 185 | if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable("c:\\private.ppk") |
| 186 | let g:netrw_scp_cmd ="pscp -i C:\\private.ppk" |
| 187 | endif |
| 188 | let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:" |
| 189 | elseif executable(g:netrw_ssh_cmd) |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 190 | " provide a default listing command |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 191 | 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] | 192 | else |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 193 | " call Decho(g:netrw_ssh_cmd." is not executable") |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 194 | let g:netrw_list_cmd= "" |
| 195 | endif |
| 196 | endif |
| 197 | if !exists("g:netrw_list_hide") |
| 198 | let g:netrw_list_hide= "" |
| 199 | endif |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 200 | " Default values - lh-lz ---------- {{{3 |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 201 | if !exists("g:netrw_local_mkdir") |
| 202 | let g:netrw_local_mkdir= "mkdir" |
| 203 | endif |
| 204 | if !exists("g:netrw_local_rmdir") |
| 205 | let g:netrw_local_rmdir= "rmdir" |
| 206 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 207 | if !exists("g:netrw_liststyle") |
| 208 | let g:netrw_liststyle= s:THINLIST |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 209 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 210 | if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 211 | " sanity check |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 212 | let g:netrw_liststyle= s:THINLIST |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 213 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 214 | if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp' |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 215 | let g:netrw_list_cmd= g:netrw_list_cmd." -l" |
| 216 | endif |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 217 | " Default values - m-r ---------- {{{3 |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 218 | if !exists("g:netrw_maxfilenamelen") |
| 219 | let g:netrw_maxfilenamelen= 32 |
| 220 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 221 | if !exists("g:netrw_menu") |
| 222 | let g:netrw_menu= 1 |
| 223 | endif |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 224 | if !exists("g:netrw_mkdir_cmd") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 225 | let g:netrw_mkdir_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir" |
Bram Moolenaar | a5792f5 | 2005-11-23 21:25:05 +0000 | [diff] [blame] | 226 | endif |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 227 | if !exists("g:netrw_scpport") |
| 228 | let g:netrw_scpport= "-P" |
| 229 | endif |
| 230 | if !exists("g:netrw_sshport") |
| 231 | let g:netrw_sshport= "-p" |
| 232 | endif |
Bram Moolenaar | a5792f5 | 2005-11-23 21:25:05 +0000 | [diff] [blame] | 233 | if !exists("g:netrw_rename_cmd") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 234 | let g:netrw_rename_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME mv" |
Bram Moolenaar | a5792f5 | 2005-11-23 21:25:05 +0000 | [diff] [blame] | 235 | endif |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 236 | if !exists("g:netrw_rm_cmd") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 237 | let g:netrw_rm_cmd = g:netrw_ssh_cmd." USEPORT HOSTNAME rm" |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 238 | endif |
| 239 | if !exists("g:netrw_rmdir_cmd") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 240 | let g:netrw_rmdir_cmd = g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir" |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 241 | endif |
| 242 | if !exists("g:netrw_rmf_cmd") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 243 | let g:netrw_rmf_cmd = g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f" |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 244 | endif |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 245 | " Default values - s ---------- {{{3 |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 246 | if exists("g:netrw_silent") && g:netrw_silent != 0 |
| 247 | let g:netrw_silentxfer= "silent " |
| 248 | else |
| 249 | let g:netrw_silentxfer= "" |
| 250 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 251 | if !exists("g:netrw_fastbrowse") |
| 252 | let g:netrw_fastbrowse= 1 |
| 253 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 254 | if !exists("g:netrw_shq") |
| 255 | if exists("&shq") && &shq != "" |
| 256 | let g:netrw_shq= &shq |
| 257 | elseif has("win32") || has("win95") || has("win64") || has("win16") |
| 258 | if g:netrw_cygwin |
| 259 | let g:netrw_shq= "'" |
| 260 | else |
| 261 | let g:netrw_shq= '"' |
| 262 | endif |
| 263 | else |
| 264 | let g:netrw_shq= "'" |
| 265 | endif |
| 266 | " call Decho("g:netrw_shq<".g:netrw_shq.">") |
| 267 | endif |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 268 | if !exists("g:netrw_sort_by") |
| 269 | " alternatives: date size |
| 270 | let g:netrw_sort_by= "name" |
| 271 | endif |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 272 | if !exists("g:netrw_sort_direction") |
| 273 | " alternative: reverse (z y x ...) |
| 274 | let g:netrw_sort_direction= "normal" |
| 275 | endif |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 276 | if !exists("g:netrw_sort_sequence") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 277 | let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,\.[a-np-z]$,*,\.info$,\.swp$,\.o$\.obj$,\.bak$' |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 278 | endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 279 | if !exists("g:netrw_ssh_browse_reject") |
| 280 | let g:netrw_ssh_browse_reject='^total\s\+\d\+$' |
| 281 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 282 | if !has("patch192") |
| 283 | if !exists("g:netrw_use_noswf") |
| 284 | let g:netrw_use_noswf= 1 |
| 285 | endif |
| 286 | else |
| 287 | let g:netrw_use_noswf= 0 |
| 288 | endif |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 289 | " Default values - t-w ---------- {{{3 |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 290 | if !exists("g:netrw_timefmt") |
| 291 | let g:netrw_timefmt= "%c" |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 292 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 293 | if !exists("g:NetrwTopLvlMenu") |
| 294 | let g:NetrwTopLvlMenu= "Netrw." |
| 295 | endif |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 296 | if !exists("g:netrw_use_errorwindow") |
| 297 | let g:netrw_use_errorwindow= 1 |
| 298 | endif |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 299 | if !exists("g:netrw_win95ftp") |
| 300 | let g:netrw_win95ftp= 1 |
| 301 | endif |
| 302 | if !exists("g:netrw_winsize") |
| 303 | let g:netrw_winsize= "" |
| 304 | endif |
| 305 | " --------------------------------------------------------------------- |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 306 | " Default values for netrw's script variables: {{{2 |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 307 | if !exists("s:netrw_cd_escape") |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 308 | let s:netrw_cd_escape="[]#*$%'\" ?`!&();<>\\" |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 309 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 310 | if !exists("g:netrw_fname_escape") |
| 311 | let g:netrw_fname_escape= ' ?&;' |
| 312 | endif |
| 313 | if !exists("g:netrw_tmpfile_escape") |
| 314 | let g:netrw_tmpfile_escape= ' ?&;' |
| 315 | endif |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 316 | if !exists("s:netrw_glob_escape") |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 317 | let s:netrw_glob_escape= '[]*?`{~$' |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 318 | endif |
Bram Moolenaar | 8299df9 | 2004-07-10 09:47:34 +0000 | [diff] [blame] | 319 | |
| 320 | " BufEnter event ignored by decho when following variable is true |
| 321 | " Has a side effect that doau BufReadPost doesn't work, so |
| 322 | " files read by network transfer aren't appropriately highlighted. |
| 323 | "let g:decho_bufenter = 1 "Decho |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 324 | |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 325 | " ============================== |
| 326 | " Netrw Utility Functions: {{{1 |
| 327 | " ============================== |
| 328 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 329 | " ------------------------------------------------------------------------ |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 330 | " NetSavePosn: saves position of cursor on screen {{{2 |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 331 | fun! netrw#NetSavePosn() |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 332 | " call Dfunc("netrw#NetSavePosn()") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 333 | " Save current line and column |
Bram Moolenaar | 488c651 | 2005-08-11 20:09:58 +0000 | [diff] [blame] | 334 | let w:netrw_winnr= winnr() |
| 335 | let w:netrw_line = line(".") |
| 336 | let w:netrw_col = virtcol(".") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 337 | |
| 338 | " Save top-of-screen line |
| 339 | norm! H0 |
Bram Moolenaar | 488c651 | 2005-08-11 20:09:58 +0000 | [diff] [blame] | 340 | let w:netrw_hline= line(".") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 341 | |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 342 | call netrw#NetRestorePosn() |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 343 | " call Dret("netrw#NetSavePosn : winnr=".w:netrw_winnr." line=".w:netrw_line." col=".w:netrw_col." hline=".w:netrw_hline) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 344 | endfun |
| 345 | |
| 346 | " ------------------------------------------------------------------------ |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 347 | " NetRestorePosn: restores the cursor and file position as saved by NetSavePosn() {{{2 |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 348 | fun! netrw#NetRestorePosn() |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 349 | " call Dfunc("netrw#NetRestorePosn() 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)) |
Bram Moolenaar | 572cb56 | 2005-08-05 21:35:02 +0000 | [diff] [blame] | 350 | let eikeep= &ei |
| 351 | set ei=all |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 352 | if expand("%") == "NetrwMessage" |
| 353 | exe s:winBeforeErr."wincmd w" |
| 354 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 355 | |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 356 | " restore window |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 357 | if exists("w:netrw_winnr") |
| 358 | " call Decho("restore window: exe silent! ".w:netrw_winnr."wincmd w") |
| 359 | exe "silent! ".w:netrw_winnr."wincmd w" |
| 360 | endif |
| 361 | if v:shell_error == 0 |
| 362 | " as suggested by Bram M: redraw on no error |
| 363 | " allows protocol error messages to remain visible |
| 364 | redraw! |
| 365 | endif |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 366 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 367 | " restore top-of-screen line |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 368 | if exists("w:netrw_hline") |
| 369 | " call Decho("restore topofscreen: exe norm! ".w:netrw_hline."G0z") |
| 370 | exe "norm! ".w:netrw_hline."G0z\<CR>" |
| 371 | endif |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 372 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 373 | " restore position |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 374 | if exists("w:netrw_line") && exists("w:netrw_col") |
| 375 | " call Decho("restore posn: exe norm! ".w:netrw_line."G0".w:netrw_col."|") |
| 376 | exe "norm! ".w:netrw_line."G0".w:netrw_col."\<bar>" |
| 377 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 378 | |
Bram Moolenaar | 572cb56 | 2005-08-05 21:35:02 +0000 | [diff] [blame] | 379 | let &ei= eikeep |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 380 | " call Dret("netrw#NetRestorePosn") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 381 | endfun |
| 382 | |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 383 | " =============================== |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 384 | " NetOptionSave: save options and set to "standard" form {{{2 |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 385 | "DechoTabOn |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 386 | fun! s:NetOptionSave() |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 387 | " call Dfunc("s:NetOptionSave() win#".winnr()." buf#".bufnr(".")) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 388 | if !exists("w:netrw_optionsave") |
| 389 | let w:netrw_optionsave= 1 |
| 390 | else |
| 391 | " call Dret("s:NetOptionSave : netoptionsave=".w:netrw_optionsave) |
| 392 | return |
| 393 | endif |
| 394 | |
| 395 | " Save current settings and current directory |
| 396 | let s:yykeep = @@ |
| 397 | if exists("&l:acd") |
| 398 | let w:netrw_acdkeep = &l:acd |
| 399 | endif |
| 400 | let w:netrw_aikeep = &l:ai |
| 401 | let w:netrw_awkeep = &l:aw |
| 402 | let w:netrw_cikeep = &l:ci |
| 403 | let w:netrw_cinkeep = &l:cin |
| 404 | let w:netrw_cinokeep = &l:cino |
| 405 | let w:netrw_comkeep = &l:com |
| 406 | let w:netrw_cpokeep = &l:cpo |
| 407 | if g:netrw_keepdir |
| 408 | let w:netrw_dirkeep = getcwd() |
| 409 | endif |
| 410 | let w:netrw_fokeep = &l:fo " formatoptions |
| 411 | let w:netrw_gdkeep = &l:gd " gdefault |
| 412 | let w:netrw_hidkeep = &l:hidden |
| 413 | let w:netrw_magickeep = &l:magic |
| 414 | let w:netrw_repkeep = &l:report |
| 415 | let w:netrw_spellkeep = &l:spell |
| 416 | let w:netrw_twkeep = &l:tw " textwidth |
| 417 | let w:netrw_wigkeep = &l:wig " wildignore |
| 418 | if has("win32") && !has("win95") |
| 419 | let w:netrw_swfkeep= &l:swf " swapfile |
| 420 | endif |
| 421 | call s:NetrwSafeOptions() |
| 422 | if &go =~ 'a' | silent! let w:netrw_regstar = @* | endif |
| 423 | silent! let w:netrw_regslash= @/ |
| 424 | |
| 425 | " call Dret("s:NetOptionSave") |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 426 | " call Dret("s:NetOptionSave : win#".winnr()." buf#".bufnr(".")) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 427 | endfun |
| 428 | |
| 429 | " ------------------------------------------------------------------------ |
| 430 | " NetOptionRestore: restore options {{{2 |
| 431 | fun! s:NetOptionRestore() |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 432 | " call Dfunc("s:NetOptionRestore() win#".winnr()." buf#".bufnr(".")) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 433 | if !exists("w:netrw_optionsave") |
| 434 | " call Dret("s:NetOptionRestore : w:netrw_optionsave doesn't exist") |
| 435 | return |
| 436 | endif |
| 437 | unlet w:netrw_optionsave |
| 438 | |
| 439 | if exists("&acd") |
| 440 | if exists("w:netrw_acdkeep") |let &l:acd = w:netrw_acdkeep |unlet w:netrw_acdkeep |endif |
| 441 | endif |
| 442 | if exists("w:netrw_aikeep") |let &l:ai = w:netrw_aikeep |unlet w:netrw_aikeep |endif |
| 443 | if exists("w:netrw_awkeep") |let &l:aw = w:netrw_awkeep |unlet w:netrw_awkeep |endif |
| 444 | if exists("w:netrw_cikeep") |let &l:ci = w:netrw_cikeep |unlet w:netrw_cikeep |endif |
| 445 | if exists("w:netrw_cinkeep") |let &l:cin = w:netrw_cinkeep |unlet w:netrw_cinkeep |endif |
| 446 | if exists("w:netrw_cinokeep") |let &l:cino = w:netrw_cinokeep |unlet w:netrw_cinokeep |endif |
| 447 | if exists("w:netrw_comkeep") |let &l:com = w:netrw_comkeep |unlet w:netrw_comkeep |endif |
| 448 | if exists("w:netrw_cpokeep") |let &l:cpo = w:netrw_cpokeep |unlet w:netrw_cpokeep |endif |
| 449 | if exists("w:netrw_dirkeep") |exe "lcd ".w:netrw_dirkeep |unlet w:netrw_dirkeep |endif |
| 450 | if exists("w:netrw_fokeep") |let &l:fo = w:netrw_fokeep |unlet w:netrw_fokeep |endif |
| 451 | if exists("w:netrw_gdkeep") |let &l:gd = w:netrw_gdkeep |unlet w:netrw_gdkeep |endif |
| 452 | if exists("w:netrw_hidkeep") |let &l:hidden = w:netrw_hidkeep |unlet w:netrw_hidkeep |endif |
| 453 | if exists("w:netrw_magic") |let &l:magic = w:netrw_magic |unlet w:netrw_magic |endif |
| 454 | if exists("w:netrw_repkeep") |let &l:report = w:netrw_repkeep |unlet w:netrw_repkeep |endif |
| 455 | if exists("w:netrw_spellkeep")|let &l:spell = w:netrw_spellkeep |unlet w:netrw_spellkeep|endif |
| 456 | if exists("w:netrw_twkeep") |let &l:tw = w:netrw_twkeep |unlet w:netrw_twkeep |endif |
| 457 | if exists("w:netrw_wigkeep") |let &l:wig = w:netrw_wigkeep |unlet w:netrw_wigkeep |endif |
| 458 | if exists("s:yykeep") |let @@ = s:yykeep |unlet s:yykeep |endif |
| 459 | if exists("w:netrw_swfkeep") |
| 460 | if &directory == "" |
| 461 | " user hasn't specified a swapfile directory; |
| 462 | " netrw will temporarily set the swapfile directory |
| 463 | " to the current directory as returned by getcwd(). |
| 464 | let &l:directory = getcwd() |
| 465 | silent! let &l:swf = w:netrw_swfkeep |
| 466 | setlocal directory= |
| 467 | unlet w:netrw_swfkeep |
| 468 | elseif &l:swf != w:netrw_swfkeep |
| 469 | " following line causes a Press ENTER in windows -- can't seem to work around it!!! (COMBAK) |
| 470 | silent! let &l:swf= w:netrw_swfkeep |
| 471 | unlet w:netrw_swfkeep |
| 472 | endif |
| 473 | endif |
| 474 | if exists("w:netrw_regstar") |silent! let @*= w:netrw_regstar |unlet w:netrw_regstar |endif |
| 475 | if exists("w:netrw_regslash")|silent! let @/= w:netrw_regslash|unlet w:netrw_regslash|endif |
| 476 | |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 477 | " call Dret("s:NetOptionRestore : win#".winnr()." buf#".bufnr(".")) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 478 | endfun |
| 479 | |
| 480 | " --------------------------------------------------------------------- |
| 481 | " NetrwSafeOptions: sets options to help netrw do its job {{{2 |
| 482 | fun! s:NetrwSafeOptions() |
| 483 | " call Dfunc("s:NetrwSafeOptions()") |
| 484 | setlocal cino= |
| 485 | setlocal com= |
| 486 | setlocal cpo-=aA |
| 487 | if exists("&acd") |
| 488 | setlocal noacd nocin noai noci magic nospell nohid wig= noaw |
| 489 | setlocal fo=nroql2 |
| 490 | else |
| 491 | setlocal nocin noai noci magic nospell nohid wig= noaw |
| 492 | setlocal fo=nroql2 |
| 493 | endif |
| 494 | setlocal tw=0 |
| 495 | setlocal report=10000 |
| 496 | if g:netrw_use_noswf && has("win32") && !has("win95") |
| 497 | setlocal noswf |
| 498 | endif |
| 499 | " call Dret("s:NetrwSafeOptions") |
| 500 | endfun |
| 501 | |
| 502 | " ------------------------------------------------------------------------ |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 503 | " Netrw Transfer Functions: {{{1 |
| 504 | " =============================== |
| 505 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 506 | " ------------------------------------------------------------------------ |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 507 | " NetRead: responsible for reading a file over the net {{{2 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 508 | " mode: =0 read remote file and insert before current line |
| 509 | " =1 read remote file and insert after current line |
| 510 | " =2 replace with remote file |
| 511 | " =3 obtain file, but leave in temporary format |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 512 | fun! netrw#NetRead(mode,...) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 513 | " 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] | 514 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 515 | " save options {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 516 | call s:NetOptionSave() |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 517 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 518 | " interpret mode into a readcmd {{{3 |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 519 | if a:mode == 0 " read remote file before current line |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 520 | let readcmd = "0r" |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 521 | elseif a:mode == 1 " read file after current line |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 522 | let readcmd = "r" |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 523 | elseif a:mode == 2 " replace with remote file |
| 524 | let readcmd = "%r" |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 525 | elseif a:mode == 3 " skip read of file (leave as temporary) |
| 526 | let readcmd = "t" |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 527 | else |
| 528 | exe a:mode |
| 529 | let readcmd = "r" |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 530 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 531 | let ichoice = (a:0 == 0)? 0 : 1 |
| 532 | " call Decho("readcmd<".readcmd."> ichoice=".ichoice) |
| 533 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 534 | " Get Temporary Filename {{{3 |
| 535 | let tmpfile= s:GetTempfile("") |
| 536 | if tmpfile == "" |
| 537 | " call Dret("netrw#NetRead : unable to get a tempfile!") |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 538 | return |
| 539 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 540 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 541 | while ichoice <= a:0 |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 542 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 543 | " attempt to repeat with previous host-file-etc |
| 544 | if exists("b:netrw_lastfile") && a:0 == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 545 | " call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 546 | let choice = b:netrw_lastfile |
| 547 | let ichoice= ichoice + 1 |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 548 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 549 | else |
| 550 | exe "let choice= a:" . ichoice |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 551 | " call Decho("no lastfile: choice<" . choice . ">") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 552 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 553 | if match(choice,"?") == 0 |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 554 | " give help |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 555 | echomsg 'NetRead Usage:' |
| 556 | echomsg ':Nread machine:path uses rcp' |
| 557 | echomsg ':Nread "machine path" uses ftp with <.netrc>' |
| 558 | echomsg ':Nread "machine id password path" uses ftp' |
| 559 | echomsg ':Nread dav://machine[:port]/path uses cadaver' |
| 560 | echomsg ':Nread fetch://machine/path uses fetch' |
| 561 | echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>' |
| 562 | echomsg ':Nread http://[user@]machine/path uses http wget' |
| 563 | echomsg ':Nread rcp://[user@]machine/path uses rcp' |
| 564 | echomsg ':Nread rsync://machine[:port]/path uses rsync' |
| 565 | echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp' |
| 566 | echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp' |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 567 | sleep 4 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 568 | break |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 569 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 570 | elseif match(choice,'^"') != -1 |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 571 | " Reconstruct Choice if choice starts with '"' |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 572 | " call Decho("reconstructing choice") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 573 | if match(choice,'"$') != -1 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 574 | " case "..." |
| 575 | let choice=strpart(choice,1,strlen(choice)-2) |
| 576 | else |
| 577 | " case "... ... ..." |
| 578 | let choice = strpart(choice,1,strlen(choice)-1) |
| 579 | let wholechoice = "" |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 580 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 581 | while match(choice,'"$') == -1 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 582 | let wholechoice = wholechoice . " " . choice |
| 583 | let ichoice = ichoice + 1 |
| 584 | if ichoice > a:0 |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 585 | if !exists("g:netrw_quiet") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 586 | call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3) |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 587 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 588 | " call Dret("netrw#NetRead :2 getcwd<".getcwd().">") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 589 | return |
| 590 | endif |
| 591 | let choice= a:{ichoice} |
| 592 | endwhile |
| 593 | let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1) |
| 594 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 595 | endif |
| 596 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 597 | |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 598 | " call Decho("choice<" . choice . ">") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 599 | let ichoice= ichoice + 1 |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 600 | |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 601 | " Determine method of read (ftp, rcp, etc) {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 602 | call s:NetMethod(choice) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 603 | let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 604 | |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 605 | " Check if NetBrowse() should be handling this request |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 606 | " call Decho("checking if NetBrowse() should handle choice<".choice."> with netrw_list_cmd<".g:netrw_list_cmd.">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 607 | if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^http://' |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 608 | " call Decho("yes, choice matches '^.*[\/]$'") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 609 | keepjumps call s:NetBrowse(0,choice) |
| 610 | " call Dret("netrw#NetRead :3 getcwd<".getcwd().">") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 611 | return |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 612 | endif |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 613 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 614 | " ============ |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 615 | " Perform Protocol-Based Read {{{3 |
| 616 | " =========================== |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 617 | if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 |
| 618 | echo "(netrw) Processing your read request..." |
| 619 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 620 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 621 | "......................................... |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 622 | " rcp: NetRead Method #1 {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 623 | if b:netrw_method == 1 " read with rcp |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 624 | " call Decho("read via rcp (method #1)") |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 625 | " ER: nothing done with g:netrw_uid yet? |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 626 | " ER: on Win2K" rcp machine[.user]:file tmpfile |
| 627 | " ER: if machine contains '.' adding .user is required (use $USERNAME) |
| 628 | " ER: the tmpfile is full path: rcp sees C:\... as host C |
| 629 | if s:netrw_has_nt_rcp == 1 |
| 630 | if exists("g:netrw_uid") && ( g:netrw_uid != "" ) |
| 631 | let uid_machine = g:netrw_machine .'.'. g:netrw_uid |
| 632 | else |
| 633 | " Any way needed it machine contains a '.' |
| 634 | let uid_machine = g:netrw_machine .'.'. $USERNAME |
| 635 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 636 | else |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 637 | if exists("g:netrw_uid") && ( g:netrw_uid != "" ) |
| 638 | let uid_machine = g:netrw_uid .'@'. g:netrw_machine |
| 639 | else |
| 640 | let uid_machine = g:netrw_machine |
| 641 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 642 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 643 | " call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".uid_machine.":".escape(b:netrw_fname,' ?&;')." ".tmpfile) |
| 644 | exe g:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".uid_machine.":".escape(b:netrw_fname,' ?&;')." ".tmpfile |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 645 | let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method) |
| 646 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 647 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 648 | "......................................... |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 649 | " ftp + <.netrc>: NetRead Method #2 {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 650 | elseif b:netrw_method == 2 " read with ftp + <.netrc> |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 651 | " call Decho("read via ftp+.netrc (method #2)") |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 652 | let netrw_fname= b:netrw_fname |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 653 | new |
Bram Moolenaar | 8299df9 | 2004-07-10 09:47:34 +0000 | [diff] [blame] | 654 | setlocal ff=unix |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 655 | exe "put ='".g:netrw_ftpmode."'" |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 656 | " call Decho("filter input: ".getline(".")) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 657 | if exists("g:netrw_ftpextracmd") |
| 658 | exe "put ='".g:netrw_ftpextracmd."'" |
| 659 | " call Decho("filter input: ".getline(".")) |
| 660 | endif |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 661 | exe "put ='".'get \"'.netrw_fname.'\" '.tmpfile."'" |
| 662 | " call Decho("filter input: ".getline(".")) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 663 | if exists("g:netrw_port") && g:netrw_port != "" |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 664 | " call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 665 | exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port |
| 666 | else |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 667 | " call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 668 | exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine |
| 669 | endif |
| 670 | " 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] | 671 | if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying ' |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 672 | let debugkeep= &debug |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 673 | setlocal debug=msg |
| 674 | call netrw#ErrorMsg(s:ERROR,getline(1),4) |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 675 | let &debug= debugkeep |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 676 | endif |
| 677 | bd! |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 678 | let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 679 | let b:netrw_lastfile = 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 | "......................................... |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 682 | " ftp + machine,id,passwd,filename: NetRead Method #3 {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 683 | elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname |
| 684 | " Construct execution string (four lines) which will be passed through filter |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 685 | " call Decho("read via ftp+mipf (method #3)") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 686 | let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 687 | new |
Bram Moolenaar | 8299df9 | 2004-07-10 09:47:34 +0000 | [diff] [blame] | 688 | setlocal ff=unix |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 689 | if exists("g:netrw_port") && g:netrw_port != "" |
| 690 | put ='open '.g:netrw_machine.' '.g:netrw_port |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 691 | " call Decho("filter input: ".getline(".")) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 692 | else |
| 693 | put ='open '.g:netrw_machine |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 694 | " call Decho("filter input: ".getline(".")) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 695 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 696 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 697 | if exists("g:netrw_ftp") && g:netrw_ftp == 1 |
| 698 | put =g:netrw_uid |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 699 | " call Decho("filter input: ".getline(".")) |
| 700 | put ='\"'.g:netrw_passwd.'\"' |
| 701 | " call Decho("filter input: ".getline(".")) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 702 | else |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 703 | put ='user \"'.g:netrw_uid.'\" \"'.g:netrw_passwd.'\"' |
| 704 | " call Decho("filter input: ".getline(".")) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 705 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 706 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 707 | if exists("g:netrw_ftpmode") && g:netrw_ftpmode != "" |
| 708 | put =g:netrw_ftpmode |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 709 | " call Decho("filter input: ".getline(".")) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 710 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 711 | if exists("g:netrw_ftpextracmd") |
| 712 | exe "put ='".g:netrw_ftpextracmd."'" |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 713 | " call Decho("filter input: ".getline(".")) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 714 | endif |
| 715 | put ='get \"'.netrw_fname.'\" '.tmpfile |
| 716 | " call Decho("filter input: ".getline(".")) |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 717 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 718 | " perform ftp: |
| 719 | " -i : turns off interactive prompting from ftp |
| 720 | " -n unix : DON'T use <.netrc>, even though it exists |
| 721 | " -n win32: quit being obnoxious about password |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 722 | norm! 1Gdd |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 723 | " call Decho("executing: %!".g:netrw_ftp_cmd." -i -n") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 724 | exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i -n" |
| 725 | " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) |
| 726 | if getline(1) !~ "^$" |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 727 | " call Decho("error<".getline(1).">") |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 728 | if !exists("g:netrw_quiet") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 729 | call netrw#ErrorMsg(s:ERROR,getline(1),5) |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 730 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 731 | endif |
| 732 | bd! |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 733 | let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 734 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 735 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 736 | "......................................... |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 737 | " scp: NetRead Method #4 {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 738 | elseif b:netrw_method == 4 " read with scp |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 739 | " call Decho("read via scp (method #4)") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 740 | if exists("g:netrw_port") && g:netrw_port != "" |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 741 | let useport= " ".g:netrw_scpport." ".g:netrw_port |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 742 | else |
| 743 | let useport= "" |
| 744 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 745 | " call Decho("executing: !".g:netrw_scp_cmd.useport." '".g:netrw_machine.":".escape(b:netrw_fname,g:netrw_fname_escape)."' ".tmpfile) |
| 746 | exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".g:netrw_shq.g:netrw_machine.":".escape(b:netrw_fname,g:netrw_fname_escape).g:netrw_shq." ".tmpfile |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 747 | let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 748 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 749 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 750 | "......................................... |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 751 | " http: NetRead Method #5 (wget) {{{3 |
| 752 | elseif b:netrw_method == 5 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 753 | " call Decho("read via http (method #5)") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 754 | if g:netrw_http_cmd == "" |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 755 | if !exists("g:netrw_quiet") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 756 | 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] | 757 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 758 | " call Dret("netrw#NetRead :4 getcwd<".getcwd().">") |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 759 | return |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 760 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 761 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 762 | if match(b:netrw_fname,"#") == -1 |
| 763 | " simple wget |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 764 | let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) |
| 765 | " call Decho("executing: !".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_fname) |
| 766 | exe g:netrw_silentxfer."!".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_fname |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 767 | let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method) |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 768 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 769 | else |
| 770 | " wget plus a jump to an in-page marker (ie. http://abc/def.html#aMarker) |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 771 | let netrw_html= substitute(netrw_fname,"#.*$","","") |
| 772 | let netrw_tag = substitute(netrw_fname,"^.*#","","") |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 773 | " call Decho("netrw_html<".netrw_html.">") |
| 774 | " call Decho("netrw_tag <".netrw_tag.">") |
| 775 | " call Decho("executing: !".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_html) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 776 | exe g:netrw_silentxfer."!".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_html |
| 777 | let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method) |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 778 | " call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/') |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 779 | exe 'norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>" |
| 780 | endif |
| 781 | let b:netrw_lastfile = choice |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 782 | setlocal ro |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 783 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 784 | "......................................... |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 785 | " cadaver: NetRead Method #6 {{{3 |
| 786 | elseif b:netrw_method == 6 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 787 | " call Decho("read via cadaver (method #6)") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 788 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 789 | " Construct execution string (four lines) which will be passed through filter |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 790 | let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 791 | new |
Bram Moolenaar | 8299df9 | 2004-07-10 09:47:34 +0000 | [diff] [blame] | 792 | setlocal ff=unix |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 793 | if exists("g:netrw_port") && g:netrw_port != "" |
| 794 | put ='open '.g:netrw_machine.' '.g:netrw_port |
| 795 | else |
| 796 | put ='open '.g:netrw_machine |
| 797 | endif |
| 798 | put ='user '.g:netrw_uid.' '.g:netrw_passwd |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 799 | put ='get '.netrw_fname.' '.tmpfile |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 800 | put ='quit' |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 801 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 802 | " perform cadaver operation: |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 803 | norm! 1Gdd |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 804 | " call Decho("executing: %!".g:netrw_dav_cmd) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 805 | exe g:netrw_silentxfer."%!".g:netrw_dav_cmd |
| 806 | bd! |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 807 | let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 808 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 809 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 810 | "......................................... |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 811 | " rsync: NetRead Method #7 {{{3 |
| 812 | elseif b:netrw_method == 7 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 813 | " call Decho("read via rsync (method #7)") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 814 | let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 815 | " call Decho("executing: !".g:netrw_rsync_cmd." ".g:netrw_machine.":".netrw_fname." ".tmpfile) |
| 816 | exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".g:netrw_machine.":".netrw_fname." ".tmpfile |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 817 | let result = s:NetGetFile(readcmd,tmpfile, b:netrw_method) |
| 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 | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 821 | " fetch: NetRead Method #8 {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 822 | " fetch://[user@]host[:http]/path |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 823 | elseif b:netrw_method == 8 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 824 | " call Decho("read via fetch (method #8)") |
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 | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 826 | if g:netrw_fetch_cmd == "" |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 827 | if !exists("g:netrw_quiet") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 828 | call netrw#ErrorMsg(s:ERROR,"fetch command not available",7) |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 829 | endif |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 830 | " call Dret("NetRead") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 831 | endif |
| 832 | if exists("g:netrw_option") && g:netrw_option == ":http" |
| 833 | let netrw_option= "http" |
| 834 | else |
| 835 | let netrw_option= "ftp" |
| 836 | endif |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 837 | " call Decho("read via fetch for ".netrw_option) |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 838 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 839 | if exists("g:netrw_uid") && g:netrw_uid != "" && exists("g:netrw_passwd") && g:netrw_passwd != "" |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 840 | " call Decho("executing: !".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_uid.':'.g:netrw_passwd.'@'.g:netrw_machine."/".netrw_fname) |
| 841 | exe g:netrw_silentxfer."!".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_uid.':'.g:netrw_passwd.'@'.g:netrw_machine."/".netrw_fname |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 842 | else |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 843 | " call Decho("executing: !".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_machine."/".netrw_fname) |
| 844 | exe g:netrw_silentxfer."!".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_machine."/".netrw_fname |
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 | let result = s:NetGetFile(readcmd,tmpfile, b:netrw_method) |
| 848 | let b:netrw_lastfile = choice |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 849 | setlocal ro |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 850 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 851 | "......................................... |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 852 | " sftp: NetRead Method #9 {{{3 |
| 853 | elseif b:netrw_method == 9 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 854 | " call Decho("read via sftp (method #9)") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 855 | let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 856 | " call Decho("executing: !".g:netrw_sftp_cmd." ".g:netrw_machine.":".netrw_fname." ".tmpfile) |
| 857 | exe g:netrw_silentxfer."!".g:netrw_sftp_cmd." ".g:netrw_machine.":".netrw_fname." ".tmpfile |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 858 | let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method) |
| 859 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 860 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 861 | "......................................... |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 862 | " Complain {{{3 |
| 863 | else |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 864 | 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] | 865 | endif |
| 866 | endwhile |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 867 | |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 868 | " cleanup {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 869 | if exists("b:netrw_method") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 870 | " call Decho("cleanup b:netrw_method and b:netrw_fname") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 871 | unlet b:netrw_method |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 872 | unlet b:netrw_fname |
| 873 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 874 | if s:FileReadable(tmpfile) && tmpfile !~ '.tar.bz2$' && tmpfile !~ '.tar.gz$' && tmpfile !~ '.zip' && tmpfile !~ '.tar' && readcmd != 't' |
| 875 | " call Decho("cleanup by deleting tmpfile<".tmpfile.">") |
| 876 | call s:System("delete",tmpfile) |
| 877 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 878 | call s:NetOptionRestore() |
Bram Moolenaar | 8299df9 | 2004-07-10 09:47:34 +0000 | [diff] [blame] | 879 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 880 | " call Dret("netrw#NetRead :5 getcwd<".getcwd().">") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 881 | endfun |
| 882 | |
| 883 | " ------------------------------------------------------------------------ |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 884 | " NetWrite: responsible for writing a file over the net {{{2 |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 885 | fun! netrw#NetWrite(...) range |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 886 | " call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw) |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 887 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 888 | " option handling |
| 889 | let mod= 0 |
| 890 | call s:NetOptionSave() |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 891 | |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 892 | " Get Temporary Filename {{{3 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 893 | let tmpfile= s:GetTempfile("") |
| 894 | if tmpfile == "" |
| 895 | " call Dret("netrw#NetWrite : unable to get a tempfile!") |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 896 | return |
| 897 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 898 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 899 | if a:0 == 0 |
| 900 | let ichoice = 0 |
| 901 | else |
| 902 | let ichoice = 1 |
| 903 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 904 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 905 | let curbufname= expand("%") |
| 906 | " call Decho("curbufname<".curbufname.">") |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 907 | if &binary |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 908 | " For binary writes, always write entire file. |
| 909 | " (line numbers don't really make sense for that). |
| 910 | " Also supports the writing of tar and zip files. |
| 911 | " call Decho("(write entire file) silent exe w! ".v:cmdarg." ".tmpfile) |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 912 | silent exe "w! ".v:cmdarg." ".tmpfile |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 913 | elseif g:netrw_cygwin |
| 914 | " write (selected portion of) file to temporary |
| 915 | let cygtmpfile= substitute(tmpfile,'/cygdrive/\(.\)','\1:','') |
| 916 | " call Decho("(write selected portion) silent exe ".a:firstline."," . a:lastline . "w! ".v:cmdarg." ".cygtmpfile) |
| 917 | silent exe a:firstline."," . a:lastline . "w! ".v:cmdarg." ".cygtmpfile |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 918 | else |
| 919 | " write (selected portion of) file to temporary |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 920 | " call Decho("(write selected portion) silent exe ".a:firstline."," . a:lastline . "w! ".v:cmdarg." ".tmpfile) |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 921 | silent exe a:firstline."," . a:lastline . "w! ".v:cmdarg." ".tmpfile |
| 922 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 923 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 924 | if curbufname == "" |
| 925 | " if the file is [No Name], and one attempts to Nwrite it, the buffer takes |
| 926 | " on the temporary file's name. Deletion of the temporary file during |
| 927 | " cleanup then causes an error message. |
| 928 | 0file! |
| 929 | endif |
| 930 | |
| 931 | " While choice loop: {{{3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 932 | while ichoice <= a:0 |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 933 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 934 | " Process arguments: {{{4 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 935 | " attempt to repeat with previous host-file-etc |
| 936 | if exists("b:netrw_lastfile") && a:0 == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 937 | " call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 938 | let choice = b:netrw_lastfile |
| 939 | let ichoice= ichoice + 1 |
| 940 | else |
| 941 | exe "let choice= a:" . ichoice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 942 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 943 | " Reconstruct Choice if choice starts with '"' |
| 944 | if match(choice,"?") == 0 |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 945 | echomsg 'NetWrite Usage:"' |
| 946 | echomsg ':Nwrite machine:path uses rcp' |
| 947 | echomsg ':Nwrite "machine path" uses ftp with <.netrc>' |
| 948 | echomsg ':Nwrite "machine id password path" uses ftp' |
| 949 | echomsg ':Nwrite dav://[user@]machine/path uses cadaver' |
| 950 | echomsg ':Nwrite fetch://[user@]machine/path uses fetch' |
| 951 | echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)' |
| 952 | echomsg ':Nwrite rcp://machine/path uses rcp' |
| 953 | echomsg ':Nwrite rsync://[user@]machine/path uses rsync' |
| 954 | echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp' |
| 955 | echomsg ':Nwrite sftp://[user@]machine/path uses sftp' |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 956 | sleep 4 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 957 | break |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 958 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 959 | elseif match(choice,"^\"") != -1 |
| 960 | if match(choice,"\"$") != -1 |
| 961 | " case "..." |
| 962 | let choice=strpart(choice,1,strlen(choice)-2) |
| 963 | else |
| 964 | " case "... ... ..." |
| 965 | let choice = strpart(choice,1,strlen(choice)-1) |
| 966 | let wholechoice = "" |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 967 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 968 | while match(choice,"\"$") == -1 |
| 969 | let wholechoice= wholechoice . " " . choice |
| 970 | let ichoice = ichoice + 1 |
| 971 | if choice > a:0 |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 972 | if !exists("g:netrw_quiet") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 973 | call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13) |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 974 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 975 | " call Dret("netrw#NetWrite") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 976 | return |
| 977 | endif |
| 978 | let choice= a:{ichoice} |
| 979 | endwhile |
| 980 | let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1) |
| 981 | endif |
| 982 | endif |
| 983 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 984 | let ichoice= ichoice + 1 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 985 | " call Decho("choice<" . choice . "> ichoice=".ichoice) |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 986 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 987 | " Determine method of write (ftp, rcp, etc) {{{4 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 988 | call s:NetMethod(choice) |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 989 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 990 | " ============= |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 991 | " Perform Protocol-Based Write {{{4 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 992 | " ============================ |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 993 | if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 |
| 994 | echo "(netrw) Processing your write request..." |
| 995 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 996 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 997 | "......................................... |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 998 | " rcp: NetWrite Method #1 {{{4 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 999 | if b:netrw_method == 1 |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 1000 | " call Decho("write via rcp (method #1)") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1001 | if s:netrw_has_nt_rcp == 1 |
| 1002 | if exists("g:netrw_uid") && ( g:netrw_uid != "" ) |
| 1003 | let uid_machine = g:netrw_machine .'.'. g:netrw_uid |
| 1004 | else |
| 1005 | let uid_machine = g:netrw_machine .'.'. $USERNAME |
| 1006 | endif |
| 1007 | else |
| 1008 | if exists("g:netrw_uid") && ( g:netrw_uid != "" ) |
| 1009 | let uid_machine = g:netrw_uid .'@'. g:netrw_machine |
| 1010 | else |
| 1011 | let uid_machine = g:netrw_machine |
| 1012 | endif |
| 1013 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1014 | let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1015 | " call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".g:netrw_shq.tmpfile.g:netrw_shq." ".uid_machine.":".netrw_fname) |
| 1016 | exe g:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".g:netrw_shq.tmpfile.g:netrw_shq." ".uid_machine.":".netrw_fname |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1017 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1018 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1019 | "......................................... |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1020 | " ftp + <.netrc>: NetWrite Method #2 {{{4 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 1021 | elseif b:netrw_method == 2 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1022 | " call Decho("write via ftp+.netrc (method #2)") |
Bram Moolenaar | 9e54a0e | 2006-04-14 20:42:25 +0000 | [diff] [blame] | 1023 | let netrw_fname= b:netrw_fname |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1024 | new |
Bram Moolenaar | 8299df9 | 2004-07-10 09:47:34 +0000 | [diff] [blame] | 1025 | setlocal ff=unix |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1026 | exe "put ='".g:netrw_ftpmode."'" |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 1027 | " call Decho(" filter input: ".getline(".")) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1028 | if exists("g:netrw_ftpextracmd") |
| 1029 | exe "put ='".g:netrw_ftpextracmd."'" |
| 1030 | " call Decho("filter input: ".getline(".")) |
| 1031 | endif |
| 1032 | exe "put ='".'put \"'.tmpfile.'\" \"'.netrw_fname.'\"'."'" |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 1033 | " call Decho(" filter input: ".getline(".")) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1034 | if exists("g:netrw_port") && g:netrw_port != "" |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1035 | " call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port) |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 1036 | exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1037 | else |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1038 | " call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine) |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 1039 | exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1040 | endif |
| 1041 | " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) |
| 1042 | if getline(1) !~ "^$" |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 1043 | if !exists("g:netrw_quiet") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1044 | call netrw#ErrorMsg(s:ERROR,getline(1),14) |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 1045 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1046 | let mod=1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1047 | endif |
| 1048 | bd! |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1049 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1050 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1051 | "......................................... |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1052 | " ftp + machine, id, passwd, filename: NetWrite Method #3 {{{4 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 1053 | elseif b:netrw_method == 3 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1054 | " Construct execution string (four lines) which will be passed through filter |
| 1055 | " call Decho("read via ftp+mipf (method #3)") |
Bram Moolenaar | 9e54a0e | 2006-04-14 20:42:25 +0000 | [diff] [blame] | 1056 | let netrw_fname= b:netrw_fname |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1057 | new |
Bram Moolenaar | 8299df9 | 2004-07-10 09:47:34 +0000 | [diff] [blame] | 1058 | setlocal ff=unix |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1059 | if exists("g:netrw_port") && g:netrw_port != "" |
| 1060 | put ='open '.g:netrw_machine.' '.g:netrw_port |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 1061 | " call Decho("filter input: ".getline(".")) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1062 | else |
| 1063 | put ='open '.g:netrw_machine |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 1064 | " call Decho("filter input: ".getline(".")) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1065 | endif |
| 1066 | if exists("g:netrw_ftp") && g:netrw_ftp == 1 |
| 1067 | put =g:netrw_uid |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 1068 | " call Decho("filter input: ".getline(".")) |
| 1069 | put ='\"'.g:netrw_passwd.'\"' |
| 1070 | " call Decho("filter input: ".getline(".")) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1071 | else |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 1072 | put ='user \"'.g:netrw_uid.'\" \"'.g:netrw_passwd.'\"' |
| 1073 | " call Decho("filter input: ".getline(".")) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1074 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1075 | put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"' |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 1076 | " call Decho("filter input: ".getline(".")) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1077 | " save choice/id/password for future use |
| 1078 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1079 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1080 | " perform ftp: |
| 1081 | " -i : turns off interactive prompting from ftp |
| 1082 | " -n unix : DON'T use <.netrc>, even though it exists |
| 1083 | " -n win32: quit being obnoxious about password |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 1084 | norm! 1Gdd |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1085 | " call Decho("executing: %!".g:netrw_ftp_cmd." -i -n") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1086 | exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i -n" |
| 1087 | " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) |
| 1088 | if getline(1) !~ "^$" |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 1089 | if !exists("g:netrw_quiet") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1090 | call netrw#ErrorMsg(s:ERROR,getline(1),15) |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 1091 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1092 | let mod=1 |
| 1093 | endif |
| 1094 | bd! |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1095 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1096 | "......................................... |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1097 | " scp: NetWrite Method #4 {{{4 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 1098 | elseif b:netrw_method == 4 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1099 | " call Decho("write via scp (method #4)") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1100 | let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1101 | if exists("g:netrw_port") && g:netrw_port != "" |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 1102 | let useport= " ".g:netrw_scpport." ".g:netrw_port |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1103 | else |
| 1104 | let useport= "" |
| 1105 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1106 | " call Decho("exe ".g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".g:netrw_shq.tmpfile.g:netrw_shq." ".g:netrw_shq.g:netrw_machine.":".netrw_fname.g:netrw_shq) |
| 1107 | exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".g:netrw_shq.tmpfile.g:netrw_shq." ".g:netrw_shq.g:netrw_machine.":".netrw_fname.g:netrw_shq |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1108 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1109 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1110 | "......................................... |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1111 | " http: NetWrite Method #5 {{{4 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1112 | elseif b:netrw_method == 5 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1113 | " call Decho("write via http (method #5)") |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 1114 | if !exists("g:netrw_quiet") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1115 | 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] | 1116 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1117 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1118 | "......................................... |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1119 | " dav: NetWrite Method #6 (cadaver) {{{4 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 1120 | elseif b:netrw_method == 6 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1121 | " call Decho("write via cadaver (method #6)") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1122 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1123 | " Construct execution string (four lines) which will be passed through filter |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1124 | let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1125 | new |
Bram Moolenaar | 8299df9 | 2004-07-10 09:47:34 +0000 | [diff] [blame] | 1126 | setlocal ff=unix |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1127 | if exists("g:netrw_port") && g:netrw_port != "" |
| 1128 | put ='open '.g:netrw_machine.' '.g:netrw_port |
| 1129 | else |
| 1130 | put ='open '.g:netrw_machine |
| 1131 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1132 | put ='user '.g:netrw_uid.' '.g:netrw_passwd |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1133 | put ='put '.tmpfile.' '.netrw_fname |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1134 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1135 | " perform cadaver operation: |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 1136 | norm! 1Gdd |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1137 | " call Decho("executing: %!".g:netrw_dav_cmd) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1138 | exe g:netrw_silentxfer."%!".g:netrw_dav_cmd |
| 1139 | bd! |
| 1140 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1141 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1142 | "......................................... |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1143 | " rsync: NetWrite Method #7 {{{4 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 1144 | elseif b:netrw_method == 7 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1145 | " call Decho("write via rsync (method #7)") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1146 | let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1147 | " call Decho("executing: !".g:netrw_rsync_cmd." ".tmpfile." ".g:netrw_machine.":".netrw_fname) |
| 1148 | exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".tmpfile." ".g:netrw_machine.":".netrw_fname |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1149 | let b:netrw_lastfile = choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1150 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1151 | "......................................... |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1152 | " sftp: NetWrite Method #9 {{{4 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 1153 | elseif b:netrw_method == 9 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1154 | " call Decho("read via sftp (method #9)") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1155 | let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1156 | if exists("g:netrw_uid") && ( g:netrw_uid != "" ) |
| 1157 | let uid_machine = g:netrw_uid .'@'. g:netrw_machine |
| 1158 | else |
| 1159 | let uid_machine = g:netrw_machine |
| 1160 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1161 | new |
Bram Moolenaar | 8299df9 | 2004-07-10 09:47:34 +0000 | [diff] [blame] | 1162 | setlocal ff=unix |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1163 | put ='put \"'.escape(tmpfile,'\').'\" '.netrw_fname |
| 1164 | " call Decho("filter input: ".getline(".")) |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 1165 | norm! 1Gdd |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1166 | " call Decho("executing: %!".g:netrw_sftp_cmd.' '.uid_machine) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1167 | exe g:netrw_silentxfer."%!".g:netrw_sftp_cmd.' '.uid_machine |
| 1168 | bd! |
| 1169 | let b:netrw_lastfile= choice |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1170 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1171 | "......................................... |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1172 | " Complain {{{4 |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 1173 | else |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1174 | call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1175 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1176 | endwhile |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1177 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1178 | " Cleanup: {{{3 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1179 | " call Decho("cleanup") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1180 | if s:FileReadable(tmpfile) |
| 1181 | " call Decho("tmpfile<".tmpfile."> readable, will now delete it") |
| 1182 | call s:System("delete",tmpfile) |
| 1183 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1184 | call s:NetOptionRestore() |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1185 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1186 | if a:firstline == 1 && a:lastline == line("$") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1187 | " restore modifiability; usually equivalent to set nomod |
| 1188 | let &mod= mod |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1189 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1190 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1191 | " call Dret("netrw#NetWrite") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1192 | endfun |
| 1193 | |
| 1194 | " --------------------------------------------------------------------- |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1195 | " NetSource: source a remotely hosted vim script {{{2 |
| 1196 | " uses NetRead to get a copy of the file into a temporarily file, |
| 1197 | " then sources that file, |
| 1198 | " then removes that file. |
| 1199 | fun! netrw#NetSource(...) |
| 1200 | " call Dfunc("netrw#NetSource() a:0=".a:0) |
| 1201 | if a:0 > 0 && a:1 == '?' |
| 1202 | " give help |
| 1203 | echomsg 'NetSource Usage:' |
| 1204 | echomsg ':Nsource dav://machine[:port]/path uses cadaver' |
| 1205 | echomsg ':Nsource fetch://machine/path uses fetch' |
| 1206 | echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>' |
| 1207 | echomsg ':Nsource http://[user@]machine/path uses http wget' |
| 1208 | echomsg ':Nsource rcp://[user@]machine/path uses rcp' |
| 1209 | echomsg ':Nsource rsync://machine[:port]/path uses rsync' |
| 1210 | echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp' |
| 1211 | echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp' |
| 1212 | sleep 4 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1213 | else |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1214 | let i= 1 |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1215 | while i <= a:0 |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1216 | call netrw#NetRead(3,a:{i}) |
| 1217 | " call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">") |
| 1218 | if s:FileReadable(s:netrw_tmpfile) |
| 1219 | " call Decho("exe so ".s:netrw_tmpfile) |
| 1220 | exe "so ".s:netrw_tmpfile |
| 1221 | call delete(s:netrw_tmpfile) |
| 1222 | unlet s:netrw_tmpfile |
| 1223 | else |
| 1224 | call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48) |
| 1225 | endif |
| 1226 | let i= i + 1 |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1227 | endwhile |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1228 | endif |
| 1229 | " call Dret("netrw#NetSource") |
| 1230 | endfun |
| 1231 | |
| 1232 | " =========================================== |
| 1233 | " NetGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2 |
| 1234 | " readcmd == %r : replace buffer with newly read file |
| 1235 | " == 0r : read file at top of buffer |
| 1236 | " == r : read file after current line |
| 1237 | " == t : leave file in temporary form (ie. don't read into buffer) |
| 1238 | fun! s:NetGetFile(readcmd, tfile, method) |
| 1239 | " call Dfunc("NetGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)") |
| 1240 | |
| 1241 | " readcmd=='t': simply do nothing |
| 1242 | if a:readcmd == 't' |
| 1243 | " call Dret("NetGetFile : skip read of <".a:tfile.">") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1244 | return |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1245 | endif |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 1246 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1247 | " get name of remote filename (ie. url and all) |
| 1248 | let rfile= bufname("%") |
| 1249 | " call Decho("rfile<".rfile.">") |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 1250 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1251 | if exists("*NetReadFixup") |
| 1252 | " for the use of NetReadFixup (not otherwise used internally) |
| 1253 | let line2= line("$") |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 1254 | endif |
| 1255 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1256 | if a:readcmd[0] == '%' |
| 1257 | " get file into buffer |
| 1258 | " call Decho("get file into buffer") |
| 1259 | |
| 1260 | " rename the current buffer to the temp file (ie. tfile) |
| 1261 | if g:netrw_cygwin |
| 1262 | let tfile= substitute(a:tfile,'/cygdrive/\(.\)','\1:','') |
| 1263 | else |
| 1264 | let tfile= a:tfile |
| 1265 | endif |
| 1266 | " call Decho("keepalt exe file ".tfile) |
| 1267 | keepalt exe "silent! keepalt file ".tfile |
| 1268 | |
| 1269 | " edit temporary file (ie. read the temporary file in) |
| 1270 | if rfile =~ '\.zip$' |
| 1271 | " call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)") |
| 1272 | call zip#Browse(tfile) |
| 1273 | elseif rfile =~ '\.tar$' |
| 1274 | " call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)") |
| 1275 | call tar#Browse(tfile) |
| 1276 | elseif rfile =~ '\.tar\.gz' |
| 1277 | " call Decho("handling remote gzip-compressed tar file") |
| 1278 | call tar#Browse(tfile) |
| 1279 | elseif rfile =~ '\.tar\.bz2' |
| 1280 | " call Decho("handling remote bz2-compressed tar file") |
| 1281 | call tar#Browse(tfile) |
| 1282 | else |
| 1283 | " call Decho("edit temporary file") |
| 1284 | e! |
| 1285 | endif |
| 1286 | |
| 1287 | " rename buffer back to remote filename |
| 1288 | exe "silent! keepalt file ".escape(rfile,' ') |
| 1289 | filetype detect |
| 1290 | " call Dredir("renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">","ls!") |
| 1291 | let line1 = 1 |
| 1292 | let line2 = line("$") |
| 1293 | |
| 1294 | elseif s:FileReadable(a:tfile) |
| 1295 | " read file after current line |
| 1296 | " call Decho("read file<".a:tfile."> after current line") |
| 1297 | let curline = line(".") |
| 1298 | let lastline= line("$") |
| 1299 | " call Decho("exe<".a:readcmd." ".v:cmdarg." ".a:tfile."> line#".curline) |
| 1300 | exe a:readcmd." ".v:cmdarg." ".a:tfile |
| 1301 | let line1= curline + 1 |
| 1302 | let line2= line("$") - lastline + 1 |
| 1303 | |
| 1304 | else |
| 1305 | " not readable |
| 1306 | " call Decho("tfile<".a:tfile."> not readable") |
| 1307 | call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9) |
| 1308 | " call Dret("NetGetFile : tfile<".a:tfile."> not readable") |
| 1309 | return |
| 1310 | endif |
| 1311 | |
| 1312 | " User-provided (ie. optional) fix-it-up command |
| 1313 | if exists("*NetReadFixup") |
| 1314 | " call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")") |
| 1315 | call NetReadFixup(a:method, line1, line2) |
| 1316 | " else " Decho |
| 1317 | " call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")") |
| 1318 | endif |
| 1319 | |
| 1320 | " update the Buffers menu |
| 1321 | if has("gui") && has("gui_running") |
| 1322 | silent! emenu Buffers.Refresh\ menu |
| 1323 | endif |
| 1324 | |
| 1325 | " call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> tfile<".a:tfile."> readable=".s:FileReadable(a:tfile)) |
| 1326 | |
| 1327 | " make sure file is being displayed |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 1328 | redraw! |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1329 | " call Dret("NetGetFile") |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 1330 | endfun |
| 1331 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1332 | " ------------------------------------------------------------------------ |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 1333 | " NetMethod: determine method of transfer {{{2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1334 | " method == 1: rcp |
| 1335 | " 2: ftp + <.netrc> |
| 1336 | " 3: ftp + machine, id, password, and [path]filename |
| 1337 | " 4: scp |
| 1338 | " 5: http (wget) |
| 1339 | " 6: cadaver |
| 1340 | " 7: rsync |
| 1341 | " 8: fetch |
| 1342 | " 9: sftp |
| 1343 | fun! s:NetMethod(choice) " globals: method machine id passwd fname |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1344 | " call Dfunc("NetMethod(a:choice<".a:choice.">)") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1345 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1346 | " initialization |
| 1347 | let b:netrw_method = 0 |
| 1348 | let g:netrw_machine = "" |
| 1349 | let b:netrw_fname = "" |
| 1350 | let g:netrw_port = "" |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1351 | let g:netrw_choice = a:choice |
| 1352 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1353 | " Patterns: |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1354 | " mipf : a:machine a:id password filename Use ftp |
| 1355 | " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid g:netrw_passwd |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1356 | " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid g:netrw_passwd |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1357 | " rcpurm : rcp://[user@]host/filename Use rcp |
| 1358 | " rcphf : [user@]host:filename Use rcp |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1359 | " scpurm : scp://[user@]host[[#:]port]/filename Use scp |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1360 | " httpurm : http://[user@]host/filename Use wget |
| 1361 | " davurm : [s]dav://host[:port]/path Use cadaver |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1362 | " rsyncurm : rsync://host[:port]/path Use rsync |
| 1363 | " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http) |
| 1364 | " sftpurm : sftp://[user@]host/filename Use scp |
| 1365 | let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$' |
| 1366 | let mf = '^\(\S\+\)\s\+\(\S\+\)$' |
| 1367 | let ftpurm = '^ftp://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$' |
Bram Moolenaar | 83bab71 | 2005-08-01 21:58:57 +0000 | [diff] [blame] | 1368 | let rcpurm = '^rcp://\%(\([^/@]\{-}\)@\)\=\([^/]\{-}\)/\(.*\)$' |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1369 | let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$' |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 1370 | let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$' |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1371 | let httpurm = '^http://\([^/]\{-}\)\(/.*\)\=$' |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1372 | let davurm = '^s\=dav://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$' |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1373 | let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$' |
| 1374 | let fetchurm = '^fetch://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$' |
| 1375 | let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$' |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1376 | |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1377 | " call Decho("determine method:") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1378 | " Determine Method |
| 1379 | " rcp://user@hostname/...path-to-file |
| 1380 | if match(a:choice,rcpurm) == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1381 | " call Decho("rcp://...") |
Bram Moolenaar | 83bab71 | 2005-08-01 21:58:57 +0000 | [diff] [blame] | 1382 | let b:netrw_method = 1 |
| 1383 | let userid = substitute(a:choice,rcpurm,'\1',"") |
| 1384 | let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"") |
| 1385 | let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1386 | if userid != "" |
| 1387 | let g:netrw_uid= userid |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1388 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1389 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1390 | " scp://user@hostname/...path-to-file |
| 1391 | elseif match(a:choice,scpurm) == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1392 | " call Decho("scp://...") |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 1393 | let b:netrw_method = 4 |
Bram Moolenaar | 83bab71 | 2005-08-01 21:58:57 +0000 | [diff] [blame] | 1394 | let g:netrw_machine = substitute(a:choice,scpurm,'\1',"") |
| 1395 | let g:netrw_port = substitute(a:choice,scpurm,'\2',"") |
| 1396 | let b:netrw_fname = substitute(a:choice,scpurm,'\3',"") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1397 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1398 | " http://user@hostname/...path-to-file |
| 1399 | elseif match(a:choice,httpurm) == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1400 | " call Decho("http://...") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1401 | let b:netrw_method = 5 |
| 1402 | let g:netrw_machine= substitute(a:choice,httpurm,'\1',"") |
| 1403 | let b:netrw_fname = substitute(a:choice,httpurm,'\2',"") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1404 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1405 | " dav://hostname[:port]/..path-to-file.. |
| 1406 | elseif match(a:choice,davurm) == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1407 | " call Decho("dav://...") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1408 | let b:netrw_method= 6 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1409 | if a:choice =~ '^s' |
| 1410 | let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"") |
| 1411 | else |
| 1412 | let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"") |
| 1413 | endif |
| 1414 | let b:netrw_fname = substitute(a:choice,davurm,'\3',"") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1415 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1416 | " rsync://user@hostname/...path-to-file |
| 1417 | elseif match(a:choice,rsyncurm) == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1418 | " call Decho("rsync://...") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1419 | let b:netrw_method = 7 |
| 1420 | let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"") |
| 1421 | let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1422 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1423 | " ftp://[user@]hostname[[:#]port]/...path-to-file |
| 1424 | elseif match(a:choice,ftpurm) == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1425 | " call Decho("ftp://...") |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 1426 | let userid = substitute(a:choice,ftpurm,'\2',"") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1427 | let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"") |
| 1428 | let g:netrw_port = substitute(a:choice,ftpurm,'\4',"") |
| 1429 | let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1430 | if userid != "" |
| 1431 | let g:netrw_uid= userid |
| 1432 | endif |
| 1433 | if exists("g:netrw_uid") && exists("g:netrw_passwd") |
| 1434 | let b:netrw_method = 3 |
| 1435 | else |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1436 | if s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1437 | let b:netrw_method= 2 |
| 1438 | else |
| 1439 | if !exists("g:netrw_uid") || g:netrw_uid == "" |
| 1440 | call NetUserPass() |
| 1441 | elseif !exists("g:netrw_passwd") || g:netrw_passwd == "" |
| 1442 | call NetUserPass(g:netrw_uid) |
| 1443 | " else just use current g:netrw_uid and g:netrw_passwd |
| 1444 | endif |
| 1445 | let b:netrw_method= 3 |
| 1446 | endif |
| 1447 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1448 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1449 | elseif match(a:choice,fetchurm) == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1450 | " call Decho("fetch://...") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1451 | let b:netrw_method = 8 |
| 1452 | let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"") |
| 1453 | let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"") |
| 1454 | let b:netrw_option = substitute(a:choice,fetchurm,'\4',"") |
| 1455 | let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1456 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1457 | " Issue an ftp : "machine id password [path/]filename" |
| 1458 | elseif match(a:choice,mipf) == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1459 | " call Decho("(ftp) host id pass file") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1460 | let b:netrw_method = 3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1461 | let g:netrw_machine = substitute(a:choice,mipf,'\1',"") |
| 1462 | let g:netrw_uid = substitute(a:choice,mipf,'\2',"") |
| 1463 | let g:netrw_passwd = substitute(a:choice,mipf,'\3',"") |
| 1464 | let b:netrw_fname = substitute(a:choice,mipf,'\4',"") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1465 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1466 | " Issue an ftp: "hostname [path/]filename" |
| 1467 | elseif match(a:choice,mf) == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1468 | " call Decho("(ftp) host file") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1469 | if exists("g:netrw_uid") && exists("g:netrw_passwd") |
| 1470 | let b:netrw_method = 3 |
| 1471 | let g:netrw_machine = substitute(a:choice,mf,'\1',"") |
| 1472 | let b:netrw_fname = substitute(a:choice,mf,'\2',"") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1473 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1474 | elseif s:FileReadable(expand("$HOME/.netrc")) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1475 | let b:netrw_method = 2 |
| 1476 | let g:netrw_machine = substitute(a:choice,mf,'\1',"") |
| 1477 | let b:netrw_fname = substitute(a:choice,mf,'\2',"") |
| 1478 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1479 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1480 | " sftp://user@hostname/...path-to-file |
| 1481 | elseif match(a:choice,sftpurm) == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1482 | " call Decho("sftp://...") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1483 | let b:netrw_method = 9 |
| 1484 | let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"") |
| 1485 | let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1486 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1487 | " Issue an rcp: hostname:filename" (this one should be last) |
| 1488 | elseif match(a:choice,rcphf) == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1489 | " call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1490 | let b:netrw_method = 1 |
| 1491 | let userid = substitute(a:choice,rcphf,'\2',"") |
| 1492 | let g:netrw_machine= substitute(a:choice,rcphf,'\3',"") |
| 1493 | let b:netrw_fname = substitute(a:choice,rcphf,'\4',"") |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1494 | " call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">") |
| 1495 | " call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">") |
| 1496 | " call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">") |
| 1497 | " call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1498 | if userid != "" |
| 1499 | let g:netrw_uid= userid |
| 1500 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1501 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1502 | else |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 1503 | if !exists("g:netrw_quiet") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1504 | call netrw#ErrorMsg(s:WARNING,"cannot determine method",45) |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 1505 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1506 | let b:netrw_method = -1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1507 | endif |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 1508 | |
| 1509 | " remove any leading [:#] from port number |
| 1510 | if g:netrw_port != "" |
| 1511 | let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','') |
| 1512 | endif |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1513 | |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1514 | " call Decho("a:choice <".a:choice.">") |
| 1515 | " call Decho("b:netrw_method <".b:netrw_method.">") |
| 1516 | " call Decho("g:netrw_machine<".g:netrw_machine.">") |
| 1517 | " call Decho("g:netrw_port <".g:netrw_port.">") |
| 1518 | " if exists("g:netrw_uid") "Decho |
| 1519 | " call Decho("g:netrw_uid <".g:netrw_uid.">") |
| 1520 | " endif "Decho |
| 1521 | " if exists("g:netrw_passwd") "Decho |
| 1522 | " call Decho("g:netrw_passwd <".g:netrw_passwd.">") |
| 1523 | " endif "Decho |
| 1524 | " call Decho("b:netrw_fname <".b:netrw_fname.">") |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1525 | " call Dret("NetMethod : b:netrw_method=".b:netrw_method) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1526 | endfun |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1527 | |
| 1528 | " ------------------------------------------------------------------------ |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1529 | " NetReadFixup: this sort of function is typically written by the user {{{2 |
| 1530 | " to handle extra junk that their system's ftp dumps |
| 1531 | " into the transfer. This function is provided as an |
| 1532 | " example and as a fix for a Windows 95 problem: in my |
| 1533 | " experience, win95's ftp always dumped four blank lines |
| 1534 | " at the end of the transfer. |
| 1535 | if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp |
| 1536 | fun! NetReadFixup(method, line1, line2) |
| 1537 | " call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")") |
| 1538 | if method == 3 " ftp (no <.netrc>) |
| 1539 | let fourblanklines= line2 - 3 |
| 1540 | silent fourblanklines.",".line2."g/^\s*/d" |
| 1541 | endif |
| 1542 | " call Dret("NetReadFixup") |
| 1543 | endfun |
| 1544 | endif |
| 1545 | |
| 1546 | " --------------------------------------------------------------------- |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 1547 | " NetUserPass: set username and password for subsequent ftp transfer {{{2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1548 | " Usage: :call NetUserPass() -- will prompt for userid and password |
| 1549 | " :call NetUserPass("uid") -- will prompt for password |
| 1550 | " :call NetUserPass("uid","password") -- sets global userid and password |
| 1551 | fun! NetUserPass(...) |
| 1552 | |
| 1553 | " get/set userid |
| 1554 | if a:0 == 0 |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1555 | " call Dfunc("NetUserPass(a:0<".a:0.">)") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1556 | if !exists("g:netrw_uid") || g:netrw_uid == "" |
| 1557 | " via prompt |
| 1558 | let g:netrw_uid= input('Enter username: ') |
| 1559 | endif |
| 1560 | else " from command line |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1561 | " call Dfunc("NetUserPass(a:1<".a:1.">) {") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1562 | let g:netrw_uid= a:1 |
| 1563 | endif |
| 1564 | |
| 1565 | " get password |
| 1566 | if a:0 <= 1 " via prompt |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1567 | " call Decho("a:0=".a:0." case <=1:") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1568 | let g:netrw_passwd= inputsecret("Enter Password: ") |
| 1569 | else " from command line |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1570 | " call Decho("a:0=".a:0." case >1: a:2<".a:2.">") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1571 | let g:netrw_passwd=a:2 |
| 1572 | endif |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 1573 | |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 1574 | " call Dret("NetUserPass") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1575 | endfun |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1576 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1577 | " =========================================== |
| 1578 | " Shared Browsing Support: {{{1 |
| 1579 | " =========================================== |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1580 | |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 1581 | " --------------------------------------------------------------------- |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1582 | " s:BrowserMaps: {{{2 |
| 1583 | fun! s:BrowserMaps(islocal) |
| 1584 | " call Dfunc("s:BrowserMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">") |
| 1585 | if a:islocal |
| 1586 | nnoremap <buffer> <silent> <cr> :call netrw#LocalBrowseCheck(<SID>NetBrowseChgDir(1,<SID>NetGetWord()))<cr> |
| 1587 | nnoremap <buffer> <silent> <leftmouse> <leftmouse>:call netrw#LocalBrowseCheck(<SID>NetBrowseChgDir(1,<SID>NetGetWord()))<cr> |
| 1588 | nnoremap <buffer> <silent> <c-l> :call <SID>NetRefresh(1,<SID>NetBrowseChgDir(1,'./'))<cr> |
| 1589 | nnoremap <buffer> <silent> - :exe "norm! 0"<bar>call netrw#LocalBrowseCheck(<SID>NetBrowseChgDir(1,'../'))<cr> |
| 1590 | nnoremap <buffer> <silent> a :call <SID>NetHide(1)<cr> |
| 1591 | nnoremap <buffer> <silent> mb :<c-u>call <SID>NetBookmarkDir(0,b:netrw_curdir)<cr> |
| 1592 | nnoremap <buffer> <silent> gb :<c-u>call <SID>NetBookmarkDir(1,b:netrw_curdir)<cr> |
| 1593 | nnoremap <buffer> <silent> c :exe "cd ".b:netrw_curdir<cr> |
| 1594 | nnoremap <buffer> <silent> C :let g:netrw_chgwin= winnr()<cr> |
| 1595 | nnoremap <buffer> <silent> d :call <SID>NetMakeDir("")<cr> |
| 1596 | nnoremap <buffer> <silent> <c-h> :call <SID>NetHideEdit(1)<cr> |
| 1597 | nnoremap <buffer> <silent> i :call <SID>NetListStyle(1)<cr> |
| 1598 | nnoremap <buffer> <silent> o :call <SID>NetSplit(3)<cr> |
| 1599 | nnoremap <buffer> <silent> O :call <SID>LocalObtain()<cr> |
| 1600 | nnoremap <buffer> <silent> p :call <SID>NetPreview(<SID>NetBrowseChgDir(1,<SID>NetGetWord(),1))<cr> |
| 1601 | nnoremap <buffer> <silent> P :call <SID>NetPrevWinOpen(1)<cr> |
| 1602 | nnoremap <buffer> <silent> q :<c-u>call <SID>NetBookmarkDir(2,b:netrw_curdir)<cr> |
| 1603 | nnoremap <buffer> <silent> r :let g:netrw_sort_direction= (g:netrw_sort_direction =~ 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetRefresh(1,<SID>NetBrowseChgDir(1,'./'))<cr> |
| 1604 | nnoremap <buffer> <silent> s :call <SID>NetSortStyle(1)<cr> |
| 1605 | nnoremap <buffer> <silent> S :call <SID>NetSortSequence(1)<cr> |
| 1606 | nnoremap <buffer> <silent> t :call <SID>NetSplit(4)<cr> |
| 1607 | nnoremap <buffer> <silent> u :<c-u>call <SID>NetBookmarkDir(4,expand("%"))<cr> |
| 1608 | nnoremap <buffer> <silent> U :<c-u>call <SID>NetBookmarkDir(5,expand("%"))<cr> |
| 1609 | nnoremap <buffer> <silent> v :call <SID>NetSplit(5)<cr> |
| 1610 | nnoremap <buffer> <silent> x :call netrw#NetBrowseX(<SID>NetBrowseChgDir(1,<SID>NetGetWord(),0),0)"<cr> |
| 1611 | if s:didstarstar || !mapcheck("<s-down>","n") |
| 1612 | nnoremap <buffer> <silent> <s-down> :Nexplore<cr> |
| 1613 | endif |
| 1614 | if s:didstarstar || !mapcheck("<s-up>","n") |
| 1615 | nnoremap <buffer> <silent> <s-up> :Pexplore<cr> |
| 1616 | endif |
| 1617 | exe 'nnoremap <buffer> <silent> <del> :call <SID>LocalBrowseRm("'.b:netrw_curdir.'")<cr>' |
| 1618 | exe 'vnoremap <buffer> <silent> <del> :call <SID>LocalBrowseRm("'.b:netrw_curdir.'")<cr>' |
| 1619 | exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>LocalBrowseRm("'.b:netrw_curdir.'")<cr>' |
| 1620 | exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>LocalBrowseRm("'.b:netrw_curdir.'")<cr>' |
| 1621 | exe 'nnoremap <buffer> <silent> D :call <SID>LocalBrowseRm("'.b:netrw_curdir.'")<cr>' |
| 1622 | exe 'vnoremap <buffer> <silent> D :call <SID>LocalBrowseRm("'.b:netrw_curdir.'")<cr>' |
| 1623 | exe 'nnoremap <buffer> <silent> R :call <SID>LocalBrowseRename("'.b:netrw_curdir.'")<cr>' |
| 1624 | exe 'vnoremap <buffer> <silent> R :call <SID>LocalBrowseRename("'.b:netrw_curdir.'")<cr>' |
| 1625 | exe 'nnoremap <buffer> <silent> <Leader>m :call <SID>NetMakeDir("")<cr>' |
| 1626 | nnoremap <buffer> <F1> :he netrw-dir<cr> |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 1627 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1628 | else " remote |
| 1629 | call s:RemotePathAnalysis(b:netrw_curdir) |
| 1630 | nnoremap <buffer> <silent> <cr> :call <SID>NetBrowse(0,<SID>NetBrowseChgDir(0,<SID>NetGetWord()))<cr> |
| 1631 | nnoremap <buffer> <silent> <leftmouse> <leftmouse>:call <SID>NetBrowse(0,<SID>NetBrowseChgDir(0,<SID>NetGetWord()))<cr> |
| 1632 | nnoremap <buffer> <silent> <c-l> :call <SID>NetRefresh(0,<SID>NetBrowseChgDir(0,'./'))<cr> |
| 1633 | nnoremap <buffer> <silent> - :exe "norm! 0"<bar>call <SID>NetBrowse(0,<SID>NetBrowseChgDir(0,'../'))<cr> |
| 1634 | nnoremap <buffer> <silent> a :call <SID>NetHide(0)<cr> |
| 1635 | nnoremap <buffer> <silent> mb :<c-u>call <SID>NetBookmarkDir(0,b:netrw_curdir)<cr> |
| 1636 | nnoremap <buffer> <silent> gb :<c-u>call <SID>NetBookmarkDir(1,b:netrw_cur)<cr> |
| 1637 | nnoremap <buffer> <silent> C :let g:netrw_chgwin= winnr()<cr> |
| 1638 | nnoremap <buffer> <silent> <c-h> :call <SID>NetHideEdit(0)<cr> |
| 1639 | nnoremap <buffer> <silent> i :call <SID>NetListStyle(0)<cr> |
| 1640 | nnoremap <buffer> <silent> o :call <SID>NetSplit(0)<cr> |
| 1641 | nnoremap <buffer> <silent> O :call netrw#NetObtain(0)<cr> |
| 1642 | vnoremap <buffer> <silent> O :call netrw#NetObtain(1)<cr> |
| 1643 | nnoremap <buffer> <silent> p :call <SID>NetPreview(<SID>NetBrowseChgDir(1,<SID>NetGetWord(),1))<cr> |
| 1644 | nnoremap <buffer> <silent> P :call <SID>NetPrevWinOpen(0)<cr> |
| 1645 | nnoremap <buffer> <silent> q :<c-u>call <SID>NetBookmarkDir(2,b:netrw_curdir)<cr> |
| 1646 | nnoremap <buffer> <silent> r :let g:netrw_sort_direction= (g:netrw_sort_direction =~ 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetBrowse(0,<SID>NetBrowseChgDir(0,'./'))<cr> |
| 1647 | nnoremap <buffer> <silent> s :call <SID>NetSortStyle(0)<cr> |
| 1648 | nnoremap <buffer> <silent> S :call <SID>NetSortSequence(0)<cr> |
| 1649 | nnoremap <buffer> <silent> t :call <SID>NetSplit(1)<cr> |
| 1650 | nnoremap <buffer> <silent> u :<c-u>call <SID>NetBookmarkDir(4,b:netrw_curdir)<cr> |
| 1651 | nnoremap <buffer> <silent> U :<c-u>call <SID>NetBookmarkDir(5,b:netrw_curdir)<cr> |
| 1652 | nnoremap <buffer> <silent> v :call <SID>NetSplit(2)<cr> |
| 1653 | nnoremap <buffer> <silent> x :call netrw#NetBrowseX(<SID>NetBrowseChgDir(0,<SID>NetGetWord()),1)<cr> |
| 1654 | exe 'nnoremap <buffer> <silent> <del> :call <SID>NetBrowseRm("'.s:user.s:machine.'","'.s:path.'")<cr>' |
| 1655 | exe 'vnoremap <buffer> <silent> <del> :call <SID>NetBrowseRm("'.s:user.s:machine.'","'.s:path.'")<cr>' |
| 1656 | exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetBrowseRm("'.s:user.s:machine.'","'.s:path.'")<cr>' |
| 1657 | exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetBrowseRm("'.s:user.s:machine.'","'.s:path.'")<cr>' |
| 1658 | exe 'nnoremap <buffer> <silent> d :call <SID>NetMakeDir("'.s:user.s:machine.'")<cr>' |
| 1659 | exe 'nnoremap <buffer> <silent> D :call <SID>NetBrowseRm("'.s:user.s:machine.'","'.s:path.'")<cr>' |
| 1660 | exe 'vnoremap <buffer> <silent> D :call <SID>NetBrowseRm("'.s:user.s:machine.'","'.s:path.'")<cr>' |
| 1661 | exe 'nnoremap <buffer> <silent> R :call <SID>NetBrowseRename("'.s:user.s:machine.'","'.s:path.'")<cr>' |
| 1662 | exe 'vnoremap <buffer> <silent> R :call <SID>NetBrowseRename("'.s:user.s:machine.'","'.s:path.'")<cr>' |
| 1663 | nnoremap <buffer> <F1> :he netrw-browse-cmds<cr> |
| 1664 | endif |
| 1665 | " call Dret("s:BrowserMaps") |
| 1666 | endfun |
| 1667 | |
| 1668 | " --------------------------------------------------------------------- |
| 1669 | " s:NetBrowse: This function uses the command in g:netrw_list_cmd to get a list {{{2 |
| 1670 | " of the contents of a remote directory. It is assumed that the |
| 1671 | " g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted |
| 1672 | " with the requested remote hostname first. |
| 1673 | fun! s:NetBrowse(islocal,dirname) |
| 1674 | if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 1675 | " call Dfunc("NetBrowse(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".w:netrw_liststyle." ".g:loaded_netrw." buf#".bufnr("%")."<".bufname("%").">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1676 | " call Dredir("ls!") |
| 1677 | |
| 1678 | if exists("s:netrw_skipbrowse") |
| 1679 | unlet s:netrw_skipbrowse |
| 1680 | " call Dret("NetBrowse : s:netrw_skipbrowse=".s:netrw_skipbrowse) |
| 1681 | return |
| 1682 | endif |
| 1683 | |
| 1684 | call s:NetOptionSave() |
| 1685 | |
| 1686 | if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep |
| 1687 | " call Decho("handle w:netrw_acdkeep:") |
| 1688 | " call Decho("cd ".escape(a:dirname,s:netrw_cd_escape)." (due to 'acd')") |
| 1689 | exe 'cd '.escape(a:dirname,s:netrw_cd_escape) |
| 1690 | " call Decho("getcwd<".getcwd().">") |
| 1691 | |
| 1692 | elseif !a:islocal && a:dirname !~ '[\/]$' && a:dirname !~ '^"' |
| 1693 | " looks like a regular file, attempt transfer |
| 1694 | " call Decho("attempt transfer as regular file<".a:dirname.">") |
| 1695 | |
| 1696 | " remove any filetype indicator from end of dirname, except for the {{{3 |
| 1697 | " "this is a directory" indicator (/). |
| 1698 | " There shouldn't be one of those here, anyway. |
| 1699 | let path= substitute(a:dirname,'[*=@|]\r\=$','','e') |
| 1700 | " call Decho("new path<".path.">") |
| 1701 | call s:RemotePathAnalysis(a:dirname) |
| 1702 | |
| 1703 | " remote-read the requested file into current buffer {{{3 |
| 1704 | mark ' |
| 1705 | call s:NetrwEnew(a:dirname) |
| 1706 | let b:netrw_curdir= a:dirname |
| 1707 | call s:NetrwSafeOptions() |
| 1708 | setlocal ma noro |
| 1709 | " call Decho("exe silent! keepalt file ".s:method."://".s:user.s:machine."/".escape(s:path,s:netrw_cd_escape)." (bt=".&bt.")") |
| 1710 | exe "silent! keepalt file ".s:method."://".s:user.s:machine."/".escape(s:path,s:netrw_cd_escape) |
| 1711 | exe "silent keepalt doau BufReadPre ".s:fname |
| 1712 | silent call netrw#NetRead(2,s:method."://".s:user.s:machine."/".s:path) |
| 1713 | exe "silent keepalt doau BufReadPost ".s:fname |
| 1714 | |
| 1715 | " save certain window-oriented variables into buffer-oriented variables {{{3 |
| 1716 | call s:SetBufWinVars() |
| 1717 | call s:NetOptionRestore() |
| 1718 | setlocal nomod nowrap |
| 1719 | |
| 1720 | " call Dret("NetBrowse : file<".s:fname.">") |
| 1721 | return |
| 1722 | endif |
| 1723 | |
| 1724 | " use buffer-oriented WinVars if buffer ones exist but window ones don't {{{3 |
| 1725 | call s:UseBufWinVars() |
| 1726 | |
| 1727 | " set up some variables {{{3 |
| 1728 | let b:netrw_browser_active = 1 |
| 1729 | let dirname = a:dirname |
| 1730 | let s:last_sort_by = g:netrw_sort_by |
| 1731 | |
| 1732 | call s:NetMenu(1) " set up menu {{{3 |
| 1733 | if s:NetGetBuffer(a:islocal,dirname) " set up buffer {{{3 |
| 1734 | " call Dret("NetBrowse : re-using buffer") |
| 1735 | return |
| 1736 | endif |
| 1737 | |
| 1738 | " set b:netrw_curdir to the new directory name {{{3 |
| 1739 | " call Decho("set b:netrw_curdir to the new directory name:") |
| 1740 | let b:netrw_curdir= dirname |
| 1741 | if b:netrw_curdir =~ '[/\\]$' |
| 1742 | let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e') |
| 1743 | endif |
| 1744 | if b:netrw_curdir == '' |
| 1745 | if has("amiga") |
| 1746 | " On the Amiga, the empty string connotes the current directory |
| 1747 | let b:netrw_curdir= getcwd() |
| 1748 | else |
| 1749 | " under unix, when the root directory is encountered, the result |
| 1750 | " from the preceding substitute is an empty string. |
| 1751 | let b:netrw_curdir= '/' |
| 1752 | endif |
| 1753 | endif |
| 1754 | if !a:islocal && b:netrw_curdir !~ '/$' |
| 1755 | let b:netrw_curdir= b:netrw_curdir.'/' |
| 1756 | endif |
| 1757 | " call Decho("b:netrw_curdir<".b:netrw_curdir.">") |
| 1758 | |
| 1759 | " ------------ |
| 1760 | " (local only) {{{3 |
| 1761 | " ------------ |
| 1762 | if a:islocal |
| 1763 | " call Decho("local only:") |
| 1764 | |
| 1765 | " Set up ShellCmdPost handling. Append current buffer to browselist |
| 1766 | call s:LocalFastBrowser() |
| 1767 | |
| 1768 | " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3 |
| 1769 | if !g:netrw_keepdir |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 1770 | " call Decho("handle keepdir: (g:netrw_keepdir=".g:netrw_keepdir.")") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1771 | " call Decho('exe cd '.escape(b:netrw_curdir,s:netrw_cd_escape)) |
| 1772 | try |
| 1773 | exe 'cd '.escape(b:netrw_curdir,s:netrw_cd_escape) |
| 1774 | catch /^Vim\%((\a\+)\)\=:E472/ |
| 1775 | call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".b:netrw_curdir."> (permissions?)",33) |
| 1776 | if exists("w:netrw_prvdir") |
| 1777 | let b:netrw_curdir= w:netrw_prvdir |
Bram Moolenaar | 83bab71 | 2005-08-01 21:58:57 +0000 | [diff] [blame] | 1778 | else |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1779 | call s:NetOptionRestore() |
| 1780 | let b:netrw_curdir= dirname |
| 1781 | " call Dret("NetBrowse : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">") |
| 1782 | return |
| 1783 | endif |
| 1784 | endtry |
| 1785 | endif |
| 1786 | |
| 1787 | " -------------------------------- |
| 1788 | " remote handling: {{{3 |
| 1789 | " -------------------------------- |
| 1790 | else |
| 1791 | " call Decho("remote only:") |
| 1792 | |
| 1793 | " analyze a:dirname and g:netrw_list_cmd {{{4 |
| 1794 | " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist")."> a:dirname<".a:dirname.">") |
| 1795 | if a:dirname == "NetrwTreeListing" |
| 1796 | let dirname= b:netrw_curdir |
| 1797 | " call Decho("(dirname was NetrwTreeListing) dirname<".dirname.">") |
| 1798 | elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir") |
| 1799 | let dirname= substitute(b:netrw_curdir,'\\','/','g') |
| 1800 | if dirname !~ '/$' |
| 1801 | let dirname= dirname.'/' |
| 1802 | endif |
| 1803 | let b:netrw_curdir = dirname |
| 1804 | " call Decho("(liststyle is TREELIST) dirname<".dirname.">") |
| 1805 | else |
| 1806 | let dirname = substitute(a:dirname,'\\','/','g') |
| 1807 | " call Decho("(normal) dirname<".dirname.">") |
| 1808 | endif |
| 1809 | |
| 1810 | let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$' |
| 1811 | if dirname !~ dirpat |
| 1812 | if !exists("g:netrw_quiet") |
| 1813 | call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20) |
| 1814 | endif |
| 1815 | call s:NetOptionRestore() |
| 1816 | " call Dret("NetBrowse : badly formatted dirname<".dirname.">") |
| 1817 | return |
| 1818 | endif |
| 1819 | let b:netrw_curdir= dirname |
| 1820 | " call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)") |
| 1821 | endif " (additional remote handling) |
| 1822 | |
| 1823 | " ----------------------- |
| 1824 | " Directory Listing: {{{3 |
| 1825 | " ----------------------- |
| 1826 | setlocal noro ma |
| 1827 | call s:BrowserMaps(a:islocal) |
| 1828 | call s:PerformListing(a:islocal) |
| 1829 | |
| 1830 | " call Dret("NetBrowse") |
| 1831 | return |
| 1832 | endfun |
| 1833 | |
| 1834 | " --------------------------------------------------------------------- |
| 1835 | " s:NetGetBuffer: {{{2 |
| 1836 | " returns 0=cleared buffer |
| 1837 | " 1=re-used buffer |
| 1838 | fun! s:NetGetBuffer(islocal,dirname) |
| 1839 | " call Dfunc("s:NetGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">)") |
| 1840 | |
| 1841 | " re-use buffer if possible {{{3 |
| 1842 | if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST |
| 1843 | " find NetrwTreeList buffer if there is one |
| 1844 | let dirname= "NetrwTreeListing" |
| 1845 | let bufnum = bufnr('\<NetrwTreeListing\>') |
| 1846 | if bufnum != -1 |
| 1847 | " call Dret("s:NetGetBuffer : bufnum#".bufnum."<NetrwTreeListing>") |
| 1848 | return |
| 1849 | endif |
| 1850 | |
| 1851 | else |
| 1852 | " find buffer number of buffer named precisely the same as dirname {{{3 |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 1853 | " call Dredir("ls!") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1854 | let dirname= a:dirname |
| 1855 | " call Decho("find buffer<".dirname.">'s number ") |
| 1856 | let bufnum= bufnr(escape(dirname,'\')) |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 1857 | " call Decho("findbuf1: bufnum=bufnr('".escape(dirname,'\')."')=".bufnum." (initial)") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1858 | let ibuf= 1 |
| 1859 | if bufnum > 0 && bufname(bufnum) != dirname |
| 1860 | let buflast = bufnr("$") |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 1861 | " call Decho("findbuf2: buflast=".buflast) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1862 | while ibuf <= buflast |
| 1863 | let bname= bufname(ibuf) |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 1864 | " call Decho("findbuf3: dirname<".dirname."> bufname(".ibuf.")<".bname.">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1865 | if bname != '' && bname !~ '/' && dirname =~ '/'.bname.'$' | break | endif |
| 1866 | if bname =~ '^'.dirname.'\=$' | break | endif |
| 1867 | let ibuf= ibuf + 1 |
| 1868 | endwhile |
| 1869 | if ibuf > buflast |
| 1870 | let bufnum= -1 |
| 1871 | else |
| 1872 | let bufnum= ibuf |
| 1873 | endif |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 1874 | " call Decho("findbuf4: bufnum=".bufnum) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1875 | endif |
| 1876 | endif |
| 1877 | |
| 1878 | " get enew buffer and name it -or- re-use buffer {{{3 |
| 1879 | mark ' |
| 1880 | if bufnum < 0 || !bufexists(bufnum) |
| 1881 | " call Decho("get enew buffer") |
| 1882 | call s:NetrwEnew(dirname) |
| 1883 | call s:NetrwSafeOptions() |
| 1884 | " name the buffer |
| 1885 | if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 1886 | " call Decho('silent! keepalt file NetrwTreeListing') |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1887 | silent! keepalt file NetrwTreeListing |
| 1888 | else |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 1889 | " call Decho('exe silent! keepalt file '.escape(dirname,s:netrw_cd_escape)) |
| 1890 | " let v:errmsg= "" " Decho |
| 1891 | let escdirname= escape(dirname,s:netrw_cd_escape) |
| 1892 | exe 'silent! keepalt file '.escdirname |
| 1893 | " call Decho("errmsg<".v:errmsg."> bufnr(".escdirname.")=".bufnr(escdirname)."<".bufname(bufnr(escdirname)).">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1894 | endif |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 1895 | " call Decho("named enew buffer#".bufnr("%")."<".bufname("%").">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1896 | |
| 1897 | else " Re-use the buffer |
| 1898 | |
| 1899 | " call Decho("re-use buffer:") |
| 1900 | let eikeep= &ei |
| 1901 | set ei=all |
| 1902 | if getline(2) =~ '^" Netrw Directory Listing' |
| 1903 | " call Decho("re-use buffer#".bufnum."<".((bufnum > 0)? bufname(bufnum) : "")."> using: keepalt b ".bufnum) |
| 1904 | exe "keepalt b ".bufnum |
| 1905 | else |
| 1906 | " call Decho("reusing buffer#".bufnum."<".((bufnum > 0)? bufname(bufnum) : "")."> using: b ".bufnum) |
| 1907 | exe "b ".bufnum |
| 1908 | endif |
| 1909 | let &ei= eikeep |
| 1910 | if line("$") <= 1 |
| 1911 | call s:NetrwListSettings(a:islocal) |
| 1912 | " call Dret("s:NetGetBuffer 0 : re-using buffer#".bufnr("%").", but its empty, so refresh it") |
| 1913 | return 0 |
| 1914 | elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST |
| 1915 | " call Decho("clear buffer<".expand("%")."> with :%d") |
| 1916 | silent %d |
| 1917 | call s:NetrwListSettings(a:islocal) |
| 1918 | " call Dret("s:NetGetBuffer 0 : re-using buffer#".bufnr("%").", but treelist mode always needs a refresh") |
| 1919 | return 0 |
| 1920 | else |
| 1921 | " call Dret("s:NetGetBuffer 1 : buf#".bufnr("%")) |
| 1922 | return 1 |
| 1923 | endif |
| 1924 | endif |
| 1925 | |
| 1926 | " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3 |
| 1927 | " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast) |
| 1928 | " slow 0 D D Deleting a buffer implies it will not be re-used (slow) |
| 1929 | " med 1 D H |
| 1930 | " fast 2 H H |
| 1931 | let fname= expand("%") |
| 1932 | call s:NetrwListSettings(a:islocal) |
| 1933 | exe "file ".escape(fname,' ') |
| 1934 | |
| 1935 | " delete all lines from buffer {{{3 |
| 1936 | " call Decho("clear buffer<".expand("%")."> with :%d") |
| 1937 | keepalt silent! %d |
| 1938 | |
| 1939 | " call Dret("s:NetGetBuffer 0 : buf#".bufnr("%")) |
| 1940 | return 0 |
| 1941 | endfun |
| 1942 | |
| 1943 | " --------------------------------------------------------------------- |
| 1944 | " s:NetrwListSettings: {{{2 |
| 1945 | fun! s:NetrwListSettings(islocal) |
| 1946 | " call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")") |
| 1947 | let fname= bufname("%") |
| 1948 | setlocal bt=nofile nobl ma nonu nowrap noro |
| 1949 | exe "file ".escape(fname,' ') |
| 1950 | if g:netrw_use_noswf |
| 1951 | setlocal noswf |
| 1952 | endif |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 1953 | " call Dredir("ls!") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1954 | " call Decho("exe setlocal ts=".g:netrw_maxfilenamelen) |
| 1955 | exe "setlocal ts=".g:netrw_maxfilenamelen |
| 1956 | if g:netrw_fastbrowse > a:islocal |
| 1957 | setlocal bh=hide |
| 1958 | else |
| 1959 | setlocal bh=delete |
| 1960 | endif |
| 1961 | " call Dret("s:NetrwListSettings") |
| 1962 | endfun |
| 1963 | |
| 1964 | " --------------------------------------------------------------------- |
| 1965 | " s:PerformListing: {{{2 |
| 1966 | fun! s:PerformListing(islocal) |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 1967 | " call Dfunc("s:PerformListing(islocal=".a:islocal.") buf(%)=".bufnr("%")."<".bufname("%").">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1968 | |
| 1969 | " if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho |
| 1970 | " call Decho("(netrw) Processing your browsing request...") |
| 1971 | " endif " Decho |
| 1972 | |
| 1973 | " call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a')) |
| 1974 | if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") |
| 1975 | " force a refresh for tree listings |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 1976 | " call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 1977 | setlocal ma noro |
| 1978 | keepjumps %d |
| 1979 | endif |
| 1980 | |
| 1981 | " save current directory on directory history list |
| 1982 | call s:NetBookmarkDir(3,b:netrw_curdir) |
| 1983 | |
| 1984 | " Set up the banner {{{3 |
| 1985 | " call Decho("set up banner") |
| 1986 | keepjumps put ='\" ============================================================================' |
| 1987 | keepjumps put ='\" Netrw Directory Listing (netrw '.g:loaded_netrw.')' |
| 1988 | keepjumps put ='\" '.b:netrw_curdir |
| 1989 | keepjumps 1d |
| 1990 | let w:netrw_bannercnt= 3 |
| 1991 | exe w:netrw_bannercnt |
| 1992 | |
| 1993 | let sortby= g:netrw_sort_by |
| 1994 | if g:netrw_sort_direction =~ "^r" |
| 1995 | let sortby= sortby." reversed" |
| 1996 | endif |
| 1997 | |
| 1998 | " Sorted by... {{{3 |
| 1999 | " call Decho("handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">") |
| 2000 | if g:netrw_sort_by =~ "^n" |
| 2001 | " call Decho("directories will be sorted by name") |
| 2002 | " sorted by name |
| 2003 | keepjumps put ='\" Sorted by '.sortby |
| 2004 | keepjumps put ='\" Sort sequence: '.g:netrw_sort_sequence |
| 2005 | let w:netrw_bannercnt= w:netrw_bannercnt + 2 |
| 2006 | else |
| 2007 | " call Decho("directories will be sorted by size or time") |
| 2008 | " sorted by size or date |
| 2009 | keepjumps put ='\" Sorted by '.sortby |
| 2010 | let w:netrw_bannercnt= w:netrw_bannercnt + 1 |
| 2011 | endif |
| 2012 | exe w:netrw_bannercnt |
| 2013 | |
| 2014 | " Hiding... -or- Showing... {{{3 |
| 2015 | " call Decho("handle hiding/showing (g:netrw_hide=".g:netrw_list_hide." g:netrw_list_hide<".g:netrw_list_hide.">)") |
| 2016 | if g:netrw_list_hide != "" && g:netrw_hide |
| 2017 | if g:netrw_hide == 1 |
| 2018 | keepjumps put ='\" Hiding: '.g:netrw_list_hide |
| 2019 | else |
| 2020 | keepjumps put ='\" Showing: '.g:netrw_list_hide |
| 2021 | endif |
| 2022 | let w:netrw_bannercnt= w:netrw_bannercnt + 1 |
| 2023 | endif |
| 2024 | exe w:netrw_bannercnt |
| 2025 | keepjumps put ='\" Quick Help: <F1>:help -:go up dir D:delete R:rename s:sort-by x:exec' |
| 2026 | keepjumps put ='\" ============================================================================' |
| 2027 | let w:netrw_bannercnt= w:netrw_bannercnt + 2 |
| 2028 | |
| 2029 | " bannercnt should index the line just after the banner |
| 2030 | let w:netrw_bannercnt= w:netrw_bannercnt + 1 |
| 2031 | exe w:netrw_bannercnt |
| 2032 | " call Decho("bannercnt=".w:netrw_bannercnt." (should index line just after banner) line($)=".line("$")) |
| 2033 | |
| 2034 | " set up syntax highlighting {{{3 |
| 2035 | " call Decho("set up syntax highlighting") |
| 2036 | if has("syntax") |
| 2037 | setlocal ft=netrw |
| 2038 | if !exists("g:syntax_on") || !g:syntax_on |
| 2039 | setlocal ft= |
| 2040 | endif |
| 2041 | endif |
| 2042 | |
| 2043 | " get list of files |
| 2044 | if a:islocal |
| 2045 | call s:LocalListing() |
| 2046 | else " remote |
| 2047 | call s:RemoteListing() |
| 2048 | endif |
| 2049 | " call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)") |
| 2050 | |
| 2051 | " manipulate the directory listing (hide, sort) {{{3 |
| 2052 | if line("$") >= w:netrw_bannercnt |
| 2053 | " call Decho("manipulate directory listing (hide)") |
| 2054 | " call Decho("g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">") |
| 2055 | if g:netrw_hide && g:netrw_list_hide != "" |
| 2056 | call s:NetListHide() |
| 2057 | endif |
| 2058 | if line("$") >= w:netrw_bannercnt |
| 2059 | " call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">") |
| 2060 | |
| 2061 | if g:netrw_sort_by =~ "^n" |
| 2062 | " sort by name |
| 2063 | call s:SetSort() |
| 2064 | |
| 2065 | if w:netrw_bannercnt < line("$") |
| 2066 | " call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")") |
| 2067 | if g:netrw_sort_direction =~ 'n' |
| 2068 | " normal direction sorting |
| 2069 | exe 'silent keepjumps '.w:netrw_bannercnt.',$sort' |
Bram Moolenaar | 83bab71 | 2005-08-01 21:58:57 +0000 | [diff] [blame] | 2070 | else |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2071 | " reverse direction sorting |
| 2072 | exe 'silent keepjumps '.w:netrw_bannercnt.',$sort!' |
Bram Moolenaar | 83bab71 | 2005-08-01 21:58:57 +0000 | [diff] [blame] | 2073 | endif |
| 2074 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2075 | " remove priority pattern prefix |
| 2076 | " call Decho("remove priority pattern prefix") |
| 2077 | exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\d\{3}\///e' |
| 2078 | |
| 2079 | elseif a:islocal |
| 2080 | if w:netrw_bannercnt < line("$") |
| 2081 | " call Decho("g:netrw_sort_direction=".g:netrw_sort_direction) |
| 2082 | if g:netrw_sort_direction =~ 'n' |
| 2083 | " call Decho('exe silent keepjumps '.w:netrw_bannercnt.',$sort') |
| 2084 | exe 'silent keepjumps '.w:netrw_bannercnt.',$sort' |
| 2085 | else |
| 2086 | " call Decho('exe silent keepjumps '.w:netrw_bannercnt.',$sort!') |
| 2087 | exe 'silent keepjumps '.w:netrw_bannercnt.',$sort!' |
| 2088 | endif |
| 2089 | endif |
| 2090 | exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\d\{-}\///e' |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 2091 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2092 | |
| 2093 | elseif g:netrw_sort_direction =~ 'r' |
| 2094 | " call Decho('reverse the sorted listing') |
| 2095 | exe 'silent keepjumps '.w:netrw_bannercnt.'g/^/m '.w:netrw_bannercnt |
| 2096 | endif |
| 2097 | endif |
| 2098 | |
| 2099 | " convert to wide/tree listing {{{3 |
| 2100 | " call Decho("modify display if wide/tree listing style") |
| 2101 | call s:NetWideListing() |
| 2102 | call s:NetTreeListing(b:netrw_curdir) |
| 2103 | |
| 2104 | if exists("w:netrw_bannercnt") && line("$") > w:netrw_bannercnt |
| 2105 | " place cursor on the top-left corner of the file listing |
| 2106 | " call Decho("place cursor on top-left corner of file listing") |
| 2107 | exe 'silent '.w:netrw_bannercnt |
| 2108 | norm! 0 |
| 2109 | endif |
| 2110 | |
| 2111 | " record previous current directory |
| 2112 | let w:netrw_prvdir= b:netrw_curdir |
| 2113 | " call Decho("record netrw_prvdir<".w:netrw_prvdir.">") |
| 2114 | |
| 2115 | " save certain window-oriented variables into buffer-oriented variables {{{3 |
| 2116 | call s:SetBufWinVars() |
| 2117 | call s:NetOptionRestore() |
| 2118 | |
| 2119 | " set display to netrw display settings |
| 2120 | " call Decho("set display to netrw display settings (noma nomod etc)") |
| 2121 | setlocal noma nomod nonu nobl nowrap ro |
| 2122 | if exists("s:treecurpos") |
| 2123 | call setpos('.',s:treecurpos) |
| 2124 | unlet s:treecurpos |
| 2125 | endif |
| 2126 | |
| 2127 | " call Dret("s:PerformListing : curpos<".string(getpos(".")).">") |
| 2128 | endfun |
| 2129 | |
| 2130 | " --------------------------------------------------------------------- |
| 2131 | " s:NetBrowseChgDir: constructs a new directory based on the current {{{2 |
| 2132 | " directory and a new directory name |
| 2133 | fun! s:NetBrowseChgDir(islocal,newdir,...) |
| 2134 | " call Dfunc("s:NetBrowseChgDir(islocal=".a:islocal."> newdir<".a:newdir.">) a:0=".a:0." curpos<".string(getpos("."))."> b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "").">") |
| 2135 | |
| 2136 | if !exists("b:netrw_curdir") |
| 2137 | " call Decho("(NetBrowseChgDir) b:netrw_curdir doesn't exist!") |
| 2138 | echoerr "(NetBrowseChgDir) b:netrw_curdir doesn't exist!" |
| 2139 | " call Dret("s:NetBrowseChgDir") |
| 2140 | return |
| 2141 | endif |
| 2142 | |
| 2143 | call netrw#NetSavePosn() |
| 2144 | let nbcd_curpos = getpos('.') |
| 2145 | let dirname = substitute(b:netrw_curdir,'\\','/','ge') |
| 2146 | let newdir = a:newdir |
| 2147 | |
| 2148 | " set up o/s-dependent directory recognition pattern |
| 2149 | if has("amiga") |
| 2150 | let dirpat= '[\/:]$' |
| 2151 | else |
| 2152 | let dirpat= '[\/]$' |
| 2153 | endif |
| 2154 | " call Decho("dirname<".dirname."> dirpat<".dirpat.">") |
| 2155 | |
| 2156 | if dirname !~ dirpat |
| 2157 | " apparently vim is "recognizing" that it is in a directory and |
| 2158 | " is removing the trailing "/". Bad idea, so I have to put it back. |
| 2159 | let dirname= dirname.'/' |
| 2160 | " call Decho("adjusting dirname<".dirname.">") |
| 2161 | endif |
| 2162 | |
| 2163 | if newdir !~ dirpat |
| 2164 | " handling a file |
| 2165 | " call Decho('case "handling a file": newdir<'.newdir.'> !~ dirpat<'.dirpat.">") |
| 2166 | if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)' |
| 2167 | let dirname= s:NetTreeDir().newdir |
| 2168 | " call Decho("tree listing") |
| 2169 | elseif newdir =~ '^\(/\|\a:\)' |
| 2170 | let dirname= newdir |
| 2171 | else |
| 2172 | let dirname= s:ComposePath(dirname,newdir) |
| 2173 | endif |
| 2174 | " call Decho("handling a file: dirname<".dirname."> (a:0=".a:0.")") |
| 2175 | " this lets NetBrowseX avoid the edit |
| 2176 | if a:0 < 1 |
| 2177 | " call Decho("dirname<".dirname."> netrw_cd_escape<".s:netrw_cd_escape."> browse_split=".g:netrw_browse_split) |
| 2178 | " call Decho("about to edit<".escape(dirname,s:netrw_cd_escape)."> didsplit=".(exists("s:didsplit")? s:didsplit : "doesn't exist")) |
| 2179 | if !exists("s:didsplit") |
| 2180 | if g:netrw_browse_split == 1 |
| 2181 | new |
| 2182 | wincmd _ |
| 2183 | elseif g:netrw_browse_split == 2 |
| 2184 | rightb vert new |
| 2185 | wincmd | |
| 2186 | elseif g:netrw_browse_split == 3 |
| 2187 | tabnew |
| 2188 | else |
| 2189 | " handling a file, didn't split, so remove menu |
| 2190 | " call Decho("handling a file+didn't split, so remove menu") |
| 2191 | call s:NetMenu(0) |
| 2192 | " optional change to window |
| 2193 | if g:netrw_chgwin >= 1 |
| 2194 | exe g:netrw_chgwin."wincmd w" |
| 2195 | endif |
| 2196 | endif |
| 2197 | endif |
| 2198 | " edit the file |
| 2199 | " its local only: LocalBrowseCheck() doesn't edit a file, but NetBrowse() will |
| 2200 | if a:islocal |
| 2201 | " call Decho("edit file: exe e! ".escape(dirname,s:netrw_cd_escape)) |
| 2202 | exe "e! ".escape(dirname,s:netrw_cd_escape) |
| 2203 | endif |
| 2204 | setlocal ma nomod noro |
| 2205 | endif |
| 2206 | |
| 2207 | elseif newdir =~ '^/' |
| 2208 | " just go to the new directory spec |
| 2209 | " call Decho('case "just go to new directory spec": newdir<'.newdir.'>') |
| 2210 | let dirname= newdir |
| 2211 | |
| 2212 | elseif newdir == './' |
| 2213 | " refresh the directory list |
| 2214 | " call Decho('case "refresh directory listing": newdir == "./"') |
| 2215 | |
| 2216 | elseif newdir == '../' |
| 2217 | " go up one directory |
| 2218 | " call Decho('case "go up one directory": newdir == "../"') |
| 2219 | |
| 2220 | if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") |
| 2221 | " force a refresh |
| 2222 | " call Decho("clear buffer<".expand("%")."> with :%d") |
| 2223 | setlocal noro ma |
| 2224 | keepjumps %d |
| 2225 | endif |
| 2226 | |
| 2227 | if has("amiga") |
| 2228 | " amiga |
| 2229 | " call Decho('case "go up one directory": newdir == "../" and amiga') |
| 2230 | if a:islocal |
| 2231 | let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','') |
| 2232 | let dirname= substitute(dirname,'/$','','') |
| 2233 | else |
| 2234 | let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','') |
| 2235 | endif |
| 2236 | " call Decho("amiga: dirname<".dirname."> (go up one dir)") |
| 2237 | |
| 2238 | else |
| 2239 | " unix or cygwin |
| 2240 | " call Decho('case "go up one directory": newdir == "../" and unix or cygwin') |
| 2241 | if a:islocal |
| 2242 | let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','') |
| 2243 | if dirname == "" |
| 2244 | let dirname= '/' |
| 2245 | endif |
| 2246 | else |
| 2247 | let dirname= substitute(dirname,'^\(\a\+://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','') |
| 2248 | endif |
| 2249 | " call Decho("unix: dirname<".dirname."> (go up one dir)") |
| 2250 | endif |
| 2251 | |
| 2252 | elseif w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") |
| 2253 | " call Decho('case liststyle is TREELIST and w:netrw_treedict exists') |
| 2254 | " force a refresh (for TREELIST, wait for NetTreeDir() to force the refresh) |
| 2255 | setlocal noro ma |
| 2256 | if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")) |
| 2257 | " call Decho("clear buffer<".expand("%")."> with :%d") |
| 2258 | keepjumps %d |
| 2259 | endif |
| 2260 | let treedir = s:NetTreeDir() |
| 2261 | let s:treecurpos = nbcd_curpos |
| 2262 | let haskey= 0 |
| 2263 | " call Decho("w:netrw_treedict<".string(w:netrw_treedict).">") |
| 2264 | |
| 2265 | " search treedict for tree dir as-is |
| 2266 | if has_key(w:netrw_treedict,treedir) |
| 2267 | " call Decho('....searched for treedir<'.treedir.'> : found it!') |
| 2268 | let haskey= 1 |
| 2269 | else |
| 2270 | " call Decho('....searched for treedir<'.treedir.'> : not found') |
| 2271 | endif |
| 2272 | |
| 2273 | " search treedict for treedir with a / appended |
| 2274 | if !haskey && treedir !~ '/$' |
| 2275 | if has_key(w:netrw_treedict,treedir."/") |
| 2276 | let treedir= treedir."/" |
| 2277 | " call Decho('....searched.for treedir<'.treedir.'> found it!') |
| 2278 | let haskey = 1 |
| 2279 | else |
| 2280 | " call Decho('....searched for treedir<'.treedir.'/> : not found') |
| 2281 | endif |
| 2282 | endif |
| 2283 | |
| 2284 | " search treedict for treedir with any trailing / elided |
| 2285 | if !haskey && treedir =~ '/$' |
| 2286 | let treedir= substitute(treedir,'/$','','') |
| 2287 | if has_key(w:netrw_treedict,treedir) |
| 2288 | " call Decho('....searched.for treedir<'.treedir.'> found it!') |
| 2289 | let haskey = 1 |
| 2290 | else |
| 2291 | " call Decho('....searched for treedir<'.treedir.'> : not found') |
| 2292 | endif |
| 2293 | endif |
| 2294 | |
| 2295 | if haskey |
| 2296 | " close tree listing for selected subdirectory |
| 2297 | " call Decho("closing selected subdirectory<".dirname.">") |
| 2298 | call remove(w:netrw_treedict,treedir) |
| 2299 | " call Decho("removed entry<".dirname."> from treedict") |
| 2300 | " call Decho("yielding treedict<".string(w:netrw_treedict).">") |
| 2301 | let dirname= w:netrw_treetop |
| 2302 | else |
| 2303 | " go down one directory |
| 2304 | let dirname= substitute(treedir,'/*$','/','') |
| 2305 | " call Decho("go down one dir: treedir<".treedir.">") |
| 2306 | endif |
| 2307 | |
| 2308 | else |
| 2309 | " go down one directory |
| 2310 | let dirname= s:ComposePath(dirname,newdir) |
| 2311 | " call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">") |
| 2312 | endif |
| 2313 | |
| 2314 | " call Dret("s:NetBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">") |
| 2315 | return dirname |
| 2316 | endfun |
| 2317 | |
| 2318 | " --------------------------------------------------------------------- |
| 2319 | " s:NetHide: this function is invoked by the "a" map for browsing {{{2 |
| 2320 | " and switches the hiding mode |
| 2321 | fun! s:NetHide(islocal) |
| 2322 | " call Dfunc("NetHide(islocal=".a:islocal.")") |
| 2323 | let g:netrw_hide=(g:netrw_hide+1)%3 |
| 2324 | exe "norm! 0" |
| 2325 | if g:netrw_hide && g:netrw_list_hide == "" |
| 2326 | call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49) |
| 2327 | " call Dret("NetHide") |
| 2328 | return |
| 2329 | endif |
| 2330 | call netrw#NetSavePosn() |
| 2331 | call s:NetRefresh(a:islocal,s:NetBrowseChgDir(a:islocal,'./')) |
| 2332 | " call Dret("NetHide") |
| 2333 | endfun |
| 2334 | |
| 2335 | " --------------------------------------------------------------------- |
| 2336 | |
| 2337 | " =========================================== |
| 2338 | " s:NetPreview: {{{2 |
| 2339 | fun! s:NetPreview(path) range |
| 2340 | " call Dfunc("NetPreview(path<".a:path.">)") |
| 2341 | if has("quickfix") |
| 2342 | if !isdirectory(a:path) |
| 2343 | exe "pedit ".escape(a:path,g:netrw_fname_escape) |
| 2344 | elseif !exists("g:netrw_quiet") |
| 2345 | call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38) |
| 2346 | endif |
| 2347 | elseif !exists("g:netrw_quiet") |
| 2348 | call netrw#ErrorMsg(s:WARNING,"sorry, to preview your vim needs the quickfix feature compiled in",39) |
| 2349 | endif |
| 2350 | " call Dret("NetPreview") |
| 2351 | endfun |
| 2352 | |
| 2353 | " --------------------------------------------------------------------- |
| 2354 | " s:NetSortStyle: change sorting style (name - time - size) and refresh display {{{2 |
| 2355 | fun! s:NetSortStyle(islocal) |
| 2356 | " call Dfunc("s:NetSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">") |
| 2357 | call s:NetSaveWordPosn() |
| 2358 | |
| 2359 | let g:netrw_sort_by= (g:netrw_sort_by =~ 'n')? 'time' : (g:netrw_sort_by =~ 't')? 'size' : 'name' |
| 2360 | norm! 0 |
| 2361 | call netrw#NetSavePosn() |
| 2362 | call s:NetRefresh(a:islocal,s:NetBrowseChgDir(a:islocal,'./')) |
| 2363 | |
| 2364 | " call Dret("s:NetSortStyle : netrw_sort_by<".g:netrw_sort_by.">") |
| 2365 | endfun |
| 2366 | |
| 2367 | " --------------------------------------------------------------------- |
| 2368 | " Remote Directory Browsing Support: {{{1 |
| 2369 | " =========================================== |
| 2370 | |
| 2371 | " --------------------------------------------------------------------- |
| 2372 | " s:RemoteListing: {{{2 |
| 2373 | fun! s:RemoteListing() |
| 2374 | " call Dfunc("s:RemoteListing() b:netrw_curdir<".b:netrw_curdir.">)") |
| 2375 | |
| 2376 | call s:RemotePathAnalysis(b:netrw_curdir) |
| 2377 | |
| 2378 | " sanity check: |
| 2379 | if exists("b:netrw_method") && b:netrw_method =~ '[235]' |
| 2380 | " call Decho("b:netrw_method=".b:netrw_method) |
| 2381 | if !executable("ftp") |
| 2382 | if !exists("g:netrw_quiet") |
| 2383 | call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18) |
| 2384 | endif |
| 2385 | call s:NetOptionRestore() |
| 2386 | " call Dret("s:RemoteListing") |
| 2387 | return |
| 2388 | endif |
| 2389 | |
| 2390 | elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == '' |
| 2391 | if !exists("g:netrw_quiet") |
| 2392 | if g:netrw_list_cmd == "" |
| 2393 | call netrw#ErrorMsg(s:ERROR,g:netrw_ssh_cmd." is not executable on your system",47) |
| 2394 | else |
| 2395 | call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ".g:netrw_list_cmd,19) |
| 2396 | endif |
| 2397 | endif |
| 2398 | |
| 2399 | call s:NetOptionRestore() |
| 2400 | " call Dret("s:RemoteListing") |
| 2401 | return |
| 2402 | endif " (remote handling sanity check) |
| 2403 | |
| 2404 | if exists("b:netrw_method") |
| 2405 | " call Decho("setting w:netrw_method<".b:netrw_method.">") |
| 2406 | let w:netrw_method= b:netrw_method |
| 2407 | endif |
| 2408 | |
| 2409 | if s:method == "ftp" |
| 2410 | " use ftp to get remote file listing |
| 2411 | " call Decho("use ftp to get remote file listing") |
| 2412 | let s:method = "ftp" |
| 2413 | let listcmd = g:netrw_ftp_list_cmd |
| 2414 | if g:netrw_sort_by =~ '^t' |
| 2415 | let listcmd= g:netrw_ftp_timelist_cmd |
| 2416 | elseif g:netrw_sort_by =~ '^s' |
| 2417 | let listcmd= g:netrw_ftp_sizelist_cmd |
| 2418 | endif |
| 2419 | " call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)") |
| 2420 | call s:NetBrowseFtpCmd(s:path,listcmd) |
| 2421 | " exe "keepjumps ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."))' |
| 2422 | |
| 2423 | if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || w:netrw_liststyle == s:TREELIST |
| 2424 | " shorten the listing |
| 2425 | " call Decho("generate short listing") |
| 2426 | exe "keepjumps ".w:netrw_bannercnt |
| 2427 | |
| 2428 | " cleanup |
| 2429 | if g:netrw_ftp_browse_reject != "" |
| 2430 | exe "silent! g/".g:netrw_ftp_browse_reject."/keepjumps d" |
| 2431 | endif |
| 2432 | silent! keepjumps %s/\r$//e |
| 2433 | |
| 2434 | " if there's no ../ listed, then put ./ and ../ in |
| 2435 | let line1= line(".") |
| 2436 | exe "keepjumps ".w:netrw_bannercnt |
| 2437 | let line2= search('^\.\.\/\%(\s\|$\)','cnW') |
| 2438 | if line2 == 0 |
| 2439 | " call Decho("netrw is putting ./ and ../ into listing") |
| 2440 | keepjumps put='../' |
| 2441 | keepjumps put='./' |
| 2442 | endif |
| 2443 | exe "keepjumps ".line1 |
| 2444 | keepjumps norm! 0 |
| 2445 | |
| 2446 | " call Decho("line1=".line1." line2=".line2." line(.)=".line(".")) |
| 2447 | if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup |
| 2448 | " call Decho("M$ ftp cleanup") |
| 2449 | exe 'silent! keepjumps '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//' |
| 2450 | else " normal ftp cleanup |
| 2451 | " call Decho("normal ftp cleanup") |
| 2452 | exe 'silent! keepjumps '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e' |
| 2453 | exe "silent! keepjumps ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e' |
| 2454 | exe "silent! keepjumps ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e' |
| 2455 | endif |
| 2456 | endif |
| 2457 | |
| 2458 | else |
| 2459 | " use ssh to get remote file listing {{{3 |
| 2460 | " call Decho("use ssh to get remote file listing: s:netrw_shq<".g:netrw_shq."> s:path<".s:path."> s:netrw_cd_escape<".s:netrw_cd_escape.">") |
| 2461 | let listcmd= s:MakeSshCmd(g:netrw_list_cmd) |
| 2462 | " call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)") |
| 2463 | if g:netrw_scp_cmd =~ '^pscp' |
| 2464 | " call Decho("1: exe silent r! ".listcmd.g:netrw_shq.s:path.g:netrw_shq) |
| 2465 | exe "silent r! ".listcmd.g:netrw_shq.s:path.g:netrw_shq |
| 2466 | " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like |
| 2467 | g/^Listing directory/d |
| 2468 | g/^d[-rwx][-rwx][-rwx]/s+$+/+e |
| 2469 | silent g/^l[-rwx][-rwx][-rwx]/s+$+@+e |
| 2470 | if g:netrw_liststyle != s:LONGLIST |
| 2471 | g/^[dlsp-][-rwx][-rwx][-rwx]/s/^.*\s\(\S\+\)$/\1/e |
| 2472 | endif |
| 2473 | else |
| 2474 | if s:path == "" |
| 2475 | " call Decho("2: exe silent r! ".listcmd) |
| 2476 | exe "silent r! ".listcmd |
| 2477 | else |
| 2478 | " call Decho("3: exe silent r! ".listcmd." ".g:netrw_shq.s:path.g:netrw_shq) |
| 2479 | exe "silent r! ".listcmd." ".g:netrw_shq.s:path.g:netrw_shq |
| 2480 | endif |
| 2481 | endif |
| 2482 | |
| 2483 | " cleanup |
| 2484 | if g:netrw_ftp_browse_reject != "" |
| 2485 | " call Decho("(cleanup) exe silent! g/".g:netrw_ssh_browse_reject."/keepjumps d") |
| 2486 | exe "silent! g/".g:netrw_ssh_browse_reject."/keepjumps d" |
| 2487 | endif |
| 2488 | endif |
| 2489 | |
| 2490 | if w:netrw_liststyle == s:LONGLIST |
| 2491 | " do a long listing; these substitutions need to be done prior to sorting {{{3 |
| 2492 | " call Decho("fix long listing:") |
| 2493 | |
| 2494 | if s:method == "ftp" |
| 2495 | " cleanup |
| 2496 | exe "keepjumps ".w:netrw_bannercnt |
| 2497 | while getline(".") =~ g:netrw_ftp_browse_reject |
| 2498 | keepjumps d |
| 2499 | endwhile |
| 2500 | " if there's no ../ listed, then put ./ and ../ in |
| 2501 | let line1= line(".") |
| 2502 | keepjumps 1 |
| 2503 | silent keepjumps call search('^\.\.\/\%(\s\|$\)','W') |
| 2504 | let line2= line(".") |
| 2505 | if line2 == 0 |
| 2506 | exe 'keepjumps '.w:netrw_bannercnt."put='./'" |
| 2507 | if b:netrw_curdir != '/' |
| 2508 | exe 'keepjumps '.w:netrw_bannercnt."put='../'" |
| 2509 | endif |
| 2510 | endif |
| 2511 | exe "keepjumps ".line1 |
| 2512 | keepjumps norm! 0 |
| 2513 | endif |
| 2514 | |
| 2515 | if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup |
| 2516 | " call Decho("M$ ftp site listing cleanup") |
| 2517 | exe 'silent! keepjumps '.w:netrw_bannercnt.',$s/^\(\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+\)\(\w.*\)$/\2\t\1/' |
| 2518 | elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") |
| 2519 | " call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$")) |
| 2520 | exe 'silent keepjumps '.w:netrw_bannercnt.',$s/ -> .*$//e' |
| 2521 | exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2\t\1/e' |
| 2522 | exe 'silent keepjumps '.w:netrw_bannercnt |
| 2523 | endif |
| 2524 | endif |
| 2525 | |
| 2526 | " if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho |
| 2527 | " exe "keepjumps ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."))' |
| 2528 | " endif " Decho |
| 2529 | " call Dret("s:RemoteListing") |
| 2530 | endfun |
| 2531 | |
| 2532 | " --------------------------------------------------------------------- |
| 2533 | " NetGetWord: it gets the directory named under the cursor {{{2 |
| 2534 | fun! s:NetGetWord() |
| 2535 | " call Dfunc("NetGetWord() line#".line(".")." liststyle=".g:netrw_liststyle." virtcol=".virtcol(".")) |
| 2536 | call s:UseBufWinVars() |
| 2537 | |
| 2538 | " insure that w:netrw_liststyle is set up |
| 2539 | if !exists("w:netrw_liststyle") |
| 2540 | if exists("g:netrw_liststyle") |
| 2541 | let w:netrw_liststyle= g:netrw_liststyle |
| 2542 | else |
| 2543 | let w:netrw_liststyle= s:THINLIST |
| 2544 | endif |
| 2545 | " call Decho("w:netrw_liststyle=".w:netrw_liststyle) |
| 2546 | endif |
| 2547 | |
| 2548 | if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt |
| 2549 | " Active Banner support |
| 2550 | " call Decho("active banner handling") |
| 2551 | norm! 0 |
| 2552 | let dirname= "./" |
| 2553 | let curline= getline(".") |
| 2554 | |
| 2555 | if curline =~ '"\s*Sorted by\s' |
| 2556 | norm s |
| 2557 | let s:netrw_skipbrowse= 1 |
| 2558 | echo 'Pressing "s" also works' |
| 2559 | |
| 2560 | elseif curline =~ '"\s*Sort sequence:' |
| 2561 | let s:netrw_skipbrowse= 1 |
| 2562 | echo 'Press "S" to edit sorting sequence' |
| 2563 | |
| 2564 | elseif curline =~ '"\s*Quick Help:' |
| 2565 | norm ? |
| 2566 | let s:netrw_skipbrowse= 1 |
| 2567 | echo 'Pressing "?" also works' |
| 2568 | |
| 2569 | elseif curline =~ '"\s*\%(Hiding\|Showing\):' |
| 2570 | norm a |
| 2571 | let s:netrw_skipbrowse= 1 |
| 2572 | echo 'Pressing "a" also works' |
| 2573 | |
| 2574 | elseif line("$") > w:netrw_bannercnt |
| 2575 | exe 'silent keepjumps '.w:netrw_bannercnt |
| 2576 | endif |
| 2577 | |
| 2578 | elseif w:netrw_liststyle == s:THINLIST |
| 2579 | " call Decho("thin column handling") |
| 2580 | norm! 0 |
| 2581 | let dirname= getline(".") |
| 2582 | |
| 2583 | elseif w:netrw_liststyle == s:LONGLIST |
| 2584 | " call Decho("long column handling") |
| 2585 | norm! 0 |
| 2586 | let dirname= substitute(getline("."),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e') |
| 2587 | |
| 2588 | elseif w:netrw_liststyle == s:TREELIST |
| 2589 | " call Decho("treelist handling") |
| 2590 | let dirname= substitute(getline("."),'^\(| \)*','','e') |
| 2591 | |
| 2592 | else |
| 2593 | " call Decho("obtain word from wide listing") |
| 2594 | let dirname= getline(".") |
| 2595 | |
| 2596 | if !exists("b:netrw_cpf") |
| 2597 | let b:netrw_cpf= 0 |
| 2598 | exe 'silent keepjumps '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif' |
| 2599 | " call Decho("computed cpf") |
| 2600 | endif |
| 2601 | |
| 2602 | " call Decho("buf#".bufnr("%")."<".bufname("%").">") |
| 2603 | let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf |
| 2604 | " call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt) |
| 2605 | " call Decho("1: dirname<".dirname.">") |
| 2606 | if filestart > 0|let dirname= substitute(dirname,'^.\{'.filestart.'}','','')|endif |
| 2607 | " call Decho("2: dirname<".dirname.">") |
| 2608 | let dirname = substitute(dirname,'^\(.\{'.b:netrw_cpf.'}\).*$','\1','e') |
| 2609 | " call Decho("3: dirname<".dirname.">") |
| 2610 | let dirname = substitute(dirname,'\s\+$','','e') |
| 2611 | " call Decho("4: dirname<".dirname.">") |
| 2612 | endif |
| 2613 | |
| 2614 | " call Dret("NetGetWord <".dirname.">") |
| 2615 | return dirname |
| 2616 | endfun |
| 2617 | |
| 2618 | " --------------------------------------------------------------------- |
| 2619 | " NetBrowseRm: remove/delete a remote file or directory {{{2 |
| 2620 | fun! s:NetBrowseRm(usrhost,path) range |
| 2621 | " call Dfunc("NetBrowseRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol(".")) |
| 2622 | " call Decho("firstline=".a:firstline." lastline=".a:lastline) |
| 2623 | |
| 2624 | " preparation for removing multiple files/directories |
| 2625 | let ctr= a:firstline |
| 2626 | let all= 0 |
| 2627 | |
| 2628 | " remove multiple files and directories |
| 2629 | while ctr <= a:lastline |
| 2630 | exe ctr |
| 2631 | |
| 2632 | let rmfile= s:NetGetWord() |
| 2633 | " call Decho("rmfile<".rmfile.">") |
| 2634 | |
| 2635 | if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$') |
| 2636 | " attempt to remove file |
| 2637 | " call Decho("attempt to remove file") |
| 2638 | if !all |
| 2639 | echohl Statement |
| 2640 | call inputsave() |
| 2641 | let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ") |
| 2642 | call inputrestore() |
| 2643 | echohl NONE |
| 2644 | if ok == "" |
| 2645 | let ok="no" |
| 2646 | endif |
| 2647 | let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e') |
| 2648 | if ok =~ 'a\%[ll]' |
| 2649 | let all= 1 |
| 2650 | endif |
| 2651 | endif |
| 2652 | |
| 2653 | if all || ok =~ 'y\%[es]' || ok == "" |
| 2654 | if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3) |
| 2655 | silent! keepjumps .,$d |
| 2656 | call s:NetBrowseFtpCmd(a:path,"delete ".rmfile) |
| 2657 | else |
| 2658 | let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd) |
| 2659 | " call Decho("attempt to remove file: system(".netrw_rm_cmd.")") |
| 2660 | let ret= s:System("system",netrw_rm_cmd) |
| 2661 | " call Decho("returned=".ret." errcode=".v:shell_error) |
| 2662 | endif |
| 2663 | elseif ok =~ 'q\%[uit]' |
| 2664 | break |
| 2665 | endif |
| 2666 | |
| 2667 | else |
| 2668 | " attempt to remove directory |
| 2669 | " call Decho("attempt to remove directory") |
| 2670 | if !all |
| 2671 | call inputsave() |
| 2672 | let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ") |
| 2673 | call inputrestore() |
| 2674 | if ok == "" |
| 2675 | let ok="no" |
| 2676 | endif |
| 2677 | let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e') |
| 2678 | if ok =~ 'a\%[ll]' |
| 2679 | let all= 1 |
| 2680 | endif |
| 2681 | endif |
| 2682 | |
| 2683 | if all || ok =~ 'y\%[es]' || ok == "" |
| 2684 | if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3) |
| 2685 | call s:NetBrowseFtpCmd(a:path,"rmdir ".rmfile) |
| 2686 | else |
| 2687 | let rmfile = substitute(a:path.rmfile,'/$','','') |
| 2688 | let netrw_rmdir_cmd = s:MakeSshCmd(g:netrw_rmdir_cmd).' '.rmfile |
| 2689 | " call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")") |
| 2690 | let ret= s:System("system",netrw_rmdir_cmd) |
| 2691 | " call Decho("returned=".ret." errcode=".v:shell_error) |
| 2692 | |
| 2693 | if v:shell_error != 0 |
| 2694 | " call Decho("v:shell_error not 0") |
| 2695 | let netrw_rmf_cmd= s:MakeSshCmd(g:netrw_rmf_cmd).' '.substitute(rmfile,'[\/]$','','e') |
| 2696 | " call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")") |
| 2697 | let ret= s:System("system",netrw_rmf_cmd) |
| 2698 | " call Decho("returned=".ret." errcode=".v:shell_error) |
| 2699 | |
| 2700 | if v:shell_error != 0 && !exists("g:netrw_quiet") |
| 2701 | call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22) |
| 2702 | endif |
| 2703 | endif |
| 2704 | endif |
| 2705 | |
| 2706 | elseif ok =~ 'q\%[uit]' |
| 2707 | break |
| 2708 | endif |
| 2709 | endif |
| 2710 | |
| 2711 | let ctr= ctr + 1 |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 2712 | endwhile |
Bram Moolenaar | 4ea8fe1 | 2006-03-09 22:32:39 +0000 | [diff] [blame] | 2713 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2714 | " refresh the (remote) directory listing |
| 2715 | " call Decho("refresh remote directory listing") |
| 2716 | call netrw#NetSavePosn() |
| 2717 | call s:NetRefresh(0,s:NetBrowseChgDir(0,'./')) |
| 2718 | |
| 2719 | " call Dret("NetBrowseRm") |
| 2720 | endfun |
| 2721 | |
| 2722 | " --------------------------------------------------------------------- |
| 2723 | " NetBrowseRename: rename a remote file or directory {{{2 |
| 2724 | fun! s:NetBrowseRename(usrhost,path) range |
| 2725 | " call Dfunc("NetBrowseRename(usrhost<".a:usrhost."> path<".a:path.">)") |
| 2726 | |
| 2727 | " preparation for removing multiple files/directories |
| 2728 | let ctr = a:firstline |
| 2729 | let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd) |
| 2730 | |
| 2731 | " attempt to rename files/directories |
| 2732 | while ctr <= a:lastline |
| 2733 | exe "keepjumps ".ctr |
| 2734 | |
| 2735 | norm! 0 |
| 2736 | let oldname= s:NetGetWord() |
| 2737 | " call Decho("oldname<".oldname.">") |
| 2738 | |
| 2739 | call inputsave() |
| 2740 | let newname= input("Moving ".oldname." to : ",oldname) |
| 2741 | call inputrestore() |
| 2742 | |
| 2743 | if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3) |
| 2744 | call s:NetBrowseFtpCmd(a:path,"rename ".oldname." ".newname) |
| 2745 | else |
| 2746 | let oldname= a:path.oldname |
| 2747 | let newname= a:path.newname |
| 2748 | " call Decho("system(rename_cmd".' "'.escape(oldname," ").'" "'.escape(newname,s:netrw_cd_escape).'"') |
| 2749 | let ret= s:System("system",rename_cmd.' "'.escape(oldname,s:netrw_cd_escape).'" "'.escape(newname,s:netrw_cd_escape).'"') |
| 2750 | endif |
| 2751 | |
| 2752 | let ctr= ctr + 1 |
| 2753 | endwhile |
| 2754 | |
| 2755 | " refresh the directory |
| 2756 | let curline= line(".") |
| 2757 | call s:NetBrowse(0,s:NetBrowseChgDir(0,'./')) |
| 2758 | exe "keepjumps ".curline |
| 2759 | " call Dret("NetBrowseRename") |
| 2760 | endfun |
| 2761 | |
| 2762 | " --------------------------------------------------------------------- |
| 2763 | " NetRefresh: {{{2 |
| 2764 | fun! s:NetRefresh(islocal,dirname) |
| 2765 | " call Dfunc("NetRefresh(islocal<".a:islocal.">,dirname=".a:dirname.") hide=".g:netrw_hide." sortdir=".g:netrw_sort_direction) |
| 2766 | " at the current time (Mar 19, 2007) all calls to NetRefresh() call NetBrowseChgDir() first. |
| 2767 | " NetBrowseChgDir() may clear the display; hence a NetSavePosn() may not work if its placed here. |
| 2768 | " Also, NetBrowseChgDir() now does a NetSavePosn() itself. |
| 2769 | setlocal ma noro |
| 2770 | " call Decho("clear buffer<".expand("%")."> with :%d") |
| 2771 | %d |
| 2772 | if a:islocal |
| 2773 | call netrw#LocalBrowseCheck(a:dirname) |
| 2774 | else |
| 2775 | call s:NetBrowse(a:islocal,a:dirname) |
| 2776 | endif |
| 2777 | call netrw#NetRestorePosn() |
| 2778 | redraw! |
| 2779 | " call Dret("NetRefresh") |
| 2780 | endfun |
| 2781 | |
| 2782 | " --------------------------------------------------------------------- |
| 2783 | " NetSplit: mode {{{2 |
| 2784 | " =0 : net and o |
| 2785 | " =1 : net and t |
| 2786 | " =2 : net and v |
| 2787 | " =3 : local and o |
| 2788 | " =4 : local and t |
| 2789 | " =5 : local and v |
| 2790 | fun! s:NetSplit(mode) |
| 2791 | " call Dfunc("NetSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv) |
| 2792 | |
| 2793 | call s:SaveWinVars() |
| 2794 | |
| 2795 | if a:mode == 0 |
| 2796 | " remote and o |
| 2797 | exe (g:netrw_alto? "bel " : "abo ").g:netrw_winsize."wincmd s" |
| 2798 | let s:didsplit= 1 |
| 2799 | call s:RestoreWinVars() |
| 2800 | call s:NetBrowse(0,s:NetBrowseChgDir(0,s:NetGetWord())) |
| 2801 | unlet s:didsplit |
| 2802 | |
| 2803 | elseif a:mode == 1 |
| 2804 | " remote and t |
| 2805 | let cursorword = s:NetGetWord() |
| 2806 | tabnew |
| 2807 | let s:didsplit= 1 |
| 2808 | call s:RestoreWinVars() |
| 2809 | call s:NetBrowse(0,s:NetBrowseChgDir(0,cursorword)) |
| 2810 | unlet s:didsplit |
| 2811 | |
| 2812 | elseif a:mode == 2 |
| 2813 | " remote and v |
| 2814 | exe (g:netrw_altv? "rightb " : "lefta ").g:netrw_winsize."wincmd v" |
| 2815 | let s:didsplit= 1 |
| 2816 | call s:RestoreWinVars() |
| 2817 | call s:NetBrowse(0,s:NetBrowseChgDir(0,s:NetGetWord())) |
| 2818 | unlet s:didsplit |
| 2819 | |
| 2820 | elseif a:mode == 3 |
| 2821 | " local and o |
| 2822 | exe (g:netrw_alto? "bel " : "abo ").g:netrw_winsize."wincmd s" |
| 2823 | let s:didsplit= 1 |
| 2824 | call s:RestoreWinVars() |
| 2825 | call netrw#LocalBrowseCheck(s:NetBrowseChgDir(1,s:NetGetWord())) |
| 2826 | unlet s:didsplit |
| 2827 | |
| 2828 | elseif a:mode == 4 |
| 2829 | " local and t |
| 2830 | let netrw_curdir= b:netrw_curdir |
| 2831 | let cursorword = s:NetGetWord() |
| 2832 | tabnew |
| 2833 | let b:netrw_curdir= netrw_curdir |
| 2834 | let s:didsplit= 1 |
| 2835 | call s:RestoreWinVars() |
| 2836 | call netrw#LocalBrowseCheck(s:NetBrowseChgDir(1,cursorword)) |
| 2837 | unlet s:didsplit |
| 2838 | |
| 2839 | elseif a:mode == 5 |
| 2840 | " local and v |
| 2841 | exe (g:netrw_altv? "rightb " : "lefta ").g:netrw_winsize."wincmd v" |
| 2842 | let s:didsplit= 1 |
| 2843 | call s:RestoreWinVars() |
| 2844 | call netrw#LocalBrowseCheck(s:NetBrowseChgDir(1,s:NetGetWord())) |
| 2845 | unlet s:didsplit |
| 2846 | |
| 2847 | else |
| 2848 | call netrw#ErrorMsg(s:ERROR,"(NetSplit) unsupported mode=".a:mode,45) |
| 2849 | endif |
| 2850 | |
| 2851 | " call Dret("NetSplit") |
| 2852 | endfun |
| 2853 | |
| 2854 | " --------------------------------------------------------------------- |
| 2855 | " NetBrowseX: allows users to write custom functions to operate on {{{2 |
| 2856 | " files given their extension. Passes 0=local, 1=remote |
| 2857 | fun! netrw#NetBrowseX(fname,remote) |
| 2858 | " call Dfunc("NetBrowseX(fname<".a:fname."> remote=".a:remote.")") |
| 2859 | |
| 2860 | " set up the filename |
| 2861 | " (lower case the extension, make a local copy of a remote file) |
| 2862 | let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e') |
| 2863 | if has("win32") || has("win95") || has("win64") || has("win16") |
| 2864 | let exten= substitute(exten,'^.*$','\L&\E','') |
| 2865 | endif |
| 2866 | let fname= escape(a:fname,"%#") |
| 2867 | " call Decho("fname<".fname."> after escape()") |
| 2868 | |
| 2869 | " seems kde systems often have gnome-open due to dependencies, even though |
| 2870 | " gnome-open's subsidiary display tools are largely absent. Kde systems |
| 2871 | " usually have "kdeinit" running, though... (tnx Mikolaj Machowski) |
| 2872 | if !exists("s:haskdeinit") |
| 2873 | if has("unix") |
| 2874 | let s:haskdeinit= s:System("system",'ps -e') =~ 'kdeinit' |
| 2875 | if v:shell_error |
| 2876 | let s:haskdeinit = 0 |
| 2877 | endif |
| 2878 | else |
| 2879 | let s:haskdeinit= 0 |
| 2880 | endif |
| 2881 | " call Decho("setting s:haskdeinit=".s:haskdeinit) |
| 2882 | endif |
| 2883 | |
| 2884 | if a:remote == 1 |
| 2885 | " create a local copy |
| 2886 | let fname= fnamemodify(tempname(),":t:r").".".exten |
| 2887 | " call Decho("a:remote=".a:remote.": create a local copy of <".a:fname."> as <".fname.">") |
| 2888 | exe "silent keepjumps bot 1new ".a:fname |
| 2889 | setlocal bh=delete |
| 2890 | " call Decho("exe w! ".fname) |
| 2891 | exe "w! ".fname |
| 2892 | q |
| 2893 | endif |
| 2894 | " call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten)) |
| 2895 | |
| 2896 | " set up redirection |
| 2897 | if &srr =~ "%s" |
| 2898 | let redir= substitute(&srr,"%s","/dev/null","") |
| 2899 | else |
| 2900 | let redir= &srr . "/dev/null" |
| 2901 | endif |
| 2902 | " call Decho("redir{".redir."} srr{".&srr."}") |
| 2903 | |
| 2904 | " execute the file handler |
| 2905 | if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-' |
| 2906 | " call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">") |
| 2907 | let ret= netrwFileHandlers#Invoke(exten,fname) |
| 2908 | |
| 2909 | elseif exists("g:netrw_browsex_viewer") && executable(g:netrw_browsex_viewer) |
| 2910 | " call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">") |
| 2911 | " call Decho("exe silent !".g:netrw_browsex_viewer." '".escape(fname,'%#')."' ".redir) |
| 2912 | exe "silent !".g:netrw_browsex_viewer." '".escape(fname,'%#')."'".redir |
| 2913 | let ret= v:shell_error |
| 2914 | |
| 2915 | elseif has("win32") || has("win64") |
| 2916 | " call Decho('exe silent !start rundll32 url.dll,FileProtocolHandler "'.escape(fname, '%#').'"') |
| 2917 | exe 'silent !start rundll32 url.dll,FileProtocolHandler "'.escape(fname, '%#').'"' |
| 2918 | call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
| 2919 | let ret= v:shell_error |
| 2920 | |
| 2921 | elseif has("unix") && executable("gnome-open") && !s:haskdeinit |
| 2922 | " call Decho("exe silent !gnome-open '".escape(fname,'%#')."' ".redir) |
| 2923 | exe "silent !gnome-open '".escape(fname,'%#')."'".redir |
| 2924 | let ret= v:shell_error |
| 2925 | |
| 2926 | elseif has("unix") && executable("kfmclient") && s:haskdeinit |
| 2927 | " call Decho("exe silent !kfmclient exec '".escape(fname,'%#')."' ".redir) |
| 2928 | exe "silent !kfmclient exec '".escape(fname,'%#')."' ".redir |
| 2929 | let ret= v:shell_error |
| 2930 | |
| 2931 | else |
| 2932 | " netrwFileHandlers#Invoke() always returns 0 |
| 2933 | let ret= netrwFileHandlers#Invoke(exten,fname) |
| 2934 | endif |
| 2935 | |
| 2936 | " if unsuccessful, attempt netrwFileHandlers#Invoke() |
| 2937 | if ret |
| 2938 | let ret= netrwFileHandlers#Invoke(exten,fname) |
| 2939 | endif |
| 2940 | |
| 2941 | redraw! |
| 2942 | |
| 2943 | " cleanup: remove temporary file, |
| 2944 | " delete current buffer if success with handler, |
| 2945 | " return to prior buffer (directory listing) |
| 2946 | if a:remote == 1 && fname != a:fname |
| 2947 | " call Decho("deleting temporary file<".fname.">") |
| 2948 | call s:System("delete",fname) |
| 2949 | endif |
| 2950 | |
| 2951 | if a:remote == 1 |
| 2952 | setlocal bh=delete bt=nofile |
| 2953 | if g:netrw_use_noswf |
| 2954 | setlocal noswf |
| 2955 | endif |
| 2956 | exe "norm! \<c-o>" |
| 2957 | redraw! |
| 2958 | endif |
| 2959 | |
| 2960 | " call Dret("NetBrowseX") |
| 2961 | endfun |
| 2962 | |
| 2963 | " --------------------------------------------------------------------- |
| 2964 | " NetBrowseFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2 |
| 2965 | " This function assumes that a long listing will be received. Size, time, |
| 2966 | " and reverse sorts will be requested of the server but not otherwise |
| 2967 | " enforced here. |
| 2968 | fun! s:NetBrowseFtpCmd(path,listcmd) |
| 2969 | " call Dfunc("NetBrowseFtpCmd(path<".a:path."> listcmd<".a:listcmd.">) netrw_method=".w:netrw_method) |
| 2970 | " call Decho("line($)=".line("$")." bannercnt=".w:netrw_bannercnt) |
| 2971 | |
| 2972 | " because WinXX ftp uses unix style input |
| 2973 | let ffkeep= &ff |
| 2974 | setlocal ma ff=unix noro |
| 2975 | |
| 2976 | " clear off any older non-banner lines |
| 2977 | " note that w:netrw_bannercnt indexes the line after the banner |
| 2978 | " call Decho('exe silent! keepjumps '.w:netrw_bannercnt.",$d (clear off old non-banner lines)") |
| 2979 | exe "silent! keepjumps ".w:netrw_bannercnt.",$d" |
| 2980 | |
| 2981 | "......................................... |
| 2982 | if w:netrw_method == 2 || w:netrw_method == 5 |
| 2983 | " ftp + <.netrc>: Method #2 |
| 2984 | if a:path != "" |
| 2985 | put ='cd \"'.a:path.'\"' |
| 2986 | endif |
| 2987 | if exists("g:netrw_ftpextracmd") |
| 2988 | exe "put ='".g:netrw_ftpextracmd."'" |
| 2989 | " call Decho("filter input: ".getline(".")) |
| 2990 | endif |
| 2991 | exe "put ='".a:listcmd."'" |
| 2992 | " exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."))' |
| 2993 | if exists("g:netrw_port") && g:netrw_port != "" |
| 2994 | " call Decho("exe ".g:netrw_silentxfer.w:netrw_bannercnt.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port) |
| 2995 | exe g:netrw_silentxfer.w:netrw_bannercnt.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port |
| 2996 | else |
| 2997 | " call Decho("exe ".g:netrw_silentxfer.w:netrw_bannercnt.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine) |
| 2998 | exe g:netrw_silentxfer.w:netrw_bannercnt.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine |
| 2999 | endif |
| 3000 | |
| 3001 | "......................................... |
| 3002 | elseif w:netrw_method == 3 |
| 3003 | " ftp + machine,id,passwd,filename: Method #3 |
| 3004 | setlocal ff=unix |
| 3005 | if exists("g:netrw_port") && g:netrw_port != "" |
| 3006 | put ='open '.g:netrw_machine.' '.g:netrw_port |
| 3007 | else |
| 3008 | put ='open '.g:netrw_machine |
| 3009 | endif |
| 3010 | |
| 3011 | if exists("g:netrw_ftp") && g:netrw_ftp == 1 |
| 3012 | put =g:netrw_uid |
| 3013 | put ='\"'.g:netrw_passwd.'\"' |
| 3014 | else |
| 3015 | put ='user \"'.g:netrw_uid.'\" \"'.g:netrw_passwd.'\"' |
| 3016 | endif |
| 3017 | |
| 3018 | if a:path != "" |
| 3019 | put ='cd \"'.a:path.'\"' |
| 3020 | endif |
| 3021 | if exists("g:netrw_ftpextracmd") |
| 3022 | exe "put ='".g:netrw_ftpextracmd."'" |
| 3023 | " call Decho("filter input: ".getline(".")) |
| 3024 | endif |
| 3025 | exe "put ='".a:listcmd."'" |
| 3026 | |
| 3027 | " perform ftp: |
| 3028 | " -i : turns off interactive prompting from ftp |
| 3029 | " -n unix : DON'T use <.netrc>, even though it exists |
| 3030 | " -n win32: quit being obnoxious about password |
| 3031 | " exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."))' |
| 3032 | " call Decho("exe ".g:netrw_silentxfer.w:netrw_bannercnt.",$!".g:netrw_ftp_cmd." -i -n") |
| 3033 | exe g:netrw_silentxfer.w:netrw_bannercnt.",$!".g:netrw_ftp_cmd." -i -n" |
| 3034 | |
| 3035 | "......................................... |
| 3036 | else |
| 3037 | call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",23) |
| 3038 | endif |
| 3039 | |
| 3040 | " cleanup for Windows |
| 3041 | if has("win32") || has("win95") || has("win64") || has("win16") |
| 3042 | silent! keepjumps %s/\r$//e |
| 3043 | endif |
| 3044 | if a:listcmd == "dir" |
| 3045 | " infer directory/link based on the file permission string |
| 3046 | silent! keepjumps g/d\%([-r][-w][-x]\)\{3}/s@$@/@ |
| 3047 | silent! keepjumps g/l\%([-r][-w][-x]\)\{3}/s/$/@/ |
| 3048 | if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || w:netrw_liststyle == s:TREELIST |
| 3049 | exe "silent! keepjumps ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e' |
| 3050 | endif |
| 3051 | endif |
| 3052 | |
| 3053 | " ftp's listing doesn't seem to include ./ or ../ |
| 3054 | if !search('^\.\/$\|\s\.\/$','wn') |
| 3055 | exe 'keepjumps '.w:netrw_bannercnt |
| 3056 | put ='./' |
| 3057 | endif |
| 3058 | if !search('^\.\.\/$\|\s\.\.\/$','wn') |
| 3059 | exe 'keepjumps '.w:netrw_bannercnt |
| 3060 | put ='../' |
| 3061 | endif |
| 3062 | |
| 3063 | " restore settings |
| 3064 | let &ff= ffkeep |
| 3065 | " call Dret("NetBrowseFtpCmd") |
| 3066 | endfun |
| 3067 | |
| 3068 | " --------------------------------------------------------------------- |
| 3069 | " NetListHide: uses [range]g~...~d to delete files that match comma {{{2 |
| 3070 | " separated patterns given in g:netrw_list_hide |
| 3071 | fun! s:NetListHide() |
| 3072 | " call Dfunc("NetListHide() hide=".g:netrw_hide." listhide<".g:netrw_list_hide.">") |
| 3073 | |
| 3074 | " find a character not in the "hide" string to use as a separator for :g and :v commands |
| 3075 | " How-it-works: take the hiding command, convert it into a range. Duplicate |
| 3076 | " characters don't matter. Remove all such characters from the '/~...90' |
| 3077 | " string. Use the first character left as a separator character. |
| 3078 | let listhide= g:netrw_list_hide |
| 3079 | let sep = strpart(substitute('/~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1) |
| 3080 | " call Decho("sep=".sep) |
| 3081 | |
| 3082 | while listhide != "" |
| 3083 | if listhide =~ ',' |
| 3084 | let hide = substitute(listhide,',.*$','','e') |
| 3085 | let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e') |
| 3086 | else |
| 3087 | let hide = listhide |
| 3088 | let listhide= "" |
| 3089 | endif |
| 3090 | |
| 3091 | " Prune the list by hiding any files which match |
| 3092 | if g:netrw_hide == 1 |
| 3093 | " call Decho("hiding<".hide."> listhide<".listhide.">") |
| 3094 | exe 'silent keepjumps '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d' |
| 3095 | elseif g:netrw_hide == 2 |
| 3096 | " call Decho("showing<".hide."> listhide<".listhide.">") |
| 3097 | exe 'silent keepjumps '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @' |
| 3098 | endif |
| 3099 | endwhile |
| 3100 | if g:netrw_hide == 2 |
| 3101 | exe 'silent keepjumps '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d' |
| 3102 | exe 'silent keepjumps '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e' |
| 3103 | endif |
| 3104 | |
| 3105 | " call Dret("NetListHide") |
| 3106 | endfun |
| 3107 | |
| 3108 | " --------------------------------------------------------------------- |
| 3109 | " NetHideEdit: allows user to edit the file/directory hiding list |
| 3110 | fun! s:NetHideEdit(islocal) |
| 3111 | " call Dfunc("NetHideEdit(islocal=".a:islocal.")") |
| 3112 | |
| 3113 | " save current cursor position |
| 3114 | let s:nhe_curpos= getpos(".") |
| 3115 | |
| 3116 | " get new hiding list from user |
| 3117 | call inputsave() |
| 3118 | let newhide= input("Edit Hiding List: ",g:netrw_list_hide) |
| 3119 | call inputrestore() |
| 3120 | let g:netrw_list_hide= newhide |
| 3121 | " call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">") |
| 3122 | |
| 3123 | " refresh the listing |
| 3124 | silent call s:NetRefresh(a:islocal,s:NetBrowseChgDir(a:islocal,"./")) |
| 3125 | |
| 3126 | " restore cursor position |
| 3127 | call setpos('.',s:nhe_curpos) |
| 3128 | unlet s:nhe_curpos |
| 3129 | |
| 3130 | " call Dret("NetHideEdit") |
| 3131 | endfun |
| 3132 | |
| 3133 | " --------------------------------------------------------------------- |
| 3134 | " NetSortSequence: allows user to edit the sorting sequence |
| 3135 | fun! s:NetSortSequence(islocal) |
| 3136 | " call Dfunc("NetSortSequence(islocal=".a:islocal.")") |
| 3137 | |
| 3138 | call inputsave() |
| 3139 | let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence) |
| 3140 | call inputrestore() |
| 3141 | |
| 3142 | " refresh the listing |
| 3143 | let g:netrw_sort_sequence= newsortseq |
| 3144 | call netrw#NetSavePosn() |
| 3145 | call s:NetRefresh(a:islocal,s:NetBrowseChgDir(a:islocal,'./')) |
| 3146 | |
| 3147 | " call Dret("NetSortSequence") |
| 3148 | endfun |
| 3149 | |
| 3150 | " --------------------------------------------------------------------- |
| 3151 | " NetListStyle: {{{2 |
| 3152 | " islocal=0: remote browsing |
| 3153 | " =1: local browsing |
| 3154 | fun! s:NetListStyle(islocal) |
| 3155 | " call Dfunc("NetListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle) |
| 3156 | let fname = s:NetGetWord() |
| 3157 | if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif |
| 3158 | let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST |
| 3159 | " call Decho("fname<".fname.">") |
| 3160 | " call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle) |
| 3161 | " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">") |
| 3162 | |
| 3163 | if w:netrw_liststyle == s:THINLIST |
| 3164 | " use one column listing |
| 3165 | " call Decho("use one column list") |
| 3166 | let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge') |
| 3167 | |
| 3168 | elseif w:netrw_liststyle == s:LONGLIST |
| 3169 | " use long list |
| 3170 | " call Decho("use long list") |
| 3171 | let g:netrw_list_cmd = g:netrw_list_cmd." -l" |
| 3172 | |
| 3173 | elseif w:netrw_liststyle == s:WIDELIST |
| 3174 | " give wide list |
| 3175 | " call Decho("use wide list") |
| 3176 | let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge') |
| 3177 | |
| 3178 | elseif w:netrw_liststyle == s:TREELIST |
| 3179 | " call Decho("use tree list") |
| 3180 | let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge') |
| 3181 | |
| 3182 | else |
| 3183 | call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46) |
| 3184 | let g:netrw_liststyle = s:THINLIST |
| 3185 | let w:netrw_liststyle = g:netrw_liststyle |
| 3186 | let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge') |
| 3187 | endif |
| 3188 | setlocal ma noro |
| 3189 | |
| 3190 | " clear buffer - this will cause NetBrowse/LocalBrowseCheck to do a refresh |
| 3191 | " call Decho("clear buffer<".expand("%")."> with :%d") |
| 3192 | %d |
| 3193 | |
| 3194 | " refresh the listing |
| 3195 | call netrw#NetSavePosn() |
| 3196 | call s:NetRefresh(a:islocal,s:NetBrowseChgDir(a:islocal,'./')) |
| 3197 | |
| 3198 | " keep cursor on the filename |
| 3199 | silent keepjumps $ |
| 3200 | let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc') |
| 3201 | " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A')) |
| 3202 | if result <= 0 && exists("w:netrw_bannercnt") |
| 3203 | exe w:netrw_bannercnt |
| 3204 | endif |
| 3205 | |
| 3206 | " call Dret("NetListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : "")) |
| 3207 | endfun |
| 3208 | |
| 3209 | " --------------------------------------------------------------------- |
| 3210 | " NetWideListing: {{{2 |
| 3211 | fun! s:NetWideListing() |
| 3212 | |
| 3213 | if w:netrw_liststyle == s:WIDELIST |
| 3214 | " call Dfunc("NetWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo) |
| 3215 | " look for longest filename (cpf=characters per filename) |
| 3216 | " cpf: characters per file |
| 3217 | " fpl: files per line |
| 3218 | " fpc: files per column |
| 3219 | setlocal ma noro |
| 3220 | let b:netrw_cpf= 0 |
| 3221 | if line("$") >= w:netrw_bannercnt |
| 3222 | exe 'silent keepjumps '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif' |
| 3223 | else |
| 3224 | " call Dret("NetWideListing") |
| 3225 | return |
| 3226 | endif |
| 3227 | " call Decho("max file strlen+1=".b:netrw_cpf) |
| 3228 | let b:netrw_cpf= b:netrw_cpf + 1 |
| 3229 | |
| 3230 | " determine qty files per line (fpl) |
| 3231 | let w:netrw_fpl= winwidth(0)/b:netrw_cpf |
| 3232 | if w:netrw_fpl <= 0 |
| 3233 | let w:netrw_fpl= 1 |
| 3234 | endif |
| 3235 | " call Decho("fpl= ".winwidth(0)."/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl) |
| 3236 | |
| 3237 | " make wide display |
| 3238 | exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'s",submatch(0)),"\\")/' |
| 3239 | let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl |
| 3240 | let newcolstart = w:netrw_bannercnt + fpc |
| 3241 | let newcolend = newcolstart + fpc - 1 |
| 3242 | " call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]") |
| 3243 | silent! let keepregstar = @* |
| 3244 | while line("$") >= newcolstart |
| 3245 | if newcolend > line("$") | let newcolend= line("$") | endif |
| 3246 | let newcolqty= newcolend - newcolstart |
| 3247 | exe newcolstart |
| 3248 | if newcolqty == 0 |
| 3249 | exe "silent keepjumps norm! 0\<c-v>$hx".w:netrw_bannercnt."G$p" |
| 3250 | else |
| 3251 | exe "silent keepjumps norm! 0\<c-v>".newcolqty.'j$hx'.w:netrw_bannercnt.'G$p' |
| 3252 | endif |
| 3253 | exe "silent keepjumps ".newcolstart.','.newcolend.'d' |
| 3254 | exe 'silent keepjumps '.w:netrw_bannercnt |
| 3255 | endwhile |
| 3256 | silent! let @*= keepregstar |
| 3257 | exe "silent keepjumps ".w:netrw_bannercnt.',$s/\s\+$//e' |
| 3258 | setlocal noma nomod ro |
| 3259 | " call Dret("NetWideListing") |
| 3260 | endif |
| 3261 | |
| 3262 | endfun |
| 3263 | |
| 3264 | " --------------------------------------------------------------------- |
| 3265 | " NetTreeDir: determine tree directory given current cursor position {{{2 |
| 3266 | " (full path directory with trailing slash returned) |
| 3267 | fun! s:NetTreeDir() |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 3268 | " call Dfunc("NetTreeDir() curline#".line(".")."<".getline(".")."> b:netrw_curdir<".b:netrw_curdir."> tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%").">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3269 | |
| 3270 | let treedir= b:netrw_curdir |
| 3271 | " call Decho("set initial treedir<".treedir.">") |
| 3272 | let s:treecurpos= getpos(".") |
| 3273 | |
| 3274 | if w:netrw_liststyle == s:TREELIST |
| 3275 | " call Decho("w:netrrw_liststyle is TREELIST:") |
| 3276 | " call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">") |
| 3277 | if getline('.') =~ '/$' |
| 3278 | let treedir= substitute(getline('.'),'^\%(| \)*\([^|].\{-}\)$','\1','e') |
| 3279 | else |
| 3280 | let treedir= "" |
| 3281 | endif |
| 3282 | |
| 3283 | " call Decho("treedir<".treedir.">") |
| 3284 | |
| 3285 | " detect user attempting to close treeroot |
| 3286 | if getline('.') !~ '|' && getline('.') != '..' |
| 3287 | " call Decho("user attempted to close treeroot") |
| 3288 | " now force a refresh |
| 3289 | " call Decho("clear buffer<".expand("%")."> with :%d") |
| 3290 | keepjumps %d |
| 3291 | " call Dret("NetTreeDir <".treedir."> : (side effect) s:treecurpos<".string(s:treecurpos).">") |
| 3292 | return b:netrw_curdir |
| 3293 | endif |
| 3294 | |
| 3295 | " elide all non-depth information |
| 3296 | let depth = substitute(getline('.'),'^\(\%(| \)*\)[^|].\{-}$','\1','e') |
| 3297 | " call Decho("depth<".depth."> 1st subst") |
| 3298 | |
| 3299 | " elide first depth |
| 3300 | let depth = substitute(depth,'^| ','','') |
| 3301 | " call Decho("depth<".depth."> 2nd subst") |
| 3302 | |
| 3303 | " construct treedir by searching backwards at correct depth |
| 3304 | " call Decho("constructing treedir<".treedir."> depth<".depth.">") |
| 3305 | while depth != "" && search('^'.depth.'[^|].\{-}/$','bW') |
| 3306 | let dirname= substitute(getline("."),'^\(| \)*','','e') |
| 3307 | let treedir= dirname.treedir |
| 3308 | let depth = substitute(depth,'^| ','','') |
| 3309 | " call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">") |
| 3310 | endwhile |
| 3311 | if w:netrw_treetop =~ '/$' |
| 3312 | let treedir= w:netrw_treetop.treedir |
| 3313 | else |
| 3314 | let treedir= w:netrw_treetop.'/'.treedir |
| 3315 | endif |
| 3316 | " call Decho("bufnr(.)=".bufnr(".")." line($)=".line("$")." line(.)=".line(".")) |
| 3317 | endif |
| 3318 | let treedir= substitute(treedir,'//$','/','') |
| 3319 | |
| 3320 | " " now force a refresh |
| 3321 | " call Decho("clear buffer<".expand("%")."> with :%d") |
| 3322 | " setlocal ma noro |
| 3323 | " keepjumps %d |
| 3324 | |
| 3325 | " call Dret("NetTreeDir <".treedir."> : (side effect) s:treecurpos<".string(s:treecurpos).">") |
| 3326 | return treedir |
| 3327 | endfun |
| 3328 | |
| 3329 | " --------------------------------------------------------------------- |
| 3330 | " NetTreeDisplay: recursive tree display {{{2 |
| 3331 | fun! s:NetTreeDisplay(dir,depth) |
| 3332 | " call Dfunc("NetTreeDisplay(dir<".a:dir."> depth<".a:depth.">)") |
| 3333 | |
| 3334 | " insure that there are no folds |
| 3335 | setlocal nofen |
| 3336 | |
| 3337 | " install ../ and shortdir |
| 3338 | if a:depth == "" |
| 3339 | call setline(line("$")+1,'../') |
| 3340 | " call Decho("setline#".line("$")." ../ (depth is zero)") |
| 3341 | endif |
| 3342 | if a:dir =~ '^\a\+://' |
| 3343 | if a:dir == w:netrw_treetop |
| 3344 | let shortdir= a:dir |
| 3345 | else |
| 3346 | let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e') |
| 3347 | endif |
| 3348 | call setline(line("$")+1,a:depth.shortdir) |
| 3349 | else |
| 3350 | let shortdir= substitute(a:dir,'^.*/','','e') |
| 3351 | call setline(line("$")+1,a:depth.shortdir.'/') |
| 3352 | endif |
| 3353 | " call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">") |
| 3354 | |
| 3355 | " append a / to dir if its missing one |
| 3356 | let dir= a:dir |
| 3357 | if dir !~ '/$' |
| 3358 | let dir= dir.'/' |
| 3359 | endif |
| 3360 | |
| 3361 | " display subtrees (if any) |
| 3362 | let depth= "| ".a:depth |
| 3363 | " call Decho("display subtrees with depth<".depth."> and current leaves") |
| 3364 | for entry in w:netrw_treedict[a:dir] |
| 3365 | let direntry= substitute(dir.entry,'/$','','e') |
| 3366 | " call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">") |
| 3367 | if entry =~ '/$' && has_key(w:netrw_treedict,direntry) |
| 3368 | " call Decho("<".direntry."> is a key in treedict - display subtree for it") |
| 3369 | call s:NetTreeDisplay(direntry,depth) |
| 3370 | elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/') |
| 3371 | " call Decho("<".direntry."/> is a key in treedict - display subtree for it") |
| 3372 | call s:NetTreeDisplay(direntry.'/',depth) |
| 3373 | else |
| 3374 | " call Decho("<".entry."> is not a key in treedict (no subtree)") |
| 3375 | call setline(line("$")+1,depth.entry) |
| 3376 | endif |
| 3377 | endfor |
| 3378 | " call Dret("NetTreeDisplay") |
| 3379 | endfun |
| 3380 | |
| 3381 | " --------------------------------------------------------------------- |
| 3382 | " NetTreeListing: displays tree listing from treetop on down, using NetTreeDisplay() {{{2 |
| 3383 | fun! s:NetTreeListing(dirname) |
| 3384 | if w:netrw_liststyle == s:TREELIST |
| 3385 | " call Dfunc("NetTreeListing() bufname<".expand("%").">") |
| 3386 | " call Decho("curdir<".a:dirname.">") |
| 3387 | |
| 3388 | " update the treetop |
| 3389 | " call Decho("update the treetop") |
| 3390 | if !exists("w:netrw_treetop") |
| 3391 | let w:netrw_treetop= a:dirname |
| 3392 | " call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)") |
| 3393 | elseif (w:netrw_treetop =~ ('^'.a:dirname) && strlen(a:dirname) < strlen(w:netrw_treetop)) || a:dirname !~ ('^'.w:netrw_treetop) |
| 3394 | let w:netrw_treetop= a:dirname |
| 3395 | " call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)") |
| 3396 | endif |
| 3397 | |
| 3398 | " insure that we have at least an empty treedict |
| 3399 | if !exists("w:netrw_treedict") |
| 3400 | let w:netrw_treedict= {} |
| 3401 | endif |
| 3402 | |
| 3403 | " update the directory listing for the current directory |
| 3404 | " call Decho("updating dictionary with ".a:dirname.":[..directory listing..]") |
| 3405 | " call Decho("bannercnt=".w:netrw_bannercnt." line($)=".line("$")) |
| 3406 | exe "silent! keepjumps ".w:netrw_bannercnt.',$g@^\.\.\=/$@d' |
| 3407 | let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$")) |
| 3408 | " call Decho("treedict=".string(w:netrw_treedict)) |
| 3409 | exe "silent! keepjumps ".w:netrw_bannercnt.",$d" |
| 3410 | |
| 3411 | " if past banner, record word |
| 3412 | if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt |
| 3413 | let fname= expand("<cword>") |
| 3414 | else |
| 3415 | let fname= "" |
| 3416 | endif |
| 3417 | |
| 3418 | " display from treetop on down |
| 3419 | call s:NetTreeDisplay(w:netrw_treetop,"") |
| 3420 | |
| 3421 | " place cursor |
| 3422 | if !exists("s:nbcd_curpos") |
| 3423 | if fname != "" |
| 3424 | " call Decho("(NetTreeListing) place cursor <".fname.">") |
| 3425 | call search('\<'.fname.'\>','cw') |
| 3426 | elseif exists("w:netrw_bannercnt") |
| 3427 | exe (w:netrw_bannercnt+1) |
| 3428 | " call Decho("(NetTreeListing) place cursor line#".(w:netrw_bannercnt+1)) |
| 3429 | endif |
| 3430 | endif |
| 3431 | |
| 3432 | " call Dret("NetTreeListing : bufname<".expand("%").">") |
| 3433 | endif |
| 3434 | endfun |
| 3435 | |
| 3436 | " --------------------------------------------------------------------- |
| 3437 | " NetSaveWordPosn: used by the "s" command in both remote and local {{{2 |
| 3438 | " browsing. Along with NetRestoreWordPosn(), it keeps the cursor on |
| 3439 | " the same word even though the sorting has changed its order of appearance. |
| 3440 | fun! s:NetSaveWordPosn() |
| 3441 | " call Dfunc("NetSaveWordPosn()") |
| 3442 | let s:netrw_saveword= '^'.escape(getline("."),s:netrw_cd_escape).'$' |
| 3443 | " call Dret("NetSaveWordPosn : saveword<".s:netrw_saveword.">") |
| 3444 | endfun |
| 3445 | |
| 3446 | " --------------------------------------------------------------------- |
| 3447 | " NetRestoreWordPosn: used by the "s" command; see NetSaveWordPosn() above {{{2 |
| 3448 | fun! s:NetRestoreWordPosn() |
| 3449 | " call Dfunc("NetRestoreWordPosn()") |
| 3450 | silent! call search(s:netrw_saveword,'w') |
| 3451 | " call Dret("NetRestoreWordPosn") |
| 3452 | endfun |
| 3453 | |
| 3454 | " --------------------------------------------------------------------- |
| 3455 | " NetMakeDir: this function makes a directory (both local and remote) {{{2 |
| 3456 | fun! s:NetMakeDir(usrhost) |
| 3457 | " call Dfunc("NetMakeDir(usrhost<".a:usrhost.">)") |
| 3458 | |
| 3459 | " get name of new directory from user. A bare <CR> will skip. |
| 3460 | " if its currently a directory, also request will be skipped, but with |
| 3461 | " a message. |
| 3462 | call inputsave() |
| 3463 | let newdirname= input("Please give directory name: ") |
| 3464 | call inputrestore() |
| 3465 | " call Decho("newdirname<".newdirname.">") |
| 3466 | |
| 3467 | if newdirname == "" |
| 3468 | " call Dret("NetMakeDir : user aborted with bare <cr>") |
| 3469 | return |
| 3470 | endif |
| 3471 | |
| 3472 | if a:usrhost == "" |
| 3473 | |
| 3474 | " Local mkdir: |
| 3475 | " sanity checks |
| 3476 | let fullnewdir= b:netrw_curdir.'/'.newdirname |
| 3477 | " call Decho("fullnewdir<".fullnewdir.">") |
| 3478 | if isdirectory(fullnewdir) |
| 3479 | if !exists("g:netrw_quiet") |
| 3480 | call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24) |
| 3481 | endif |
| 3482 | " call Dret("NetMakeDir : directory<".newdirname."> exists previously") |
| 3483 | return |
| 3484 | endif |
| 3485 | if s:FileReadable(fullnewdir) |
| 3486 | if !exists("g:netrw_quiet") |
| 3487 | call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25) |
| 3488 | endif |
| 3489 | " call Dret("NetMakeDir : file<".newdirname."> exists previously") |
| 3490 | return |
| 3491 | endif |
| 3492 | |
| 3493 | " requested new local directory is neither a pre-existing file or |
| 3494 | " directory, so make it! |
| 3495 | if exists("*mkdir") |
| 3496 | call mkdir(fullnewdir,"p") |
| 3497 | else |
| 3498 | let netrw_origdir= s:NetGetcwd(1) |
| 3499 | exe 'keepjumps cd '.b:netrw_curdir |
| 3500 | " call Decho("netrw_origdir<".netrw_origdir.">: cd b:netrw_curdir<".b:netrw_curdir.">") |
| 3501 | " call Decho("exe silent! !".g:netrw_local_mkdir.' '.g:netrw_shq.newdirname.g:netrw_shq) |
| 3502 | exe "silent! !".g:netrw_local_mkdir.' '.g:netrw_shq.newdirname.g:netrw_shq |
| 3503 | if !g:netrw_keepdir | exe 'keepjumps cd '.netrw_origdir | endif |
| 3504 | if !g:netrw_keepdir |
| 3505 | exe 'keepjumps cd '.netrw_origdir |
| 3506 | " call Decho("netrw_keepdir=".g:netrw_keepdir.": cd ".netrw_origdir) |
| 3507 | endif |
| 3508 | endif |
| 3509 | |
| 3510 | if v:shell_error == 0 |
| 3511 | " refresh listing |
| 3512 | " call Decho("refresh listing") |
| 3513 | call netrw#NetSavePosn() |
| 3514 | call s:NetRefresh(1,s:NetBrowseChgDir(1,'./')) |
| 3515 | elseif !exists("g:netrw_quiet") |
| 3516 | call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26) |
| 3517 | endif |
| 3518 | redraw! |
| 3519 | |
| 3520 | else |
| 3521 | " Remote mkdir: |
| 3522 | let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd) |
| 3523 | let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname |
| 3524 | " call Decho("exe silent! !".mkdircmd." ".g:netrw_shq.newdirname.g:netrw_shq) |
| 3525 | exe "silent! !".mkdircmd." ".g:netrw_shq.newdirname.g:netrw_shq |
| 3526 | if v:shell_error == 0 |
| 3527 | " refresh listing |
| 3528 | call netrw#NetSavePosn() |
| 3529 | call s:NetRefresh(0,s:NetBrowseChgDir(0,'./')) |
| 3530 | elseif !exists("g:netrw_quiet") |
| 3531 | call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27) |
| 3532 | endif |
| 3533 | redraw! |
| 3534 | endif |
| 3535 | |
| 3536 | " call Dret("NetMakeDir") |
| 3537 | endfun |
| 3538 | |
| 3539 | " --------------------------------------------------------------------- |
| 3540 | " NetBookmarkDir: {{{2 |
| 3541 | " 0: (user: <b>) bookmark current directory |
| 3542 | " 1: (user: <B>) change to the bookmarked directory |
| 3543 | " 2: (user: <q>) list bookmarks |
| 3544 | " 3: (browsing) record current directory history |
| 3545 | " 4: (user: <u>) go up (previous) bookmark |
| 3546 | " 5: (user: <U>) go down (next) bookmark |
| 3547 | fun! s:NetBookmarkDir(chg,curdir) |
| 3548 | " call Dfunc("NetBookmarkDir(chg=".a:chg." curdir<".a:curdir.">) cnt=".v:count." bookmarkcnt=".g:NETRW_BOOKMARKMAX." histcnt=".g:NETRW_DIRHIST_CNT." bookmax=".g:NETRW_BOOKMARKMAX." histmax=".g:netrw_dirhistmax) |
| 3549 | |
| 3550 | if a:chg == 0 |
| 3551 | " bookmark the current directory |
| 3552 | " call Decho("(user: <b>) bookmark the current directory") |
| 3553 | if v:count > 0 |
| 3554 | " handle bookmark# specified via the count |
| 3555 | let g:NETRW_BOOKMARKDIR_{v:count}= a:curdir |
| 3556 | if !exists("g:NETRW_BOOKMARKMAX") |
| 3557 | let g:NETRW_BOOKMARKMAX= v:count |
| 3558 | elseif v:count > g:NETRW_BOOKMARKMAX |
| 3559 | let g:NETRW_BOOKMARKMAX= v:count |
| 3560 | endif |
| 3561 | else |
| 3562 | " handle no count specified |
| 3563 | let g:NETRW_BOOKMARKMAX = g:NETRW_BOOKMARKMAX + 1 |
| 3564 | let g:NETRW_BOOKMARKDIR_{g:NETRW_BOOKMARKMAX} = a:curdir |
| 3565 | endif |
| 3566 | echo "bookmarked the current directory" |
| 3567 | |
| 3568 | elseif a:chg == 1 |
| 3569 | " change to the bookmarked directory |
| 3570 | " call Decho("(user: <B>) change to the bookmarked directory") |
| 3571 | if exists("g:NETRW_BOOKMARKDIR_{v:count}") |
| 3572 | exe "e ".g:NETRW_BOOKMARKDIR_{v:count} |
| 3573 | else |
| 3574 | echomsg "Sorry, bookmark#".v:count." doesn't exist!" |
| 3575 | endif |
| 3576 | |
| 3577 | elseif a:chg == 2 |
| 3578 | redraw! |
| 3579 | let didwork= 0 |
| 3580 | " list user's bookmarks |
| 3581 | " call Decho("(user: <q>) list user's bookmarks") |
| 3582 | if exists("g:NETRW_BOOKMARKMAX") |
| 3583 | " call Decho("list bookmarks [0,".g:NETRW_BOOKMARKMAX."]") |
| 3584 | let cnt= 0 |
| 3585 | while cnt <= g:NETRW_BOOKMARKMAX |
| 3586 | if exists("g:NETRW_BOOKMARKDIR_{cnt}") |
| 3587 | " call Decho("Netrw Bookmark#".cnt.": ".g:NETRW_BOOKMARKDIR_{cnt}) |
| 3588 | echo "Netrw Bookmark#".cnt.": ".g:NETRW_BOOKMARKDIR_{cnt} |
| 3589 | let didwork= 1 |
| 3590 | endif |
| 3591 | let cnt= cnt + 1 |
| 3592 | endwhile |
| 3593 | endif |
| 3594 | |
| 3595 | " list directory history |
| 3596 | let cnt = g:NETRW_DIRHIST_CNT |
| 3597 | let first = 1 |
| 3598 | let histcnt = 0 |
| 3599 | while ( first || cnt != g:NETRW_DIRHIST_CNT ) |
| 3600 | " call Decho("first=".first." cnt=".cnt." dirhist_cnt=".g:NETRW_DIRHIST_CNT) |
| 3601 | let histcnt= histcnt + 1 |
| 3602 | if exists("g:NETRW_DIRHIST_{cnt}") |
| 3603 | " call Decho("Netrw History#".histcnt.": ".g:NETRW_DIRHIST_{cnt}) |
| 3604 | echo "Netrw History#".histcnt.": ".g:NETRW_DIRHIST_{cnt} |
| 3605 | let didwork= 1 |
| 3606 | endif |
| 3607 | let first = 0 |
| 3608 | let cnt = ( cnt - 1 ) % g:netrw_dirhistmax |
| 3609 | if cnt < 0 |
| 3610 | let cnt= cnt + g:netrw_dirhistmax |
| 3611 | endif |
| 3612 | endwhile |
| 3613 | if didwork |
| 3614 | call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
| 3615 | endif |
| 3616 | |
| 3617 | elseif a:chg == 3 |
| 3618 | " saves most recently visited directories (when they differ) |
| 3619 | " call Decho("(browsing) record curdir history") |
| 3620 | if !exists("g:NETRW_DIRHIST_0") || g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT} != a:curdir |
| 3621 | let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT + 1 ) % g:netrw_dirhistmax |
| 3622 | " let g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}= substitute(a:curdir,'[/\\]$','','e') |
| 3623 | let g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}= a:curdir |
| 3624 | " call Decho("save dirhist#".g:NETRW_DIRHIST_CNT."<".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}.">") |
| 3625 | endif |
| 3626 | |
| 3627 | elseif a:chg == 4 |
| 3628 | " u: change to the previous directory stored on the history list |
| 3629 | " call Decho("(user: <u>) chg to prev dir from history") |
| 3630 | let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT - 1 ) % g:netrw_dirhistmax |
| 3631 | if g:NETRW_DIRHIST_CNT < 0 |
| 3632 | let g:NETRW_DIRHIST_CNT= g:NETRW_DIRHIST_CNT + g:netrw_dirhistmax |
| 3633 | endif |
| 3634 | if exists("g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}") |
| 3635 | " call Decho("changedir u#".g:NETRW_DIRHIST_CNT."<".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}.">") |
| 3636 | if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir") |
| 3637 | setlocal ma noro |
| 3638 | %d |
| 3639 | setlocal nomod |
| 3640 | endif |
| 3641 | " call Decho("exe e! ".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}) |
| 3642 | exe "e! ".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT} |
| 3643 | else |
| 3644 | let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT + 1 ) % g:netrw_dirhistmax |
| 3645 | echo "Sorry, no predecessor directory exists yet" |
| 3646 | endif |
| 3647 | |
| 3648 | elseif a:chg == 5 |
| 3649 | " U: change to the subsequent directory stored on the history list |
| 3650 | " call Decho("(user: <U>) chg to next dir from history") |
| 3651 | let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT + 1 ) % g:netrw_dirhistmax |
| 3652 | if exists("g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}") |
| 3653 | " call Decho("changedir U#".g:NETRW_DIRHIST_CNT."<".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}.">") |
| 3654 | if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir") |
| 3655 | setlocal ma noro |
| 3656 | %d |
| 3657 | setlocal nomod |
| 3658 | endif |
| 3659 | " call Decho("exe e! ".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}) |
| 3660 | exe "e! ".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT} |
| 3661 | else |
| 3662 | let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT - 1 ) % g:netrw_dirhistmax |
| 3663 | if g:NETRW_DIRHIST_CNT < 0 |
| 3664 | let g:NETRW_DIRHIST_CNT= g:NETRW_DIRHIST_CNT + g:netrw_dirhistmax |
| 3665 | endif |
| 3666 | echo "Sorry, no successor directory exists yet" |
| 3667 | endif |
| 3668 | endif |
| 3669 | call s:NetBookmarkMenu() |
| 3670 | " call Dret("NetBookmarkDir") |
| 3671 | endfun |
| 3672 | |
| 3673 | " --------------------------------------------------------------------- |
| 3674 | " NetBookmarkMenu: {{{2 |
| 3675 | fun! s:NetBookmarkMenu() |
| 3676 | if !exists("s:netrw_menucnt") |
| 3677 | return |
| 3678 | endif |
| 3679 | " call Dfunc("NetBookmarkMenu() bookmarkcnt=".g:NETRW_BOOKMARKMAX." histcnt=".g:NETRW_DIRHIST_CNT." menucnt=".s:netrw_menucnt) |
| 3680 | if has("menu") && has("gui_running") && &go =~ 'm' |
| 3681 | if exists("g:NetrwTopLvlMenu") |
| 3682 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Bookmark' |
| 3683 | endif |
| 3684 | |
| 3685 | " show bookmarked places |
| 3686 | let cnt = 0 |
| 3687 | while cnt <= g:NETRW_BOOKMARKMAX |
| 3688 | if exists("g:NETRW_BOOKMARKDIR_{cnt}") |
| 3689 | let bmdir= escape(g:NETRW_BOOKMARKDIR_{cnt},'.') |
| 3690 | " call Decho('silent! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmdir.' :e '.g:NETRW_BOOKMARKDIR_{cnt}) |
| 3691 | exe 'silent! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmdir.' :e '.g:NETRW_BOOKMARKDIR_{cnt}."\<cr>" |
| 3692 | endif |
| 3693 | let cnt= cnt + 1 |
| 3694 | endwhile |
| 3695 | |
| 3696 | " show directory browsing history |
| 3697 | let cnt = g:NETRW_DIRHIST_CNT |
| 3698 | let first = 1 |
| 3699 | let histcnt = 0 |
| 3700 | while ( first || cnt != g:NETRW_DIRHIST_CNT ) |
| 3701 | let histcnt = histcnt + 1 |
| 3702 | let priority = g:NETRW_DIRHIST_CNT + histcnt |
| 3703 | if exists("g:NETRW_DIRHIST_{cnt}") |
| 3704 | let bmdir= escape(g:NETRW_DIRHIST_{cnt},'.') |
| 3705 | " call Decho('silent! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.bmdir.' :e '.g:NETRW_DIRHIST_{cnt}) |
| 3706 | exe 'silent! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.bmdir.' :e '.g:NETRW_DIRHIST_{cnt}."\<cr>" |
| 3707 | endif |
| 3708 | let first = 0 |
| 3709 | let cnt = ( cnt - 1 ) % g:netrw_dirhistmax |
| 3710 | if cnt < 0 |
| 3711 | let cnt= cnt + g:netrw_dirhistmax |
| 3712 | endif |
| 3713 | endwhile |
| 3714 | endif |
| 3715 | " call Dret("NetBookmarkMenu") |
| 3716 | endfun |
| 3717 | |
| 3718 | " --------------------------------------------------------------------- |
| 3719 | " NetObtain: obtain file under cursor (for remote browsing support) {{{2 |
| 3720 | fun! netrw#NetObtain(vismode,...) range |
| 3721 | " call Dfunc("NetObtain(vismode=".a:vismode.") a:0=".a:0) |
| 3722 | |
| 3723 | if a:vismode == 0 |
| 3724 | " normal mode |
| 3725 | let fname= expand("<cWORD>") |
| 3726 | " call Decho("no arguments, use <".fname.">") |
| 3727 | elseif a:vismode == 1 |
| 3728 | " visual mode |
| 3729 | let keeprega = @a |
| 3730 | norm! gv"ay |
| 3731 | if g:netrw_liststyle == s:THINLIST |
| 3732 | " thin listing |
| 3733 | let filelist= split(@a,'\n') |
| 3734 | elseif g:netrw_liststyle == s:LONGLIST |
| 3735 | " long listing |
| 3736 | let filelist= split(substitute(@a,'\t.\{-}\n','\n','g'),'\n') |
| 3737 | else |
| 3738 | " wide listing |
| 3739 | let filelist = split(substitute(@a,'\s\{2,}','\n','g'),'\n') |
| 3740 | let filelist = map(filelist,'substitute(v:val,"^\\s\\+","","")') |
| 3741 | let filelist = map(filelist,'substitute(v:val,"\\s\\+$","","")') |
| 3742 | endif |
| 3743 | " call Decho("filelist<".string(filelist).">") |
| 3744 | let @a= keeprega |
| 3745 | for f in filelist |
| 3746 | if f != "" |
| 3747 | call netrw#NetObtain(2,f) |
| 3748 | endif |
| 3749 | endfor |
| 3750 | " call Dret("NetObtain : visual mode handler") |
| 3751 | return |
| 3752 | elseif a:vismode == 2 |
| 3753 | " multiple file mode |
| 3754 | let fname= a:1 |
| 3755 | " call Decho("visual mode handling: <".fname.">") |
| 3756 | endif |
| 3757 | |
| 3758 | " NetrwStatusLine support - for obtaining support |
| 3759 | call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.fname) |
| 3760 | |
| 3761 | if exists("w:netrw_method") && w:netrw_method =~ '[235]' |
| 3762 | " call Decho("method=".w:netrw_method) |
| 3763 | if executable("ftp") |
| 3764 | " call Decho("ftp is executable, method=".w:netrw_method) |
| 3765 | let curdir = b:netrw_curdir |
| 3766 | let path = substitute(curdir,'ftp://[^/]\+/','','e') |
| 3767 | let curline= line(".") |
| 3768 | let endline= line("$")+1 |
| 3769 | setlocal ma noro |
| 3770 | keepjumps $ |
| 3771 | " call Decho("getcwd<".getcwd().">") |
| 3772 | " call Decho("curdir<".curdir.">") |
| 3773 | " call Decho("path<".path.">") |
| 3774 | " call Decho("curline=".curline) |
| 3775 | " call Decho("endline=".endline) |
| 3776 | |
| 3777 | "......................................... |
| 3778 | if w:netrw_method == 2 |
| 3779 | " ftp + <.netrc>: Method #2 |
| 3780 | setlocal ff=unix |
| 3781 | if path != "" |
| 3782 | put ='cd '.path |
| 3783 | " call Decho("ftp: cd ".path) |
| 3784 | endif |
| 3785 | put ='get '.fname |
| 3786 | " call Decho("ftp: get ".fname) |
| 3787 | put ='quit' |
| 3788 | " call Decho("ftp: quit") |
| 3789 | if exists("g:netrw_port") && g:netrw_port != "" |
| 3790 | " call Decho("exe ".g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port) |
| 3791 | exe g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port |
| 3792 | else |
| 3793 | " call Decho("exe ".g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine) |
| 3794 | exe g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine |
| 3795 | endif |
| 3796 | |
| 3797 | "......................................... |
| 3798 | elseif w:netrw_method == 3 |
| 3799 | " ftp + machine,id,passwd,filename: Method #3 |
| 3800 | setlocal ff=unix |
| 3801 | if exists("g:netrw_port") && g:netrw_port != "" |
| 3802 | put ='open '.g:netrw_machine.' '.g:netrw_port |
| 3803 | " call Decho('ftp: open '.g:netrw_machine.' '.g:netrw_port) |
| 3804 | else |
| 3805 | put ='open '.g:netrw_machine |
| 3806 | " call Decho('ftp: open '.g:netrw_machine) |
| 3807 | endif |
| 3808 | |
| 3809 | if exists("g:netrw_ftp") && g:netrw_ftp == 1 |
| 3810 | put =g:netrw_uid |
| 3811 | put ='\"'.g:netrw_passwd.'\"' |
| 3812 | " call Decho('ftp: g:netrw_uid') |
| 3813 | " call Decho('ftp: g:netrw_passwd') |
| 3814 | else |
| 3815 | put ='user \"'.g:netrw_uid.'\" \"'.g:netrw_passwd.'\"' |
| 3816 | " call Decho('user '.g:netrw_uid.' '.g:netrw_passwd) |
| 3817 | endif |
| 3818 | |
| 3819 | if path != "" |
| 3820 | put ='cd '.path |
| 3821 | " call Decho('cd '.a:path) |
| 3822 | endif |
| 3823 | put ='get '.fname |
| 3824 | " call Decho("ftp: get ".fname) |
| 3825 | put ='quit' |
| 3826 | " call Decho("ftp: quit") |
| 3827 | |
| 3828 | " perform ftp: |
| 3829 | " -i : turns off interactive prompting from ftp |
| 3830 | " -n unix : DON'T use <.netrc>, even though it exists |
| 3831 | " -n win32: quit being obnoxious about password |
| 3832 | " call Decho("exe ".g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i -n") |
| 3833 | exe g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i -n" |
| 3834 | |
| 3835 | "......................................... |
| 3836 | else |
| 3837 | call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",28) |
| 3838 | endif |
| 3839 | " restore |
| 3840 | exe "silent! ".endline.",$d" |
| 3841 | exe "keepjumps ".curline |
| 3842 | setlocal noma nomod ro |
| 3843 | else |
| 3844 | " call Decho("ftp not executable") |
| 3845 | if !exists("g:netrw_quiet") |
| 3846 | call netrw#ErrorMsg(s:ERROR,"this system doesn't support ftp",29) |
| 3847 | endif |
| 3848 | " restore status line |
| 3849 | let &stl = s:netrw_users_stl |
| 3850 | let &laststatus = s:netrw_users_ls |
| 3851 | " restore NetMethod |
| 3852 | if exists("keep_netrw_method") |
| 3853 | call s:NetMethod(keep_netrw_choice) |
| 3854 | let w:netrw_method = keep_netrw_wmethod |
| 3855 | endif |
| 3856 | " call Dret("NetObtain") |
| 3857 | return |
| 3858 | endif |
| 3859 | |
| 3860 | "......................................... |
| 3861 | else |
| 3862 | " scp: Method#4 |
| 3863 | " call Decho("using scp") |
| 3864 | let curdir = b:netrw_curdir |
| 3865 | let path = substitute(curdir,'scp://[^/]\+/','','e') |
| 3866 | " call Decho("path<".path.">") |
| 3867 | if exists("g:netrw_port") && g:netrw_port != "" |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 3868 | let useport= " ".g:netrw_scpport." ".g:netrw_port |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 3869 | else |
| 3870 | let useport= "" |
| 3871 | endif |
| 3872 | " call Decho("executing: !".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".path.escape(fname,' ?&')." .") |
| 3873 | exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".path.escape(fname,' ?&')." ." |
| 3874 | endif |
| 3875 | endif |
| 3876 | |
| 3877 | " restore status line |
| 3878 | let &stl = s:netrw_users_stl |
| 3879 | let &laststatus = s:netrw_users_ls |
| 3880 | redraw! |
| 3881 | |
| 3882 | " restore NetMethod |
| 3883 | if exists("keep_netrw_method") |
| 3884 | call s:NetMethod(keep_netrw_choice) |
| 3885 | let w:netrw_method = keep_netrw_wmethod |
| 3886 | endif |
| 3887 | |
| 3888 | " call Dret("NetObtain") |
| 3889 | endfun |
| 3890 | |
| 3891 | " --------------------------------------------------------------------- |
| 3892 | " NetPrevWinOpen: open file/directory in previous window. {{{2 |
| 3893 | " If there's only one window, then the window will first be split. |
| 3894 | fun! s:NetPrevWinOpen(islocal) |
| 3895 | " call Dfunc("NetPrevWinOpen(islocal=".a:islocal.")") |
| 3896 | |
| 3897 | " get last window number and the word currently under the cursor |
| 3898 | let lastwinnr = winnr("$") |
| 3899 | let curword = s:NetGetWord() |
| 3900 | " call Decho("lastwinnr=".lastwinnr." curword<".curword.">") |
| 3901 | |
| 3902 | let didsplit = 0 |
| 3903 | if lastwinnr == 1 |
| 3904 | " if only one window, open a new one first |
| 3905 | " call Decho("only one window, so open a new one (g:netrw_alto=".g:netrw_alto.")") |
| 3906 | exe (g:netrw_alto? "bel " : "abo ").g:netrw_winsize."wincmd s" |
| 3907 | let didsplit = 1 |
| 3908 | |
| 3909 | else |
| 3910 | wincmd p |
| 3911 | " if the previous window's buffer has been changed (is modified), |
| 3912 | " and it doesn't appear in any other extant window, then ask the |
| 3913 | " user if s/he wants to abandon modifications therein. |
| 3914 | let bnr = winbufnr(0) |
| 3915 | let bnrcnt = 0 |
| 3916 | if &mod |
| 3917 | windo if winbufnr(0) == bnr | let bnrcnt=bnrcnt+1 | endif |
| 3918 | " call Decho("bnr=".bnr." bnrcnt=".bnrcnt) |
| 3919 | if bnrcnt == 1 |
| 3920 | let bufname= bufname(winbufnr(winnr())) |
| 3921 | let choice= confirm("Save modified file<".bufname.">?","&Yes\n&No\n&Cancel") |
| 3922 | |
| 3923 | if choice == 1 |
| 3924 | " Yes -- write file & then browse |
| 3925 | let v:errmsg= "" |
| 3926 | silent w |
| 3927 | if v:errmsg != "" |
| 3928 | call netrw#ErrorMsg(s:ERROR,"unable to write <".bufname.">!",30) |
| 3929 | if didsplit |
| 3930 | q |
| 3931 | else |
| 3932 | wincmd p |
| 3933 | endif |
| 3934 | " call Dret("NetPrevWinOpen : unable to write <".bufname.">") |
| 3935 | return |
| 3936 | endif |
| 3937 | |
| 3938 | elseif choice == 2 |
| 3939 | " No -- don't worry about changed file, just browse anyway |
| 3940 | setlocal nomod |
| 3941 | call netrw#ErrorMsg(s:WARNING,bufname." changes abandoned",31) |
| 3942 | |
| 3943 | else |
| 3944 | " Cancel -- don't do this |
| 3945 | if didsplit |
| 3946 | q |
| 3947 | else |
| 3948 | wincmd p |
| 3949 | endif |
| 3950 | " call Dret("NetPrevWinOpen : cancelled") |
| 3951 | return |
| 3952 | endif |
| 3953 | endif |
| 3954 | endif |
| 3955 | endif |
| 3956 | |
| 3957 | if a:islocal |
| 3958 | call netrw#LocalBrowseCheck(s:NetBrowseChgDir(a:islocal,curword)) |
| 3959 | else |
| 3960 | call s:NetBrowse(a:islocal,s:NetBrowseChgDir(a:islocal,curword)) |
| 3961 | endif |
| 3962 | " call Dret("NetPrevWinOpen") |
| 3963 | endfun |
| 3964 | |
| 3965 | " --------------------------------------------------------------------- |
| 3966 | " NetMenu: generates the menu for gvim and netrw {{{2 |
| 3967 | fun! s:NetMenu(domenu) |
| 3968 | |
| 3969 | if !exists("g:NetrwMenuPriority") |
| 3970 | let g:NetrwMenuPriority= 80 |
| 3971 | endif |
| 3972 | |
| 3973 | if has("menu") && has("gui_running") && &go =~ 'm' && g:netrw_menu |
| 3974 | " call Dfunc("NetMenu(domenu=".a:domenu.")") |
| 3975 | |
| 3976 | if !exists("s:netrw_menu_enabled") && a:domenu |
| 3977 | " call Decho("initialize menu") |
| 3978 | let s:netrw_menu_enabled= 1 |
| 3979 | exe 'silent! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>' |
| 3980 | call s:NetBookmarkMenu() " provide some history! |
| 3981 | exe 'silent! menu '.g:NetrwMenuPriority.'.4 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -' |
| 3982 | exe 'silent! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x' |
| 3983 | exe 'silent! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Bookmark\ Current\ Directory<tab>mb mb' |
| 3984 | exe 'silent! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Goto\ Bookmarked\ Directory<tab>gb gb' |
| 3985 | exe 'silent! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Change\ To\ Recently\ Used\ Directory<tab>u u' |
| 3986 | exe 'silent! menu '.g:NetrwMenuPriority.'.9 '.g:NetrwTopLvlMenu.'Change\ To\ Subsequently\ Used\ Directory<tab>U U' |
| 3987 | exe 'silent! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D' |
| 3988 | exe 'silent! menu '.g:NetrwMenuPriority.'.11 '.g:NetrwTopLvlMenu.'Edit\ File\ Hiding\ List<tab>'."<ctrl-h> \<c-h>" |
| 3989 | exe 'silent! menu '.g:NetrwMenuPriority.'.12 '.g:NetrwTopLvlMenu.'Edit\ File/Directory<tab><cr> '."\<cr>" |
| 3990 | exe 'silent! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Edit\ File/Directory,\ New\ Window<tab>o o' |
| 3991 | exe 'silent! menu '.g:NetrwMenuPriority.'.14 '.g:NetrwTopLvlMenu.'Edit\ File/Directory,\ New\ Vertical\ Window<tab>v v' |
| 3992 | exe 'silent! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'List\ Bookmarks\ and\ History<tab>q q' |
| 3993 | exe 'silent! menu '.g:NetrwMenuPriority.'.16 '.g:NetrwTopLvlMenu.'Listing\ Style\ (thin-long-wide)<tab>i i' |
| 3994 | exe 'silent! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d' |
| 3995 | exe 'silent! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Normal-Hide-Show<tab>a a' |
| 3996 | exe 'silent! menu '.g:NetrwMenuPriority.'.19 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O' |
| 3997 | exe 'silent! menu '.g:NetrwMenuPriority.'.20 '.g:NetrwTopLvlMenu.'Preview\ File/Directory<tab>p p' |
| 3998 | exe 'silent! menu '.g:NetrwMenuPriority.'.21 '.g:NetrwTopLvlMenu.'Previous\ Window\ Browser<tab>P P' |
| 3999 | exe 'silent! menu '.g:NetrwMenuPriority.'.22 '.g:NetrwTopLvlMenu.'Refresh\ Listing<tab>'."<ctrl-l> \<c-l>" |
| 4000 | exe 'silent! menu '.g:NetrwMenuPriority.'.23 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R' |
| 4001 | exe 'silent! menu '.g:NetrwMenuPriority.'.24 '.g:NetrwTopLvlMenu.'Reverse\ Sorting\ Order<tab>'."r r" |
| 4002 | exe 'silent! menu '.g:NetrwMenuPriority.'.25 '.g:NetrwTopLvlMenu.'Select\ Sorting\ Style<tab>s s' |
| 4003 | exe 'silent! menu '.g:NetrwMenuPriority.'.26 '.g:NetrwTopLvlMenu.'Sorting\ Sequence\ Edit<tab>S S' |
| 4004 | exe 'silent! menu '.g:NetrwMenuPriority.'.27 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c' |
| 4005 | exe 'silent! menu '.g:NetrwMenuPriority.'.28 '.g:NetrwTopLvlMenu.'Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>" |
| 4006 | let s:netrw_menucnt= 28 |
| 4007 | |
| 4008 | elseif !a:domenu |
| 4009 | let s:netrwcnt = 0 |
| 4010 | let curwin = winnr() |
| 4011 | windo if getline(2) =~ "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif |
| 4012 | exe curwin."wincmd w" |
| 4013 | |
| 4014 | if s:netrwcnt <= 1 |
| 4015 | " call Decho("clear menus") |
| 4016 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Help' |
| 4017 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer' |
| 4018 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Bookmark\ Current\ Directory' |
| 4019 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Go\ Up\ Directory' |
| 4020 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Goto\ Bookmarked\ Directory' |
| 4021 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Change\ To\ Recently\ Used\ Directory' |
| 4022 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Change\ To\ Subsequently\ Used\ Directory' |
| 4023 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Delete\ File/Directory' |
| 4024 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Edit\ File/Directory' |
| 4025 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Edit\ File/Directory,\ New\ Window' |
| 4026 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Edit\ File/Directory,\ New\ Vertical\ Window' |
| 4027 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Edit\ File\ Hiding\ List' |
| 4028 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Edit\ File' |
| 4029 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Enter\ File/Directory' |
| 4030 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Enter\ File/Directory\ (vertical\ split)' |
| 4031 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'List\ Bookmarks\ and\ History' |
| 4032 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Listing\ Style\ (thin-long-wide)' |
| 4033 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Make\ Subdirectory' |
| 4034 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Normal-Hide-Show' |
| 4035 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Obtain\ File' |
| 4036 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Preview\ File/Directory' |
| 4037 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Previous\ Window\ Browser' |
| 4038 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Refresh\ Listing' |
| 4039 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Rename\ File/Directory' |
| 4040 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Reverse\ Sorting\ Order' |
| 4041 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Select\ Sorting\ Style' |
| 4042 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Sorting\ Sequence\ Edit' |
| 4043 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Set\ Current\ Directory' |
| 4044 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Settings/Options' |
| 4045 | exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Bookmarks' |
| 4046 | silent! unlet s:netrw_menu_enabled |
| 4047 | endif |
| 4048 | endif |
| 4049 | " call Dret("NetMenu") |
| 4050 | endif |
| 4051 | |
| 4052 | endfun |
| 4053 | |
| 4054 | " ========================================== |
| 4055 | " Local Directory Browsing Support: {{{1 |
| 4056 | " ========================================== |
| 4057 | |
| 4058 | " --------------------------------------------------------------------- |
| 4059 | " LocalBrowseCheck: {{{2 |
| 4060 | fun! netrw#LocalBrowseCheck(dirname) |
| 4061 | " unfortunate interaction -- split window debugging can't be |
| 4062 | " " used here, must use DechoRemOn or DechoTabOn -- the BufEnter |
| 4063 | " event triggers another call to LocalBrowseCheck() when attempts |
| 4064 | " to write to the DBG buffer are made. |
| 4065 | " call Dfunc("LocalBrowseCheck(dirname<".a:dirname.">") |
| 4066 | if isdirectory(a:dirname) |
| 4067 | silent! call s:NetBrowse(1,a:dirname) |
| 4068 | endif |
| 4069 | " call Dret("LocalBrowseCheck") |
| 4070 | " not a directory, ignore it |
| 4071 | endfun |
| 4072 | |
| 4073 | " --------------------------------------------------------------------- |
| 4074 | " LocalListing: does the job of "ls" for local directories {{{2 |
| 4075 | fun! s:LocalListing() |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 4076 | " call Dfunc("LocalListing() &ma=".&ma." &mod=".&mod." &ro=".&ro." buf(%)=".buf("%")) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4077 | " if exists("b:netrw_curdir") |call Decho('b:netrw_curdir<'.b:netrw_curdir.">") |else|call Decho("b:netrw_curdir doesn't exist") |endif |
| 4078 | " 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 |
| 4079 | |
| 4080 | " get the list of files contained in the current directory |
| 4081 | let dirname = escape(b:netrw_curdir,s:netrw_glob_escape) |
| 4082 | let dirnamelen = strlen(b:netrw_curdir) |
| 4083 | let filelist = glob(s:ComposePath(dirname,"*")) |
| 4084 | " call Decho("glob(dirname<".dirname."/*>)=".filelist) |
| 4085 | if filelist != "" |
| 4086 | let filelist= filelist."\n" |
| 4087 | endif |
| 4088 | let filelist= filelist.glob(s:ComposePath(dirname,".*")) |
| 4089 | " call Decho("glob(dirname<".dirname."/.*>)=".glob(dirname.".*")) |
| 4090 | |
| 4091 | " if the directory name includes a "$", and possibly other characters, |
| 4092 | " the glob() doesn't include "." and ".." entries. |
| 4093 | if filelist !~ '[\\/]\.[\\/]\=\(\n\|$\)' |
| 4094 | " call Decho("forcibly tacking on .") |
| 4095 | if filelist == "" |
| 4096 | let filelist= s:ComposePath(dirname,"./") |
| 4097 | else |
| 4098 | let filelist= filelist."\n".s:ComposePath(b:netrw_curdir,"./") |
| 4099 | endif |
| 4100 | " call Decho("filelist<".filelist.">") |
| 4101 | endif |
| 4102 | if filelist !~ '[\\/]\.\.[\\/]\=\(\n\|$\)' |
| 4103 | " call Decho("forcibly tacking on ..") |
| 4104 | let filelist= filelist."\n".s:ComposePath(b:netrw_curdir,"../") |
| 4105 | " call Decho("filelist<".filelist.">") |
| 4106 | endif |
| 4107 | if b:netrw_curdir == '/' |
| 4108 | " remove .. from filelist when current directory is root directory |
| 4109 | let filelist= substitute(filelist,'/\.\.\n','','') |
| 4110 | " call Decho("remove .. from filelist") |
| 4111 | endif |
| 4112 | let filelist= substitute(filelist,'\n\{2,}','\n','ge') |
| 4113 | if (has("win32") || has("win95") || has("win64") || has("win16")) |
| 4114 | let filelist= substitute(filelist,'\','/','ge') |
| 4115 | else |
| 4116 | let filelist= substitute(filelist,'\','\\','ge') |
| 4117 | endif |
| 4118 | |
| 4119 | " call Decho("dirname<".dirname.">") |
| 4120 | " call Decho("dirnamelen<".dirnamelen.">") |
| 4121 | " call Decho("filelist<".filelist.">") |
| 4122 | |
| 4123 | while filelist != "" |
| 4124 | if filelist =~ '\n' |
| 4125 | let filename = substitute(filelist,'\n.*$','','e') |
| 4126 | let filelist = substitute(filelist,'^.\{-}\n\(.*\)$','\1','e') |
| 4127 | else |
| 4128 | let filename = filelist |
| 4129 | let filelist = "" |
| 4130 | endif |
| 4131 | let pfile= filename |
| 4132 | if isdirectory(filename) |
| 4133 | let pfile= filename."/" |
| 4134 | endif |
| 4135 | if pfile =~ '//$' |
| 4136 | let pfile= substitute(pfile,'//$','/','e') |
| 4137 | endif |
| 4138 | let pfile= strpart(pfile,dirnamelen) |
| 4139 | let pfile= substitute(pfile,'^[/\\]','','e') |
| 4140 | " call Decho(" ") |
| 4141 | " call Decho("filename<".filename.">") |
| 4142 | " call Decho("pfile <".pfile.">") |
| 4143 | |
| 4144 | if w:netrw_liststyle == s:LONGLIST |
| 4145 | let sz = getfsize(filename) |
| 4146 | let fsz = strpart(" ",1,15-strlen(sz)).sz |
| 4147 | let pfile= pfile."\t".fsz." ".strftime(g:netrw_timefmt,getftime(filename)) |
| 4148 | " call Decho("sz=".sz." fsz=".fsz) |
| 4149 | endif |
| 4150 | |
| 4151 | if g:netrw_sort_by =~ "^t" |
| 4152 | " sort by time (handles time up to 1 quintillion seconds, US) |
| 4153 | " call Decho("getftime(".filename.")=".getftime(filename)) |
| 4154 | let t = getftime(filename) |
| 4155 | let ft = strpart("000000000000000000",1,18-strlen(t)).t |
| 4156 | " call Decho("exe keepjumps put ='".ft.'/'.filename."'") |
| 4157 | let ftpfile= ft.'/'.pfile |
| 4158 | keepjumps silent! put=ftpfile |
| 4159 | |
| 4160 | elseif g:netrw_sort_by =~ "^s" |
| 4161 | " sort by size (handles file sizes up to 1 quintillion bytes, US) |
| 4162 | " call Decho("getfsize(".filename.")=".getfsize(filename)) |
| 4163 | let sz = getfsize(filename) |
| 4164 | let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz |
| 4165 | " call Decho("exe keepjumps put ='".fsz.'/'.filename."'") |
| 4166 | let fszpfile= fsz.'/'.pfile |
| 4167 | keepjumps silent! put =fszpfile |
| 4168 | |
| 4169 | else |
| 4170 | " sort by name |
| 4171 | " call Decho("exe keepjumps put ='".pfile."'") |
| 4172 | keepjumps silent! put=pfile |
| 4173 | endif |
| 4174 | endwhile |
| 4175 | |
| 4176 | " cleanup any windows mess at end-of-line |
| 4177 | silent! keepjumps %s/\r$//e |
| 4178 | setlocal ts=32 |
| 4179 | " call Decho("setlocal ts=32") |
| 4180 | |
| 4181 | " call Dret("LocalListing") |
| 4182 | endfun |
| 4183 | |
| 4184 | " --------------------------------------------------------------------- |
| 4185 | " LocalBrowseShellCmdRefresh: this function is called after a user has {{{2 |
| 4186 | " performed any shell command. The idea is to cause all local-browsing |
| 4187 | " buffers to be refreshed after a user has executed some shell command, |
| 4188 | " on the chance that s/he removed/created a file/directory with it. |
| 4189 | fun! s:LocalBrowseShellCmdRefresh() |
| 4190 | " call Dfunc("LocalBrowseShellCmdRefresh() browselist=".string(s:netrw_browselist)) |
| 4191 | " determine which buffers currently reside in a tab |
| 4192 | let itab = 1 |
| 4193 | let buftablist = [] |
| 4194 | while itab <= tabpagenr("$") |
| 4195 | let buftablist= buftablist + tabpagebuflist() |
| 4196 | let itab= itab + 1 |
| 4197 | tabn |
| 4198 | endwhile |
| 4199 | " call Decho("buftablist".string(buftablist)) |
| 4200 | " GO through all buffers on netrw_browselist (ie. just local-netrw buffers): |
| 4201 | " | refresh any netrw window |
| 4202 | " | wipe out any non-displaying netrw buffer |
| 4203 | let curwin = winnr() |
| 4204 | let ibl = 0 |
| 4205 | for ibuf in s:netrw_browselist |
| 4206 | " call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf)) |
| 4207 | if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1 |
| 4208 | " call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">") |
| 4209 | exe "silent! bw ".ibuf |
| 4210 | call remove(s:netrw_browselist,ibl) |
| 4211 | " call Decho("browselist=".string(s:netrw_browselist)) |
| 4212 | continue |
| 4213 | elseif index(tabpagebuflist(),ibuf) != -1 |
| 4214 | " call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf)) |
| 4215 | exe bufwinnr(ibuf)."wincmd w" |
| 4216 | call s:NetRefresh(1,s:NetBrowseChgDir(1,'./')) |
| 4217 | endif |
| 4218 | let ibl= ibl + 1 |
| 4219 | endfor |
| 4220 | exe curwin."wincmd w" |
| 4221 | |
| 4222 | " call Dret("LocalBrowseShellCmdRefresh") |
| 4223 | endfun |
| 4224 | |
| 4225 | " --------------------------------------------------------------------- |
| 4226 | " LocalBrowseRm: {{{2 |
| 4227 | fun! s:LocalBrowseRm(path) range |
| 4228 | " call Dfunc("LocalBrowseRm(path<".a:path.">)") |
| 4229 | " call Decho("firstline=".a:firstline." lastline=".a:lastline) |
| 4230 | |
| 4231 | " preparation for removing multiple files/directories |
| 4232 | let ctr = a:firstline |
| 4233 | let ret = 0 |
| 4234 | let all= 0 |
| 4235 | |
| 4236 | " remove multiple files and directories |
| 4237 | while ctr <= a:lastline |
| 4238 | exe "keepjumps ".ctr |
| 4239 | |
| 4240 | " sanity checks |
| 4241 | if line(".") < w:netrw_bannercnt |
| 4242 | let ctr= ctr + 1 |
| 4243 | continue |
| 4244 | endif |
| 4245 | let curword= s:NetGetWord() |
| 4246 | if curword == "./" || curword == "../" |
| 4247 | let ctr= ctr + 1 |
| 4248 | continue |
| 4249 | endif |
| 4250 | |
| 4251 | norm! 0 |
| 4252 | let rmfile= s:ComposePath(a:path,curword) |
| 4253 | " call Decho("rmfile<".rmfile.">") |
| 4254 | |
| 4255 | if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$') |
| 4256 | " attempt to remove file |
| 4257 | if !all |
| 4258 | echohl Statement |
| 4259 | call inputsave() |
| 4260 | let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ") |
| 4261 | call inputrestore() |
| 4262 | echohl NONE |
| 4263 | if ok == "" |
| 4264 | let ok="no" |
| 4265 | endif |
| 4266 | " call Decho("response: ok<".ok.">") |
| 4267 | let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e') |
| 4268 | " call Decho("response: ok<".ok."> (after sub)") |
| 4269 | if ok =~ 'a\%[ll]' |
| 4270 | let all= 1 |
| 4271 | endif |
| 4272 | endif |
| 4273 | |
| 4274 | if all || ok =~ 'y\%[es]' || ok == "" |
| 4275 | let ret= s:System("delete",rmfile) |
| 4276 | " call Decho("errcode=".v:shell_error." ret=".ret) |
| 4277 | elseif ok =~ 'q\%[uit]' |
| 4278 | break |
| 4279 | endif |
| 4280 | |
| 4281 | else |
| 4282 | " attempt to remove directory |
| 4283 | if !all |
| 4284 | echohl Statement |
| 4285 | call inputsave() |
| 4286 | let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ") |
| 4287 | call inputrestore() |
| 4288 | let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e') |
| 4289 | if ok == "" |
| 4290 | let ok="no" |
| 4291 | endif |
| 4292 | if ok =~ 'a\%[ll]' |
| 4293 | let all= 1 |
| 4294 | endif |
| 4295 | endif |
| 4296 | let rmfile= substitute(rmfile,'[\/]$','','e') |
| 4297 | |
| 4298 | if all || ok =~ 'y\%[es]' || ok == "" |
| 4299 | " call Decho("1st attempt: system(".g:netrw_local_rmdir.' "'.rmfile.'")') |
| 4300 | call s:System("system",g:netrw_local_rmdir.' "'.rmfile.'"') |
| 4301 | " call Decho("v:shell_error=".v:shell_error) |
| 4302 | |
| 4303 | if v:shell_error != 0 |
| 4304 | " call Decho("2nd attempt to remove directory<".rmfile.">") |
| 4305 | let errcode= s:System("delete",rmfile) |
| 4306 | " call Decho("errcode=".errcode) |
| 4307 | |
| 4308 | if errcode != 0 |
| 4309 | if has("unix") |
| 4310 | " call Decho("3rd attempt to remove directory<".rmfile.">") |
| 4311 | call s:System("system","rm ".rmfile) |
| 4312 | if v:shell_error != 0 && !exists("g:netrw_quiet") |
| 4313 | call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",34) |
Bram Moolenaar | 83bab71 | 2005-08-01 21:58:57 +0000 | [diff] [blame] | 4314 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4315 | elseif !exists("g:netrw_quiet") |
| 4316 | call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",35) |
| 4317 | endif |
| 4318 | endif |
| 4319 | endif |
| 4320 | |
| 4321 | elseif ok =~ 'q\%[uit]' |
| 4322 | break |
| 4323 | endif |
| 4324 | endif |
| 4325 | |
| 4326 | let ctr= ctr + 1 |
| 4327 | endwhile |
| 4328 | |
| 4329 | " refresh the directory |
| 4330 | let curline= line(".") |
| 4331 | " call Decho("refresh the directory") |
| 4332 | call s:NetRefresh(1,s:NetBrowseChgDir(1,'./')) |
| 4333 | exe curline |
| 4334 | |
| 4335 | " call Dret("LocalBrowseRm") |
| 4336 | endfun |
| 4337 | |
| 4338 | " --------------------------------------------------------------------- |
| 4339 | " LocalBrowseRename: rename a remote file or directory {{{2 |
| 4340 | fun! s:LocalBrowseRename(path) range |
| 4341 | " call Dfunc("LocalBrowseRename(path<".a:path.">)") |
| 4342 | |
| 4343 | " preparation for removing multiple files/directories |
| 4344 | let ctr= a:firstline |
| 4345 | |
| 4346 | " attempt to rename files/directories |
| 4347 | while ctr <= a:lastline |
| 4348 | exe "keepjumps ".ctr |
| 4349 | |
| 4350 | " sanity checks |
| 4351 | if line(".") < w:netrw_bannercnt |
| 4352 | let ctr= ctr + 1 |
| 4353 | continue |
| 4354 | endif |
| 4355 | let curword= s:NetGetWord() |
| 4356 | if curword == "./" || curword == "../" |
| 4357 | let ctr= ctr + 1 |
| 4358 | continue |
| 4359 | endif |
| 4360 | |
| 4361 | norm! 0 |
| 4362 | let oldname= s:ComposePath(a:path,curword) |
| 4363 | " call Decho("oldname<".oldname.">") |
| 4364 | |
| 4365 | call inputsave() |
| 4366 | let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e')) |
| 4367 | call inputrestore() |
| 4368 | |
| 4369 | let ret= rename(oldname,newname) |
| 4370 | " call Decho("renaming <".oldname."> to <".newname.">") |
| 4371 | |
| 4372 | let ctr= ctr + 1 |
| 4373 | endwhile |
| 4374 | |
| 4375 | " refresh the directory |
| 4376 | " call Decho("refresh the directory listing") |
| 4377 | call netrw#NetSavePosn() |
| 4378 | call s:NetRefresh(1,s:NetBrowseChgDir(1,'./')) |
| 4379 | " call Dret("LocalBrowseRename") |
| 4380 | endfun |
| 4381 | |
| 4382 | " --------------------------------------------------------------------- |
| 4383 | " LocalFastBrowser: handles setting up/taking down fast browsing for the {{{2 |
| 4384 | " local browser |
| 4385 | " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast) |
| 4386 | " slow 0 D D Deleting a buffer implies it will not be re-used (slow) |
| 4387 | " med 1 D H |
| 4388 | " fast 2 H H |
| 4389 | fun! s:LocalFastBrowser() |
| 4390 | " call Dfunc("LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse) |
| 4391 | |
| 4392 | " initialize browselist, a list of buffer numbers that the local browser has used |
| 4393 | if !exists("s:netrw_browselist") |
| 4394 | " call Decho("initialize s:netrw_browselist") |
| 4395 | let s:netrw_browselist= [] |
| 4396 | endif |
| 4397 | |
| 4398 | " append current buffer to fastbrowse list |
| 4399 | if g:netrw_fastbrowse <= 1 && (empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]) |
| 4400 | " call Decho("appendng current buffer to browselist") |
| 4401 | call add(s:netrw_browselist,bufnr("%")) |
| 4402 | " call Decho("browselist=".string(s:netrw_browselist)) |
| 4403 | endif |
| 4404 | |
| 4405 | " enable autocmd events to handle refreshing/removing local browser buffers |
| 4406 | " If local browse buffer is currently showing: refresh it |
| 4407 | " If local browse buffer is currently hidden : wipe it |
| 4408 | if !exists("s:netrw_browser_shellcmd") && g:netrw_fastbrowse <= 1 |
| 4409 | " call Decho("setting up local-browser shell command refresh") |
| 4410 | let s:netrw_browser_shellcmd= 1 |
| 4411 | augroup AuNetrwShellCmd |
| 4412 | au! |
| 4413 | if (has("win32") || has("win95") || has("win64") || has("win16")) |
| 4414 | au ShellCmdPost * call s:LocalBrowseShellCmdRefresh() |
| 4415 | else |
| 4416 | au ShellCmdPost,FocusGained * call s:LocalBrowseShellCmdRefresh() |
| 4417 | endif |
| 4418 | augroup END |
| 4419 | endif |
| 4420 | |
| 4421 | " user must have changed fastbrowse to its fast setting, so remove |
| 4422 | " the associated autocmd events |
| 4423 | if g:netrw_fastbrowse > 1 && exists("s:netrw_browser_shellcmd") |
| 4424 | " call Decho("remove AuNetrwShellCmd autcmd group") |
| 4425 | unlet s:netrw_browser_shellcmd |
| 4426 | augroup AuNetrwShellCmd |
| 4427 | au! |
| 4428 | augroup END |
| 4429 | augroup! AuNetrwShellCmd |
| 4430 | endif |
| 4431 | |
| 4432 | " call Dret("LocalFastBrowser") |
| 4433 | endfun |
| 4434 | |
| 4435 | " --------------------------------------------------------------------- |
| 4436 | " LocalObtain: copy selected file to current working directory {{{2 |
| 4437 | fun! s:LocalObtain() |
| 4438 | " call Dfunc("LocalObtain()") |
| 4439 | if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir |
| 4440 | let fname= expand("<cWORD>") |
| 4441 | let fcopy= readfile(b:netrw_curdir."/".fname,"b") |
| 4442 | call writefile(fcopy,getcwd()."/".fname,"b") |
| 4443 | elseif !exists("b:netrw_curdir") |
| 4444 | call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36) |
| 4445 | else |
| 4446 | call netrw#ErrorMsg(s:ERROR,"local browsing directory and current directory are identical",37) |
| 4447 | endif |
| 4448 | " call Dret("LocalObtain") |
| 4449 | endfun |
| 4450 | |
| 4451 | " --------------------------------------------------------------------- |
| 4452 | " netrw#Explore: launch the local browser in the directory of the current file {{{2 |
| 4453 | " dosplit==0: the window will be split iff the current file has |
| 4454 | " been modified |
| 4455 | " dosplit==1: the window will be split before running the local |
| 4456 | " browser |
| 4457 | fun! netrw#Explore(indx,dosplit,style,...) |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 4458 | " 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] | 4459 | if !exists("b:netrw_curdir") |
| 4460 | let b:netrw_curdir= getcwd() |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 4461 | " call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4462 | endif |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 4463 | let curfile= b:netrw_curdir |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4464 | " call Decho("curfile<".curfile.">") |
| 4465 | |
| 4466 | " save registers |
| 4467 | silent! let keepregstar = @* |
| 4468 | silent! let keepregplus = @+ |
| 4469 | silent! let keepregslash= @/ |
| 4470 | |
| 4471 | " if dosplit or file has been modified |
| 4472 | if a:dosplit || &modified || a:style == 6 |
| 4473 | " call Decho("case: dosplit=".a:dosplit." modified=".&modified." a:style=".a:style) |
| 4474 | call s:SaveWinVars() |
| 4475 | |
| 4476 | if a:style == 0 " Explore, Sexplore |
| 4477 | " call Decho("style=0: Explore or Sexplore") |
| 4478 | exe g:netrw_winsize."wincmd s" |
| 4479 | |
| 4480 | elseif a:style == 1 "Explore!, Sexplore! |
| 4481 | " call Decho("style=1: Explore! or Sexplore!") |
| 4482 | exe g:netrw_winsize."wincmd v" |
| 4483 | |
| 4484 | elseif a:style == 2 " Hexplore |
| 4485 | " call Decho("style=2: Hexplore") |
| 4486 | exe "bel ".g:netrw_winsize."wincmd s" |
| 4487 | |
| 4488 | elseif a:style == 3 " Hexplore! |
| 4489 | " call Decho("style=3: Hexplore!") |
| 4490 | exe "abo ".g:netrw_winsize."wincmd s" |
| 4491 | |
| 4492 | elseif a:style == 4 " Vexplore |
| 4493 | " call Decho("style=4: Vexplore") |
| 4494 | exe "lefta ".g:netrw_winsize."wincmd v" |
| 4495 | |
| 4496 | elseif a:style == 5 " Vexplore! |
| 4497 | " call Decho("style=5: Vexplore!") |
| 4498 | exe "rightb ".g:netrw_winsize."wincmd v" |
| 4499 | |
| 4500 | elseif a:style == 6 " Texplore |
| 4501 | call s:SaveBufVars() |
| 4502 | " call Decho("style = 6: Texplore") |
| 4503 | tabnew |
| 4504 | call s:RestoreBufVars() |
| 4505 | endif |
| 4506 | call s:RestoreWinVars() |
| 4507 | endif |
| 4508 | norm! 0 |
| 4509 | |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 4510 | if a:0 > 0 |
| 4511 | " call Decho("a:1<".a:1.">") |
| 4512 | if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)) |
| 4513 | let dirname= substitute(a:1,'\~',expand("$HOME"),'') |
| 4514 | " call Decho("using dirname<".dirname."> (case: ~ && unix||cygwin)") |
| 4515 | elseif a:1 == '.' |
| 4516 | let dirname= exists("b:netrw_curdir")? b:netrw_curdir : getcwd() |
| 4517 | if dirname !~ '/$' |
| 4518 | let dirname= dirname."/" |
| 4519 | endif |
| 4520 | " call Decho("using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")") |
| 4521 | elseif a:1 =~ '\$' |
| 4522 | let dirname= expand(a:1) |
| 4523 | else |
| 4524 | let dirname= a:1 |
| 4525 | " call Decho("using dirname<".dirname.">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4526 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4527 | endif |
| 4528 | |
| 4529 | if dirname =~ '^\*/' |
| 4530 | " Explore */pattern |
| 4531 | " call Decho("case Explore */pattern") |
| 4532 | let pattern= substitute(dirname,'^\*/\(.*\)$','\1','') |
| 4533 | " call Decho("Explore */pat: dirname<".dirname."> -> pattern<".pattern.">") |
| 4534 | if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif |
| 4535 | elseif dirname =~ '^\*\*//' |
| 4536 | " Explore **//pattern |
| 4537 | " call Decho("case Explore **//pattern") |
| 4538 | let pattern = substitute(dirname,'^\*\*//','','') |
| 4539 | let starstarpat = 1 |
| 4540 | " call Decho("Explore **//pat: dirname<".dirname."> -> pattern<".pattern.">") |
| 4541 | endif |
| 4542 | |
| 4543 | if dirname == "" && a:indx >= 0 |
| 4544 | " Explore Hexplore Vexplore Sexplore |
| 4545 | " call Decho("case Explore Hexplore Vexplore Sexplore") |
| 4546 | let newdir= substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e') |
| 4547 | if newdir =~ '^scp:' || newdir =~ '^ftp:' |
| 4548 | " call Decho("calling NetBrowse(0,newdir<".newdir.">)") |
| 4549 | call s:NetBrowse(0,newdir) |
| 4550 | else |
| 4551 | if newdir == ""|let newdir= getcwd()|endif |
| 4552 | " call Decho("calling LocalBrowseCheck(newdir<".newdir.">)") |
| 4553 | call netrw#LocalBrowseCheck(newdir) |
| 4554 | endif |
| 4555 | call search('\<'.substitute(curfile,'^.*/','','e').'\>','cW') |
| 4556 | |
| 4557 | elseif dirname =~ '^\*\*/' || a:indx < 0 || dirname =~ '^\*/' |
| 4558 | " Nexplore, Pexplore, Explore **/... , or Explore */pattern |
| 4559 | " call Decho("case Nexplore, Pexplore, <s-down>, <s-up>, Explore dirname<".dirname.">") |
| 4560 | if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir") |
| 4561 | " call Decho("set up <s-up> and <s-down> maps") |
| 4562 | let s:didstarstar= 1 |
| 4563 | nnoremap <buffer> <silent> <s-up> :Pexplore<cr> |
| 4564 | nnoremap <buffer> <silent> <s-down> :Nexplore<cr> |
| 4565 | endif |
| 4566 | |
| 4567 | if has("path_extra") |
| 4568 | " call Decho("has path_extra") |
| 4569 | if !exists("w:netrw_explore_indx") |
| 4570 | let w:netrw_explore_indx= 0 |
| 4571 | endif |
| 4572 | let indx = a:indx |
| 4573 | " call Decho("set indx= [a:indx=".indx."]") |
| 4574 | " |
| 4575 | if indx == -1 |
| 4576 | "Nexplore |
| 4577 | " call Decho("case Nexplore: (indx=".indx.")") |
| 4578 | if !exists("w:netrw_explore_list") " sanity check |
| 4579 | call netrw#ErrorMsg(s:WARNING,"using Nexplore or <s-down> improperly; see help for netrw-starstar",40) |
| 4580 | silent! let @* = keepregstar |
| 4581 | silent! let @+ = keepregstar |
| 4582 | silent! let @/ = keepregslash |
| 4583 | " call Dret("netrw#Explore") |
| 4584 | return |
| 4585 | endif |
| 4586 | let indx= w:netrw_explore_indx |
| 4587 | if indx < 0 | let indx= 0 | endif |
| 4588 | if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif |
| 4589 | let curfile= w:netrw_explore_list[indx] |
| 4590 | " call Decho("indx=".indx." curfile<".curfile.">") |
| 4591 | while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx] |
| 4592 | let indx= indx + 1 |
| 4593 | " call Decho("indx=".indx." (Nexplore while loop)") |
| 4594 | endwhile |
| 4595 | if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif |
| 4596 | " call Decho("Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx) |
| 4597 | |
| 4598 | elseif indx == -2 |
| 4599 | "Pexplore |
| 4600 | " call Decho("case Pexplore: (indx=".indx.")") |
| 4601 | if !exists("w:netrw_explore_list") " sanity check |
| 4602 | call netrw#ErrorMsg(s:WARNING,"using Pexplore or <s-up> improperly; see help for netrw-starstar",41) |
| 4603 | silent! let @* = keepregstar |
| 4604 | silent! let @+ = keepregstar |
| 4605 | silent! let @/ = keepregslash |
| 4606 | " call Dret("netrw#Explore") |
| 4607 | return |
| 4608 | endif |
| 4609 | let indx= w:netrw_explore_indx |
| 4610 | if indx < 0 | let indx= 0 | endif |
| 4611 | if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif |
| 4612 | let curfile= w:netrw_explore_list[indx] |
| 4613 | " call Decho("indx=".indx." curfile<".curfile.">") |
| 4614 | while indx >= 0 && curfile == w:netrw_explore_list[indx] |
| 4615 | let indx= indx - 1 |
| 4616 | " call Decho("indx=".indx." (Pexplore while loop)") |
| 4617 | endwhile |
| 4618 | if indx < 0 | let indx= 0 | endif |
| 4619 | " call Decho("Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx) |
| 4620 | |
| 4621 | else |
| 4622 | " Explore -- initialize |
| 4623 | " build list of files to Explore with Nexplore/Pexplore |
| 4624 | " call Decho("case Explore: initialize (indx=".indx.")") |
| 4625 | let w:netrw_explore_indx= 0 |
| 4626 | if !exists("b:netrw_curdir") |
| 4627 | let b:netrw_curdir= getcwd() |
| 4628 | endif |
| 4629 | " call Decho("b:netrw_curdir<".b:netrw_curdir.">") |
| 4630 | |
| 4631 | if exists("pattern") |
| 4632 | " call Decho("pattern exists: building list pattern<".pattern."> cwd<".getcwd().">") |
| 4633 | if exists("starstarpat") |
| 4634 | " call Decho("starstarpat<".starstarpat.">") |
| 4635 | try |
| 4636 | exe "silent vimgrep /".pattern."/gj "."**/*" |
| 4637 | catch /^Vim\%((\a\+)\)\=:E480/ |
| 4638 | call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45) |
| 4639 | if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif |
| 4640 | silent! let @* = keepregstar |
| 4641 | silent! let @+ = keepregstar |
| 4642 | silent! let @/ = keepregslash |
| 4643 | " call Dret("netrw#Explore : no files matched pattern") |
| 4644 | return |
| 4645 | endtry |
| 4646 | let s:netrw_curdir = b:netrw_curdir |
| 4647 | let w:netrw_explore_list = getqflist() |
| 4648 | let w:netrw_explore_list = map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)') |
| 4649 | else |
| 4650 | " call Decho("no starstarpat") |
| 4651 | exe "vimgrep /".pattern."/gj ".b:netrw_curdir."/*" |
| 4652 | let w:netrw_explore_list = map(getqflist(),'bufname(v:val.bufnr)') |
| 4653 | if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif |
| 4654 | endif |
| 4655 | else |
| 4656 | " call Decho("no pattern: building list based on ".b:netrw_curdir."/".dirname) |
| 4657 | let w:netrw_explore_list= split(expand(b:netrw_curdir."/".dirname),'\n') |
| 4658 | if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif |
| 4659 | endif |
| 4660 | |
| 4661 | let w:netrw_explore_listlen = len(w:netrw_explore_list) |
| 4662 | " call Decho("w:netrw_explore_list<".string(w:netrw_explore_list)."> listlen=".w:netrw_explore_listlen) |
| 4663 | |
| 4664 | if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/') |
| 4665 | call netrw#ErrorMsg(s:WARNING,"no files matched",42) |
| 4666 | silent! let @* = keepregstar |
| 4667 | silent! let @+ = keepregstar |
| 4668 | silent! let @/ = keepregslash |
| 4669 | " call Dret("netrw#Explore : no files matched") |
| 4670 | return |
| 4671 | endif |
| 4672 | endif |
| 4673 | |
| 4674 | " NetrwStatusLine support - for exploring support |
| 4675 | let w:netrw_explore_indx= indx |
| 4676 | " call Decho("explorelist<".join(w:netrw_explore_list,',')."> len=".w:netrw_explore_listlen) |
| 4677 | |
| 4678 | " wrap the indx around, but issue a note |
| 4679 | if indx >= w:netrw_explore_listlen || indx < 0 |
| 4680 | " call Decho("wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")") |
| 4681 | let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0 |
| 4682 | let w:netrw_explore_indx= indx |
| 4683 | call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43) |
| 4684 | sleep 1 |
| 4685 | endif |
| 4686 | |
| 4687 | exe "let dirfile= w:netrw_explore_list[".indx."]" |
| 4688 | " call Decho("dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">") |
| 4689 | let newdir= substitute(dirfile,'/[^/]*$','','e') |
| 4690 | " call Decho("newdir<".newdir.">") |
| 4691 | |
| 4692 | " call Decho("calling LocalBrowseCheck(newdir<".newdir.">)") |
| 4693 | call netrw#LocalBrowseCheck(newdir) |
| 4694 | if !exists("w:netrw_liststyle") |
| 4695 | let w:netrw_liststyle= g:netrw_liststyle |
| 4696 | endif |
| 4697 | if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST |
| 4698 | call search('^'.substitute(dirfile,"^.*/","","").'\>',"W") |
| 4699 | else |
| 4700 | call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w") |
| 4701 | endif |
| 4702 | let w:netrw_explore_mtchcnt = indx + 1 |
| 4703 | let w:netrw_explore_bufnr = bufnr("%") |
| 4704 | let w:netrw_explore_line = line(".") |
| 4705 | call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}') |
| 4706 | " call Decho("explore: mtchcnt=".w:netrw_explore_mtchcnt." bufnr=".w:netrw_explore_bufnr." line#".w:netrw_explore_line) |
| 4707 | |
| 4708 | else |
| 4709 | " call Decho("vim does not have path_extra") |
| 4710 | if !exists("g:netrw_quiet") |
| 4711 | call netrw#ErrorMsg(s:WARNING,"your vim needs the +path_extra feature for Exploring with **!",44) |
| 4712 | endif |
| 4713 | silent! let @* = keepregstar |
| 4714 | silent! let @+ = keepregstar |
| 4715 | silent! let @/ = keepregslash |
| 4716 | " call Dret("netrw#Explore : missing +path_extra") |
| 4717 | return |
| 4718 | endif |
| 4719 | |
| 4720 | else |
| 4721 | " call Decho("case Explore newdir<".dirname.">") |
| 4722 | if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/' |
| 4723 | silent! unlet w:netrw_treedict |
| 4724 | silent! unlet w:netrw_treetop |
| 4725 | endif |
| 4726 | let newdir= dirname |
| 4727 | if !exists("b:netrw_curdir") |
| 4728 | call netrw#LocalBrowseCheck(getcwd()) |
| 4729 | else |
| 4730 | call netrw#LocalBrowseCheck(s:NetBrowseChgDir(1,newdir)) |
| 4731 | endif |
| 4732 | endif |
| 4733 | |
| 4734 | silent! let @* = keepregstar |
| 4735 | silent! let @+ = keepregstar |
| 4736 | silent! let @/ = keepregslash |
| 4737 | " call Dret("netrw#Explore : @/<".@/.">") |
| 4738 | endfun |
| 4739 | |
| 4740 | " --------------------------------------------------------------------- |
| 4741 | " s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2 |
| 4742 | fun! s:ExplorePatHls(pattern) |
| 4743 | " call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)") |
| 4744 | let repat= substitute(a:pattern,'^**/\{1,2}','','') |
| 4745 | " call Decho("repat<".repat.">") |
| 4746 | let repat= escape(repat,'][.\') |
| 4747 | " call Decho("repat<".repat.">") |
| 4748 | let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>' |
| 4749 | " call Dret("s:ExplorePatHls repat<".repat.">") |
| 4750 | return repat |
| 4751 | endfun |
| 4752 | |
| 4753 | " --------------------------------------------------------------------- |
| 4754 | " SetupNetrwStatusLine: {{{2 |
| 4755 | fun! s:SetupNetrwStatusLine(statline) |
| 4756 | " call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)") |
| 4757 | |
| 4758 | if !exists("s:netrw_setup_statline") |
| 4759 | let s:netrw_setup_statline= 1 |
| 4760 | " call Decho("do first-time status line setup") |
| 4761 | |
| 4762 | if !exists("s:netrw_users_stl") |
| 4763 | let s:netrw_users_stl= &stl |
| 4764 | endif |
| 4765 | if !exists("s:netrw_users_ls") |
| 4766 | let s:netrw_users_ls= &laststatus |
| 4767 | endif |
| 4768 | |
| 4769 | " set up User9 highlighting as needed |
| 4770 | let keepa= @a |
| 4771 | redir @a |
| 4772 | try |
| 4773 | hi User9 |
| 4774 | catch /^Vim\%((\a\+)\)\=:E411/ |
| 4775 | if &bg == "dark" |
| 4776 | hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue |
| 4777 | else |
| 4778 | hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue |
| 4779 | endif |
| 4780 | endtry |
| 4781 | redir END |
| 4782 | let @a= keepa |
| 4783 | endif |
| 4784 | |
| 4785 | " set up status line (may use User9 highlighting) |
| 4786 | " insure that windows have a statusline |
| 4787 | " make sure statusline is displayed |
| 4788 | let &stl=a:statline |
| 4789 | setlocal laststatus=2 |
| 4790 | " call Decho("stl=".&stl) |
| 4791 | redraw! |
| 4792 | |
| 4793 | " call Dret("SetupNetrwStatusLine : stl=".&stl) |
| 4794 | endfun |
| 4795 | |
| 4796 | " --------------------------------------------------------------------- |
| 4797 | " NetrwStatusLine: {{{2 |
| 4798 | fun! NetrwStatusLine() |
| 4799 | |
| 4800 | " vvv NetrwStatusLine() debugging vvv |
| 4801 | " let g:stlmsg="" |
| 4802 | " if !exists("w:netrw_explore_bufnr") |
| 4803 | " let g:stlmsg="!X<explore_bufnr>" |
| 4804 | " elseif w:netrw_explore_bufnr != bufnr("%") |
| 4805 | " let g:stlmsg="explore_bufnr!=".bufnr("%") |
| 4806 | " endif |
| 4807 | " if !exists("w:netrw_explore_line") |
| 4808 | " let g:stlmsg=" !X<explore_line>" |
| 4809 | " elseif w:netrw_explore_line != line(".") |
| 4810 | " let g:stlmsg=" explore_line!={line(.)<".line(".").">" |
| 4811 | " endif |
| 4812 | " if !exists("w:netrw_explore_list") |
| 4813 | " let g:stlmsg=" !X<explore_list>" |
| 4814 | " endif |
| 4815 | " ^^^ NetrwStatusLine() debugging ^^^ |
| 4816 | |
| 4817 | 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") |
| 4818 | " restore user's status line |
| 4819 | let &stl = s:netrw_users_stl |
| 4820 | let &laststatus = s:netrw_users_ls |
| 4821 | if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif |
| 4822 | if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif |
| 4823 | return "" |
| 4824 | else |
| 4825 | return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen |
| 4826 | endif |
| 4827 | endfun |
| 4828 | |
| 4829 | " --------------------------------------------------------------------- |
| 4830 | " NetGetcwd: get the current directory. {{{2 |
| 4831 | " Change backslashes to forward slashes, if any. |
| 4832 | " If doesc is true, escape certain troublesome characters |
| 4833 | fun! s:NetGetcwd(doesc) |
| 4834 | " call Dfunc("NetGetcwd(doesc=".a:doesc.")") |
| 4835 | let curdir= substitute(getcwd(),'\\','/','ge') |
| 4836 | if curdir !~ '[\/]$' |
| 4837 | let curdir= curdir.'/' |
| 4838 | endif |
| 4839 | if a:doesc |
| 4840 | let curdir= escape(curdir,s:netrw_cd_escape) |
| 4841 | endif |
| 4842 | " call Dret("NetGetcwd <".curdir.">") |
| 4843 | return curdir |
| 4844 | endfun |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 4845 | |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 4846 | " --------------------------------------------------------------------- |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 4847 | " SetSort: sets up the sort based on the g:netrw_sort_sequence {{{2 |
Bram Moolenaar | 8299df9 | 2004-07-10 09:47:34 +0000 | [diff] [blame] | 4848 | " What this function does is to compute a priority for the patterns |
| 4849 | " in the g:netrw_sort_sequence. It applies a substitute to any |
| 4850 | " "files" that satisfy each pattern, putting the priority / in |
| 4851 | " front. An "*" pattern handles the default priority. |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 4852 | fun! s:SetSort() |
Bram Moolenaar | 488c651 | 2005-08-11 20:09:58 +0000 | [diff] [blame] | 4853 | " call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt) |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4854 | if w:netrw_liststyle == s:LONGLIST |
Bram Moolenaar | 8299df9 | 2004-07-10 09:47:34 +0000 | [diff] [blame] | 4855 | let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge') |
| 4856 | else |
| 4857 | let seqlist = g:netrw_sort_sequence |
| 4858 | endif |
| 4859 | " sanity check -- insure that * appears somewhere |
| 4860 | if seqlist == "" |
| 4861 | let seqlist= '*' |
| 4862 | elseif seqlist !~ '\*' |
| 4863 | let seqlist= seqlist.',*' |
| 4864 | endif |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 4865 | let priority = 1 |
| 4866 | while seqlist != "" |
| 4867 | if seqlist =~ ',' |
| 4868 | let seq = substitute(seqlist,',.*$','','e') |
| 4869 | let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e') |
| 4870 | else |
| 4871 | let seq = seqlist |
| 4872 | let seqlist = "" |
| 4873 | endif |
| 4874 | let eseq= escape(seq,'/') |
| 4875 | if priority < 10 |
| 4876 | let spriority= "00".priority.'\/' |
| 4877 | elseif priority < 100 |
| 4878 | let spriority= "0".priority.'\/' |
| 4879 | else |
| 4880 | let spriority= priority.'\/' |
| 4881 | endif |
| 4882 | " call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">") |
| 4883 | |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4884 | " sanity check |
Bram Moolenaar | 488c651 | 2005-08-11 20:09:58 +0000 | [diff] [blame] | 4885 | if w:netrw_bannercnt > line("$") |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4886 | " apparently no files were left after a Hiding pattern was used |
| 4887 | " call Dret("SetSort : no files left after hiding") |
| 4888 | return |
| 4889 | endif |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 4890 | if seq == '*' |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 4891 | exe 'silent keepjumps '.w:netrw_bannercnt.',$v/^\d\{3}\//s/^/'.spriority.'/' |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 4892 | else |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 4893 | exe 'silent keepjumps '.w:netrw_bannercnt.',$g/'.eseq.'/s/^/'.spriority.'/' |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 4894 | endif |
| 4895 | let priority = priority + 1 |
| 4896 | endwhile |
| 4897 | |
Bram Moolenaar | 7fc904b | 2006-04-13 20:37:35 +0000 | [diff] [blame] | 4898 | " Following line associated with priority -- items that satisfy a priority |
| 4899 | " pattern get prefixed by ###/ which permits easy sorting by priority. |
| 4900 | " Sometimes files can satisfy multiple priority patterns -- only the latest |
| 4901 | " priority pattern needs to be retained. So, at this point, these excess |
| 4902 | " priority prefixes need to be removed, but not directories that happen to |
| 4903 | " be just digits themselves. |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 4904 | exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\(\d\{3}\/\)\%(\d\{3}\/\)\+\ze./\1/e' |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 4905 | |
| 4906 | " call Dret("SetSort") |
| 4907 | endfun |
| 4908 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4909 | " ===================================================================== |
| 4910 | " Support Functions: {{{1 |
| 4911 | |
Bram Moolenaar | 488c651 | 2005-08-11 20:09:58 +0000 | [diff] [blame] | 4912 | " --------------------------------------------------------------------- |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4913 | " ComposePath: Appends a new part to a path taking different systems into consideration {{{2 |
| 4914 | fun! s:ComposePath(base,subdir) |
| 4915 | " call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)") |
| 4916 | if(has("amiga")) |
| 4917 | let ec = a:base[strlen(a:base)-1] |
| 4918 | if ec != '/' && ec != ':' |
| 4919 | let ret = a:base . "/" . a:subdir |
| 4920 | else |
| 4921 | let ret = a:base . a:subdir |
| 4922 | endif |
| 4923 | elseif a:base =~ '^\a\+://' |
| 4924 | let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','') |
| 4925 | let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','') |
| 4926 | let ret = urlbase.curpath.a:subdir |
| 4927 | " call Decho("urlbase<".urlbase.">") |
| 4928 | " call Decho("curpath<".curpath.">") |
| 4929 | " call Decho("ret<".ret.">") |
| 4930 | else |
| 4931 | let ret = substitute(a:base."/".a:subdir,"//","/","g") |
| 4932 | endif |
| 4933 | " call Dret("s:ComposePath ".ret) |
| 4934 | return ret |
Bram Moolenaar | 488c651 | 2005-08-11 20:09:58 +0000 | [diff] [blame] | 4935 | endfun |
| 4936 | |
| 4937 | " --------------------------------------------------------------------- |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4938 | " netrw#ErrorMsg: {{{2 |
| 4939 | " 0=note = s:NOTE |
| 4940 | " 1=warning = s:WARNING |
| 4941 | " 2=error = s:ERROR |
| 4942 | " Mar 19, 2007 : max errnum currently is 49 |
| 4943 | fun! netrw#ErrorMsg(level,msg,errnum) |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 4944 | " 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] | 4945 | |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 4946 | if a:level == 1 |
| 4947 | let level= "**warning** (netrw) " |
| 4948 | elseif a:level == 2 |
| 4949 | let level= "**error** (netrw) " |
| 4950 | else |
| 4951 | let level= "**note** (netrw) " |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4952 | endif |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 4953 | |
| 4954 | if g:netrw_use_errorwindow |
| 4955 | " (default) netrw creates a one-line window to show error/warning |
| 4956 | " messages (reliably displayed) |
| 4957 | |
| 4958 | " record current window number for NetRestorePosn()'s benefit |
| 4959 | let s:winBeforeErr= winnr() |
| 4960 | |
| 4961 | " getting messages out reliably is just plain difficult! |
| 4962 | " This attempt splits the current window, creating a one line window. |
| 4963 | if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0 |
| 4964 | exe bufwinnr("NetrwMessage")."wincmd w" |
| 4965 | set ma noro |
| 4966 | call setline(line("$")+1,level.a:msg) |
| 4967 | $ |
| 4968 | else |
| 4969 | bo 1split |
| 4970 | enew |
| 4971 | setlocal bt=nofile |
| 4972 | file NetrwMessage |
| 4973 | call setline(line("$"),level.a:msg) |
| 4974 | endif |
| 4975 | if &fo !~ '[ta]' |
| 4976 | syn clear |
| 4977 | syn match netrwMesgNote "^\*\*note\*\*" |
| 4978 | syn match netrwMesgWarning "^\*\*warning\*\*" |
| 4979 | syn match netrwMesgError "^\*\*error\*\*" |
| 4980 | hi link netrwMesgWarning WarningMsg |
| 4981 | hi link netrwMesgError Error |
| 4982 | endif |
| 4983 | setlocal noma ro bh=wipe |
| 4984 | |
| 4985 | else |
| 4986 | " (optional) netrw will show messages using echomsg. Even if the |
| 4987 | " message doesn't appear, at least it'll be recallable via :messages |
| 4988 | redraw! |
| 4989 | if a:level == s:WARNING |
| 4990 | echohl WarningMsg |
| 4991 | elseif a:level == s:ERROR |
| 4992 | echohl Error |
| 4993 | endif |
| 4994 | echomsg level.a:msg |
| 4995 | " call Decho("echomsg ***netrw*** ".a:msg) |
| 4996 | echohl None |
| 4997 | endif |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 4998 | |
| 4999 | " call Dret("netrw#ErrorMsg") |
| 5000 | endfun |
| 5001 | |
| 5002 | " --------------------------------------------------------------------- |
| 5003 | " netrw#RFC2396: converts %xx into characters {{{2 |
| 5004 | fun! netrw#RFC2396(fname) |
| 5005 | " call Dfunc("netrw#RFC2396(fname<".a:fname.">)") |
| 5006 | let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t") |
| 5007 | " call Dret("netrw#RFC2396 ".fname) |
| 5008 | return fname |
| 5009 | endfun |
| 5010 | |
| 5011 | " --------------------------------------------------------------------- |
| 5012 | " s:FileReadable: o/s independent filereadable {{{2 |
| 5013 | fun! s:FileReadable(fname) |
| 5014 | " call Dfunc("s:FileReadable(fname<".a:fname.">)") |
| 5015 | |
| 5016 | if g:netrw_cygwin |
| 5017 | let ret= filereadable(substitute(a:fname,'/cygdrive/\(.\)','\1:/','')) |
| 5018 | else |
| 5019 | let ret= filereadable(a:fname) |
| 5020 | endif |
| 5021 | |
| 5022 | " call Dret("s:FileReadable ".ret) |
| 5023 | return ret |
| 5024 | endfun |
| 5025 | |
| 5026 | " --------------------------------------------------------------------- |
| 5027 | " s:GetTempfile: gets a tempname that'll work for various o/s's {{{2 |
| 5028 | " Places correct suffix on end of temporary filename, |
| 5029 | " using the suffix provided with fname |
| 5030 | fun! s:GetTempfile(fname) |
| 5031 | " call Dfunc("s:GetTempfile(fname<".a:fname.">)") |
| 5032 | |
| 5033 | if !exists("b:netrw_tmpfile") |
| 5034 | " get a brand new temporary filename |
| 5035 | let tmpfile= tempname() |
| 5036 | " call Decho("tmpfile<".tmpfile."> : from tempname()") |
| 5037 | |
| 5038 | let tmpfile= escape(substitute(tmpfile,'\','/','ge'),g:netrw_tmpfile_escape) |
| 5039 | " call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /") |
| 5040 | |
| 5041 | " sanity check -- does the temporary file's directory exist? |
| 5042 | if !isdirectory(substitute(tmpfile,'[^/]\+$','','e')) |
| 5043 | call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2) |
| 5044 | " call Dret("s:GetTempfile getcwd<".getcwd().">") |
| 5045 | return "" |
| 5046 | endif |
| 5047 | |
| 5048 | " let netrw#NetSource() know about the tmpfile |
| 5049 | let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() |
| 5050 | " call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">") |
| 5051 | |
| 5052 | " o/s dependencies |
| 5053 | if g:netrw_cygwin == 1 |
| 5054 | let tmpfile = substitute(tmpfile,'^\(\a\):','/cygdrive/\1','e') |
| 5055 | elseif has("win32") || has("win95") || has("win64") || has("win16") |
| 5056 | let tmpfile = substitute(tmpfile,'/','\\','g') |
| 5057 | else |
| 5058 | let tmpfile = tmpfile |
| 5059 | endif |
| 5060 | let b:netrw_tmpfile= tmpfile |
| 5061 | " call Decho("o/s dependent fixed tempname<".tmpfile.">") |
| 5062 | else |
| 5063 | " re-use temporary filename |
| 5064 | let tmpfile= b:netrw_tmpfile |
| 5065 | " call Decho("tmpfile<".tmpfile."> re-using") |
| 5066 | endif |
| 5067 | |
| 5068 | " use fname's suffix for the temporary file |
| 5069 | if a:fname != "" |
| 5070 | if a:fname =~ '\.[^./]\+$' |
| 5071 | " call Decho("using fname<".a:fname.">'s suffix") |
| 5072 | if a:fname =~ '.tar.gz' || a:fname =~ '.tar.bz2' |
| 5073 | let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e') |
| 5074 | else |
| 5075 | let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e') |
| 5076 | endif |
| 5077 | let suffix = escape(suffix,g:netrw_tmpfile_escape) |
| 5078 | " call Decho("suffix<".suffix.">") |
| 5079 | let tmpfile= substitute(tmpfile,'\.tmp$','','e') |
| 5080 | " call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)") |
| 5081 | let tmpfile .= suffix |
| 5082 | " call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">") |
| 5083 | let s:netrw_tmpfile= tmpfile " supports netrw#NetSource() |
| 5084 | endif |
| 5085 | endif |
| 5086 | |
| 5087 | " call Dret("s:GetTempfile <".tmpfile.">") |
| 5088 | return tmpfile |
| 5089 | endfun |
| 5090 | |
| 5091 | " --------------------------------------------------------------------- |
| 5092 | " s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2 |
| 5093 | " a correct command |
| 5094 | fun! s:MakeSshCmd(sshcmd) |
| 5095 | " call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">)") |
| 5096 | let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user.s:machine,'') |
| 5097 | if exists("g:netrw_port") && g:netrw_port != "" |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 5098 | let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'') |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 5099 | elseif exists("s:port") && s:port != "" |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 5100 | let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'') |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 5101 | else |
| 5102 | let sshcmd= substitute(sshcmd,"USEPORT ",'','') |
| 5103 | endif |
| 5104 | " call Dret("s:MakeSshCmd <".sshcmd.">") |
| 5105 | return sshcmd |
| 5106 | endfun |
| 5107 | |
| 5108 | " --------------------------------------------------------------------- |
| 5109 | " s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2 |
| 5110 | fun! s:NetrwEnew(curdir) |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 5111 | " call Dfunc("s:NetrwEnew(curdir<".a:curdir.">) buf#".bufnr("%")."<".bufname("%").">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 5112 | |
| 5113 | " grab a function-local copy of buffer variables |
| 5114 | if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif |
| 5115 | if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif |
| 5116 | if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif |
| 5117 | if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif |
| 5118 | if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif |
| 5119 | if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif |
| 5120 | if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif |
| 5121 | if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif |
| 5122 | if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif |
| 5123 | if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif |
| 5124 | if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif |
| 5125 | if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif |
| 5126 | if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif |
| 5127 | if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif |
| 5128 | if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif |
| 5129 | if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif |
| 5130 | |
| 5131 | if getline(2) =~ '^" Netrw Directory Listing' |
| 5132 | " call Decho("generate a buffer with keepjumps keepalt enew! (1)") |
| 5133 | keepjumps keepalt enew! |
| 5134 | else |
| 5135 | " call Decho("generate a buffer with keepjumps enew! (2)") |
| 5136 | keepjumps enew! |
| 5137 | endif |
| 5138 | |
| 5139 | " copy function-local variables to buffer variable equivalents |
| 5140 | if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif |
| 5141 | if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif |
| 5142 | if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif |
| 5143 | if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif |
| 5144 | if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif |
| 5145 | if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif |
| 5146 | if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif |
| 5147 | if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif |
| 5148 | if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif |
| 5149 | if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif |
| 5150 | if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif |
| 5151 | if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif |
| 5152 | if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif |
| 5153 | if exists("netrw_method") |let b:netrw_method = netrw_method |endif |
| 5154 | if exists("netrw_option") |let b:netrw_option = netrw_option |endif |
| 5155 | if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif |
| 5156 | |
| 5157 | let b:netrw_curdir= a:curdir |
| 5158 | if b:netrw_curdir =~ '/$' |
| 5159 | if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST |
| 5160 | file NetrwTreeListing |
| 5161 | else |
| 5162 | exe "silent! file ".b:netrw_curdir |
| 5163 | endif |
| 5164 | endif |
| 5165 | |
Bram Moolenaar | 7aa9f6a | 2007-05-10 18:00:30 +0000 | [diff] [blame^] | 5166 | " call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%").">") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 5167 | endfun |
| 5168 | |
| 5169 | " ------------------------------------------------------------------------ |
| 5170 | " s:RemotePathAnalysis: {{{2 |
| 5171 | fun! s:RemotePathAnalysis(dirname) |
| 5172 | " call Dfunc("s:RemotePathAnalysis()") |
| 5173 | |
| 5174 | let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$' |
| 5175 | let s:method = substitute(a:dirname,dirpat,'\1','') |
| 5176 | let s:user = substitute(a:dirname,dirpat,'\2','') |
| 5177 | let s:machine = substitute(a:dirname,dirpat,'\3','') |
| 5178 | let s:port = substitute(a:dirname,dirpat,'\4','') |
| 5179 | let s:path = substitute(a:dirname,dirpat,'\5','') |
| 5180 | let s:fname = substitute(a:dirname,'^.*/\ze.','','') |
| 5181 | |
| 5182 | " call Decho("set up s:method <".s:method .">") |
| 5183 | " call Decho("set up s:user <".s:user .">") |
| 5184 | " call Decho("set up s:machine<".s:machine.">") |
| 5185 | " call Decho("set up s:port <".s:port.">") |
| 5186 | " call Decho("set up s:path <".s:path .">") |
| 5187 | " call Decho("set up s:fname <".s:fname .">") |
| 5188 | |
| 5189 | " call Dret("s:RemotePathAnalysis") |
| 5190 | endfun |
| 5191 | |
| 5192 | " --------------------------------------------------------------------- |
| 5193 | " s:RestoreBufVars: {{{2 |
| 5194 | fun! s:RestoreBufVars() |
| 5195 | " call Dfunc("s:RestoreBufVars()") |
| 5196 | |
| 5197 | if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif |
| 5198 | if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif |
| 5199 | if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif |
| 5200 | if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif |
| 5201 | if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif |
| 5202 | if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif |
| 5203 | |
| 5204 | " call Dret("s:RestoreBufVars") |
| 5205 | endfun |
| 5206 | |
| 5207 | " --------------------------------------------------------------------- |
| 5208 | " s:RestoreWinVars: (used by Explore() and NetSplit()) {{{2 |
| 5209 | fun! s:RestoreWinVars() |
| 5210 | " call Dfunc("s:RestoreWinVars()") |
Bram Moolenaar | 488c651 | 2005-08-11 20:09:58 +0000 | [diff] [blame] | 5211 | 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] | 5212 | if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif |
| 5213 | if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif |
| 5214 | if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif |
| 5215 | if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif |
| 5216 | if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif |
| 5217 | if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif |
| 5218 | if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif |
| 5219 | if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif |
| 5220 | if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif |
| 5221 | if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif |
| 5222 | if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif |
| 5223 | 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] | 5224 | if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif |
| 5225 | 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] | 5226 | if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif |
| 5227 | if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif |
| 5228 | if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif |
| 5229 | " call Dret("s:RestoreWinVars") |
Bram Moolenaar | 488c651 | 2005-08-11 20:09:58 +0000 | [diff] [blame] | 5230 | endfun |
| 5231 | |
Bram Moolenaar | 90cfdbe | 2005-08-12 19:59:19 +0000 | [diff] [blame] | 5232 | " --------------------------------------------------------------------- |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 5233 | " s:SaveBufVars: {{{2 |
| 5234 | fun! s:SaveBufVars() |
| 5235 | " call Dfunc("s:SaveBufVars()") |
| 5236 | |
| 5237 | if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif |
| 5238 | if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif |
| 5239 | if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif |
| 5240 | if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif |
| 5241 | if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif |
| 5242 | if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif |
| 5243 | |
| 5244 | " call Dret("s:SaveBufVars") |
| 5245 | endfun |
| 5246 | |
| 5247 | " --------------------------------------------------------------------- |
| 5248 | " s:SaveWinVars: (used by Explore() and NetSplit()) {{{2 |
| 5249 | fun! s:SaveWinVars() |
| 5250 | " call Dfunc("s:SaveWinVars()") |
| 5251 | if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif |
| 5252 | if exists("w:netrw_col") |let s:col = w:netrw_col |endif |
| 5253 | if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif |
| 5254 | if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif |
| 5255 | if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif |
| 5256 | if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif |
| 5257 | if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif |
| 5258 | if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif |
| 5259 | if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif |
| 5260 | if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif |
| 5261 | if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif |
| 5262 | if exists("w:netrw_line") |let s:line = w:netrw_line |endif |
| 5263 | if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif |
| 5264 | if exists("w:netrw_method") |let s:method = w:netrw_method |endif |
| 5265 | if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif |
| 5266 | if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif |
| 5267 | if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif |
| 5268 | if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif |
| 5269 | " call Dret("s:SaveWinVars") |
| 5270 | endfun |
| 5271 | |
| 5272 | " --------------------------------------------------------------------- |
| 5273 | " s:SetBufWinVars: (used by NetBrowse() and LocalBrowseCheck()) {{{2 |
Bram Moolenaar | 90cfdbe | 2005-08-12 19:59:19 +0000 | [diff] [blame] | 5274 | " To allow separate windows to have their own activities, such as |
| 5275 | " Explore **/pattern, several variables have been made window-oriented. |
| 5276 | " 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] | 5277 | " variables are not inherited by the new window. SetBufWinVars() and |
Bram Moolenaar | 90cfdbe | 2005-08-12 19:59:19 +0000 | [diff] [blame] | 5278 | " UseBufWinVars() get around that. |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 5279 | fun! s:SetBufWinVars() |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 5280 | " call Dfunc("s:SetBufWinVars()") |
| 5281 | if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif |
| 5282 | if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif |
| 5283 | if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif |
| 5284 | if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif |
| 5285 | if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif |
| 5286 | if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif |
| 5287 | if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif |
| 5288 | if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif |
| 5289 | if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif |
| 5290 | if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif |
| 5291 | " call Dret("s:SetBufWinVars") |
Bram Moolenaar | 90cfdbe | 2005-08-12 19:59:19 +0000 | [diff] [blame] | 5292 | endfun |
| 5293 | |
| 5294 | " --------------------------------------------------------------------- |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 5295 | " s:System: using Steve Hall's idea to insure that Windows paths stay {{{2 |
| 5296 | " acceptable. No effect on Unix paths. |
| 5297 | " Examples of use: let result= s:System("system",path) |
| 5298 | " let result= s:System("delete",path) |
| 5299 | fun! s:System(cmd,path) |
| 5300 | " call Dfunc("s:System(cmd<".a:cmd."> path<".a:path.">)") |
| 5301 | |
| 5302 | let path = a:path |
| 5303 | if (has("win32") || has("win95") || has("win64") || has("win16")) |
| 5304 | " system call prep |
| 5305 | " remove trailing slash (Win95) |
| 5306 | let path = substitute(path, '\(\\\|/\)$', '', 'g') |
| 5307 | " remove escaped spaces |
| 5308 | let path = substitute(path, '\ ', ' ', 'g') |
| 5309 | " convert slashes to backslashes |
| 5310 | let path = substitute(path, '/', '\', 'g') |
| 5311 | if exists("+shellslash") |
| 5312 | let sskeep= &shellslash |
| 5313 | setlocal noshellslash |
| 5314 | exe "let result= ".a:cmd."('".path."')" |
| 5315 | let &shellslash = sskeep |
| 5316 | else |
| 5317 | exe "let result= ".a:cmd."(".g:netrw_shq.path.g:netrw_shq.")" |
| 5318 | endif |
| 5319 | else |
| 5320 | exe "let result= ".a:cmd."('".path."')" |
| 5321 | endif |
| 5322 | |
| 5323 | " call Decho("result<".result.">") |
| 5324 | " call Dret("s:System") |
| 5325 | return result |
| 5326 | endfun |
| 5327 | |
| 5328 | " --------------------------------------------------------------------- |
| 5329 | " s:UseBufWinVars: (used by NetBrowse() and LocalBrowseCheck() {{{2 |
Bram Moolenaar | 90cfdbe | 2005-08-12 19:59:19 +0000 | [diff] [blame] | 5330 | " Matching function to BufferWinVars() |
| 5331 | fun! s:UseBufWinVars() |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 5332 | " call Dfunc("s:UseBufWinVars()") |
| 5333 | 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] | 5334 | if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif |
| 5335 | if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif |
| 5336 | if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif |
| 5337 | if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif |
| 5338 | if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif |
| 5339 | if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif |
| 5340 | if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif |
| 5341 | if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif |
| 5342 | 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] | 5343 | " call Dret("s:UseBufWinVars") |
Bram Moolenaar | 90cfdbe | 2005-08-12 19:59:19 +0000 | [diff] [blame] | 5344 | endfun |
| 5345 | |
Bram Moolenaar | 1afcace | 2005-11-25 19:54:28 +0000 | [diff] [blame] | 5346 | " --------------------------------------------------------------------- |
Bram Moolenaar | afeb4fa | 2006-02-01 21:51:12 +0000 | [diff] [blame] | 5347 | " Settings Restoration: {{{2 |
Bram Moolenaar | 83bab71 | 2005-08-01 21:58:57 +0000 | [diff] [blame] | 5348 | let &cpo= s:keepcpo |
| 5349 | unlet s:keepcpo |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 5350 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5351 | " ------------------------------------------------------------------------ |
Bram Moolenaar | 83bab71 | 2005-08-01 21:58:57 +0000 | [diff] [blame] | 5352 | " Modelines: {{{1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5353 | " vim:ts=8 fdm=marker |