Skip to content

Show breakpoint signs #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 73 additions & 2 deletions plugin/scriptease.vim
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,10 @@ augroup scriptease_breakadd
autocmd!
autocmd FileType vim command!
\ -buffer -bar -nargs=? -complete=custom,s:Complete_breakadd Breakadd
\ :exe s:break('add',<q-args>)
\ :exe s:break('add',<q-args>) | :call s:show_breakpoint_signs()
autocmd FileType vim command!
\ -buffer -bar -nargs=? -complete=custom,s:Complete_breakdel Breakdel
\ :exe s:break('del',<q-args>)
\ :exe s:break('del',<q-args>) | :call s:show_breakpoint_signs()
augroup END

function! s:breaksnr(arg) abort
Expand Down Expand Up @@ -786,4 +786,75 @@ augroup END

" }}}1

function! s:to_function_name(symbol)
let result = matchstr(a:symbol, '^.*<SNR>\d\+_\zs.*\ze$')
return empty(result) ? a:symbol : result
endfunction

function! s:to_SID(symbol)
return matchstr(a:symbol, '^.*<SNR>\zs\d\+\ze_.*$')
endfunction

let s:sign_name = 'scriptease_break'
" ID number of the next sign to place
let s:sign_id = 17607
execute 'sign define ' . s:sign_name . ' texthl=ErrorMsg text=>>'

function! s:show_breakpoint_signs()
sign unplace *
" get output of :breaklist
redir => result
silent execute 'breaklist'
redir END
if result =~# 'No breakpoints defined'
return
endif
" make breakpoint list
let l:blist = []
for bstr in split(result, '\n')
let bcols = split(bstr)
let bentry = { 'type' : bcols[1], 'line' : bcols[4] }
if bentry['type'] ==# 'file'
" set fullpath of the file
let bentry['file'] = expand(bcols[2])
elseif bentry['type'] ==# 'func'
" set SID and function name
let bentry['func'] = { 'SID': s:to_SID(bcols[2]), 'name': s:to_function_name(bcols[2]) }
endif
call add(l:blist, l:bentry)
endfor
" PPmsg l:blist
for be in l:blist
if be['type'] ==# 'file'
" place sign to the file
execute 'sign place ' . s:sign_id . ' line=' . be['line'] . ' name=' . s:sign_name . ' file=' . be['file']
" PPmsg 'sign place ' . s:sign_id . ' line=' . be['line'] . ' name=' . s:sign_name . ' file=' . be['file']
elseif be['type'] ==# 'func'
if empty(be['func']['SID'])
" search global function and place sign
" PPmsg '\v^\s*fu%[nction]>.*' . be['func']['name']
let l:lnum = search('\v^\s*fu%[nction]>.*' . be['func']['name'], 'n')
if l:lnum != 0
execute 'sign place ' . s:sign_id . ' line=' . (l:lnum + be['line']) . ' name=' . s:sign_name . ' file=' . expand('%:p')
" PPmsg 'sign place ' . s:sign_id . ' line=' . l:lnum + be['line'] . ' name=' . s:sign_name . ' file=' . expand('%:p')
endif
elseif be['func']['SID'] !=# scriptease#scriptid('%')
" the script-local function is not of this file
continue
else
" search script-local function and place sign
" PPmsg '\v^\s*fu%[nction]>.*<(s:|\<SID\>).*' . be['func']['name']
let l:lnum = search('\v^\s*fu%[nction]>.*<(s:|\<SID\>).*' . be['func']['name'], 'n')
if l:lnum != 0
execute 'sign place ' . s:sign_id . ' line=' . (l:lnum + be['line']) . ' name=' . s:sign_name . ' file=' . expand('%:p')
" PPmsg 'sign place ' . s:sign_id . ' line=' . l:lnum + be['line'] . ' name=' . s:sign_name . ' file=' . expand('%:p')
endif
endif
endif
let s:sign_id += 1
endfor
endfunction

autocmd BufEnter vim call s:show_breakpoint_signs()

" vim:set et sw=2: