From 2cea8346cfaf0d92da079c27708bec7c092cef84 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Wed, 7 Sep 2022 09:43:51 +0200 Subject: [PATCH] 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 --- autoload/airline.vim | 14 ++++++++++++-- autoload/airline/util.vim | 7 ++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/autoload/airline.vim b/autoload/airline.vim index 21118ec7..641a3360 100644 --- a/autoload/airline.vim +++ b/autoload/airline.vim @@ -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 diff --git a/autoload/airline/util.vim b/autoload/airline/util.vim index 40a54d58..7802994b 100644 --- a/autoload/airline/util.vim +++ b/autoload/airline/util.vim @@ -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)