aboutsummaryrefslogtreecommitdiff
path: root/runtime/autoload
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-11-19 22:57:13 +0000
committerJosh Rahm <joshuarahm@gmail.com>2024-11-19 22:57:13 +0000
commit9be89f131f87608f224f0ee06d199fcd09d32176 (patch)
tree11022dcfa9e08cb4ac5581b16734196128688d48 /runtime/autoload
parentff7ed8f586589d620a806c3758fac4a47a8e7e15 (diff)
parent88085c2e80a7e3ac29aabb6b5420377eed99b8b6 (diff)
downloadrneovim-9be89f131f87608f224f0ee06d199fcd09d32176.tar.gz
rneovim-9be89f131f87608f224f0ee06d199fcd09d32176.tar.bz2
rneovim-9be89f131f87608f224f0ee06d199fcd09d32176.zip
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'runtime/autoload')
-rw-r--r--runtime/autoload/dist/vim.vim3
-rw-r--r--runtime/autoload/hare.vim26
-rw-r--r--runtime/autoload/hcl.vim40
-rw-r--r--runtime/autoload/javaformat.vim92
-rw-r--r--runtime/autoload/msgpack.vim50
-rw-r--r--runtime/autoload/netrw.vim243
-rw-r--r--runtime/autoload/provider/clipboard.vim12
-rw-r--r--runtime/autoload/shada.vim4
-rw-r--r--runtime/autoload/typst.vim50
-rw-r--r--runtime/autoload/zip.vim282
10 files changed, 479 insertions, 323 deletions
diff --git a/runtime/autoload/dist/vim.vim b/runtime/autoload/dist/vim.vim
index 021244c93b..bb858c5732 100644
--- a/runtime/autoload/dist/vim.vim
+++ b/runtime/autoload/dist/vim.vim
@@ -18,6 +18,9 @@ endif
if !has('vim9script')
function dist#vim#IsSafeExecutable(filetype, executable)
let cwd = getcwd()
+ if empty(exepath(a:executable))
+ return v:false
+ endif
return get(g:, a:filetype .. '_exec', get(g:, 'plugin_exec', 0)) &&
\ (fnamemodify(exepath(a:executable), ':p:h') !=# cwd
\ || (split($PATH, has('win32') ? ';' : ':')->index(cwd) != -1 &&
diff --git a/runtime/autoload/hare.vim b/runtime/autoload/hare.vim
new file mode 100644
index 0000000000..c4581fccf9
--- /dev/null
+++ b/runtime/autoload/hare.vim
@@ -0,0 +1,26 @@
+" Vim autoload file.
+" Language: Hare
+" Maintainer: Amelia Clarke <selene@perilune.dev>
+" Last Updated: 2024-05-10
+" Upstream: https://git.sr.ht/~sircmpwn/hare.vim
+
+" Attempt to find the directory for a given Hare module.
+function hare#FindModule(str)
+ let path = substitute(trim(a:str, ':', 2), '::', '/', 'g')
+ let dir = finddir(path)
+ while !empty(path) && empty(dir)
+ let path = substitute(path, '/\?\h\w*$', '', '')
+ let dir = finddir(path)
+ endwhile
+ return dir
+endfunction
+
+" Return the value of HAREPATH if it exists. Otherwise use a reasonable default.
+function hare#GetPath()
+ if empty($HAREPATH)
+ return '/usr/src/hare/stdlib,/usr/src/hare/third-party'
+ endif
+ return substitute($HAREPATH, ':', ',', 'g')
+endfunction
+
+" vim: et sts=2 sw=2 ts=8
diff --git a/runtime/autoload/hcl.vim b/runtime/autoload/hcl.vim
new file mode 100644
index 0000000000..2215fc8f27
--- /dev/null
+++ b/runtime/autoload/hcl.vim
@@ -0,0 +1,40 @@
+" Language: HCL
+" Maintainer: Gregory Anders
+" Last Change: 2024-09-03
+" Based on: https://github.com/hashivim/vim-terraform
+
+function! hcl#indentexpr(lnum)
+ " Beginning of the file should have no indent
+ if a:lnum == 0
+ return 0
+ endif
+
+ " Usual case is to continue at the same indent as the previous non-blank line.
+ let prevlnum = prevnonblank(a:lnum-1)
+ let thisindent = indent(prevlnum)
+
+ " If that previous line is a non-comment ending in [ { (, increase the
+ " indent level.
+ let prevline = getline(prevlnum)
+ if prevline !~# '^\s*\(#\|//\)' && prevline =~# '[\[{\(]\s*$'
+ let thisindent += &shiftwidth
+ endif
+
+ " If the current line ends a block, decrease the indent level.
+ let thisline = getline(a:lnum)
+ if thisline =~# '^\s*[\)}\]]'
+ let thisindent -= &shiftwidth
+ endif
+
+ " If the previous line starts a block comment /*, increase by one
+ if prevline =~# '/\*'
+ let thisindent += 1
+ endif
+
+ " If the previous line ends a block comment */, decrease by one
+ if prevline =~# '\*/'
+ let thisindent -= 1
+ endif
+
+ return thisindent
+endfunction
diff --git a/runtime/autoload/javaformat.vim b/runtime/autoload/javaformat.vim
new file mode 100644
index 0000000000..4d7d32cf19
--- /dev/null
+++ b/runtime/autoload/javaformat.vim
@@ -0,0 +1,92 @@
+" Vim formatting plugin file
+" Language: Java
+" Maintainer: Aliaksei Budavei <0x000c70 AT gmail DOT com>
+" Repository: https://github.com/zzzyxwvut/java-vim.git
+" Last Change: 2024 Sep 26
+
+" Documented in ":help ft-java-plugin".
+if &cp || exists("g:loaded_javaformat") || exists("g:java_ignore_javadoc") || exists("g:java_ignore_markdown")
+ finish
+endif
+
+let g:loaded_javaformat = 1
+
+"""" STRIVE TO REMAIN COMPATIBLE FOR AT LEAST VIM 7.0.
+
+function! javaformat#RemoveCommonMarkdownWhitespace() abort
+ if mode() != 'n'
+ return 0
+ endif
+
+ let pattern = '\(^\s*///\)\(\s*\)\(.*\)'
+
+ " E121 for v:numbermax before v8.2.2388.
+ " E15 for expr-<< before v8.2.5003.
+ let common = 0x7fffffff
+ let comments = []
+
+ for n in range(v:lnum, (v:lnum + v:count - 1))
+ let parts = matchlist(getline(n), pattern)
+ let whitespace = get(parts, 2, '')
+ let nonwhitespace = get(parts, 3, '')
+
+ if !empty(whitespace)
+ let common = min([common, strlen(whitespace)])
+ elseif !empty(nonwhitespace) || empty(parts)
+ " No whitespace prefix or not a Markdown comment.
+ return 0
+ endif
+
+ call add(comments, [whitespace, parts[1], nonwhitespace])
+ endfor
+
+ let cursor = v:lnum
+
+ for line in comments
+ call setline(cursor, join(line[1 :], strpart(line[0], common)))
+ let cursor += 1
+ endfor
+
+ return 0
+endfunction
+
+" See ":help vim9-mix".
+if !has("vim9script")
+ finish
+endif
+
+def! g:javaformat#RemoveCommonMarkdownWhitespace(): number
+ if mode() != 'n'
+ return 0
+ endif
+
+ const pattern: string = '\(^\s*///\)\(\s*\)\(.*\)'
+ var common: number = v:numbermax
+ var comments: list<list<string>> = []
+
+ for n in range(v:lnum, (v:lnum + v:count - 1))
+ const parts: list<string> = matchlist(getline(n), pattern)
+ const whitespace: string = get(parts, 2, '')
+ const nonwhitespace: string = get(parts, 3, '')
+
+ if !empty(whitespace)
+ common = min([common, strlen(whitespace)])
+ elseif !empty(nonwhitespace) || empty(parts)
+ # No whitespace prefix or not a Markdown comment.
+ return 0
+ endif
+
+ add(comments, [whitespace, parts[1], nonwhitespace])
+ endfor
+
+ var cursor: number = v:lnum
+
+ for line in comments
+ setline(cursor, join(line[1 :], strpart(line[0], common)))
+ cursor += 1
+ endfor
+
+ return 0
+enddef
+
+" vim: fdm=syntax sw=4 ts=8 noet sta
diff --git a/runtime/autoload/msgpack.vim b/runtime/autoload/msgpack.vim
index 18dcd1e6a6..fb438def4f 100644
--- a/runtime/autoload/msgpack.vim
+++ b/runtime/autoload/msgpack.vim
@@ -361,7 +361,7 @@ endfunction
let s:MSGPACK_STANDARD_TYPES = {
\type(0): 'integer',
\type(0.0): 'float',
- \type(''): 'binary',
+ \type(''): 'string',
\type([]): 'array',
\type({}): 'map',
\type(v:true): 'boolean',
@@ -412,9 +412,15 @@ endfunction
""
" Dump |msgpack-special-dict| that represents a string. If any additional
" parameter is given then it dumps binary string.
-function s:msgpack_dump_string(v, ...) abort
- let ret = [a:0 ? '"' : '="']
- for v in a:v._VAL
+function s:msgpack_dump_string(v) abort
+ if type(a:v) == type({})
+ let val = a:v
+ else
+ let val = {'_VAL': split(a:v, "\n", 1)}
+ end
+
+ let ret = ['"']
+ for v in val._VAL
call add(
\ret,
\substitute(
@@ -427,16 +433,6 @@ function s:msgpack_dump_string(v, ...) abort
endfunction
""
-" Dump binary string.
-function s:msgpack_dump_binary(v) abort
- if type(a:v) == type({})
- return s:msgpack_dump_string(a:v, 1)
- else
- return s:msgpack_dump_string({'_VAL': split(a:v, "\n", 1)}, 1)
- endif
-endfunction
-
-""
" Dump array value.
function s:msgpack_dump_array(v) abort
let val = type(a:v) == type({}) ? a:v._VAL : a:v
@@ -449,7 +445,7 @@ function s:msgpack_dump_map(v) abort
let ret = ['{']
if msgpack#special_type(a:v) is 0
for [k, v] in items(a:v)
- let ret += [s:msgpack_dump_string({'_VAL': split(k, "\n", 1)}),
+ let ret += [s:msgpack_dump_string({'_VAL': split(k, "\n")}),
\': ',
\msgpack#string(v),
\', ']
@@ -479,7 +475,7 @@ endfunction
" Dump extension value.
function s:msgpack_dump_ext(v) abort
return printf('+(%i)%s', a:v._VAL[0],
- \s:msgpack_dump_string({'_VAL': a:v._VAL[1]}, 1))
+ \s:msgpack_dump_string({'_VAL': a:v._VAL[1]}))
endfunction
""
@@ -619,9 +615,7 @@ function msgpack#eval(s, special_objs) abort
throw '"-invalid:Invalid string: ' . s
endif
call add(expr, '{''_TYPE'': v:msgpack_types.')
- if empty(match[1])
- call add(expr, 'binary')
- elseif match[1] is# '='
+ if empty(match[1]) || match[1] is# '='
call add(expr, 'string')
else
call add(expr, 'ext')
@@ -772,7 +766,7 @@ function msgpack#equal(a, b)
let a = aspecial is 0 ? a:a : a:a._VAL
let b = bspecial is 0 ? a:b : a:b._VAL
return msgpack#equal(a, b)
- elseif atype is# 'binary'
+ elseif atype is# 'string'
let a = (aspecial is 0 ? split(a:a, "\n", 1) : a:a._VAL)
let b = (bspecial is 0 ? split(a:b, "\n", 1) : a:b._VAL)
return a ==# b
@@ -787,13 +781,17 @@ function msgpack#equal(a, b)
" Non-special mapping cannot have non-string keys
return 0
endif
- if (empty(k._VAL)
- \|| k._VAL ==# [""]
- \|| !empty(filter(copy(k._VAL), 'stridx(v:val, "\n") != -1')))
- " Non-special mapping cannot have zero byte in key or an empty key
- return 0
+ if type(k) == type({})
+ if (empty(k._VAL)
+ \|| k._VAL ==# [""]
+ \|| !empty(filter(copy(k._VAL), 'stridx(v:val, "\n") != -1')))
+ " Non-special mapping cannot have zero byte in key or an empty key
+ return 0
+ endif
+ let kstr = join(k._VAL, "\n")
+ else
+ let kstr = k
endif
- let kstr = join(k._VAL, "\n")
if !has_key(akeys, kstr)
" Protects from both missing and duplicate keys
return 0
diff --git a/runtime/autoload/netrw.vim b/runtime/autoload/netrw.vim
index ae602c5be6..a96364fb4b 100644
--- a/runtime/autoload/netrw.vim
+++ b/runtime/autoload/netrw.vim
@@ -3,7 +3,7 @@
" Maintainer: This runtime file is looking for a new maintainer.
" Date: May 03, 2023
" Version: 173a
-" Last Change:
+" Last Change: {{{1
" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
" 2024 Feb 19 by Vim Project: (announce adoption)
@@ -12,6 +12,21 @@
" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
" 2024 May 09 by Vim Project: remove hard-coded private.ppk
" 2024 May 10 by Vim Project: recursively delete directories by default
+" 2024 May 13 by Vim Project: prefer scp over pscp
+" 2024 Jun 04 by Vim Project: set bufhidden if buffer changed, nohidden is set and buffer shall be switched (#14915)
+" 2024 Jun 13 by Vim Project: glob() on Windows fails when a directory name contains [] (#14952)
+" 2024 Jun 23 by Vim Project: save ad restore registers when liststyle = WIDELIST (#15077, #15114)
+" 2024 Jul 22 by Vim Project: avoid endless recursion (#15318)
+" 2024 Jul 23 by Vim Project: escape filename before trying to delete it (#15330)
+" 2024 Jul 30 by Vim Project: handle mark-copy to same target directory (#12112)
+" 2024 Aug 02 by Vim Project: honor g:netrw_alt{o,v} for :{S,H,V}explore (#15417)
+" 2024 Aug 15 by Vim Project: style changes, prevent E121 (#15501)
+" 2024 Aug 22 by Vim Project: fix mf-selection highlight (#15551)
+" 2024 Aug 22 by Vim Project: adjust echo output of mx command (#15550)
+" 2024 Sep 15 by Vim Project: more strict confirmation dialog (#15680)
+" 2024 Sep 19 by Vim Project: mf-selection highlight uses wrong pattern (#15700)
+" 2024 Sep 21 by Vim Project: remove extraneous closing bracket (#15718)
+" }}}
" Former Maintainer: Charles E Campbell
" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
@@ -54,11 +69,6 @@ if exists("s:needspatches")
endif
let g:loaded_netrw = "v173"
-if !exists("s:NOTE")
- let s:NOTE = 0
- let s:WARNING = 1
- let s:ERROR = 2
-endif
let s:keepcpo= &cpo
setl cpo&vim
@@ -96,7 +106,7 @@ fun! netrw#ErrorMsg(level,msg,errnum)
endif
" call Decho("level=".level,'~'.expand("<slnum>"))
- if g:netrw_use_errorwindow == 2 && (v:version > 802 || (v:version == 802 && has("patch486")))
+ if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
" use popup window
if type(a:msg) == 3
let msg = [level]+a:msg
@@ -212,6 +222,11 @@ if !exists("s:LONGLIST")
call s:NetrwInit("s:MAXLIST" ,4)
endif
+let s:NOTE = 0
+let s:WARNING = 1
+let s:ERROR = 2
+call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
+
" ---------------------------------------------------------------------
" Default option values: {{{2
let g:netrw_localcopycmdopt = ""
@@ -337,7 +352,6 @@ call s:NetrwInit("s:didstarstar",0)
call s:NetrwInit("g:netrw_dirhistcnt" , 0)
call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
call s:NetrwInit("g:netrw_dirhistmax" , 10)
-call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
call s:NetrwInit("g:netrw_fastbrowse" , 1)
call s:NetrwInit("g:netrw_ftp_browse_reject", '^total\s\+\d\+$\|^Trying\s\+\d\+.*$\|^KERBEROS_V\d rejected\|^Security extensions not\|No such file\|: connect to address [0-9a-fA-F:]*: No route to host$')
if !exists("g:netrw_ftp_list_cmd")
@@ -688,12 +702,11 @@ fun! netrw#Explore(indx,dosplit,style,...)
\ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
\ '~'.expand("<slnum>"))
if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
-" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">",'~'.expand("<slnum>"))
- call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
-" call Dret("netrw#Explore : returning from retry")
- return
-" else " Decho
-" call Decho("retry not needed",'~'.expand("<slnum>"))
+ let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
+ if a1 != a:1
+ call netrw#Explore(a:indx, a:dosplit, a:style, a1)
+ return
+ endif
endif
endif
@@ -704,7 +717,6 @@ fun! netrw#Explore(indx,dosplit,style,...)
" -or- file has been modified AND file not hidden when abandoned
" -or- Texplore used
if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
-" call Decho("case dosplit=".a:dosplit." modified=".&modified." a:style=".a:style.": dosplit or file has been modified",'~'.expand("<slnum>"))
call s:SaveWinVars()
let winsz= g:netrw_winsize
if a:indx > 0
@@ -712,57 +724,41 @@ fun! netrw#Explore(indx,dosplit,style,...)
endif
if a:style == 0 " Explore, Sexplore
-" call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
if winsz == 0|let winsz= ""|endif
- exe "noswapfile ".winsz."wincmd s"
-" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
+ exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
- elseif a:style == 1 "Explore!, Sexplore!
-" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
+ elseif a:style == 1 " Explore!, Sexplore!
let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
if winsz == 0|let winsz= ""|endif
- exe "keepalt noswapfile ".winsz."wincmd v"
-" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
+ exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
elseif a:style == 2 " Hexplore
-" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
if winsz == 0|let winsz= ""|endif
- exe "keepalt noswapfile bel ".winsz."wincmd s"
-" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
+ exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
elseif a:style == 3 " Hexplore!
-" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
if winsz == 0|let winsz= ""|endif
- exe "keepalt noswapfile abo ".winsz."wincmd s"
-" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
+ exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
elseif a:style == 4 " Vexplore
-" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
if winsz == 0|let winsz= ""|endif
- exe "keepalt noswapfile lefta ".winsz."wincmd v"
-" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
+ exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
elseif a:style == 5 " Vexplore!
-" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
if winsz == 0|let winsz= ""|endif
- exe "keepalt noswapfile rightb ".winsz."wincmd v"
-" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
+ exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
elseif a:style == 6 " Texplore
call s:SaveBufVars()
-" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
exe "keepalt tabnew ".fnameescape(curdir)
-" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
call s:RestoreBufVars()
endif
call s:RestoreWinVars()
-" else " Decho
-" call Decho("case a:dosplit=".a:dosplit." AND modified=".&modified." AND a:style=".a:style." is not 6",'~'.expand("<slnum>"))
endif
NetrwKeepj norm! 0
@@ -4188,7 +4184,7 @@ fun! s:NetrwGetBuffer(islocal,dirname)
endif
" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
if !bufexists(bufnum)
- call remove(s:netrwbuf,"NetrwTreeListing"])
+ call remove(s:netrwbuf,"NetrwTreeListing")
let bufnum= -1
endif
elseif bufnr("NetrwTreeListing") != -1
@@ -4446,7 +4442,15 @@ fun! s:NetrwGetWord()
call cursor(line("."),filestart+1)
NetrwKeepj norm! ma
endif
- let rega= @a
+
+ let dict={}
+ " save the unnamed register and register 0-9 and a
+ let dict.a=[getreg('a'), getregtype('a')]
+ for i in range(0, 9)
+ let dict[i] = [getreg(i), getregtype(i)]
+ endfor
+ let dict.unnamed = [getreg(''), getregtype('')]
+
let eofname= filestart + b:netrw_cpf + 1
if eofname <= col("$")
call cursor(line("."),filestart+b:netrw_cpf+1)
@@ -4454,8 +4458,10 @@ fun! s:NetrwGetWord()
else
NetrwKeepj norm! "ay$
endif
+
let dirname = @a
- let @a = rega
+ call s:RestoreRegister(dict)
+
" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
let dirname= substitute(dirname,'\s\+$','','e')
" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
@@ -5523,13 +5529,12 @@ endfun
" ---------------------------------------------------------------------
" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
fun! netrw#BrowseXVis()
-" call Dfunc("netrw#BrowseXVis()")
- let akeep = @a
+ let dict={}
+ let dict.a=[getreg('a'), getregtype('a')]
norm! gv"ay
let gxfile= @a
- let @a = akeep
+ call s:RestoreRegister(dict)
call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
-" call Dret("netrw#BrowseXVis")
endfun
" ---------------------------------------------------------------------
@@ -5681,6 +5686,9 @@ fun! s:NetrwEditFile(cmd,opt,fname)
exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
else
" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
+ if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
+ call setbufvar(bufname('%'), '&bufhidden', 'hide')
+ endif
exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
endif
" call Dret("s:NetrwEditFile")
@@ -5751,16 +5759,20 @@ fun! s:NetrwGlob(direntry,expr,pare)
let filelist= w:netrw_treedict[a:direntry]
endif
let w:netrw_liststyle= keep_liststyle
- elseif v:version > 704 || (v:version == 704 && has("patch656"))
- let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
- if a:pare
- let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
- endif
else
- let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
- if a:pare
- let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
- endif
+ let path= s:ComposePath(fnameescape(a:direntry),a:expr)
+ if has("win32")
+ " escape [ so it is not detected as wildcard character, see :h wildcard
+ let path= substitute(path, '[', '[[]', 'g')
+ endif
+ if v:version > 704 || (v:version == 704 && has("patch656"))
+ let filelist= glob(path,0,1,1)
+ else
+ let filelist= glob(path,0,1)
+ endif
+ if a:pare
+ let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
+ endif
endif
" call Dret("s:NetrwGlob ".string(filelist))
return filelist
@@ -6817,11 +6829,7 @@ fun! s:NetrwMarkFile(islocal,fname)
let ykeep = @@
let curbufnr= bufnr("%")
- if a:fname =~ '^\a'
- let leader= '\<'
- else
- let leader= ''
- endif
+ let leader= '\%(^\|\s\)\zs'
if a:fname =~ '\a$'
let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
else
@@ -7084,7 +7092,7 @@ fun! s:NetrwMarkFileCopy(islocal,...)
endif
" copy marked files while within the same directory (ie. allow renaming)
- if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
+ if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
" only one marked file
" call Decho("case: only one marked file",'~'.expand("<slnum>"))
@@ -7161,7 +7169,7 @@ fun! s:NetrwMarkFileCopy(islocal,...)
" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
if v:shell_error != 0
- if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
+ if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
call netrw#ErrorMsg(s:ERROR,"copy failed; perhaps due to vim's current directory<".getcwd()."> not matching netrw's (".b:netrw_curdir.") (see :help netrw-cd)",101)
else
call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
@@ -7430,7 +7438,13 @@ fun! s:NetrwMarkFileExe(islocal,enbloc)
NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
break
else
- echo ret
+ if ret !=# ''
+ echo "\n"
+ " skip trailing new line
+ echo ret[0:-2]
+ else
+ echo ret
+ endif
endif
endfor
@@ -9669,7 +9683,13 @@ fun! s:NetrwWideListing()
" fpl: filenames per line
" fpc: filenames per column
setl ma noro
- let keepa= @a
+ let dict={}
+ " save the unnamed register and register 0-9 and a
+ let dict.a=[getreg('a'), getregtype('a')]
+ for i in range(0, 9)
+ let dict[i] = [getreg(i), getregtype(i)]
+ endfor
+ let dict.unnamed = [getreg(''), getregtype('')]
" call Decho("setl ma noro",'~'.expand("<slnum>"))
let b:netrw_cpf= 0
if line("$") >= w:netrw_bannercnt
@@ -9677,7 +9697,8 @@ fun! s:NetrwWideListing()
exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
NetrwKeepj call histdel("/",-1)
else
- let @a= keepa
+ " restore stored registers
+ call s:RestoreRegister(dict)
" call Dret("NetrwWideListing")
return
endif
@@ -9719,7 +9740,7 @@ fun! s:NetrwWideListing()
exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
exe "setl ".g:netrw_bufsettings
- let @a= keepa
+ call s:RestoreRegister(dict)
" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
" call Dret("NetrwWideListing")
return
@@ -9731,7 +9752,6 @@ fun! s:NetrwWideListing()
sil! nunmap <buffer> b
endif
endif
-
endfun
" ---------------------------------------------------------------------
@@ -10052,7 +10072,8 @@ fun! s:SetupNetrwStatusLine(statline)
endif
" set up User9 highlighting as needed
- let keepa= @a
+ let dict={}
+ let dict.a=[getreg('a'), getregtype('a')]
redir @a
try
hi User9
@@ -10064,7 +10085,7 @@ fun! s:SetupNetrwStatusLine(statline)
endif
endtry
redir END
- let @a= keepa
+ call s:RestoreRegister(dict)
endif
" set up status line (may use User9 highlighting)
@@ -11257,7 +11278,7 @@ fun! s:NetrwLocalRm(path) range
let ok= s:NetrwLocalRmFile(a:path,fname,all)
if ok =~# 'q\%[uit]' || ok == "no"
break
- elseif ok =~# 'a\%[ll]'
+ elseif ok =~# '^a\%[ll]$'
let all= 1
endif
endfor
@@ -11286,7 +11307,7 @@ fun! s:NetrwLocalRm(path) range
let ok= s:NetrwLocalRmFile(a:path,curword,all)
if ok =~# 'q\%[uit]' || ok == "no"
break
- elseif ok =~# 'a\%[ll]'
+ elseif ok =~# '^a\%[ll]$'
let all= 1
endif
let ctr= ctr + 1
@@ -11315,7 +11336,7 @@ fun! s:NetrwLocalRmFile(path,fname,all)
let all= a:all
let ok = ""
NetrwKeepj norm! 0
- let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
+ let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
@@ -11324,7 +11345,7 @@ fun! s:NetrwLocalRmFile(path,fname,all)
if !all
echohl Statement
call inputsave()
- let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
+ let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
call inputrestore()
echohl NONE
if ok == ""
@@ -11333,12 +11354,12 @@ fun! s:NetrwLocalRmFile(path,fname,all)
" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
- if ok =~# 'a\%[ll]'
+ if ok =~# '^a\%[ll]$'
let all= 1
endif
endif
- if all || ok =~# 'y\%[es]' || ok == ""
+ if all || ok =~# '^y\%[es]$' || ok == ""
let ret= s:NetrwDelete(rmfile)
" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
endif
@@ -11348,19 +11369,19 @@ fun! s:NetrwLocalRmFile(path,fname,all)
if !all
echohl Statement
call inputsave()
- let ok= input("Confirm *recursive* deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
+ let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
call inputrestore()
let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
if ok == ""
let ok="no"
endif
- if ok =~# 'a\%[ll]'
+ if ok =~# '^a\%[ll]$'
let all= 1
endif
endif
let rmfile= substitute(rmfile,'[\/]$','','e')
- if all || ok =~# 'y\%[es]' || ok == ""
+ if all || ok =~# '^y\%[es]$' || ok == ""
if delete(rmfile,"rf")
call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
endif
@@ -11508,6 +11529,13 @@ fun! netrw#WinPath(path)
endfun
" ---------------------------------------------------------------------
+" s:StripTrailingSlash: removes trailing slashes from a path {{{2
+fun! s:StripTrailingSlash(path)
+ " remove trailing slash
+ return substitute(a:path, '[/\\]$', '', 'g')
+endfun
+
+" ---------------------------------------------------------------------
" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
" cb : bl2mf=0 add marked files to buffer list
" cB : bl2mf=1 use bufferlist to mark files
@@ -11874,6 +11902,16 @@ fun! s:RestoreCursorline()
" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
endfun
+" s:RestoreRegister: restores all registers given in the dict {{{2
+fun! s:RestoreRegister(dict)
+ for [key, val] in items(a:dict)
+ if key == 'unnamed'
+ let key = ''
+ endif
+ call setreg(key, val[0], val[1])
+ endfor
+endfun
+
" ---------------------------------------------------------------------
" s:NetrwDelete: Deletes a file. {{{2
" Uses Steve Hall's idea to insure that Windows paths stay
@@ -12681,54 +12719,3 @@ unlet s:keepcpo
" Modelines: {{{1
" ===============
" vim:ts=8 fdm=marker
-" doing autoload/netrw.vim version v172g ~57
-" varname<g:netrw_dirhistcnt> value=0 ~1
-" varname<s:THINLIST> value=0 ~1
-" varname<s:LONGLIST> value=1 ~1
-" varname<s:WIDELIST> value=2 ~1
-" varname<s:TREELIST> value=3 ~1
-" varname<s:MAXLIST> value=4 ~1
-" varname<g:netrw_use_errorwindow> value=2 ~1
-" varname<g:netrw_http_xcmd> value=-q -O ~1
-" varname<g:netrw_http_put_cmd> value=curl -T ~1
-" varname<g:netrw_keepj> value=keepj ~1
-" varname<g:netrw_rcp_cmd> value=rcp ~1
-" varname<g:netrw_rsync_cmd> value=rsync ~1
-" varname<g:netrw_rsync_sep> value=/ ~1
-" varname<g:netrw_scp_cmd> value=scp -q ~1
-" varname<g:netrw_sftp_cmd> value=sftp ~1
-" varname<g:netrw_ssh_cmd> value=ssh ~1
-" varname<g:netrw_alto> value=0 ~1
-" varname<g:netrw_altv> value=1 ~1
-" varname<g:netrw_banner> value=1 ~1
-" varname<g:netrw_browse_split> value=0 ~1
-" varname<g:netrw_bufsettings> value=noma nomod nonu nobl nowrap ro nornu ~1
-" varname<g:netrw_chgwin> value=-1 ~1
-" varname<g:netrw_clipboard> value=1 ~1
-" varname<g:netrw_compress> value=gzip ~1
-" varname<g:netrw_ctags> value=ctags ~1
-" varname<g:netrw_cursor> value=2 ~1
-" (netrw) COMBAK: cuc=0 cul=0 initialization of s:netrw_cu[cl]
-" varname<g:netrw_cygdrive> value=/cygdrive ~1
-" varname<s:didstarstar> value=0 ~1
-" varname<g:netrw_dirhistcnt> value=0 ~1
-" varname<g:netrw_decompress> value={ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" } ~1
-" varname<g:netrw_dirhistmax> value=10 ~1
-" varname<g:netrw_errorlvl> value=0 ~1
-" varname<g:netrw_fastbrowse> value=1 ~1
-" varname<g:netrw_ftp_browse_reject> value=^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$ ~1
-" varname<g:netrw_ftpmode> value=binary ~1
-" varname<g:netrw_hide> value=1 ~1
-" varname<g:netrw_keepdir> value=1 ~1
-" varname<g:netrw_list_hide> value= ~1
-" varname<g:netrw_localmkdir> value=mkdir ~1
-" varname<g:netrw_remote_mkdir> value=mkdir ~1
-" varname<g:netrw_liststyle> value=0 ~1
-" varname<g:netrw_markfileesc> value=*./[\~ ~1
-" varname<g:netrw_maxfilenamelen> value=32 ~1
-" varname<g:netrw_menu> value=1 ~1
-" varname<g:netrw_mkdir_cmd> value=ssh USEPORT HOSTNAME mkdir ~1
-" varname<g:netrw_mousemaps> value=1 ~1
-" varname<g:netrw_retmap> value=0 ~1
-" varname<g:netrw_chgperm> value=chmod PERM FILENAME ~1
-" varname<g:netrw_preview> value=0 ~1
diff --git a/runtime/autoload/provider/clipboard.vim b/runtime/autoload/provider/clipboard.vim
index 82e0953196..58d3d4550f 100644
--- a/runtime/autoload/provider/clipboard.vim
+++ b/runtime/autoload/provider/clipboard.vim
@@ -140,6 +140,18 @@ function! provider#clipboard#Executable() abort
let s:copy['*'] = s:copy['+']
let s:paste['*'] = s:paste['+']
return 'win32yank'
+ elseif executable('putclip') && executable('getclip')
+ let s:copy['+'] = ['putclip']
+ let s:paste['+'] = ['getclip']
+ let s:copy['*'] = s:copy['+']
+ let s:paste['*'] = s:paste['+']
+ return 'putclip'
+ elseif executable('clip') && executable('powershell')
+ let s:copy['+'] = ['clip']
+ let s:paste['+'] = ['powershell', '-NoProfile', '-NoLogo', '-Command', 'Get-Clipboard']
+ let s:copy['*'] = s:copy['+']
+ let s:paste['*'] = s:paste['+']
+ return 'clip'
elseif executable('termux-clipboard-set')
let s:copy['+'] = ['termux-clipboard-set']
let s:paste['+'] = ['termux-clipboard-get']
diff --git a/runtime/autoload/shada.vim b/runtime/autoload/shada.vim
index ae718ad2e7..4753973196 100644
--- a/runtime/autoload/shada.vim
+++ b/runtime/autoload/shada.vim
@@ -230,7 +230,7 @@ function s:shada_check_type(type, val) abort
return 0
elseif a:type is# 'bin'
" Binary string without zero bytes
- if type isnot# 'binary'
+ if type isnot# 'string'
return 'Expected binary string'
elseif (type(a:val) == type({})
\&& !empty(filter(copy(a:val._VAL), 'stridx(v:val, "\n") != -1')))
@@ -247,7 +247,7 @@ function s:shada_check_type(type, val) abort
if type isnot# 'array'
return 'Expected array value'
elseif !empty(filter(copy(type(a:val) == type({}) ? a:val._VAL : a:val),
- \'msgpack#type(v:val) isnot# "binary"'))
+ \'msgpack#type(v:val) isnot# "string"'))
return 'Expected array of binary strings'
else
for element in (type(a:val) == type({}) ? a:val._VAL : a:val)
diff --git a/runtime/autoload/typst.vim b/runtime/autoload/typst.vim
new file mode 100644
index 0000000000..55edd23928
--- /dev/null
+++ b/runtime/autoload/typst.vim
@@ -0,0 +1,50 @@
+" Language: Typst
+" Maintainer: Gregory Anders
+" Last Change: 2024-07-14
+" Based on: https://github.com/kaarmu/typst.vim
+
+function! typst#indentexpr() abort
+ let l:lnum = v:lnum
+ let s:sw = shiftwidth()
+
+ let [l:plnum, l:pline] = s:get_prev_nonblank(l:lnum - 1)
+ if l:plnum == 0 | return 0 | endif
+
+ let l:line = getline(l:lnum)
+ let l:ind = indent(l:plnum)
+
+ let l:synname = synIDattr(synID(l:lnum, 1, 1), 'name')
+
+ " Use last indent for block comments
+ if l:synname == 'typstCommentBlock'
+ return l:ind
+ endif
+
+ if l:pline =~ '\v[{[(]\s*$'
+ let l:ind += s:sw
+ endif
+
+ if l:line =~ '\v^\s*[}\])]'
+ let l:ind -= s:sw
+ endif
+
+ return l:ind
+endfunction
+
+" Gets the previous non-blank line that is not a comment.
+function! s:get_prev_nonblank(lnum) abort
+ let l:lnum = prevnonblank(a:lnum)
+ let l:line = getline(l:lnum)
+
+ while l:lnum > 0 && l:line =~ '^\s*//'
+ let l:lnum = prevnonblank(l:lnum - 1)
+ let l:line = getline(l:lnum)
+ endwhile
+
+ return [l:lnum, s:remove_comments(l:line)]
+endfunction
+
+" Removes comments from the given line.
+function! s:remove_comments(line) abort
+ return substitute(a:line, '\s*//.*', '', '')
+endfunction
diff --git a/runtime/autoload/zip.vim b/runtime/autoload/zip.vim
index c0034f8a7a..172de98d36 100644
--- a/runtime/autoload/zip.vim
+++ b/runtime/autoload/zip.vim
@@ -1,36 +1,38 @@
" zip.vim: Handles browsing zipfiles
-" AUTOLOAD PORTION
-" Date: Mar 12, 2023
-" Version: 33
+" AUTOLOAD PORTION
+" Date: 2024 Aug 21
+" Version: 34
" Maintainer: This runtime file is looking for a new maintainer.
" Former Maintainer: Charles E Campbell
+" Last Change:
+" 2024 Jun 16 by Vim Project: handle whitespace on Windows properly (#14998)
+" 2024 Jul 23 by Vim Project: fix 'x' command
+" 2024 Jul 24 by Vim Project: use delete() function
+" 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
+" 2024 Aug 18 by Vim Project: correctly handle special globbing chars
+" 2024 Aug 21 by Vim Project: simplify condition to detect MS-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,
-" with or without modifications, provided that this copyright
-" notice is copied with it. Like anything else that's free,
-" zip.vim and zipPlugin.vim are provided *as is* and comes with
-" no warranty of any kind, either expressed or implied. By using
-" this plugin, you agree that in no event will the copyright
-" holder be liable for any damages resulting from the use
-" of this software.
-"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
+" Copyright: Copyright (C) 2005-2019 Charles E. Campbell {{{1
+" Permission is hereby granted to use and distribute this code,
+" with or without modifications, provided that this copyright
+" notice is copied with it. Like anything else that's free,
+" zip.vim and zipPlugin.vim are provided *as is* and comes with
+" no warranty of any kind, either expressed or implied. By using
+" this plugin, you agree that in no event will the copyright
+" holder be liable for any damages resulting from the use
+" of this software.
" ---------------------------------------------------------------------
" Load Once: {{{1
if &cp || exists("g:loaded_zip")
finish
endif
-let g:loaded_zip= "v33"
-if v:version < 702
- echohl WarningMsg
- echo "***warning*** this version of zip needs vim 7.2 or later"
- echohl Normal
- finish
-endif
+let g:loaded_zip= "v34"
let s:keepcpo= &cpo
set cpo&vim
-"DechoTabOn
let s:zipfile_escape = ' ?&;\'
let s:ERROR = 2
@@ -58,8 +60,27 @@ 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
+" sanity checks
+if !executable(g:zip_unzipcmd)
+ call s:Mess('Error', "***error*** (zip#Browse) unzip not available on your system")
+ 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
@@ -70,47 +91,28 @@ endif
" ---------------------------------------------------------------------
" zip#Browse: {{{2
fun! zip#Browse(zipfile)
-" call Dfunc("zip#Browse(zipfile<".a:zipfile.">)")
- " sanity check: insure that the zipfile has "PK" as its first two letters
- " (zipped files have a leading PK as a "magic cookie")
- if !filereadable(a:zipfile) || readfile(a:zipfile, "", 1)[0] !~ '^PK'
- exe "noswapfile noautocmd noswapfile e ".fnameescape(a:zipfile)
-" call Dret("zip#Browse : not a zipfile<".a:zipfile.">")
+ " sanity check: ensure that the zipfile has "PK" as its first two letters
+ " (zip files have a leading PK as a "magic cookie")
+ if filereadable(a:zipfile) && readblob(a:zipfile, 0, 2) != 0z50.4B
+ exe "noswapfile noautocmd e " .. fnameescape(a:zipfile)
return
-" else " Decho
-" call Decho("zip#Browse: a:zipfile<".a:zipfile."> passed PK test - it's a zip file")
endif
- let repkeep= &report
- set report=10
+ let dict = s:SetSaneOpts()
+ defer s:RestoreOpts(dict)
" 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 | echo "***error*** (zip#Browse) unzip not available on your system"
-" call inputsave()|call input("Press <cr> to continue")|call inputrestore()
- let &report= repkeep
-" call Dret("zip#Browse")
+ call s:Mess('Error', "***error*** (zip#Browse) unzip not available on your system")
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 | echo "***error*** (zip#Browse) File not readable<".a:zipfile.">" | echohl None
-" call inputsave()|call input("Press <cr> to continue")|call inputrestore()
+ call s:Mess('Error', "***error*** (zip#Browse) File not readable <".a:zipfile.">")
endif
- let &report= repkeep
-" call Dret("zip#Browse : file<".a:zipfile."> not readable")
return
endif
-" call Decho("passed sanity checks")
if &ma != 1
set ma
endif
@@ -135,19 +137,15 @@ fun! zip#Browse(zipfile)
\ '" Select a file with cursor and press ENTER'])
keepj $
-" call Decho("exe silent r! ".g:zip_unzipcmd." -l -- ".s:Escape(a:zipfile,1))
- exe "keepj sil! r! ".g:zip_unzipcmd." -Z -1 -- ".s:Escape(a:zipfile,1)
+ 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
-" call inputsave()|call input("Press <cr> to continue")|call inputrestore()
+ 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
exe "keepj r ".fnameescape(a:zipfile)
let &ei= eikeep
keepj 1d
-" call Dret("zip#Browse")
return
endif
@@ -159,64 +157,46 @@ fun! zip#Browse(zipfile)
noremap <silent> <buffer> <leftmouse> <leftmouse>:call <SID>ZipBrowseSelect()<cr>
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 dict = s:SetSaneOpts()
+ defer s:RestoreOpts(dict)
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 <cr> to continue")|call inputrestore()
- let &report= repkeep
-" call Dret("ZipBrowseSelect")
+ call s:Mess('Error', "***error*** (zip#Browse) Please specify a file, not a directory")
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
" ---------------------------------------------------------------------
" zip#Read: {{{2
fun! zip#Read(fname,mode)
-" call Dfunc("zip#Read(fname<".a:fname.">,mode=".a:mode.")")
- let repkeep= &report
- set report=10
+ let dict = s:SetSaneOpts()
+ defer s:RestoreOpts(dict)
if has("unix")
let zipfile = substitute(a:fname,'zipfile://\(.\{-}\)::[^\\].*$','\1','')
@@ -224,28 +204,20 @@ fun! zip#Read(fname,mode)
else
let zipfile = substitute(a:fname,'^.\{-}zipfile://\(.\{-}\)::[^\\].*$','\1','')
let fname = substitute(a:fname,'^.\{-}zipfile://.\{-}::\([^\\].*\)$','\1','')
- let fname = substitute(fname, '[', '[[]', 'g')
endif
-" call Decho("zipfile<".zipfile.">")
-" call Decho("fname <".fname.">")
+ let fname = fname->substitute('[', '[[]', 'g')->escape('?*\\')
" 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
-" call inputsave()|call input("Press <cr> to continue")|call inputrestore()
- let &report= repkeep
-" call Dret("zip#Write")
+ call s:Mess('Error', "***error*** (zip#Read) sorry, your system doesn't appear to have the ".g:zip_unzipcmd." program")
return
endif
" the following code does much the same thing as
- " exe "keepj sil! r! ".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1)
+ " exe "keepj sil! r! ".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fname,1)
" but allows zipfile://... entries in quickfix lists
let temp = tempname()
-" call Decho("using temp file<".temp.">")
let fn = expand('%:p')
- exe "sil! !".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1).' > '.temp
-" call Decho("exe sil! !".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1).' > '.temp)
+ exe "sil !".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fname,1).' > '.temp
sil exe 'keepalt file '.temp
sil keepj e!
sil exe 'keepalt file '.fnameescape(fn)
@@ -254,62 +226,44 @@ fun! zip#Read(fname,mode)
filetype detect
" cleanup
- " keepj 0d " used to be needed for the ...r! ... method
set nomod
- let &report= repkeep
-" call Dret("zip#Read")
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
+ let dict = s:SetSaneOpts()
+ defer s:RestoreOpts(dict)
" 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
-" call inputsave()|call input("Press <cr> to continue")|call inputrestore()
- let &report= repkeep
-" call Dret("zip#Write")
+ call s:Mess('Error', "***error*** (zip#Write) sorry, your system doesn't appear to have the ".g:zip_zipcmd." program")
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 <cr> to continue")|call inputrestore()
- let &report= repkeep
-" call Dret("zip#Write")
+ call s:Mess('Error', "***error*** (zip#Write) sorry, mkdir() doesn't work on your system")
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_")
- call s:Rmdir("_ZIPVIM_")
+ call delete("_ZIPVIM_", "rf")
endif
call mkdir("_ZIPVIM_")
cd _ZIPVIM_
-" call Decho("current directory now: ".getcwd())
if has("unix")
let zipfile = substitute(a:fname,'zipfile://\(.\{-}\)::[^\\].*$','\1','')
@@ -318,21 +272,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")
@@ -343,17 +293,13 @@ 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 <cr> to continue")|call inputrestore()
+ 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
let netzipfile= s:zipfile_{winnr()}
-" call Decho("handle writing <".zipfile."> across network as <".netzipfile.">")
1split|enew
let binkeep= &binary
let eikeep = &ei
@@ -365,64 +311,63 @@ fun! zip#Write(fname)
q!
unlet s:zipfile_{winnr()}
endif
-
+
" cleanup and restore current directory
cd ..
- call s:Rmdir("_ZIPVIM_")
+ call delete("_ZIPVIM_", "rf")
call s:ChgDir(curdir,s:WARNING,"(zip#Write) unable to return to ".curdir."!")
- call s:Rmdir(tmpdir)
+ call delete(tmpdir, "rf")
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 dict = s:SetSaneOpts()
+ defer s:RestoreOpts(dict)
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")
+ call s:Mess('Error', "***error*** (zip#Extract) Please specify a file, not a directory")
return
endif
+ if filereadable(fname)
+ call s:Mess('Error', "***error*** (zip#Extract) <" .. fname .."> already exists in directory, not overwriting!")
+ return
+ endif
+ let target = fname->substitute('\[', '[[]', 'g')
+ if &shell =~ 'cmd' && has("win32")
+ let target = target
+ \ ->substitute('[?*]', '[&]', 'g')
+ \ ->substitute('[\\]', '?', 'g')
+ \ ->shellescape()
+ " there cannot be a file name with '\' in its name, unzip replaces it by _
+ let fname = fname->substitute('[\\?*]', '_', 'g')
+ else
+ let target = target->escape('*?\\')->shellescape()
+ endif
" extract the file mentioned under the cursor
-" call Decho("system(".g:zip_extractcmd." ".shellescape(b:zipfile)." ".shellescape(shell).")")
- call system(g:zip_extractcmd." ".shellescape(b:zipfile)." ".shellescape(shell))
-" call Decho("zipfile<".b:zipfile.">")
+ call system($"{g:zip_extractcmd} -o {shellescape(b:zipfile)} {target}")
if v:shell_error != 0
- echohl Error | echo "***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 | echo "***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
- echo "***note*** successfully extracted ".fname
+ echomsg "***note*** successfully extracted ".fname
endif
- " restore option
- let &report= repkeep
-
-" call Dret("zip#Extract")
endfun
" ---------------------------------------------------------------------
" s:Escape: {{{2
fun! s:Escape(fname,isfilt)
-" call Dfunc("QuoteFileDir(fname<".a:fname."> isfilt=".a:isfilt.")")
if exists("*shellescape")
if a:isfilt
let qnameq= shellescape(a:fname,1)
@@ -432,45 +377,48 @@ fun! s:Escape(fname,isfilt)
else
let qnameq= g:zip_shq.escape(a:fname,g:zip_shq).g:zip_shq
endif
-" call Dret("QuoteFileDir <".qnameq.">")
return qnameq
endfun
" ---------------------------------------------------------------------
-" ChgDir: {{{2
+" s: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/
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
+ call s:Mess("WarningMsg", "***warning*** ".a:errmsg)
elseif a:errlvl == s:ERROR
- echohl Error | echo "***error*** ".a:errmsg | echohl NONE
+ call s:Mess("Error", "***error*** ".a:errmsg)
endif
-" call inputsave()|call input("Press <cr> to continue")|call inputrestore()
-" call Dret("ChgDir 1")
return 1
endtry
-" call Dret("ChgDir 0")
return 0
endfun
" ---------------------------------------------------------------------
-" s:Rmdir: {{{2
-fun! s:Rmdir(fname)
-" call Dfunc("Rmdir(fname<".a:fname.">)")
- if (has("win32") || has("win95") || has("win64") || has("win16")) && &shell !~? 'sh$'
- call system("rmdir /S/Q ".s:Escape(a:fname,0))
- else
- call system("/bin/rm -rf ".s:Escape(a:fname,0))
- endif
-" call Dret("Rmdir")
+" 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
" ------------------------------------------------------------------------