From 83bab71b3cc435eb5551167d02949dbfc90c1bcd Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Mon, 1 Aug 2005 21:58:57 +0000 Subject: updated for version 7.0122 --- runtime/plugin/netrw.vim | 475 ++++++++++++++++++++++++----------------------- 1 file changed, 245 insertions(+), 230 deletions(-) (limited to 'runtime/plugin') diff --git a/runtime/plugin/netrw.vim b/runtime/plugin/netrw.vim index f1da4b072c..52220120aa 100644 --- a/runtime/plugin/netrw.vim +++ b/runtime/plugin/netrw.vim @@ -1,7 +1,7 @@ " netrw.vim: Handles file transfer and remote directory listing across a network -" last change: Dec 29, 2004 +" Last Change: Aug 01, 2005 " Maintainer: Charles E Campbell, Jr -" Version: 54 +" Version: 56 " License: Vim License (see vim's :help license) " " But be doers of the Word, and not only hearers, deluding your own selves @@ -10,13 +10,13 @@ " GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim " --------------------------------------------------------------------- -" Prevent Reloading: {{{1 +" Load Once: {{{1 if exists("g:loaded_netrw") || &cp finish endif -let g:loaded_netrw = "v54" -let s:save_cpo = &cpo +let g:loaded_netrw = "v56" let loaded_explorer = 1 +let s:keepcpo = &cpo set cpo&vim " --------------------------------------------------------------------- @@ -43,7 +43,7 @@ if !exists("g:netrw_list_cmd") " provide a default listing command let g:netrw_list_cmd= "ssh HOSTNAME ls -FLa" else -" call Decho("ssh is not executable, can't do remote directory exploring") +" call Decho("ssh is not executable, can't do remote directory exploring with ssh") let g:netrw_list_cmd= "" endif endif @@ -100,15 +100,6 @@ endif if !exists("g:netrw_local_rmdir") let g:netrw_local_rmdir= "rmdir" endif -if !exists("g:netrw_local_rename") - if g:netrw_cygwin - let g:netrw_local_rename= "mv" - elseif has("win32") || has("win95") || has("win64") || has("win16") - let g:netrw_local_rename= "rename" - elseif has("unix") - let g:netrw_local_rename= "mv" - endif -endif if !exists("g:netrw_local_mkdir") let g:netrw_local_mkdir= "mkdir" endif @@ -216,30 +207,36 @@ endif if version >= 600 augroup FileExplorer au! - au BufEnter * call LocalBrowse(expand("")) + au BufEnter * call LocalBrowse(expand("")) augroup END " Network Handler: {{{2 augroup Network au! if has("win32") || has("win95") || has("win64") || has("win16") - au BufReadCmd file://* exe "silent doau BufReadPre ".expand("")|exe 'e '.substitute(expand(""),"file:/*","","")|exe "silent doau BufReadPost ".expand("") + au BufReadCmd file://* exe "silent doau BufReadPre ".expand("")|exe 'e '.substitute(expand(""),"file:/*","","")|exe "silent doau BufReadPost ".expand("") else - au BufReadCmd file:///* exe "silent doau BufReadPre ".expand("")|exe 'e /'.substitute(expand(""),"file:/*","","")|exe "silent doau BufReadPost ".expand("") - au BufReadCmd file://localhost/* exe "silent doau BufReadPre ".expand("")|exe 'e /'.substitute(expand(""),"file:/*","","")|exe "silent doau BufReadPost ".expand("") + au BufReadCmd file:///* exe "silent doau BufReadPre ".expand("")|exe 'e /'.substitute(expand(""),"file:/*","","")|exe "silent doau BufReadPost ".expand("") + au BufReadCmd file://localhost/* exe "silent doau BufReadPre ".expand("")|exe 'e /'.substitute(expand(""),"file:/*","","")|exe "silent doau BufReadPost ".expand("") endif - au BufReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe "silent doau BufReadPre ".expand("")|exe "Nread 0r ".expand("")|exe "silent doau BufReadPost ".expand("") - au FileReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe "silent doau BufReadPre ".expand("")|exe "Nread " .expand("")|exe "silent doau FileReadPost ".expand("") - au BufWriteCmd ftp://*,rcp://*,scp://*,dav://*,rsync://*,sftp://* exe "silent doau BufWritePre ".expand("")|exe "Nwrite " .expand("")|exe "silent doau BufWritePost ".expand("") - au FileWriteCmd ftp://*,rcp://*,scp://*,dav://*,rsync://*,sftp://* exe "silent doau BufWritePre ".expand("")|exe "'[,']Nwrite " .expand("")|exe "silent doau FileWritePost ".expand("") + au BufReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe "silent doau BufReadPre ".expand("")|exe "Nread 0r ".expand("")|exe "silent doau BufReadPost ".expand("") + au FileReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe "silent doau BufReadPre ".expand("")|exe "Nread " .expand("")|exe "silent doau FileReadPost ".expand("") + au BufWriteCmd ftp://*,rcp://*,scp://*,dav://*,rsync://*,sftp://* exe "silent doau BufWritePre ".expand("")|exe "Nwrite " .expand("")|exe "silent doau BufWritePost ".expand("") + au FileWriteCmd ftp://*,rcp://*,scp://*,dav://*,rsync://*,sftp://* exe "silent doau BufWritePre ".expand("")|exe "'[,']Nwrite " .expand("")|exe "silent doau FileWritePost ".expand("") augroup END endif " ------------------------------------------------------------------------ -" Commands: :Nread, :Nwrite, and :NetUserPass {{{1 -com! -nargs=* Nread call NetSavePosn()call NetRead()call NetRestorePosn() -com! -range=% -nargs=* Nwrite call NetSavePosn(),call NetWrite()call NetRestorePosn() +" Commands: :Nread, :Nwrite, :NetUserPass {{{1 +com! -nargs=* Nread call s:NetSavePosn()call s:NetRead()call s:NetRestorePosn() +com! -range=% -nargs=* Nwrite call s:NetSavePosn(),call s:NetWrite()call s:NetRestorePosn() com! -nargs=* NetUserPass call NetUserPass() +" Commands: :Explore, :Sexplore, Hexplore, Vexplore {{{1 +com! -nargs=? -bar -bang Explore call s:Explore(0,0+0,) +com! -nargs=? -bar -bang Sexplore call s:Explore(1,0+0,) +com! -nargs=? -bar -bang Hexplore call s:Explore(1,2+0,) +com! -nargs=? -bar -bang Vexplore call s:Explore(1,4+0,) + " ------------------------------------------------------------------------ " NetSavePosn: saves position of cursor on screen {{{1 fun! s:NetSavePosn() @@ -352,7 +349,7 @@ fun! s:NetRead(...) let ichoice = ichoice + 1 if ichoice > a:0 if !exists("g:netrw_quiet") - echoerr "Unbalanced string in filename '". wholechoice ."'" + echoerr "***netrw*** Unbalanced string in filename '". wholechoice ."'" call inputsave()|call input("Press to continue")|call inputrestore() endif " call Dret("NetRead") @@ -436,10 +433,10 @@ fun! s:NetRead(...) exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine endif " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) - if getline(1) !~ "^$" && !exists("g:netrw_quiet") + if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying ' let debugkeep= &debug set debug=msg - echoerr getline(1) + echoerr "***netrw*** ".getline(1) call inputsave()|call input("Press to continue")|call inputrestore() let &debug= debugkeep endif @@ -485,7 +482,7 @@ fun! s:NetRead(...) if getline(1) !~ "^$" " call Decho("error<".getline(1).">") if !exists("g:netrw_quiet") - echoerr getline(1) + echoerr "***netrw*** ".getline(1) call inputsave()|call input("Press to continue")|call inputrestore() endif endif @@ -518,7 +515,7 @@ fun! s:NetRead(...) " call Decho("read via http (method #5)") if g:netrw_http_cmd == "" if !exists("g:netrw_quiet") - echoerr "neither wget nor fetch command is available" + echoerr "***netrw*** neither wget nor fetch command is available" call inputsave()|call input("Press to continue")|call inputrestore() endif exit @@ -596,7 +593,7 @@ fun! s:NetRead(...) elseif b:netrw_method == 8 " read with fetch if g:netrw_fetch_cmd == "" if !exists("g:netrw_quiet") - echoerr "fetch command not available" + echoerr "***netrw*** fetch command not available" call inputsave()|call input("Press to continue")|call inputrestore() endif exit @@ -678,17 +675,23 @@ fun! s:NetGetFile(readcmd, fname, method) if a:readcmd[0] == '0' " get file into buffer + " record remote filename - let rfile= bufname("%") -" call Decho("edit remotefile<".rfile.">") + let rfile= bufname(".") +" call Decho("remotefile<".rfile.">") +" call Dredir("ls!","starting buffer list") + " rename the current buffer to the temp file (ie. fname) - exe "keepalt file ".fname + keepalt exe "file ".fname +" call Dredir("ls!","after renaming current buffer to <".fname.">") + " edit temporary file e +" call Dredir("ls!","after editing temporary file") + " rename buffer back to remote filename - exe "keepalt file ".rfile - " wipe out the buffer with the temp file name - exe "bwipe ".fname + keepalt exe "file ".rfile +" call Dredir("ls!","renaming buffer back to remote filename<".rfile.">") let line1 = 1 let line2 = line("$") @@ -712,6 +715,8 @@ fun! s:NetGetFile(readcmd, fname, method) if exists("*NetReadFixup") " call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")") call NetReadFixup(a:method, line1, line2) +" else " Decho +" call Decho("NetReadFixup() not called, doesn't exist") endif " update the Buffers menu @@ -787,7 +792,7 @@ fun! s:NetWrite(...) range let ichoice = ichoice + 1 if choice > a:0 if !exists("g:netrw_quiet") - echoerr "Unbalanced string in filename '". wholechoice ."'" + echoerr "***netrw*** Unbalanced string in filename '". wholechoice ."'" call inputsave()|call input("Press to continue")|call inputrestore() endif " call Dret("NetWrite") @@ -858,7 +863,7 @@ fun! s:NetWrite(...) range " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) if getline(1) !~ "^$" if !exists("g:netrw_quiet") - echoerr getline(1) + echoerr "***netrw*** ".getline(1) call inputsave()|call input("Press to continue")|call inputrestore() endif let mod=1 @@ -898,7 +903,7 @@ fun! s:NetWrite(...) range " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) if getline(1) !~ "^$" if !exists("g:netrw_quiet") - echoerr getline(1) + echoerr "***netrw*** ".getline(1) call inputsave()|call input("Press to continue")|call inputrestore() endif let mod=1 @@ -927,7 +932,7 @@ fun! s:NetWrite(...) range " http: NetWrite Method #5 elseif b:netrw_method == 5 if !exists("g:netrw_quiet") - echoerr "***warning*** currently does not support writing using http:" + echoerr "***netrw*** currently does not support writing using http:" call inputsave()|call input("Press to continue")|call inputrestore() endif @@ -1010,8 +1015,10 @@ fun! s:NetWrite(...) range " call Dret("NetWrite") endfun -" ------------------------------------------------------------------------ -" Browsing Support For Remote Directories And Files: {{{1 +" =========================================== +" Remote Directory Browsing Support: {{{1 +" =========================================== + " NetBrowse: This function uses the command in g:netrw_list_cmd to get a list {{{2 " of the contents of a remote directory. It is assumed that the " g:netrw_list_cmd has a string, HOSTNAME, that needs to be substituted @@ -1040,7 +1047,7 @@ fun! NetBrowse(dirname) endif " make this buffer modifiable - setlocal ma + setlocal ma nonu nowrap " analyze a:dirname and g:netrw_list_cmd let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$' @@ -1048,7 +1055,7 @@ fun! NetBrowse(dirname) " call Decho("dirpat<".dirpat.">") if dirname !~ dirpat if !exists("g:netrw_quiet") - echoerr "NetBrowse: I don't understand your dirname<".dirname.">" + echoerr "***netrw*** netrw doesn't understand your dirname<".dirname.">" call inputsave()|call input("Press to continue")|call inputrestore() endif " call Dret("NetBrowse : badly formatted dirname<".dirname.">") @@ -1080,7 +1087,7 @@ fun! NetBrowse(dirname) " optionally sort by time (-t) or by size (-S) if listcmd == "dir" && g:netrw_sort_by =~ "^[ts]" - echoerr "***warning*** windows' ftp doesn't support time/size sorts (get cygwin, set g:netrw_cygwin)" + echoerr "***netrw*** windows' ftp doesn't support time/size sorts (get cygwin, set g:netrw_cygwin)" call inputsave()|call input("Press to continue")|call inputrestore() else if g:netrw_sort_by =~ "^t" @@ -1185,7 +1192,7 @@ fun! NetBrowse(dirname) exe 'nnoremap R :exe "norm! 0"call NetBrowseRename("'.user.machine.'","'.path.'")' exe 'vnoremap R :call NetBrowseRename("'.user.machine.'","'.path.'")' nnoremap ? :he netrw-browse-cmds - setlocal ma nonu + setlocal ma nonu nowrap " Set up the banner " call Decho("set up the banner: sortby<".g:netrw_sort_by."> method<".method.">") @@ -1251,9 +1258,9 @@ fun! NetBrowse(dirname) keepjumps norm! 0 " more cleanup - exe 'keepjumps silent '.s:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e' - exe "keepjumps silent ".s:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#' - exe "keepjumps silent ".s:netrw_bannercnt.',$g/ -> /s# -> .*$#/#' + exe 'keepjumps silent! '.s:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e' + exe "keepjumps silent! ".s:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e' + exe "keepjumps silent! ".s:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e' endif else @@ -1307,7 +1314,11 @@ fun! NetBrowse(dirname) if line("$") >= s:netrw_bannercnt if g:netrw_sort_by =~ "^n" call s:SetSort() - exe 'keepjumps silent '.s:netrw_bannercnt.',$call s:NetSort()' + if v:version < 700 + exe 'keepjumps silent '.s:netrw_bannercnt.',$call s:NetSort()' + else + exe 'keepjumps silent '.s:netrw_bannercnt.',$sort' + endif exe 'keepjumps silent '.s:netrw_bannercnt.',$s/^\d\{3}\///e' endif if g:netrw_longlist @@ -1459,7 +1470,7 @@ fun! NetBrowseRm(usrhost,path) range " call Decho("returned=".ret." errcode=".v:shell_error) if v:shell_error != 0 && !exists("g:netrw_quiet") - echoerr "unable to remove directory<".rmfile."> -- is it empty?" + echoerr "***netrw*** unable to remove directory<".rmfile."> -- is it empty?" call inputsave()|call input("Press to continue")|call inputrestore() endif endif @@ -1669,14 +1680,14 @@ fun! NetBrowseFtpCmd(path,cmd) " cleanup for Windows if has("win32") || has("win95") || has("win64") || has("win16") - keepjumps silent! %s/\r$// + keepjumps silent!! %s/\r$//e endif if a:cmd == "dir" " infer directory/link based on the file permission string - keepjumps silent g/d\%([-r][-w][-x]\)\{3}/s@$@/@ - keepjumps silent g/l\%([-r][-w][-x]\)\{3}/s/$/@/ + keepjumps silent! g/d\%([-r][-w][-x]\)\{3}/s@$@/@ + keepjumps silent! g/l\%([-r][-w][-x]\)\{3}/s/$/@/ if !g:netrw_longlist - exe "keepjumps silent ".curline.',$s/^\%(\S\+\s\+\)\{8}//' + exe "keepjumps silent! ".curline.',$s/^\%(\S\+\s\+\)\{8}//e' endif endif @@ -1782,7 +1793,7 @@ fun! NetLongList(mode) endfun " --------------------------------------------------------------------- -" NetSaveWordPosn: used by the "s" command in both remote and local +" NetSaveWordPosn: used by the "s" command in both remote and local {{{2 " browsing. Along with NetRestoreWordPosn(), it keeps the cursor on " the same word even though the sorting has changed its order of appearance. fun! s:NetSaveWordPosn() @@ -1792,7 +1803,7 @@ fun! s:NetSaveWordPosn() endfun " --------------------------------------------------------------------- -" NetRestoreWordPosn: used by the "s" command; see NetSaveWordPosn() above +" NetRestoreWordPosn: used by the "s" command; see NetSaveWordPosn() above {{{2 fun! s:NetRestoreWordPosn() " call Dfunc("NetRestoreWordPosn()") silent! call search(s:netrw_saveword,'w') @@ -1800,7 +1811,7 @@ fun! s:NetRestoreWordPosn() endfun " --------------------------------------------------------------------- -" NetMakeDir: this function makes a directory (both local and remote) +" NetMakeDir: this function makes a directory (both local and remote) {{{2 fun! NetMakeDir(usrhost) " call Dfunc("NetMakeDir(usrhost<".a:usrhost.">)") @@ -1825,7 +1836,7 @@ fun! NetMakeDir(usrhost) " call Decho("fullnewdir<".fullnewdir.">") if isdirectory(fullnewdir) if !exists("g:netrw_quiet") - echoerr "***warning*** <".newdirname."> is already a directory!" + echoerr "***netrw*** <".newdirname."> is already a directory!" call inputsave()|call input("Press to continue")|call inputrestore() endif " call Dret("NetMakeDir : directory<".newdirname."> exists previously") @@ -1833,14 +1844,25 @@ fun! NetMakeDir(usrhost) endif if filereadable(fullnewdir) if !exists("g:netrw_quiet") - echoerr "***warning*** <".newdirname."> is already a file!" + echoerr "***netrw*** <".newdirname."> is already a file!" call inputsave()|call input("Press to continue")|call inputrestore() endif " call Dret("NetMakeDir : file<".newdirname."> exists previously") return endif -" call Decho("exe silent! !".g:netrw_local_mkdir.' "'.fullnewdir.'"') - exe "silent! !".g:netrw_local_mkdir.' "'.fullnewdir.'"' + + " requested new local directory is neither a pre-existing file or + " directory, so make it! + if exists("*mkdir") + call mkdir(fullnewdir,"p") + else + let netrw_origdir= s:NetGetcwd(1) + exe 'cd '.b:netrw_curdir +" call Decho("netrw_origdir<".netrw_origdir."> b:netrw_curdir<".b:netrw_curdir.">") +" call Decho("exe silent! !".g:netrw_local_mkdir.' "'.newdirname.'"') + exe "silent! !".g:netrw_local_mkdir.' "'.newdirname.'"' + if g:netrw_keepdir | exe 'keepjumps cd '.netrw_origdir | endif + endif if v:shell_error == 0 " refresh listing @@ -1852,7 +1874,7 @@ fun! NetMakeDir(usrhost) exe "norm! ".hline."G0z\" exe linenum elseif !exists("g:netrw_quiet") - echoerr "***warning*** unable to make directory<".newdirname.">" + echoerr "***netrw*** unable to make directory<".newdirname.">" call inputsave()|call input("Press to continue")|call inputrestore() endif redraw! @@ -1872,7 +1894,7 @@ fun! NetMakeDir(usrhost) exe "norm! ".hline."G0z\" exe linenum elseif !exists("g:netrw_quiet") - echoerr "***warning*** unable to make directory<".newdirname.">" + echoerr "***netrw*** unable to make directory<".newdirname.">" call inputsave()|call input("Press to continue")|call inputrestore() endif redraw! @@ -1882,7 +1904,7 @@ fun! NetMakeDir(usrhost) endfun " --------------------------------------------------------------------- -" NetBookmarkDir: +" NetBookmarkDir: {{{2 " 0: bookmark the current directory " 1: change to the bookmarked directory fun! NetBookmarkDir(chg,curdir) @@ -1974,8 +1996,9 @@ fun! NetBookmarkDir(chg,curdir) " call Dret("NetBookmarkDir") endfun -" --------------------------------------------------------------------- -" Browsing Support For Local Directories And Files: {{{1 +" ========================================== +" Local Directory Browsing Support: {{{1 +" ========================================== " --------------------------------------------------------------------- " LocalBrowse: supports local file/directory browsing {{{2 @@ -1995,107 +2018,43 @@ fun! LocalBrowse(dirname) if v:version < 603 if !exists("g:netrw_quiet") - echoerr "vim version<".v:version."> too old for browsing with netrw" + echoerr "***netrw*** vim version<".v:version."> too old for browsing with netrw" call inputsave()|call input("Press to continue")|call inputrestore() endif " call Dret("LocalBrowse : vim version<".v:version."> too old") return endif + " record autochdir setting and then insure its unset (tnx to David Fishburn) + let keep_autochdir= &autochdir + set noautochdir + " record and change current directory - let netrw_origdir= s:NetGetcwd(1) - try - cd - - let netrw_altdir= s:NetGetcwd(1) - cd - - catch - let netrw_altdir= '' - endtry - exe 'cd '.escape(substitute(a:dirname,'\\','/','ge'),s:netrw_cd_escape) -" call Decho("dirname<".a:dirname."> buf#".bufnr("%")." winnr=".winnr()) + let b:netrw_curdir= substitute(a:dirname,'\\','/','ge') + if b:netrw_curdir =~ '[/\\]$' + let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e') + endif +" call Decho("b:netrw_curdir<".b:netrw_curdir.">") + " make netrw's idea of the current directory vim's if the user wishes + if g:netrw_keepdir +" call Decho("change directory: cd ".b:netrw_curdir) + exe 'cd '.b:netrw_curdir + endif + + " change the name of the buffer to reflect the b:netrw_curdir + exe 'silent file '.escape(b:netrw_curdir,s:netrw_cd_escape) " make this buffer modifiable setlocal ma - " disable 'autochdir', it breaks things - set noautochdir - " --------------------------- " Perform Directory Listing: -" call Decho("Perform directory listing...") - " set up new buffer and map - " dirname : current working directory, no escapes, has trailing / - " dirnamens : dirname, but with no trailing slash - " dirnamenr : buffer number containing dirnamens - " dirnamebuf: buffer's idea of dirname, with all \ -> / - let dirname = s:NetGetcwd(0) - let dirnamens = substitute(dirname,'[\/]$','','e') - let dirnamenr = bufnr(dirnamens.'$') - let dirnamebuf = substitute(bufname(dirnamenr),'\\','/','ge') -" call Decho("dirnamenr= bufnr(".dirnamens.")=".dirnamenr." bufname(".dirnamenr.")=".bufname(dirnamenr)) - - if dirnamenr != 0 && dirnamebuf != dirnamens - " try keeping the trailing slash - let dirnamenr = bufnr(dirname.'$') -" call Decho("dirnamenr= bufnr(".dirname.")=".dirnamenr." bufname(".dirnamenr.")=".bufname(dirnamenr)." (retry with /)") - endif - - if dirnamenr != -1 - " buffer already exists (hidden), so switch to it! -" call Decho("buffer already exists: dirnamenr=".dirnamenr." dirname<".dirname."> pre-exists") -" call Dredir("ls!") - exe "b ".dirnamenr - exe 'silent! cd '.escape(dirname,s:netrw_cd_escape) -" call Decho("changed directory to<".dirname.">") - if a:dirname != "." && line("$") >= 5 && exists("b:netrw_curdir") - if b:netrw_curdir == dirname -" call Dret("LocalBrowse : buffer already exists with info, #".dirnamenr) - if g:netrw_keepdir - if netrw_altdir != '' - exe 'keepjumps cd '.netrw_altdir - endif - exe 'keepjumps cd '.netrw_origdir - endif - return - endif - endif -" call Decho("buffer already exists, but needs re-listing (buf#".dirnamenr.")") -" call Decho("buffer name<".bufname("%")."> dirname<".dirname.">") - setlocal ma - keepjumps %d - let curdir= substitute(substitute(expand("%"),'\\','/','ge'),'[^/]$','&/','e') - if curdir != dirname - " set standard browser options on buffer - setlocal bt=nofile bh=hide nobl noswf - exe 'silent file '.escape(dirname,s:netrw_cd_escape) -" call Decho("errmsg1<".v:errmsg.">") -" call Decho("renamed buffer to<".escape(dirname,s:netrw_cd_escape).">") -" call Decho("yielding actual bufname<".bufname("%").">") - endif - else -" call Decho("generate new buffer named<".escape(dirname,' #').">") - silent! enew! - " set standard browser options on buffer - setlocal bt=nofile bh=hide nobl noswf nonu - exe 'silent file '.substitute(escape(dirname,s:netrw_cd_escape),'[\/]$','','e') -" call Decho("errmsg2<".v:errmsg.">") -" call Decho("renamed buffer to<".substitute(escape(dirname,s:netrw_cd_escape),'[\/]$','','e').">") -" call Decho("yielding actual bufname<".bufname("%").">") - endif - exe "setlocal ts=".g:netrw_maxfilenamelen - - if bufname("#") == "" && bufnr("#") != -1 - " the file command produces a lot of [No File] buffers -" call Decho("wiping out nofile buffer#".bufnr("#")) - exe bufnr("#")."bwipe" - endif " save current directory on directory history list - call NetBookmarkDir(3,s:NetGetcwd(0)) + call NetBookmarkDir(3,b:netrw_curdir) " set up all the maps " call Decho("Setting up local browser maps") - let b:netrw_curdir= s:NetGetcwd(1) nnoremap :exe "norm! 0"call LocalBrowse(LocalBrowseChgDir(b:netrw_curdir,NetGetWord())) nnoremap :exe "norm! 0"call LocalBrowse(LocalBrowseChgDir(b:netrw_curdir,'./')) nnoremap - :exe "norm! 0"call LocalBrowse(LocalBrowseChgDir(b:netrw_curdir,'../')) @@ -2131,7 +2090,7 @@ fun! LocalBrowse(dirname) keepjumps put ='\" ============================================================================' keepjumps 1d keepjumps put ='\" Directory Listing (netrw '.g:loaded_netrw.')' - keepjumps put ='\" '.dirname + keepjumps put ='\" '.b:netrw_curdir let s:netrw_bannercnt= 3 let sortby= g:netrw_sort_by @@ -2171,7 +2130,7 @@ fun! LocalBrowse(dirname) " call Decho("bannercnt=".s:netrw_bannercnt) " generate the requested directory listing - call LocalBrowseList(dirname) + call LocalBrowseList() " manipulate the directory listing (hide, sort) setlocal ft=netrwlist @@ -2182,10 +2141,18 @@ fun! LocalBrowse(dirname) if line("$") >= s:netrw_bannercnt if g:netrw_sort_by =~ "^n" call s:SetSort() - exe 'keepjumps silent '.s:netrw_bannercnt.',$call s:NetSort()' + if v:version < 700 + exe 'keepjumps silent '.s:netrw_bannercnt.',$call s:NetSort()' + else + exe 'keepjumps silent '.s:netrw_bannercnt.',$sort' + endif exe 'keepjumps silent '.s:netrw_bannercnt.',$s/^\d\{3}\///e' else - exe 'keepjumps silent '.s:netrw_bannercnt.',$call s:NetSort()' + if v:version < 700 + exe 'keepjumps silent '.s:netrw_bannercnt.',$call s:NetSort()' + else + exe 'keepjumps silent '.s:netrw_bannercnt.',$sort' + endif exe 'keepjumps silent '.s:netrw_bannercnt.',$s/^\d\{-}\///e' endif endif @@ -2193,30 +2160,25 @@ fun! LocalBrowse(dirname) exe s:netrw_bannercnt setlocal noma nomod nonu - if g:netrw_keepdir - if netrw_altdir != '' - exe 'keepjumps cd '.netrw_altdir - endif - exe 'keepjumps cd '.netrw_origdir - endif + let &autochdir= keep_autochdir " call Dret("LocalBrowse : file<".expand("%:p")."> bufname<".bufname("%").">") endfun " --------------------------------------------------------------------- " LocalBrowseList: does the job of "ls" for local directories {{{2 -fun! LocalBrowseList(dirname) -" call Dfunc("LocalBrowseList(dirname<".a:dirname.">)") +fun! LocalBrowseList() +" call Dfunc("LocalBrowseList() b:netrw_curdir<".b:netrw_curdir.">") " get the list of files contained in the current directory - let dirname = escape(a:dirname,s:netrw_glob_escape) - let dirnamelen = strlen(a:dirname) - let filelist = glob(dirname."*") + let dirname = escape(b:netrw_curdir,s:netrw_glob_escape) + let dirnamelen = strlen(b:netrw_curdir) + let filelist = glob(dirname."/*") " call Decho("glob(dirname<".dirname.">,*)=".filelist) if filelist != "" let filelist= filelist."\n" endif - let filelist= filelist.glob(dirname.".*") + let filelist= filelist.glob(dirname."/.*") " call Decho("glob(dirname<".dirname.">,.*)=".glob(dirname.".*")) " if the directory name includes a "$", and possibly other characters, @@ -2226,13 +2188,13 @@ fun! LocalBrowseList(dirname) if filelist == "" let filelist= dirname."." else - let filelist= filelist."\n".a:dirname."." + let filelist= filelist."\n".b:netrw_curdir."." endif " call Decho("filelist<".filelist.">") endif if filelist !~ '[\\/]\.\.[\\/]\=\(\n\|$\)' " call Decho("forcibly tacking on ..") - let filelist= filelist."\n".a:dirname.".." + let filelist= filelist."\n".b:netrw_curdir.".." " call Decho("filelist<".filelist.">") endif let filelist= substitute(filelist,'\n\{2,}','\n','ge') @@ -2243,41 +2205,47 @@ fun! LocalBrowseList(dirname) while filelist != "" if filelist =~ '\n' - let file = substitute(filelist,'\n.*$','','e') + let filename = substitute(filelist,'\n.*$','','e') let filelist = substitute(filelist,'^.\{-}\n\(.*\)$','\1','e') else - let file = filelist + let filename = filelist let filelist = "" endif - let pfile= file - if isdirectory(file) - let pfile= file."/" + let pfile= filename + if isdirectory(filename) + let pfile= filename."/" endif + let pfile= substitute(pfile,'^/','','e') if pfile =~ '//$' let pfile= substitute(pfile,'//$','/','e') endif let pfile= strpart(pfile,dirnamelen) +" call Decho(" ") +" call Decho("filename<".filename.">") +" call Decho("pfile <".pfile.">") + if g:netrw_longlist - let sz = getfsize(file) + let sz = getfsize(filename) let fsz = strpart(" ",1,15-strlen(sz)).sz - let pfile= pfile."\t".fsz." ".strftime(g:netrw_timefmt,getftime(file)) + let pfile= pfile."\t".fsz." ".strftime(g:netrw_timefmt,getftime(filename)) +" call Decho("sz=".sz." fsz=".fsz) endif if g:netrw_sort_by =~ "^t" " sort by time (handles time up to 1 quintillion seconds, US) -" call Decho("getftime(".file.")=".getftime(file)) - let t = getftime(file) +" call Decho("getftime(".filename.")=".getftime(filename)) + let t = getftime(filename) let ft = strpart("000000000000000000",1,18-strlen(t)).t -" call Decho("exe keepjumps put ='".ft.'/'.file."'") +" call Decho("exe keepjumps put ='".ft.'/'.filename."'") let ftpfile= ft.'/'.pfile keepjumps put=ftpfile elseif g:netrw_sort_by =~ "^s" " sort by size (handles file sizes up to 1 quintillion bytes, US) -" call Decho("getfsize(".file.")=".getfsize(file)) - let sz = getfsize(file) +" call Decho("getfsize(".filename.")=".getfsize(filename)) + let sz = getfsize(filename) let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz -" call Decho("exe keepjumps put ='".fsz.'/'.file."'") +" call Decho("exe keepjumps put ='".fsz.'/'.filename."'") let fszpfile= fsz.'/'.pfile keepjumps put =fszpfile @@ -2287,6 +2255,7 @@ fun! LocalBrowseList(dirname) keepjumps put=pfile endif endwhile + setlocal ts=32 " call Dret("LocalBrowseList") endfun @@ -2305,6 +2274,8 @@ fun! LocalBrowseChgDir(dirname,newdir,...) " is removing the "/". Bad idea, so I have to put it back. let dirname= dirname.'/' " call Decho("adjusting dirname<".dirname.">") + setlocal ma + %d endif if newdir !~ '[\/]$' @@ -2313,24 +2284,28 @@ fun! LocalBrowseChgDir(dirname,newdir,...) " call Decho("handling a file: dirname<".dirname.">") " this lets NetBrowseX avoid the edit if a:0 < 1 - exe "e ".escape(dirname,s:netrw_cd_escape) +" call Decho("dirname<".dirname."> netrw_cd_escape<".s:netrw_cd_escape.">") +" call Decho("about to edit<".escape(dirname,s:netrw_cd_escape).">") + exe "e! ".escape(dirname,s:netrw_cd_escape) endif elseif newdir == './' " refresh the directory list " call Decho("refresh directory listing") - setlocal ma - %d elseif newdir == '../' " go up one directory let dirname= substitute(dirname,'^\(.*/\)\([^/]\+[\/]$\)','\1','e') " call Decho("go up one dir: dirname<".dirname.">") + setlocal ma + %d else " go down one directory let dirname= dirname.newdir " call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">") + setlocal ma + %d endif " call Dret("LocalBrowseChgDir <".dirname.">") @@ -2364,7 +2339,7 @@ fun! LocalBrowseRm(path) range endif norm! 0 - let rmfile= a:path.curword + let rmfile= a:path."/".curword " call Decho("rmfile<".rmfile.">") if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$') @@ -2417,11 +2392,11 @@ fun! LocalBrowseRm(path) range " call Decho("3rd attempt to remove directory<".rmfile.">") call system("rm ".rmfile) if v:shell_error != 0 && !exists("g:netrw_quiet") - echoerr "unable to remove directory<".rmfile."> -- is it empty?" + echoerr "***netrw*** unable to remove directory<".rmfile."> -- is it empty?" call inputsave()|call input("Press to continue")|call inputrestore() endif elseif !exists("g:netrw_quiet") - echoerr "unable to remove directory<".rmfile."> -- is it empty?" + echoerr "***netrw*** unable to remove directory<".rmfile."> -- is it empty?" call inputsave()|call input("Press to continue")|call inputrestore() endif endif @@ -2475,8 +2450,8 @@ fun! LocalBrowseRename(path) range let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e')) call inputrestore() - let ret= system(g:netrw_local_rename.' "'.oldname.'" "'.newname.'"') -" call Decho("executing system(".g:netrw_local_rename." ".oldname." ".newname) + let ret= rename(oldname,newname) +" call Decho("renaming <".oldname."> to <".newname.">") let ctr= ctr + 1 endwhile @@ -2497,16 +2472,54 @@ fun! LocalPreview(path) range if !isdirectory(a:path) exe "pedit ".a:path elseif !exists("g:netrw_quiet") - echoerr "sorry, cannot preview a directory such as <".a:path.">" + echoerr "***netrw*** sorry, cannot preview a directory such as <".a:path.">" call inputsave()|call input("Press to continue")|call inputrestore() endif elseif !exists("g:netrw_quiet") - echoerr "sorry, to preview your vim needs the quickfix feature compiled in" + echoerr "***netrw*** sorry, to preview your vim needs the quickfix feature compiled in" call inputsave()|call input("Press to continue")|call inputrestore() endif " call Dret("LocalPreview") endfun +" --------------------------------------------------------------------- +" Explore: launch the local browser in the directory of the current file {{{2 +" dosplit==0: the window will be split iff the current file has +" been modified +" dosplit==1: the window will be split before running the local +" browser +fun! s:Explore(dosplit,style,...) +" call Dfunc("Explore(dosplit=".a:dosplit." style=".a:style.")") + + " if dosplit or file has been modified + if a:dosplit || &modified + if a:style == 0 " Explore, Sexplore + exe g:netrw_winsize."wincmd s" + elseif a:style == 1 "Explore!, Sexplore! + exe g:netrw_winsize."wincmd v" + elseif a:style == 2 " Hexplore + exe "bel ".g:netrw_winsize."wincmd s" + elseif a:style == 3 " Hexplore! + exe "abo ".g:netrw_winsize."wincmd s" + elseif a:style == 4 " Vexplore + exe "lefta ".g:netrw_winsize."wincmd v" + elseif a:style == 5 " Vexplore! + exe "rightb ".g:netrw_winsize."wincmd v" + endif + endif + norm! 0 + + if a:1 == "" + let newdir= substitute(expand("%:p"),'^\(.*\)[/\\][^/\\]*$','\1','e') + else + let newdir= a:1 + endif +" call Decho("newdir<".newdir.">") + call s:LocalBrowse(newdir) + +" call Dret("Explore") +endfun + " --------------------------------------------------------------------- " NetGetcwd: get the current directory. {{{2 " Change backslashes to forward slashes, if any. @@ -2559,7 +2572,7 @@ fun! s:NetMethod(choice) " globals: method machine id passwd fname let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$' let mf = '^\(\S\+\)\s\+\(\S\+\)$' let ftpurm = '^ftp://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$' - let rcpurm = '^rcp://\(\([^/@]\{-}\)@\)\=\([^/]\{-}\)/\(.*\)$' + let rcpurm = '^rcp://\%(\([^/@]\{-}\)@\)\=\([^/]\{-}\)/\(.*\)$' let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$' let scpurm = '^scp://\([^/]\{-}\)\([#:]\d\+\)\=/\(.*\)$' let httpurm = '^http://\([^/]\{-}\)\(/.*\)\=$' @@ -2573,10 +2586,10 @@ fun! s:NetMethod(choice) " globals: method machine id passwd fname " rcp://user@hostname/...path-to-file if match(a:choice,rcpurm) == 0 " call Decho("rcp://...") - let b:netrw_method = 1 - let userid = substitute(a:choice,rcpurm,'\2',"") - let g:netrw_machine= substitute(a:choice,rcpurm,'\3',"") - let b:netrw_fname = substitute(a:choice,rcpurm,'\4',"") + let b:netrw_method = 1 + let userid = substitute(a:choice,rcpurm,'\1',"") + let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"") + let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"") if userid != "" let g:netrw_uid= userid endif @@ -2585,9 +2598,9 @@ fun! s:NetMethod(choice) " globals: method machine id passwd fname elseif match(a:choice,scpurm) == 0 " call Decho("scp://...") let b:netrw_method = 4 - let g:netrw_machine= substitute(a:choice,scpurm,'\1',"") - let g:netrw_port = substitute(a:choice,scpurm,'\2',"") - let b:netrw_fname = substitute(a:choice,scpurm,'\3',"") + let g:netrw_machine = substitute(a:choice,scpurm,'\1',"") + let g:netrw_port = substitute(a:choice,scpurm,'\2',"") + let b:netrw_fname = substitute(a:choice,scpurm,'\3',"") " http://user@hostname/...path-to-file elseif match(a:choice,httpurm) == 0 @@ -2699,7 +2712,7 @@ fun! s:NetMethod(choice) " globals: method machine id passwd fname else if !exists("g:netrw_quiet") - echoerr "***error*** cannot determine method" + echoerr "***netrw*** cannot determine method" call inputsave()|call input("Press to continue")|call inputrestore() endif let b:netrw_method = -1 @@ -2840,9 +2853,10 @@ endif " --------------------------------------------------------------------- " NetSort: Piet Delport's BISort2() function, modified to take a range {{{1 -fun! NetSort() range -" call Dfunc("NetSort()") - +if v:version < 700 + fun! NetSort() range +" " call Dfunc("NetSort()") + let i = a:firstline + 1 while i <= a:lastline " find insertion point via binary search @@ -2850,36 +2864,37 @@ fun! NetSort() range let lo = a:firstline let hi = i while lo < hi - let mid = (lo + hi) / 2 - let mid_val = getline(mid) - if g:netrw_sort_direction =~ '^n' - " normal sorting order - if i_val < mid_val - let hi = mid - else - let lo = mid + 1 - if i_val == mid_val | break | endif - endif + let mid = (lo + hi) / 2 + let mid_val = getline(mid) + if g:netrw_sort_direction =~ '^n' + " normal sorting order + if i_val < mid_val + let hi = mid else - " reverse sorting order - if i_val > mid_val - let hi = mid - else - let lo = mid + 1 - if i_val == mid_val | break | endif - endif + let lo = mid + 1 + if i_val == mid_val | break | endif endif + else + " reverse sorting order + if i_val > mid_val + let hi = mid + else + let lo = mid + 1 + if i_val == mid_val | break | endif + endif + endif endwhile " do insert if lo < i - exe 'keepjumps '.i.'d_' - keepjumps call append(lo - 1, i_val) + exe 'keepjumps '.i.'d_' + keepjumps call append(lo - 1, i_val) endif let i = i + 1 endwhile - -" call Dret("NetSort") -endfun + +" " call Dret("NetSort") + endfun +endif " --------------------------------------------------------------------- " SetSort: sets up the sort based on the g:netrw_sort_sequence {{{1 @@ -2938,8 +2953,8 @@ fun! SetSort() " call Dret("SetSort") endfun +let &cpo= s:keepcpo +unlet s:keepcpo " ------------------------------------------------------------------------ -" Restore {{{1 -let &cpo= s:save_cpo -unlet s:save_cpo +" Modelines: {{{1 " vim:ts=8 fdm=marker -- cgit v1.2.3