mirror of
https://github.com/jdhao/nvim-config.git
synced 2025-06-08 14:14:33 +02:00
Refactor: use a unified log function
This commit is contained in:
parent
b0eb7c4508
commit
f7475f3e4f
@ -11,7 +11,7 @@ function! buf_utils#GoToBuffer(count, direction) abort
|
|||||||
endif
|
endif
|
||||||
" Check the validity of buffer number.
|
" Check the validity of buffer number.
|
||||||
if index(s:GetBufNums(), a:count) == -1
|
if index(s:GetBufNums(), a:count) == -1
|
||||||
echohl WarningMsg | echomsg 'Invalid bufnr: ' a:count | echohl None
|
call utils#Log('Invalid bufnr: ' . a:count, 'error')
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|||||||
@ -145,3 +145,25 @@ function! utils#Get_titlestr() abort
|
|||||||
|
|
||||||
return l:title_str
|
return l:title_str
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Log a message using certain highlight group
|
||||||
|
function! utils#Log(msg, ...) abort
|
||||||
|
let l:hi = ''
|
||||||
|
if len(a:000) == 1
|
||||||
|
if a:1 ==? 'info'
|
||||||
|
let l:hi = 'Normal'
|
||||||
|
elseif a:1 ==? 'warning'
|
||||||
|
let l:hi = 'WarningMsg'
|
||||||
|
elseif a:1 ==? 'error'
|
||||||
|
let l:hi = 'ErrorMsg'
|
||||||
|
else
|
||||||
|
echoerr 'Unsupported log level:' a:1
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
let l:hi = 'Normal'
|
||||||
|
endif
|
||||||
|
|
||||||
|
execute 'echohl' l:hi
|
||||||
|
unsilent echomsg a:msg
|
||||||
|
echohl None
|
||||||
|
endfunction
|
||||||
|
|||||||
@ -42,8 +42,7 @@ augroup END
|
|||||||
" https://vi.stackexchange.com/a/20397/15292.
|
" https://vi.stackexchange.com/a/20397/15292.
|
||||||
augroup auto_read
|
augroup auto_read
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd FileChangedShellPost * echohl WarningMsg
|
autocmd FileChangedShellPost * call utils#Log("File changed on disk. Buffer reloaded!", 'warning')
|
||||||
\ | echo "File changed on disk. Buffer reloaded!" | echohl None
|
|
||||||
autocmd FocusGained,CursorHold * if getcmdwintype() == '' | checktime | endif
|
autocmd FocusGained,CursorHold * if getcmdwintype() == '' | checktime | endif
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
|
|||||||
@ -61,9 +61,7 @@ let s:colorscheme_func = printf('s:my_theme_dict.%s()', s:theme)
|
|||||||
if has_key(s:my_theme_dict, s:theme)
|
if has_key(s:my_theme_dict, s:theme)
|
||||||
execute 'call ' . s:colorscheme_func
|
execute 'call ' . s:colorscheme_func
|
||||||
else
|
else
|
||||||
echohl WarningMsg
|
call utils#Log('Invalid colorscheme function: ' . s:colorscheme_func, 'error')
|
||||||
echomsg 'Invalid colorscheme function: ' s:colorscheme_func
|
|
||||||
echohl None
|
|
||||||
endif
|
endif
|
||||||
"}}
|
"}}
|
||||||
"}
|
"}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user