aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjdhao <jdhao@hotmail.com>2021-07-24 14:53:48 +0800
committerjdhao <jdhao@hotmail.com>2021-07-24 14:53:48 +0800
commitf7475f3e4fb01d5a34b0eec3ebff18981e910e87 (patch)
treec6df470308f67c4204390a40577788d5de5d6144
parentb0eb7c4508599a7eace480d89e764612664839a3 (diff)
Refactor: use a unified log function
-rw-r--r--autoload/buf_utils.vim2
-rw-r--r--autoload/utils.vim22
-rw-r--r--core/autocommands.vim3
-rw-r--r--core/ui.vim4
4 files changed, 25 insertions, 6 deletions
diff --git a/autoload/buf_utils.vim b/autoload/buf_utils.vim
index db34ae0..fa2aefd 100644
--- a/autoload/buf_utils.vim
+++ b/autoload/buf_utils.vim
@@ -11,7 +11,7 @@ function! buf_utils#GoToBuffer(count, direction) abort
endif
" Check the validity of buffer number.
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
endif
diff --git a/autoload/utils.vim b/autoload/utils.vim
index 9d84c9b..217666b 100644
--- a/autoload/utils.vim
+++ b/autoload/utils.vim
@@ -145,3 +145,25 @@ function! utils#Get_titlestr() abort
return l:title_str
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
diff --git a/core/autocommands.vim b/core/autocommands.vim
index 29b4cea..64b86f8 100644
--- a/core/autocommands.vim
+++ b/core/autocommands.vim
@@ -42,8 +42,7 @@ augroup END
" https://vi.stackexchange.com/a/20397/15292.
augroup auto_read
autocmd!
- autocmd FileChangedShellPost * echohl WarningMsg
- \ | echo "File changed on disk. Buffer reloaded!" | echohl None
+ autocmd FileChangedShellPost * call utils#Log("File changed on disk. Buffer reloaded!", 'warning')
autocmd FocusGained,CursorHold * if getcmdwintype() == '' | checktime | endif
augroup END
diff --git a/core/ui.vim b/core/ui.vim
index aa31bf0..919d3e3 100644
--- a/core/ui.vim
+++ b/core/ui.vim
@@ -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)
execute 'call ' . s:colorscheme_func
else
- echohl WarningMsg
- echomsg 'Invalid colorscheme function: ' s:colorscheme_func
- echohl None
+ call utils#Log('Invalid colorscheme function: ' . s:colorscheme_func, 'error')
endif
"}}
"}