Skip to content

Commit 4abe233

Browse files
committed
Add sy#util#get_signs() function
This provides a unified interface for getting placed signs, modeled after sign_getplaced(). When sign_getplaced() is available, it is used, otherwise we fall back to manually parsing the output for ":sign place".
1 parent 47375a5 commit 4abe233

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

autoload/sy/util.vim

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,33 @@ function! s:offset() abort
229229
endif
230230
return offset
231231
endfunction
232+
233+
" #get_signs {{{1
234+
if exists('*sign_getplaced')
235+
function! sy#util#get_signs(bufnr)
236+
return sign_getplaced(a:bufnr)[0].signs
237+
endfunction
238+
else
239+
function! sy#util#get_signs(bufnr)
240+
let buf = bufnr(a:bufnr)
241+
let signs = []
242+
243+
let signlist = execute('sign place buffer='. buf)
244+
for signline in split(signlist, '\n')[2:]
245+
let tokens = matchlist(signline, '\v^\s+\S+\=(\d+)\s+\S+\=(\d+)\s+\S+\=(.*)\s+\S+\=(\d+)$')
246+
let line = str2nr(tokens[1])
247+
let id = str2nr(tokens[2])
248+
let name = tokens[3]
249+
let priority = str2nr(tokens[4])
250+
call add(signs, {
251+
\ 'lnum': line,
252+
\ 'id': id,
253+
\ 'name': name,
254+
\ 'priority': priority,
255+
\ 'group': ''
256+
\ })
257+
endfor
258+
259+
return signs
260+
endfunction
261+
endif

0 commit comments

Comments
 (0)