~toastal/vim-signify

6a9499c1e13a7356780d9cf813380baefaebcb32 — James McCoy 1 year, 2 months ago cefe37e + 6850672
Merge pull request #401 from albfan/i18n

parse signlist locale agnostic
3 files changed, 38 insertions(+), 20 deletions(-)

M autoload/sy/fold.vim
M autoload/sy/sign.vim
M autoload/sy/util.vim
M autoload/sy/fold.vim => autoload/sy/fold.vim +1 -8
@@ 88,14 88,7 @@ endfunction

" s:get_lines {{{1
function! s:get_lines() abort
  let signlist = sy#util#execute('sign place buffer='. b:sy.buffer)

  let lines = []
  for line in split(signlist, '\n')[2:]
    call insert(lines, matchlist(line, '\v^\s+line\=(\d+)')[1], 0)
  endfor

  return reverse(lines)
  return map(sy#util#get_signs(b:sy.buffer), {_, val -> val.lnum})
endfunction

" s:get_levels {{{1

M autoload/sy/sign.vim => autoload/sy/sign.vim +7 -12
@@ 28,24 28,19 @@ function! sy#sign#get_current_signs(sy) abort
  let a:sy.internal = {}
  let a:sy.external = {}

  let signlist = sy#util#execute('sign place buffer='. a:sy.buffer)
  let signlist = sy#util#get_signs(a:sy.buffer)

  for signline in split(signlist, '\n')[2:]
    let tokens = matchlist(signline, '\v^\s+\S+\=(\d+)\s+\S+\=(\d+)\s+\S+\=(.*)$')
    let line   = str2nr(tokens[1])
    let id     = str2nr(tokens[2])
    let type   = tokens[3]

    if type =~# '^Signify'
  for sign in signlist
    if sign.name =~# '^Signify'
      " Handle ambiguous signs. Assume you have signs on line 3 and 4.
      " Removing line 3 would lead to the second sign to be shifted up
      " to line 3. Now there are still 2 signs, both one line 3.
      if has_key(a:sy.internal, line)
        execute 'sign unplace' a:sy.internal[line].id 'buffer='.a:sy.buffer
      if has_key(a:sy.internal, sign.lnum)
        execute 'sign unplace' a:sy.internal[sign.lnum].id 'buffer='.a:sy.buffer
      endif
      let a:sy.internal[line] = { 'type': type, 'id': id }
      let a:sy.internal[sign.lnum] = { 'type': sign.name, 'id': sign.id }
    else
      let a:sy.external[line] = id
      let a:sy.external[sign.lnum] = sign.id
    endif
  endfor
endfunction

M autoload/sy/util.vim => autoload/sy/util.vim +30 -0
@@ 229,3 229,33 @@ function! s:offset() abort
  endif
  return offset
endfunction

" #get_signs {{{1
if exists('*sign_getplaced')
  function! sy#util#get_signs(bufnr)
    return sign_getplaced(a:bufnr)[0].signs
  endfunction
else
  function! sy#util#get_signs(bufnr)
    let buf = bufnr(a:bufnr)
    let signs = []

    let signlist = execute('sign place buffer='. buf)
    for signline in split(signlist, '\n')[2:]
      let tokens = matchlist(signline, '\v^\s+\S+\=(\d+)\s+\S+\=(\d+)\s+\S+\=(.*)\s+\S+\=(\d+)$')
      let line   = str2nr(tokens[1])
      let id     = str2nr(tokens[2])
      let name   = tokens[3]
      let priority = str2nr(tokens[4])
      call add(signs, {
            \ 'lnum': line,
            \ 'id': id,
            \ 'name': name,
            \ 'priority': priority,
            \ 'group': ''
            \ })
    endfor

    return signs
  endfunction
endif