From 0bf9a574b5e3d738f323c497d7360f84e9c940c0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 7 Aug 2024 07:05:58 +0800 Subject: vim-patch:a63f66e: runtime(zip): clean up and remove comments Problem: zip plugin contains a lot of comments from the decho plugin Solution: Clean up and remove un-used comments https://github.com/vim/vim/commit/a63f66e953d811bb6d044e92fe338e533ad94ff5 Co-authored-by: Christian Brabandt --- runtime/autoload/zip.vim | 46 +--------------------------------------------- 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/runtime/autoload/zip.vim b/runtime/autoload/zip.vim index 8876ef08e6..de88b55907 100644 --- a/runtime/autoload/zip.vim +++ b/runtime/autoload/zip.vim @@ -11,6 +11,7 @@ " 2024 Jul 30 by Vim Project: fix opening remote zipfile " 2024 Aug 04 by Vim Project: escape '[' in name of file to be extracted " 2024 Aug 05 by Vim Project: workaround for the FreeBSD's unzip +" 2024 Aug 05 by Vim Project: clean-up and make it work with shellslash on Windows " License: Vim License (see vim's :help license) " Copyright: Copyright (C) 2005-2019 Charles E. Campbell {{{1 " Permission is hereby granted to use and distribute this code, @@ -36,7 +37,6 @@ if v:version < 702 endif let s:keepcpo= &cpo set cpo&vim -"DechoTabOn let s:zipfile_escape = ' ?&;\' let s:ERROR = 2 @@ -136,14 +136,12 @@ fun! zip#Browse(zipfile) if v:shell_error != 0 redraw! echohl WarningMsg | echo "***warning*** (zip#Browse) ".fnameescape(a:zipfile)." is not a zip file" | echohl None -" call inputsave()|call input("Press to continue")|call inputrestore() keepj sil! %d let eikeep= &ei set ei=BufReadCmd,FileReadCmd exe "keepj r ".fnameescape(a:zipfile) let &ei= eikeep keepj 1d -" call Dret("zip#Browse") return endif @@ -156,55 +154,43 @@ fun! zip#Browse(zipfile) endif let &report= repkeep -" call Dret("zip#Browse") endfun " --------------------------------------------------------------------- " ZipBrowseSelect: {{{2 fun! s:ZipBrowseSelect() - " call Dfunc("ZipBrowseSelect() zipfile<".((exists("b:zipfile"))? b:zipfile : "n/a")."> curfile<".expand("%").">") let repkeep= &report set report=10 let fname= getline(".") if !exists("b:zipfile") -" call Dret("ZipBrowseSelect : b:zipfile doesn't exist!") return endif " sanity check if fname =~ '^"' let &report= repkeep -" call Dret("ZipBrowseSelect") return endif if fname =~ '/$' redraw! echohl Error | echo "***error*** (zip#Browse) Please specify a file, not a directory" | echohl None -" call inputsave()|call input("Press to continue")|call inputrestore() let &report= repkeep -" call Dret("ZipBrowseSelect") return endif -" call Decho("fname<".fname.">") - " get zipfile to the new-window let zipfile = b:zipfile let curfile = expand("%") -" call Decho("zipfile<".zipfile.">") -" call Decho("curfile<".curfile.">") noswapfile new if !exists("g:zip_nomax") || g:zip_nomax == 0 wincmd _ endif let s:zipfile_{winnr()}= curfile -" call Decho("exe e ".fnameescape("zipfile://".zipfile.'::'.fname)) exe "noswapfile e ".fnameescape("zipfile://".zipfile.'::'.fname) filetype detect let &report= repkeep -" call Dret("ZipBrowseSelect : s:zipfile_".winnr()."<".s:zipfile_{winnr()}.">") endfun " --------------------------------------------------------------------- @@ -225,7 +211,6 @@ fun! zip#Read(fname,mode) if !executable(substitute(g:zip_unzipcmd,'\s\+.*$','','')) redraw! echohl Error | echo "***error*** (zip#Read) sorry, your system doesn't appear to have the ".g:zip_unzipcmd." program" | echohl None -" call inputsave()|call input("Press to continue")|call inputrestore() let &report= repkeep return endif @@ -252,7 +237,6 @@ endfun " --------------------------------------------------------------------- " zip#Write: {{{2 fun! zip#Write(fname) -" call Dfunc("zip#Write(fname<".a:fname.">) zipfile_".winnr()."<".s:zipfile_{winnr()}.">") let repkeep= &report set report=10 @@ -260,36 +244,28 @@ fun! zip#Write(fname) if !executable(substitute(g:zip_zipcmd,'\s\+.*$','','')) redraw! echohl Error | echo "***error*** (zip#Write) sorry, your system doesn't appear to have the ".g:zip_zipcmd." program" | echohl None -" call inputsave()|call input("Press to continue")|call inputrestore() let &report= repkeep -" call Dret("zip#Write") return endif if !exists("*mkdir") redraw! echohl Error | echo "***error*** (zip#Write) sorry, mkdir() doesn't work on your system" | echohl None -" call inputsave()|call input("Press to continue")|call inputrestore() let &report= repkeep -" call Dret("zip#Write") return endif let curdir= getcwd() let tmpdir= tempname() -" call Decho("orig tempname<".tmpdir.">") if tmpdir =~ '\.' let tmpdir= substitute(tmpdir,'\.[^.]*$','','e') endif -" call Decho("tmpdir<".tmpdir.">") call mkdir(tmpdir,"p") " attempt to change to the indicated directory if s:ChgDir(tmpdir,s:ERROR,"(zip#Write) cannot cd to temporary directory") let &report= repkeep -" call Dret("zip#Write") return endif -" call Decho("current directory now: ".getcwd()) " place temporary files under .../_ZIPVIM_/ if isdirectory("_ZIPVIM_") @@ -297,7 +273,6 @@ fun! zip#Write(fname) endif call mkdir("_ZIPVIM_") cd _ZIPVIM_ -" call Decho("current directory now: ".getcwd()) if has("unix") let zipfile = substitute(a:fname,'zipfile://\(.\{-}\)::[^\\].*$','\1','') @@ -306,21 +281,17 @@ fun! zip#Write(fname) let zipfile = substitute(a:fname,'^.\{-}zipfile://\(.\{-}\)::[^\\].*$','\1','') let fname = substitute(a:fname,'^.\{-}zipfile://.\{-}::\([^\\].*\)$','\1','') endif -" call Decho("zipfile<".zipfile.">") -" call Decho("fname <".fname.">") if fname =~ '/' let dirpath = substitute(fname,'/[^/]\+$','','e') if has("win32unix") && executable("cygpath") let dirpath = substitute(system("cygpath ".s:Escape(dirpath,0)),'\n','','e') endif -" call Decho("mkdir(dirpath<".dirpath.">,p)") call mkdir(dirpath,"p") endif if zipfile !~ '/' let zipfile= curdir.'/'.zipfile endif -" call Decho("zipfile<".zipfile."> fname<".fname.">") exe "w! ".fnameescape(fname) if has("win32unix") && executable("cygpath") @@ -331,17 +302,14 @@ fun! zip#Write(fname) let fname = substitute(fname, '[', '[[]', 'g') endif -" call Decho(g:zip_zipcmd." -u ".s:Escape(fnamemodify(zipfile,":p"),0)." ".s:Escape(fname,0)) call system(g:zip_zipcmd." -u ".s:Escape(fnamemodify(zipfile,":p"),0)." ".s:Escape(fname,0)) if v:shell_error != 0 redraw! echohl Error | echo "***error*** (zip#Write) sorry, unable to update ".zipfile." with ".fname | echohl None -" call inputsave()|call input("Press to continue")|call inputrestore() elseif s:zipfile_{winnr()} =~ '^\a\+://' " support writing zipfiles across a network let netzipfile= s:zipfile_{winnr()} -" call Decho("handle writing <".zipfile."> across network as <".netzipfile.">") 1split|enew let binkeep= &binary let eikeep = &ei @@ -362,36 +330,30 @@ fun! zip#Write(fname) setlocal nomod let &report= repkeep -" call Dret("zip#Write") endfun " --------------------------------------------------------------------- " zip#Extract: extract a file from a zip archive {{{2 fun! zip#Extract() -" call Dfunc("zip#Extract()") let repkeep= &report set report=10 let fname= getline(".") -" call Decho("fname<".fname.">") " sanity check if fname =~ '^"' let &report= repkeep -" call Dret("zip#Extract") return endif if fname =~ '/$' redraw! echohl Error | echo "***error*** (zip#Extract) Please specify a file, not a directory" | echohl None let &report= repkeep -" call Dret("zip#Extract") return endif " extract the file mentioned under the cursor call system($"{g:zip_extractcmd} {shellescape(b:zipfile)} {shellescape(fname)}") -" call Decho("zipfile<".b:zipfile.">") if v:shell_error != 0 echohl Error | echo "***error*** ".g:zip_extractcmd." ".b:zipfile." ".fname.": failed!" | echohl NONE elseif !filereadable(fname) @@ -403,7 +365,6 @@ fun! zip#Extract() " restore option let &report= repkeep -" call Dret("zip#Extract") endfun " --------------------------------------------------------------------- @@ -428,8 +389,6 @@ endfun " --------------------------------------------------------------------- " ChgDir: {{{2 fun! s:ChgDir(newdir,errlvl,errmsg) -" call Dfunc("ChgDir(newdir<".a:newdir."> errlvl=".a:errlvl." errmsg<".a:errmsg.">)") - try exe "cd ".fnameescape(a:newdir) catch /^Vim\%((\a\+)\)\=:E344/ @@ -441,12 +400,9 @@ fun! s:ChgDir(newdir,errlvl,errmsg) elseif a:errlvl == s:ERROR echohl Error | echo "***error*** ".a:errmsg | echohl NONE endif -" call inputsave()|call input("Press to continue")|call inputrestore() -" call Dret("ChgDir 1") return 1 endtry -" call Dret("ChgDir 0") return 0 endfun -- cgit From 303b3e153d5786fa53c7e5b8bdde3b1c7c318b5e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 7 Aug 2024 07:06:27 +0800 Subject: vim-patch:120c0dd: runtime(zip): use :echomsg instead of :echo Problem: zip plugin uses :echo which does not store messages Solution: use :echomsg instead of :echo so that messages are stored in the message history https://github.com/vim/vim/commit/120c0dd815fa3b44df0fa477f7f3313e4a69c652 Co-authored-by: Christian Brabandt --- runtime/autoload/zip.vim | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/runtime/autoload/zip.vim b/runtime/autoload/zip.vim index de88b55907..d22e2e0141 100644 --- a/runtime/autoload/zip.vim +++ b/runtime/autoload/zip.vim @@ -31,7 +31,7 @@ endif let g:loaded_zip= "v33" if v:version < 702 echohl WarningMsg - echo "***warning*** this version of zip needs vim 7.2 or later" + echomsg "***warning*** this version of zip needs vim 7.2 or later" echohl Normal finish endif @@ -95,7 +95,7 @@ fun! zip#Browse(zipfile) endif if !executable(g:zip_unzipcmd) redraw! - echohl Error | echo "***error*** (zip#Browse) unzip not available on your system" + echohl Error | echomsg "***error*** (zip#Browse) unzip not available on your system" let &report= repkeep return endif @@ -103,7 +103,7 @@ fun! zip#Browse(zipfile) if a:zipfile !~# '^\a\+://' " if it's an url, don't complain, let url-handlers such as vim do its thing redraw! - echohl Error | echo "***error*** (zip#Browse) File not readable<".a:zipfile.">" | echohl None + echohl Error | echomsg "***error*** (zip#Browse) File not readable<".a:zipfile.">" | echohl None endif let &report= repkeep return @@ -135,7 +135,7 @@ fun! zip#Browse(zipfile) exe $"keepj sil r! {g:zip_unzipcmd} -Z1 -- {s:Escape(a:zipfile, 1)}" if v:shell_error != 0 redraw! - echohl WarningMsg | echo "***warning*** (zip#Browse) ".fnameescape(a:zipfile)." is not a zip file" | echohl None + echohl WarningMsg | echomsg "***warning*** (zip#Browse) ".fnameescape(a:zipfile)." is not a zip file" | echohl None keepj sil! %d let eikeep= &ei set ei=BufReadCmd,FileReadCmd @@ -173,7 +173,7 @@ fun! s:ZipBrowseSelect() endif if fname =~ '/$' redraw! - echohl Error | echo "***error*** (zip#Browse) Please specify a file, not a directory" | echohl None + echohl Error | echomsg "***error*** (zip#Browse) Please specify a file, not a directory" | echohl None let &report= repkeep return endif @@ -210,7 +210,7 @@ fun! zip#Read(fname,mode) " sanity check if !executable(substitute(g:zip_unzipcmd,'\s\+.*$','','')) redraw! - echohl Error | echo "***error*** (zip#Read) sorry, your system doesn't appear to have the ".g:zip_unzipcmd." program" | echohl None + echohl Error | echomsg "***error*** (zip#Read) sorry, your system doesn't appear to have the ".g:zip_unzipcmd." program" | echohl None let &report= repkeep return endif @@ -243,13 +243,13 @@ fun! zip#Write(fname) " sanity checks if !executable(substitute(g:zip_zipcmd,'\s\+.*$','','')) redraw! - echohl Error | echo "***error*** (zip#Write) sorry, your system doesn't appear to have the ".g:zip_zipcmd." program" | echohl None + echohl Error | echomsg "***error*** (zip#Write) sorry, your system doesn't appear to have the ".g:zip_zipcmd." program" | echohl None let &report= repkeep return endif if !exists("*mkdir") redraw! - echohl Error | echo "***error*** (zip#Write) sorry, mkdir() doesn't work on your system" | echohl None + echohl Error | echomsg "***error*** (zip#Write) sorry, mkdir() doesn't work on your system" | echohl None let &report= repkeep return endif @@ -305,7 +305,7 @@ fun! zip#Write(fname) call system(g:zip_zipcmd." -u ".s:Escape(fnamemodify(zipfile,":p"),0)." ".s:Escape(fname,0)) if v:shell_error != 0 redraw! - echohl Error | echo "***error*** (zip#Write) sorry, unable to update ".zipfile." with ".fname | echohl None + echohl Error | echomsg "***error*** (zip#Write) sorry, unable to update ".zipfile." with ".fname | echohl None elseif s:zipfile_{winnr()} =~ '^\a\+://' " support writing zipfiles across a network @@ -347,7 +347,7 @@ fun! zip#Extract() endif if fname =~ '/$' redraw! - echohl Error | echo "***error*** (zip#Extract) Please specify a file, not a directory" | echohl None + echohl Error | echomsg "***error*** (zip#Extract) Please specify a file, not a directory" | echohl None let &report= repkeep return endif @@ -355,11 +355,11 @@ fun! zip#Extract() " extract the file mentioned under the cursor call system($"{g:zip_extractcmd} {shellescape(b:zipfile)} {shellescape(fname)}") if v:shell_error != 0 - echohl Error | echo "***error*** ".g:zip_extractcmd." ".b:zipfile." ".fname.": failed!" | echohl NONE + echohl Error | echomsg "***error*** ".g:zip_extractcmd." ".b:zipfile." ".fname.": failed!" | echohl NONE elseif !filereadable(fname) - echohl Error | echo "***error*** attempted to extract ".fname." but it doesn't appear to be present!" + echohl Error | echomsg "***error*** attempted to extract ".fname." but it doesn't appear to be present!" else - echo "***note*** successfully extracted ".fname + echomsg "***note*** successfully extracted ".fname endif " restore option @@ -394,11 +394,11 @@ fun! s:ChgDir(newdir,errlvl,errmsg) catch /^Vim\%((\a\+)\)\=:E344/ redraw! if a:errlvl == s:NOTE - echo "***note*** ".a:errmsg + echomsg "***note*** ".a:errmsg elseif a:errlvl == s:WARNING - echohl WarningMsg | echo "***warning*** ".a:errmsg | echohl NONE + echohl WarningMsg | echomsg "***warning*** ".a:errmsg | echohl NONE elseif a:errlvl == s:ERROR - echohl Error | echo "***error*** ".a:errmsg | echohl NONE + echohl Error | echomsg "***error*** ".a:errmsg | echohl NONE endif return 1 endtry -- cgit From 11c57c25ef9b413088014cdb23636a440cd917c2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 7 Aug 2024 07:07:03 +0800 Subject: vim-patch:33836d3: runtime(zip): remove test for fnameescape Problem: zip plugin tests for fnameescape() function Solution: Remove the check, fnameescape() has been available since 7.1.299, it should nowadays always be available https://github.com/vim/vim/commit/33836d38b82aa926a2a2b3f945a0139f373f7e56 Co-authored-by: Christian Brabandt --- runtime/autoload/zip.vim | 6 ------ 1 file changed, 6 deletions(-) diff --git a/runtime/autoload/zip.vim b/runtime/autoload/zip.vim index d22e2e0141..cf70135186 100644 --- a/runtime/autoload/zip.vim +++ b/runtime/autoload/zip.vim @@ -87,12 +87,6 @@ fun! zip#Browse(zipfile) set report=10 " sanity checks - if !exists("*fnameescape") - if &verbose > 1 - echoerr "the zip plugin is not available (your vim doesn't support fnameescape())" - endif - return - endif if !executable(g:zip_unzipcmd) redraw! echohl Error | echomsg "***error*** (zip#Browse) unzip not available on your system" -- cgit From 92981c8e0bea4a2ef23665df61aa820ed0a23eb3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 7 Aug 2024 07:07:29 +0800 Subject: vim-patch:19636be: runtime(zip): refactor save and restore of options Problem: zip plugin has no way to set/restore option values Solution: Add the SetSaneOpts() and RestoreOpts() functions, so options that cause issues are set to sane values and restored back to their initial values later on. (this affects the 'shellslash' option on windows, which also changes how the shellescape() function works) https://github.com/vim/vim/commit/19636be55e023cb726389107e9e7d62049b6fd58 Co-authored-by: Christian Brabandt --- runtime/autoload/zip.vim | 74 ++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/runtime/autoload/zip.vim b/runtime/autoload/zip.vim index cf70135186..7e833fe5ad 100644 --- a/runtime/autoload/zip.vim +++ b/runtime/autoload/zip.vim @@ -83,14 +83,13 @@ fun! zip#Browse(zipfile) return endif - let repkeep= &report - set report=10 + let dict = s:SetSaneOpts() " sanity checks if !executable(g:zip_unzipcmd) redraw! echohl Error | echomsg "***error*** (zip#Browse) unzip not available on your system" - let &report= repkeep + call s:RestoreOpts(dict) return endif if !filereadable(a:zipfile) @@ -99,7 +98,7 @@ fun! zip#Browse(zipfile) redraw! echohl Error | echomsg "***error*** (zip#Browse) File not readable<".a:zipfile.">" | echohl None endif - let &report= repkeep + call s:RestoreOpts(dict) return endif if &ma != 1 @@ -136,6 +135,7 @@ fun! zip#Browse(zipfile) exe "keepj r ".fnameescape(a:zipfile) let &ei= eikeep keepj 1d + call s:RestoreOpts(dict) return endif @@ -147,28 +147,28 @@ fun! zip#Browse(zipfile) noremap :call ZipBrowseSelect() endif - let &report= repkeep + call s:RestoreOpts(dict) endfun " --------------------------------------------------------------------- " ZipBrowseSelect: {{{2 fun! s:ZipBrowseSelect() - let repkeep= &report - set report=10 + let dict = s:SetSaneOpts() let fname= getline(".") if !exists("b:zipfile") + call s:RestoreOpts(dict) return endif " sanity check if fname =~ '^"' - let &report= repkeep + call s:RestoreOpts(dict) return endif if fname =~ '/$' redraw! echohl Error | echomsg "***error*** (zip#Browse) Please specify a file, not a directory" | echohl None - let &report= repkeep + call s:RestoreOpts(dict) return endif @@ -184,14 +184,13 @@ fun! s:ZipBrowseSelect() exe "noswapfile e ".fnameescape("zipfile://".zipfile.'::'.fname) filetype detect - let &report= repkeep + call s:RestoreOpts(dict) endfun " --------------------------------------------------------------------- " zip#Read: {{{2 fun! zip#Read(fname,mode) - let repkeep= &report - set report=10 + let dict = s:SetSaneOpts() if has("unix") let zipfile = substitute(a:fname,'zipfile://\(.\{-}\)::[^\\].*$','\1','') @@ -205,7 +204,7 @@ fun! zip#Read(fname,mode) if !executable(substitute(g:zip_unzipcmd,'\s\+.*$','','')) redraw! echohl Error | echomsg "***error*** (zip#Read) sorry, your system doesn't appear to have the ".g:zip_unzipcmd." program" | echohl None - let &report= repkeep + call s:RestoreOpts(dict) return endif @@ -225,26 +224,25 @@ fun! zip#Read(fname,mode) " cleanup set nomod - let &report= repkeep + call s:RestoreOpts(dict) endfun " --------------------------------------------------------------------- " zip#Write: {{{2 fun! zip#Write(fname) - let repkeep= &report - set report=10 + let dict = s:SetSaneOpts() " sanity checks if !executable(substitute(g:zip_zipcmd,'\s\+.*$','','')) redraw! echohl Error | echomsg "***error*** (zip#Write) sorry, your system doesn't appear to have the ".g:zip_zipcmd." program" | echohl None - let &report= repkeep + call s:RestoreOpts(dict) return endif if !exists("*mkdir") redraw! echohl Error | echomsg "***error*** (zip#Write) sorry, mkdir() doesn't work on your system" | echohl None - let &report= repkeep + call s:RestoreOpts(dict) return endif @@ -257,7 +255,7 @@ fun! zip#Write(fname) " attempt to change to the indicated directory if s:ChgDir(tmpdir,s:ERROR,"(zip#Write) cannot cd to temporary directory") - let &report= repkeep + call s:RestoreOpts(dict) return endif @@ -323,26 +321,25 @@ fun! zip#Write(fname) call delete(tmpdir, "rf") setlocal nomod - let &report= repkeep + call s:RestoreOpts(dict) endfun " --------------------------------------------------------------------- " zip#Extract: extract a file from a zip archive {{{2 fun! zip#Extract() - let repkeep= &report - set report=10 + let dict = s:SetSaneOpts() let fname= getline(".") " sanity check if fname =~ '^"' - let &report= repkeep + call s:RestoreOpts(dict) return endif if fname =~ '/$' redraw! echohl Error | echomsg "***error*** (zip#Extract) Please specify a file, not a directory" | echohl None - let &report= repkeep + call s:RestoreOpts(dict) return endif @@ -357,7 +354,7 @@ fun! zip#Extract() endif " restore option - let &report= repkeep + call s:RestoreOpts(dict) endfun @@ -373,15 +370,11 @@ fun! s:Escape(fname,isfilt) else let qnameq= g:zip_shq.escape(a:fname,g:zip_shq).g:zip_shq endif - if exists("+shellslash") && &shellslash && &shell =~ "cmd.exe" - " renormalize directory separator on Windows - let qnameq=substitute(qnameq, '/', '\\', 'g') - endif return qnameq endfun " --------------------------------------------------------------------- -" ChgDir: {{{2 +" s:ChgDir: {{{2 fun! s:ChgDir(newdir,errlvl,errmsg) try exe "cd ".fnameescape(a:newdir) @@ -400,6 +393,27 @@ fun! s:ChgDir(newdir,errlvl,errmsg) return 0 endfun +" --------------------------------------------------------------------- +" s:SetSaneOpts: {{{2 +fun! s:SetSaneOpts() + let dict = {} + let dict.report = &report + let dict.shellslash = &shellslash + + let &report = 10 + let &shellslash = 0 + + return dict +endfun + +" --------------------------------------------------------------------- +" s:RestoreOpts: {{{2 +fun! s:RestoreOpts(dict) + for [key, val] in items(a:dict) + exe $"let &{key} = {val}" + endfor +endfun + " ------------------------------------------------------------------------ " Modelines And Restoration: {{{1 let &cpo= s:keepcpo -- cgit From 025920b330c4dc14ef1df780794cf27a4e504e94 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 7 Aug 2024 07:10:41 +0800 Subject: vim-patch:a336d8f: runtime(zip): increment base version of zip plugin Problem: the zip plugin version is still v33 Solution: increment the version to v34 https://github.com/vim/vim/commit/a336d8f21e4cce877e23d47db238801a5a406992 Co-authored-by: Christian Brabandt --- runtime/autoload/zip.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/autoload/zip.vim b/runtime/autoload/zip.vim index 7e833fe5ad..5e56086484 100644 --- a/runtime/autoload/zip.vim +++ b/runtime/autoload/zip.vim @@ -1,7 +1,7 @@ " zip.vim: Handles browsing zipfiles " AUTOLOAD PORTION " Date: Aug 05, 2024 -" Version: 33 +" Version: 34 " Maintainer: This runtime file is looking for a new maintainer. " Former Maintainer: Charles E Campbell " Last Change: @@ -28,7 +28,7 @@ if &cp || exists("g:loaded_zip") finish endif -let g:loaded_zip= "v33" +let g:loaded_zip= "v34" if v:version < 702 echohl WarningMsg echomsg "***warning*** this version of zip needs vim 7.2 or later" -- cgit From 221c489edd40e3c9042503e501596ac9fa8e38dc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 7 Aug 2024 07:11:11 +0800 Subject: vim-patch:8d52926: runtime(zip): add a generic Message function Problem: the zip plugin duplicates a lot of code for displaying warnings/errors Solution: refactor common code into a generic Mess() function https://github.com/vim/vim/commit/8d52926857ec7f08a9bee8f96470748cecf58002 Co-authored-by: Christian Brabandt --- runtime/autoload/zip.vim | 57 ++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/runtime/autoload/zip.vim b/runtime/autoload/zip.vim index 5e56086484..ced3a57c20 100644 --- a/runtime/autoload/zip.vim +++ b/runtime/autoload/zip.vim @@ -29,12 +29,6 @@ if &cp || exists("g:loaded_zip") finish endif let g:loaded_zip= "v34" -if v:version < 702 - echohl WarningMsg - echomsg "***warning*** this version of zip needs vim 7.2 or later" - echohl Normal - finish -endif let s:keepcpo= &cpo set cpo&vim @@ -64,8 +58,22 @@ if !exists("g:zip_extractcmd") let g:zip_extractcmd= g:zip_unzipcmd endif +" --------------------------------------------------------------------- +" required early +" s:Mess: {{{2 +fun! s:Mess(group, msg) + redraw! + exe "echohl " . a:group + echomsg a:msg + echohl Normal +endfun + +if v:version < 702 + call s:Mess('WarningMsg', "***warning*** this version of zip needs vim 7.2 or later") + finish +endif if !dist#vim#IsSafeExecutable('zip', g:zip_unzipcmd) - echoerr "Warning: NOT executing " .. g:zip_unzipcmd .. " from current directory!" + call s:Mess('Error', "Warning: NOT executing " .. g:zip_unzipcmd .. " from current directory!") finish endif @@ -87,16 +95,14 @@ fun! zip#Browse(zipfile) " sanity checks if !executable(g:zip_unzipcmd) - redraw! - echohl Error | echomsg "***error*** (zip#Browse) unzip not available on your system" + call s:Mess('Error', "***error*** (zip#Browse) unzip not available on your system") call s:RestoreOpts(dict) return endif if !filereadable(a:zipfile) if a:zipfile !~# '^\a\+://' " if it's an url, don't complain, let url-handlers such as vim do its thing - redraw! - echohl Error | echomsg "***error*** (zip#Browse) File not readable<".a:zipfile.">" | echohl None + call s:Mess('Error', "***error*** (zip#Browse) File not readable <".a:zipfile.">") endif call s:RestoreOpts(dict) return @@ -127,8 +133,7 @@ fun! zip#Browse(zipfile) exe $"keepj sil r! {g:zip_unzipcmd} -Z1 -- {s:Escape(a:zipfile, 1)}" if v:shell_error != 0 - redraw! - echohl WarningMsg | echomsg "***warning*** (zip#Browse) ".fnameescape(a:zipfile)." is not a zip file" | echohl None + call s:Mess('WarningMsg', "***warning*** (zip#Browse) ".fnameescape(a:zipfile)." is not a zip file") keepj sil! %d let eikeep= &ei set ei=BufReadCmd,FileReadCmd @@ -166,8 +171,7 @@ fun! s:ZipBrowseSelect() return endif if fname =~ '/$' - redraw! - echohl Error | echomsg "***error*** (zip#Browse) Please specify a file, not a directory" | echohl None + call s:Mess('Error', "***error*** (zip#Browse) Please specify a file, not a directory") call s:RestoreOpts(dict) return endif @@ -202,8 +206,7 @@ fun! zip#Read(fname,mode) let fname = substitute(fname, '[', '[[]', 'g') " sanity check if !executable(substitute(g:zip_unzipcmd,'\s\+.*$','','')) - redraw! - echohl Error | echomsg "***error*** (zip#Read) sorry, your system doesn't appear to have the ".g:zip_unzipcmd." program" | echohl None + call s:Mess('Error', "***error*** (zip#Read) sorry, your system doesn't appear to have the ".g:zip_unzipcmd." program") call s:RestoreOpts(dict) return endif @@ -234,14 +237,12 @@ fun! zip#Write(fname) " sanity checks if !executable(substitute(g:zip_zipcmd,'\s\+.*$','','')) - redraw! - echohl Error | echomsg "***error*** (zip#Write) sorry, your system doesn't appear to have the ".g:zip_zipcmd." program" | echohl None + call s:Mess('Error', "***error*** (zip#Write) sorry, your system doesn't appear to have the ".g:zip_zipcmd." program") call s:RestoreOpts(dict) return endif if !exists("*mkdir") - redraw! - echohl Error | echomsg "***error*** (zip#Write) sorry, mkdir() doesn't work on your system" | echohl None + call s:Mess('Error', "***error*** (zip#Write) sorry, mkdir() doesn't work on your system") call s:RestoreOpts(dict) return endif @@ -296,8 +297,7 @@ fun! zip#Write(fname) call system(g:zip_zipcmd." -u ".s:Escape(fnamemodify(zipfile,":p"),0)." ".s:Escape(fname,0)) if v:shell_error != 0 - redraw! - echohl Error | echomsg "***error*** (zip#Write) sorry, unable to update ".zipfile." with ".fname | echohl None + call s:Mess('Error', "***error*** (zip#Write) sorry, unable to update ".zipfile." with ".fname) elseif s:zipfile_{winnr()} =~ '^\a\+://' " support writing zipfiles across a network @@ -337,8 +337,7 @@ fun! zip#Extract() return endif if fname =~ '/$' - redraw! - echohl Error | echomsg "***error*** (zip#Extract) Please specify a file, not a directory" | echohl None + call s:Mess('Error', "***error*** (zip#Extract) Please specify a file, not a directory") call s:RestoreOpts(dict) return endif @@ -346,9 +345,9 @@ fun! zip#Extract() " extract the file mentioned under the cursor call system($"{g:zip_extractcmd} {shellescape(b:zipfile)} {shellescape(fname)}") if v:shell_error != 0 - echohl Error | echomsg "***error*** ".g:zip_extractcmd." ".b:zipfile." ".fname.": failed!" | echohl NONE + call s:Mess('Error', "***error*** ".g:zip_extractcmd." ".b:zipfile." ".fname.": failed!") elseif !filereadable(fname) - echohl Error | echomsg "***error*** attempted to extract ".fname." but it doesn't appear to be present!" + call s:Mess('Error', "***error*** attempted to extract ".fname." but it doesn't appear to be present!") else echomsg "***note*** successfully extracted ".fname endif @@ -383,9 +382,9 @@ fun! s:ChgDir(newdir,errlvl,errmsg) if a:errlvl == s:NOTE echomsg "***note*** ".a:errmsg elseif a:errlvl == s:WARNING - echohl WarningMsg | echomsg "***warning*** ".a:errmsg | echohl NONE + call s:Mess("WarningMsg", "***warning*** ".a:errmsg) elseif a:errlvl == s:ERROR - echohl Error | echomsg "***error*** ".a:errmsg | echohl NONE + call s:Mess("Error", "***error*** ".a:errmsg) endif return 1 endtry -- cgit From 450d49660f52d915f78da3b0aeb21d9d658f98bd Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 7 Aug 2024 07:15:59 +0800 Subject: vim-patch:afea6b9: runtime(zip): use defer to restore old settings Problem: RestoreOpts() plugin called too often Solution: use :defer to have the RestoreOpts() function called when the function returns automatically https://github.com/vim/vim/commit/afea6b946827e964271eb19579946a7f88d2f329 Co-authored-by: Christian Brabandt --- runtime/autoload/zip.vim | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/runtime/autoload/zip.vim b/runtime/autoload/zip.vim index ced3a57c20..d0d6863329 100644 --- a/runtime/autoload/zip.vim +++ b/runtime/autoload/zip.vim @@ -92,11 +92,11 @@ fun! zip#Browse(zipfile) endif let dict = s:SetSaneOpts() + defer s:RestoreOpts(dict) " sanity checks if !executable(g:zip_unzipcmd) call s:Mess('Error', "***error*** (zip#Browse) unzip not available on your system") - call s:RestoreOpts(dict) return endif if !filereadable(a:zipfile) @@ -104,7 +104,6 @@ fun! zip#Browse(zipfile) " if it's an url, don't complain, let url-handlers such as vim do its thing call s:Mess('Error', "***error*** (zip#Browse) File not readable <".a:zipfile.">") endif - call s:RestoreOpts(dict) return endif if &ma != 1 @@ -140,7 +139,6 @@ fun! zip#Browse(zipfile) exe "keepj r ".fnameescape(a:zipfile) let &ei= eikeep keepj 1d - call s:RestoreOpts(dict) return endif @@ -152,27 +150,24 @@ fun! zip#Browse(zipfile) noremap :call ZipBrowseSelect() endif - call s:RestoreOpts(dict) endfun " --------------------------------------------------------------------- " ZipBrowseSelect: {{{2 fun! s:ZipBrowseSelect() let dict = s:SetSaneOpts() + defer s:RestoreOpts(dict) let fname= getline(".") if !exists("b:zipfile") - call s:RestoreOpts(dict) return endif " sanity check if fname =~ '^"' - call s:RestoreOpts(dict) return endif if fname =~ '/$' call s:Mess('Error', "***error*** (zip#Browse) Please specify a file, not a directory") - call s:RestoreOpts(dict) return endif @@ -188,13 +183,13 @@ fun! s:ZipBrowseSelect() exe "noswapfile e ".fnameescape("zipfile://".zipfile.'::'.fname) filetype detect - call s:RestoreOpts(dict) endfun " --------------------------------------------------------------------- " zip#Read: {{{2 fun! zip#Read(fname,mode) let dict = s:SetSaneOpts() + defer s:RestoreOpts(dict) if has("unix") let zipfile = substitute(a:fname,'zipfile://\(.\{-}\)::[^\\].*$','\1','') @@ -207,7 +202,6 @@ fun! zip#Read(fname,mode) " sanity check if !executable(substitute(g:zip_unzipcmd,'\s\+.*$','','')) call s:Mess('Error', "***error*** (zip#Read) sorry, your system doesn't appear to have the ".g:zip_unzipcmd." program") - call s:RestoreOpts(dict) return endif @@ -227,23 +221,21 @@ fun! zip#Read(fname,mode) " cleanup set nomod - call s:RestoreOpts(dict) endfun " --------------------------------------------------------------------- " zip#Write: {{{2 fun! zip#Write(fname) let dict = s:SetSaneOpts() + defer s:RestoreOpts(dict) " sanity checks if !executable(substitute(g:zip_zipcmd,'\s\+.*$','','')) call s:Mess('Error', "***error*** (zip#Write) sorry, your system doesn't appear to have the ".g:zip_zipcmd." program") - call s:RestoreOpts(dict) return endif if !exists("*mkdir") call s:Mess('Error', "***error*** (zip#Write) sorry, mkdir() doesn't work on your system") - call s:RestoreOpts(dict) return endif @@ -256,7 +248,6 @@ fun! zip#Write(fname) " attempt to change to the indicated directory if s:ChgDir(tmpdir,s:ERROR,"(zip#Write) cannot cd to temporary directory") - call s:RestoreOpts(dict) return endif @@ -321,7 +312,6 @@ fun! zip#Write(fname) call delete(tmpdir, "rf") setlocal nomod - call s:RestoreOpts(dict) endfun " --------------------------------------------------------------------- @@ -329,16 +319,15 @@ endfun fun! zip#Extract() let dict = s:SetSaneOpts() + defer s:RestoreOpts(dict) let fname= getline(".") " sanity check if fname =~ '^"' - call s:RestoreOpts(dict) return endif if fname =~ '/$' call s:Mess('Error', "***error*** (zip#Extract) Please specify a file, not a directory") - call s:RestoreOpts(dict) return endif @@ -352,9 +341,6 @@ fun! zip#Extract() echomsg "***note*** successfully extracted ".fname endif - " restore option - call s:RestoreOpts(dict) - endfun " --------------------------------------------------------------------- -- cgit From 1937870114f5dd824a9bb61ee8dfd3be2acc5439 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 7 Aug 2024 07:07:49 +0800 Subject: vim-patch:9.1.0663: tests: zip test still resets 'shellslash' option Problem: tests: zip test still resets 'shellslash' option Solution: Remove resetting the 'shellslash' option, the zip plugin should now be able to handle this options closes: vim/vim#15434 https://github.com/vim/vim/commit/91efcd115e700725b9ebded0f5d7bc0d3fa98d9d Co-authored-by: Christian Brabandt --- test/old/testdir/test_zip_plugin.vim | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/old/testdir/test_zip_plugin.vim b/test/old/testdir/test_zip_plugin.vim index 741e4ed91f..b214516e05 100644 --- a/test/old/testdir/test_zip_plugin.vim +++ b/test/old/testdir/test_zip_plugin.vim @@ -10,8 +10,6 @@ endif runtime plugin/zipPlugin.vim func Test_zip_basic() - let _sl = &shellslash - set noshellslash "## get our zip file if !filecopy("samples/test.zip", "X.zip") @@ -134,6 +132,4 @@ func Test_zip_basic() bw - let &shellslash = _sl - endfunc -- cgit