plugin: handle sandbox mode gracefully

When the sandbox is active (e.g. while debugging something), certains
commands and expressions are not allowed (see :h sandbox) and may cause
nasty exceptions to be thrown.

So try to catch E48 and handle it gracefully
This commit is contained in:
Christian Brabandt 2022-09-07 09:43:51 +02:00
parent 90c6746311
commit 2cea8346cf
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
2 changed files with 18 additions and 3 deletions

View File

@ -156,7 +156,12 @@ function! airline#update_statusline()
" Now create the active statusline
let w:airline_active = 1
let context = { 'winnr': winnr(), 'active': 1, 'bufnr': winbufnr(winnr()) }
call s:invoke_funcrefs(context, g:airline_statusline_funcrefs)
try
call s:invoke_funcrefs(context, g:airline_statusline_funcrefs)
catch /^Vim\%((\a\+)\)\=:E48:/
" Catch: Sandbox mode
" no-op
endtry
endfunction
" Function to be called to make all statuslines inactive
@ -186,7 +191,12 @@ function! airline#update_statusline_inactive(range)
\ 'left_sep': g:airline_left_alt_sep,
\ 'right_sep': g:airline_right_alt_sep }, 'keep')
endif
call s:invoke_funcrefs(context, g:airline_inactive_funcrefs)
try
call s:invoke_funcrefs(context, g:airline_inactive_funcrefs)
catch /^Vim\%((\a\+)\)\=:E48:/
" Catch: Sandbox mode
" no-op
endtry
endfor
endfunction

View File

@ -180,7 +180,12 @@ function! airline#util#doautocmd(event)
" airline disabled
return
endif
exe printf("silent doautocmd %s User %s", s:nomodeline, a:event)
try
exe printf("silent doautocmd %s User %s", s:nomodeline, a:event)
catch /^Vim\%((\a\+)\)\=:E48:/
" Catch: Sandbox mode
" no-op
endtry
endfunction
function! airline#util#themes(match)