Skip to content

Commit

Permalink
Merge pull request #401 from albfan/i18n
Browse files Browse the repository at this point in the history
parse signlist locale agnostic
  • Loading branch information
jamessan committed Apr 27, 2023
2 parents cefe37e + 6850672 commit 6a9499c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
9 changes: 1 addition & 8 deletions autoload/sy/fold.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 7 additions & 12 deletions autoload/sy/sign.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions autoload/sy/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6a9499c

Please sign in to comment.