mirror of
https://github.com/amix/vimrc
synced 2025-07-09 10:45:00 +08:00
Updated plugins
This commit is contained in:
@ -223,24 +223,7 @@ function! s:_get_cflags(ft, ck, opts) abort " {{{2
|
||||
|
||||
" check if the user manually set some cflags
|
||||
let b_cflags = s:_get_checker_var('b', a:ft, a:ck, 'cflags', '')
|
||||
if b_cflags ==# ''
|
||||
if a:ft ==# 'c' || a:ft ==# 'cpp'
|
||||
" check whether to search for include files at all
|
||||
if !s:_get_checker_var('g', a:ft, a:ck, 'no_include_search', 0)
|
||||
" refresh the include file search if desired
|
||||
if s:_get_checker_var('g', a:ft, a:ck, 'auto_refresh_includes', 0)
|
||||
let flags .= ' ' . s:_search_headers()
|
||||
else
|
||||
" search for header includes if not cached already
|
||||
if !exists('b:syntastic_' . a:ft . '_includes')
|
||||
let b:syntastic_{a:ft}_includes = s:_search_headers()
|
||||
endif
|
||||
let flags .= ' ' . b:syntastic_{a:ft}_includes
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
else
|
||||
" user-defined cflags
|
||||
if b_cflags !=# ''
|
||||
let flags .= ' ' . b_cflags
|
||||
endif
|
||||
|
||||
@ -248,6 +231,19 @@ function! s:_get_cflags(ft, ck, opts) abort " {{{2
|
||||
let config_file = s:_get_checker_var('g', a:ft, a:ck, 'config_file', '.syntastic_' . a:ft . '_config')
|
||||
let flags .= ' ' . syntastic#c#ReadConfig(config_file)
|
||||
|
||||
if b_cflags ==# '' && (a:ft ==# 'c' || a:ft ==# 'cpp') && !s:_get_checker_var('g', a:ft, a:ck, 'no_include_search', 0)
|
||||
" refresh the include file search if desired
|
||||
if s:_get_checker_var('g', a:ft, a:ck, 'auto_refresh_includes', 0)
|
||||
let flags .= ' ' . s:_search_headers()
|
||||
else
|
||||
" search for header includes if not cached already
|
||||
if !exists('b:syntastic_' . a:ft . '_includes')
|
||||
let b:syntastic_{a:ft}_includes = s:_search_headers()
|
||||
endif
|
||||
let flags .= ' ' . b:syntastic_{a:ft}_includes
|
||||
endif
|
||||
endif
|
||||
|
||||
return flags
|
||||
endfunction " }}}2
|
||||
|
||||
|
@ -59,27 +59,51 @@ function! syntastic#preprocess#cppcheck(errors) abort " {{{2
|
||||
return map(copy(a:errors), 'substitute(v:val, ''\v^\[[^]]+\]\zs( -\> \[[^]]+\])+\ze:'', "", "")')
|
||||
endfunction " }}}2
|
||||
|
||||
" @vimlint(EVL102, 1, l:true)
|
||||
" @vimlint(EVL102, 1, l:false)
|
||||
" @vimlint(EVL102, 1, l:null)
|
||||
function! syntastic#preprocess#flow(errors) abort " {{{2
|
||||
" JSON artifacts
|
||||
let true = 1
|
||||
let false = 0
|
||||
let null = ''
|
||||
function! syntastic#preprocess#dockerfile_lint(errors) abort " {{{2
|
||||
let out = []
|
||||
let json = s:_decode_JSON(join(a:errors, ''))
|
||||
|
||||
if type(json) == type({})
|
||||
try
|
||||
let data = json['error']['data'] + json['warn']['data'] + json['info']['data']
|
||||
for e in data
|
||||
let type = toupper(e['level'][0])
|
||||
if type ==# 'I'
|
||||
let type = 'W'
|
||||
let style = 1
|
||||
else
|
||||
let style = 0
|
||||
endif
|
||||
|
||||
let line = get(e, 'line', 1)
|
||||
let message = e['message']
|
||||
if has_key(e, 'description') && e['description'] !=# 'None'
|
||||
let message = message . '. ' . e['description']
|
||||
endif
|
||||
|
||||
let msg =
|
||||
\ type . ':' .
|
||||
\ style . ':' .
|
||||
\ line . ':' .
|
||||
\ message
|
||||
call add(out, msg)
|
||||
endfor
|
||||
catch /\m^Vim\%((\a\+)\)\=:E716/
|
||||
call syntastic#log#warn('checker dockerfile/dockerfile_lint: unrecognized error format')
|
||||
let out = []
|
||||
endtry
|
||||
else
|
||||
call syntastic#log#warn('checker dockerfile/dockerfile_lint: unrecognized error format')
|
||||
endif
|
||||
return out
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#preprocess#flow(errors) abort " {{{2
|
||||
let idx = 0
|
||||
while idx < len(a:errors) && a:errors[idx][0] != '{'
|
||||
while idx < len(a:errors) && a:errors[idx][0] !=# '{'
|
||||
let idx += 1
|
||||
endwhile
|
||||
|
||||
" A hat tip to Marc Weber for this trick
|
||||
" http://stackoverflow.com/questions/17751186/iterating-over-a-string-in-vimscript-or-parse-a-json-file/19105763#19105763
|
||||
try
|
||||
let errs = eval(join(a:errors[idx :], ''))
|
||||
catch
|
||||
let errs = {}
|
||||
endtry
|
||||
let errs = s:_decode_JSON(join(a:errors[idx :], ''))
|
||||
|
||||
let out = []
|
||||
if type(errs) == type({}) && has_key(errs, 'errors') && type(errs['errors']) == type([])
|
||||
@ -108,29 +132,26 @@ function! syntastic#preprocess#flow(errors) abort " {{{2
|
||||
|
||||
call add(out, msg)
|
||||
catch /\m^Vim\%((\a\+)\)\=:E716/
|
||||
call syntastic#log#warn('checker javascript/flow: unknown error format')
|
||||
call syntastic#log#warn('checker javascript/flow: unrecognized error format')
|
||||
let out = []
|
||||
break
|
||||
endtry
|
||||
else
|
||||
call syntastic#log#warn('checker javascript/flow: unknown error format')
|
||||
call syntastic#log#warn('checker javascript/flow: unrecognized error format')
|
||||
let out = []
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
else
|
||||
call syntastic#log#warn('checker javascript/flow: unknown error format')
|
||||
call syntastic#log#warn('checker javascript/flow: unrecognized error format')
|
||||
endif
|
||||
|
||||
return out
|
||||
endfunction " }}}2
|
||||
" @vimlint(EVL102, 0, l:true)
|
||||
" @vimlint(EVL102, 0, l:false)
|
||||
" @vimlint(EVL102, 0, l:null)
|
||||
|
||||
function! syntastic#preprocess#iconv(errors) abort " {{{2
|
||||
return
|
||||
\ (has('iconv') || has('iconv/dyn')) && &encoding !=# '' && &encoding !=# 'utf-8' ?
|
||||
\ has('iconv') && &encoding !=# '' && &encoding !=# 'utf-8' ?
|
||||
\ map(a:errors, 'iconv(v:val, "utf-8", &encoding)') :
|
||||
\ a:errors
|
||||
endfunction " }}}2
|
||||
@ -152,22 +173,8 @@ function! syntastic#preprocess#perl(errors) abort " {{{2
|
||||
return syntastic#util#unique(out)
|
||||
endfunction " }}}2
|
||||
|
||||
" @vimlint(EVL102, 1, l:true)
|
||||
" @vimlint(EVL102, 1, l:false)
|
||||
" @vimlint(EVL102, 1, l:null)
|
||||
function! syntastic#preprocess#prospector(errors) abort " {{{2
|
||||
" JSON artifacts
|
||||
let true = 1
|
||||
let false = 0
|
||||
let null = ''
|
||||
|
||||
" A hat tip to Marc Weber for this trick
|
||||
" http://stackoverflow.com/questions/17751186/iterating-over-a-string-in-vimscript-or-parse-a-json-file/19105763#19105763
|
||||
try
|
||||
let errs = eval(join(a:errors, ''))
|
||||
catch
|
||||
let errs = {}
|
||||
endtry
|
||||
let errs = s:_decode_JSON(join(a:errors, ''))
|
||||
|
||||
let out = []
|
||||
if type(errs) == type({}) && has_key(errs, 'messages')
|
||||
@ -189,26 +196,23 @@ function! syntastic#preprocess#prospector(errors) abort " {{{2
|
||||
|
||||
call add(out, msg)
|
||||
catch /\m^Vim\%((\a\+)\)\=:E716/
|
||||
call syntastic#log#warn('checker python/prospector: unknown error format')
|
||||
call syntastic#log#warn('checker python/prospector: unrecognized error format')
|
||||
let out = []
|
||||
break
|
||||
endtry
|
||||
else
|
||||
call syntastic#log#warn('checker python/prospector: unknown error format')
|
||||
call syntastic#log#warn('checker python/prospector: unrecognized error format')
|
||||
let out = []
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
else
|
||||
call syntastic#log#warn('checker python/prospector: unknown error format')
|
||||
call syntastic#log#warn('checker python/prospector: unrecognized error format')
|
||||
endif
|
||||
endif
|
||||
|
||||
return out
|
||||
endfunction " }}}2
|
||||
" @vimlint(EVL102, 0, l:true)
|
||||
" @vimlint(EVL102, 0, l:false)
|
||||
" @vimlint(EVL102, 0, l:null)
|
||||
|
||||
function! syntastic#preprocess#rparse(errors) abort " {{{2
|
||||
let errlist = copy(a:errors)
|
||||
@ -249,6 +253,42 @@ function! syntastic#preprocess#rparse(errors) abort " {{{2
|
||||
return out
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#preprocess#stylelint(errors) abort " {{{2
|
||||
let out = []
|
||||
|
||||
" CssSyntaxError: /path/to/file.css:2:11: Missed semicolon
|
||||
let parts = matchlist(a:errors[0], '\v^CssSyntaxError: (.{-1,}):(\d+):(\d+): (.+)')
|
||||
if len(parts) > 4
|
||||
call add(out, 'E:' . join(parts[1:4], ':'))
|
||||
else
|
||||
let errs = s:_decode_JSON(join(a:errors, ''))
|
||||
|
||||
let out = []
|
||||
if type(errs) == type([]) && len(errs) == 1 && type(errs[0]) == type({}) &&
|
||||
\ has_key(errs[0], 'source') && has_key(errs[0], 'warnings') && type(errs[0]['warnings']) == type([])
|
||||
|
||||
for e in errs[0]['warnings']
|
||||
try
|
||||
let msg =
|
||||
\ ['W', 'E'][e['severity']-1] . ':' .
|
||||
\ errs[0]['source'] . ':' .
|
||||
\ e['line'] . ':' .
|
||||
\ e['column'] . ':' .
|
||||
\ e['text']
|
||||
call add(out, msg)
|
||||
catch /\m^Vim\%((\a\+)\)\=:E716/
|
||||
call syntastic#log#warn('checker css/stylelint: unrecognized error format')
|
||||
let out = []
|
||||
break
|
||||
endtry
|
||||
endfor
|
||||
else
|
||||
call syntastic#log#warn('checker css/stylelint: unrecognized error format')
|
||||
endif
|
||||
endif
|
||||
return out
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#preprocess#tslint(errors) abort " {{{2
|
||||
return map(copy(a:errors), 'substitute(v:val, ''\m^\(([^)]\+)\)\s\(.\+\)$'', ''\2 \1'', "")')
|
||||
endfunction " }}}2
|
||||
@ -268,22 +308,8 @@ function! syntastic#preprocess#validator(errors) abort " {{{2
|
||||
return out
|
||||
endfunction " }}}2
|
||||
|
||||
" @vimlint(EVL102, 1, l:true)
|
||||
" @vimlint(EVL102, 1, l:false)
|
||||
" @vimlint(EVL102, 1, l:null)
|
||||
function! syntastic#preprocess#vint(errors) abort " {{{2
|
||||
" JSON artifacts
|
||||
let true = 1
|
||||
let false = 0
|
||||
let null = ''
|
||||
|
||||
" A hat tip to Marc Weber for this trick
|
||||
" http://stackoverflow.com/questions/17751186/iterating-over-a-string-in-vimscript-or-parse-a-json-file/19105763#19105763
|
||||
try
|
||||
let errs = eval(join(a:errors, ''))
|
||||
catch
|
||||
let errs = []
|
||||
endtry
|
||||
let errs = s:_decode_JSON(join(a:errors, ''))
|
||||
|
||||
let out = []
|
||||
if type(errs) == type([])
|
||||
@ -300,22 +326,166 @@ function! syntastic#preprocess#vint(errors) abort " {{{2
|
||||
|
||||
call add(out, msg)
|
||||
catch /\m^Vim\%((\a\+)\)\=:E716/
|
||||
call syntastic#log#warn('checker vim/vint: unknown error format')
|
||||
call syntastic#log#warn('checker vim/vint: unrecognized error format')
|
||||
let out = []
|
||||
break
|
||||
endtry
|
||||
else
|
||||
call syntastic#log#warn('checker vim/vint: unknown error format')
|
||||
call syntastic#log#warn('checker vim/vint: unrecognized error format')
|
||||
let out = []
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
else
|
||||
call syntastic#log#warn('checker vim/vint: unknown error format')
|
||||
call syntastic#log#warn('checker vim/vint: unrecognized error format')
|
||||
endif
|
||||
|
||||
return out
|
||||
endfunction " }}}2
|
||||
|
||||
" }}}1
|
||||
|
||||
" Workarounds {{{1
|
||||
|
||||
" In errorformat, \ or % following %f make it depend on isfname. The default
|
||||
" setting of isfname is crafted to work with completion, rather than general
|
||||
" filename matching. The result for syntastic is that filenames containing
|
||||
" spaces (or a few other special characters) can't be matched.
|
||||
"
|
||||
" Fixing isfname to address this problem would depend on the set of legal
|
||||
" characters for filenames on the filesystem the project's files lives on.
|
||||
" Inferring the kind of filesystem a file lives on, in advance to parsing the
|
||||
" file's name, is an interesting problem (think f.i. a file loaded from a VFAT
|
||||
" partition, mounted on Linux). A problem syntastic is not prepared to solve.
|
||||
"
|
||||
" As a result, the functions below exist for the only reason to avoid using
|
||||
" things like %f\, in errorformat.
|
||||
"
|
||||
" References:
|
||||
" https://groups.google.com/forum/#!topic/vim_dev/pTKmZmouhio
|
||||
" https://vimhelp.appspot.com/quickfix.txt.html#error-file-format
|
||||
|
||||
function! syntastic#preprocess#basex(errors) abort " {{{2
|
||||
let out = []
|
||||
let idx = 0
|
||||
while idx < len(a:errors)
|
||||
let parts = matchlist(a:errors[idx], '\v^\[\S+\] Stopped at (.+), (\d+)/(\d+):')
|
||||
if len(parts) > 3
|
||||
let err = parts[1] . ':' . parts[2] . ':' . parts[3] . ':'
|
||||
let parts = matchlist(a:errors[idx+1], '\v^\[(.)\D+(\d+)\] (.+)')
|
||||
if len(parts) > 3
|
||||
let err .= (parts[1] ==? 'W' || parts[1] ==? 'E' ? parts[1] : 'E') . ':' . parts[2] . ':' . parts[3]
|
||||
call add(out, err)
|
||||
let idx +=1
|
||||
endif
|
||||
elseif a:errors[idx] =~# '\m^\['
|
||||
" unparseable errors
|
||||
call add(out, a:errors[idx])
|
||||
endif
|
||||
let idx +=1
|
||||
endwhile
|
||||
return out
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#preprocess#bro(errors) abort " {{{2
|
||||
let out = []
|
||||
for e in a:errors
|
||||
let parts = matchlist(e, '\v^%(fatal )?(error|warning) in (.{-1,}), line (\d+): (.+)')
|
||||
if len(parts) > 4
|
||||
let parts[1] = parts[1][0]
|
||||
call add(out, join(parts[1:4], ':'))
|
||||
endif
|
||||
endfor
|
||||
return out
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#preprocess#coffeelint(errors) abort " {{{2
|
||||
let out = []
|
||||
for e in a:errors
|
||||
let parts = matchlist(e, '\v^(.{-1,}),(\d+)%(,\d*)?,(error|warn),(.+)')
|
||||
if len(parts) > 4
|
||||
let parts[3] = parts[3][0]
|
||||
call add(out, join(parts[1:4], ':'))
|
||||
endif
|
||||
endfor
|
||||
return out
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#preprocess#mypy(errors) abort " {{{2
|
||||
let out = []
|
||||
for e in a:errors
|
||||
" new format
|
||||
let parts = matchlist(e, '\v^(.{-1,}):(\d+): error: (.+)')
|
||||
if len(parts) > 3
|
||||
call add(out, join(parts[1:3], ':'))
|
||||
continue
|
||||
endif
|
||||
|
||||
" old format
|
||||
let parts = matchlist(e, '\v^(.{-1,}), line (\d+): (.+)')
|
||||
if len(parts) > 3
|
||||
call add(out, join(parts[1:3], ':'))
|
||||
endif
|
||||
endfor
|
||||
return out
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#preprocess#nix(errors) abort " {{{2
|
||||
let out = []
|
||||
for e in a:errors
|
||||
let parts = matchlist(e, '\v^(.{-1,}), at (.{-1,}):(\d+):(\d+)$')
|
||||
if len(parts) > 4
|
||||
call add(out, join(parts[2:4], ':') . ':' . parts[1])
|
||||
continue
|
||||
endif
|
||||
|
||||
let parts = matchlist(e, '\v^(.{-1,}) at (.{-1,}), line (\d+):')
|
||||
if len(parts) > 3
|
||||
call add(out, parts[2] . ':' . parts[3] . ':' . parts[1])
|
||||
continue
|
||||
endif
|
||||
|
||||
let parts = matchlist(e, '\v^error: (.{-1,}), in (.{-1,})$')
|
||||
if len(parts) > 2
|
||||
call add(out, parts[2] . ':' . parts[1])
|
||||
endif
|
||||
endfor
|
||||
return out
|
||||
endfunction " }}}2
|
||||
|
||||
" }}}1
|
||||
|
||||
" Private functions {{{1
|
||||
|
||||
" @vimlint(EVL102, 1, l:true)
|
||||
" @vimlint(EVL102, 1, l:false)
|
||||
" @vimlint(EVL102, 1, l:null)
|
||||
function! s:_decode_JSON(json) abort " {{{2
|
||||
if a:json ==# ''
|
||||
return []
|
||||
endif
|
||||
|
||||
" The following is inspired by https://github.com/MarcWeber/vim-addon-manager and
|
||||
" http://stackoverflow.com/questions/17751186/iterating-over-a-string-in-vimscript-or-parse-a-json-file/19105763#19105763
|
||||
" A hat tip to Marc Weber for this trick
|
||||
if substitute(a:json, '\v\"%(\\.|[^"\\])*\"|true|false|null|[+-]?\d+%(\.\d+%([Ee][+-]?\d+)?)?', '', 'g') !~# "[^,:{}[\\] \t]"
|
||||
" JSON artifacts
|
||||
let true = 1
|
||||
let false = 0
|
||||
let null = ''
|
||||
|
||||
try
|
||||
let object = eval(a:json)
|
||||
catch
|
||||
" malformed JSON
|
||||
let object = ''
|
||||
endtry
|
||||
else
|
||||
let object = ''
|
||||
endif
|
||||
|
||||
return object
|
||||
endfunction " }}}2
|
||||
" @vimlint(EVL102, 0, l:true)
|
||||
" @vimlint(EVL102, 0, l:false)
|
||||
" @vimlint(EVL102, 0, l:null)
|
||||
|
@ -107,16 +107,16 @@ function! syntastic#util#rmrf(what) abort " {{{2
|
||||
endif
|
||||
endfunction " }}}2
|
||||
|
||||
"search the first 5 lines of the file for a magic number and return a map
|
||||
"containing the args and the executable
|
||||
" Search the first 5 lines of the file for a magic number and return a map
|
||||
" containing the args and the executable
|
||||
"
|
||||
"e.g.
|
||||
" e.g.
|
||||
"
|
||||
"#!/usr/bin/perl -f -bar
|
||||
" #!/usr/bin/perl -f -bar
|
||||
"
|
||||
"returns
|
||||
" returns
|
||||
"
|
||||
"{'exe': '/usr/bin/perl', 'args': ['-f', '-bar']}
|
||||
" {'exe': '/usr/bin/perl', 'args': ['-f', '-bar']}
|
||||
function! syntastic#util#parseShebang() abort " {{{2
|
||||
for lnum in range(1, 5)
|
||||
let line = getline(lnum)
|
||||
@ -183,7 +183,7 @@ function! syntastic#util#screenWidth(str, tabstop) abort " {{{2
|
||||
return width
|
||||
endfunction " }}}2
|
||||
|
||||
"print as much of a:msg as possible without "Press Enter" prompt appearing
|
||||
" Print as much of a:msg as possible without "Press Enter" prompt appearing
|
||||
function! syntastic#util#wideMsg(msg) abort " {{{2
|
||||
let old_ruler = &ruler
|
||||
let old_showcmd = &showcmd
|
||||
@ -226,7 +226,7 @@ function! syntastic#util#bufIsActive(buffer) abort " {{{2
|
||||
return 0
|
||||
endfunction " }}}2
|
||||
|
||||
" start in directory a:where and walk up the parent folders until it finds a
|
||||
" Start in directory a:where and walk up the parent folders until it finds a
|
||||
" file named a:what; return path to that file
|
||||
function! syntastic#util#findFileInParent(what, where) abort " {{{2
|
||||
let old_suffixesadd = &suffixesadd
|
||||
@ -236,7 +236,7 @@ function! syntastic#util#findFileInParent(what, where) abort " {{{2
|
||||
return file
|
||||
endfunction " }}}2
|
||||
|
||||
" start in directory a:where and walk up the parent folders until it finds a
|
||||
" Start in directory a:where and walk up the parent folders until it finds a
|
||||
" file matching a:what; return path to that file
|
||||
function! syntastic#util#findGlobInParent(what, where) abort " {{{2
|
||||
let here = fnamemodify(a:where, ':p')
|
||||
@ -303,7 +303,7 @@ function! syntastic#util#argsescape(opt) abort " {{{2
|
||||
return []
|
||||
endfunction " }}}2
|
||||
|
||||
" decode XML entities
|
||||
" Decode XML entities
|
||||
function! syntastic#util#decodeXMLEntities(string) abort " {{{2
|
||||
let str = a:string
|
||||
let str = substitute(str, '\m<', '<', 'g')
|
||||
@ -339,6 +339,87 @@ function! syntastic#util#stamp() abort " {{{2
|
||||
return split( split(reltimestr(reltime(g:_SYNTASTIC_START)))[0], '\.' )
|
||||
endfunction " }}}2
|
||||
|
||||
let s:_wid_base = 'syntastic_' . getpid() . '_' . reltimestr(g:_SYNTASTIC_START) . '_'
|
||||
let s:_wid_pool = 0
|
||||
|
||||
" Add unique IDs to windows
|
||||
function! syntastic#util#setWids() abort " {{{2
|
||||
for tab in range(1, tabpagenr('$'))
|
||||
for win in range(1, tabpagewinnr(tab, '$'))
|
||||
if gettabwinvar(tab, win, 'syntastic_wid') ==# ''
|
||||
call settabwinvar(tab, win, 'syntastic_wid', s:_wid_base . s:_wid_pool)
|
||||
let s:_wid_pool += 1
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
endfunction " }}}2
|
||||
|
||||
let s:_str2float = function(exists('*str2float') ? 'str2float' : 'str2nr')
|
||||
lockvar s:_str2float
|
||||
|
||||
function! syntastic#util#str2float(val) abort " {{{2
|
||||
return s:_str2float(a:val)
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#util#float2str(val) abort " {{{2
|
||||
return s:_float2str(a:val)
|
||||
endfunction " }}}2
|
||||
|
||||
" Crude printf()-like width formatter. Handles wide characters.
|
||||
function! syntastic#util#wformat(format, str) abort " {{{2
|
||||
if a:format ==# ''
|
||||
return a:str
|
||||
endif
|
||||
|
||||
echomsg string(a:format) . ', ' . string(a:str)
|
||||
let specs = matchlist(a:format, '\v^(-?)(0?)(%([1-9]\d*))?%(\.(\d+))?$')
|
||||
if len(specs) < 5
|
||||
return a:str
|
||||
endif
|
||||
|
||||
let flushleft = specs[1] ==# '-'
|
||||
let lpad = specs[2] ==# '0' ? '0' : ' '
|
||||
let minlen = str2nr(specs[3])
|
||||
let maxlen = str2nr(specs[4])
|
||||
let out = substitute(a:str, "\t", ' ', 'g')
|
||||
|
||||
if maxlen && s:_width(out) > maxlen
|
||||
let chars = filter(split(out, '\zs\ze', 1), 'v:val !=# ""')
|
||||
let out = ''
|
||||
|
||||
if flushleft
|
||||
for c in chars
|
||||
if s:_width(out . c) < maxlen
|
||||
let out .= c
|
||||
else
|
||||
let out .= &encoding ==# 'utf-8' && &termencoding ==# 'utf-8' ? "\u2026" : '>'
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
else
|
||||
call reverse(chars)
|
||||
for c in chars
|
||||
if s:_width(c . out) < maxlen
|
||||
let out = c . out
|
||||
else
|
||||
let out = (&encoding ==# 'utf-8' && &termencoding ==# 'utf-8' ? "\u2026" : '<') . out
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
endif
|
||||
|
||||
if minlen && s:_width(out) < minlen
|
||||
if flushleft
|
||||
let out .= repeat(' ', minlen - s:_width(out))
|
||||
else
|
||||
let out = repeat(lpad, minlen - s:_width(out)) . out
|
||||
endif
|
||||
endif
|
||||
|
||||
return out
|
||||
endfunction " }}}2
|
||||
|
||||
" }}}1
|
||||
|
||||
" Private functions {{{1
|
||||
@ -416,6 +497,17 @@ function! s:_rmrf(what) abort " {{{2
|
||||
endif
|
||||
endfunction " }}}2
|
||||
|
||||
function! s:_float2str_smart(val) abort " {{{2
|
||||
return printf('%.1f', a:val)
|
||||
endfunction " }}}2
|
||||
|
||||
function! s:_float2str_dumb(val) abort " {{{2
|
||||
return a:val
|
||||
endfunction " }}}2
|
||||
|
||||
let s:_float2str = function(has('float') ? 's:_float2str_smart' : 's:_float2str_dumb')
|
||||
lockvar s:_float2str
|
||||
|
||||
" }}}1
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
|
Reference in New Issue
Block a user