Skip to content

Commit 6850672

Browse files
committed
Use sy#util#get_signs() instead of manual parsing
1 parent 4abe233 commit 6850672

File tree

2 files changed

+8
-41
lines changed

2 files changed

+8
-41
lines changed

autoload/sy/fold.vim

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,24 +88,7 @@ endfunction
8888

8989
" s:get_lines {{{1
9090
function! s:get_lines() abort
91-
let lines = []
92-
93-
let has_sign_func = has('patch-8.1.614')
94-
if has_sign_func
95-
let signlist = sign_getplaced(b:sy.buffer)[0].signs
96-
else
97-
let signlist = split(sy#util#execute('sign place buffer='. b:sy.buffer), '\n')[2:]
98-
endif
99-
100-
for signline in signlist
101-
if has_sign_func
102-
call insert(lines, signline.lnum, 0)
103-
else
104-
call insert(lines, matchlist(line, '\v^\s+line\=(\d+)')[1], 0)
105-
endif
106-
endfor
107-
108-
return reverse(lines)
91+
return map(sy#util#get_signs(b:sy.buffer), {_, val -> val.lnum})
10992
endfunction
11093

11194
" s:get_levels {{{1

autoload/sy/sign.vim

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,19 @@ function! sy#sign#get_current_signs(sy) abort
2828
let a:sy.internal = {}
2929
let a:sy.external = {}
3030

31-
let has_sign_func = has('patch-8.1.614')
32-
if has_sign_func
33-
let signlist = sign_getplaced(a:sy.buffer)[0].signs
34-
else
35-
let signlist = split(sy#util#execute('sign place buffer='. a:sy.buffer), '\n')[2:]
36-
endif
37-
38-
for signline in signlist
39-
if has_sign_func
40-
let line = signline.lnum
41-
let id = signline.id
42-
let type = signline.name
43-
else
44-
let tokens = matchlist(signline, '\v^\s+\S+\=(\d+)\s+\S+\=(\d+)\s+\S+\=(.*)$')
45-
let line = str2nr(tokens[1])
46-
let id = str2nr(tokens[2])
47-
let type = tokens[3]
48-
endif
31+
let signlist = sy#util#get_signs(a:sy.buffer)
4932

50-
if type =~# '^Signify'
33+
for sign in signlist
34+
if sign.name =~# '^Signify'
5135
" Handle ambiguous signs. Assume you have signs on line 3 and 4.
5236
" Removing line 3 would lead to the second sign to be shifted up
5337
" to line 3. Now there are still 2 signs, both one line 3.
54-
if has_key(a:sy.internal, line)
55-
execute 'sign unplace' a:sy.internal[line].id 'buffer='.a:sy.buffer
38+
if has_key(a:sy.internal, sign.lnum)
39+
execute 'sign unplace' a:sy.internal[sign.lnum].id 'buffer='.a:sy.buffer
5640
endif
57-
let a:sy.internal[line] = { 'type': type, 'id': id }
41+
let a:sy.internal[sign.lnum] = { 'type': sign.name, 'id': sign.id }
5842
else
59-
let a:sy.external[line] = id
43+
let a:sy.external[sign.lnum] = sign.id
6044
endif
6145
endfor
6246
endfunction

0 commit comments

Comments
 (0)