aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjdhao <jdhao@hotmail.com>2021-08-05 01:56:13 +0800
committerjdhao <jdhao@hotmail.com>2021-08-05 01:57:35 +0800
commitc4d050e99da5a10ebe83e9229dcbd2b21758f54d (patch)
treea9b6c65ef3d1ba494976febbe4e08d90a0c51176
parent4d3c038cb500de307eb95e6b7c1ec21f075323c7 (diff)
Use nvim-notify for showing messages
-rw-r--r--autoload/buf_utils.vim6
-rw-r--r--autoload/utils.vim22
-rw-r--r--core/autocommands.vim5
-rw-r--r--core/mappings.vim2
-rw-r--r--core/ui.vim2
-rw-r--r--lua/plugins.lua4
6 files changed, 14 insertions, 27 deletions
diff --git a/autoload/buf_utils.vim b/autoload/buf_utils.vim
index fa2aefd..37e7a75 100644
--- a/autoload/buf_utils.vim
+++ b/autoload/buf_utils.vim
@@ -11,7 +11,11 @@ function! buf_utils#GoToBuffer(count, direction) abort
endif
" Check the validity of buffer number.
if index(s:GetBufNums(), a:count) == -1
- call utils#Log('Invalid bufnr: ' . a:count, 'error')
+ " Using `lua vim.notify('invalid bufnr: ' .. a:count)` won't work, because
+ " we are essentially mixing Lua and vim script. We need to make sure that
+ " args inside vim.notify() are valid vim values. The conversion from vim
+ " value to lua value will be done by Nvim. See also https://github.com/neovim/neovim/pull/11338.
+ call v:lua.vim.notify('Invalid bufnr: ' . a:count, 'error', {'title': 'nvim-config'})
return
endif
diff --git a/autoload/utils.vim b/autoload/utils.vim
index 217666b..9d84c9b 100644
--- a/autoload/utils.vim
+++ b/autoload/utils.vim
@@ -145,25 +145,3 @@ 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 64b86f8..1cc207a 100644
--- a/core/autocommands.vim
+++ b/core/autocommands.vim
@@ -32,7 +32,8 @@ augroup END
" https://github.com/vim/vim/issues/4379
augroup non_utf8_file_warn
autocmd!
- autocmd BufRead * if &fileencoding != 'utf-8' | unsilent echomsg 'File not in UTF-8 format!' | endif
+ " we can not `lua vim.notify()`: it will error out E5107 parsing lua.
+ autocmd BufRead * if &fileencoding != 'utf-8' | call v:lua.vim.notify('File not in UTF-8 format!', 'warn', {'title': 'nvim-config'}) | endif
augroup END
" Automatically reload the file if it is changed outside of Nvim, see
@@ -42,7 +43,7 @@ augroup END
" https://vi.stackexchange.com/a/20397/15292.
augroup auto_read
autocmd!
- autocmd FileChangedShellPost * call utils#Log("File changed on disk. Buffer reloaded!", 'warning')
+ autocmd FileChangedShellPost * call v:lua.vim.notify("File changed on disk. Buffer reloaded!", 'warn', {'title': 'nvim-config'})
autocmd FocusGained,CursorHold * if getcmdwintype() == '' | checktime | endif
augroup END
diff --git a/core/mappings.vim b/core/mappings.vim
index a7712df..19e6a10 100644
--- a/core/mappings.vim
+++ b/core/mappings.vim
@@ -102,7 +102,7 @@ inoremap <expr> <s-tab> pumvisible() ? "\<c-p>" : "\<s-tab>"
" Edit and reload init.vim quickly
nnoremap <silent> <leader>ev :<C-U>tabnew $MYVIMRC <bar> tcd %:h<cr>
nnoremap <silent> <leader>sv :<C-U>silent update $MYVIMRC <bar> source $MYVIMRC <bar>
- \ echomsg "Nvim config successfully reloaded!"<cr>
+ \ call v:lua.vim.notify("Nvim config successfully reloaded!", 'info', {'title': 'nvim-config'})<cr>
" Reselect the text that has just been pasted, see also https://stackoverflow.com/a/4317090/6064933.
nnoremap <expr> <leader>v printf('`[%s`]', getregtype()[0])
diff --git a/core/ui.vim b/core/ui.vim
index c29682f..f93c10e 100644
--- a/core/ui.vim
+++ b/core/ui.vim
@@ -64,7 +64,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
- call utils#Log('Invalid colorscheme function: ' . s:colorscheme_func, 'error')
+ call v:lua.vim.notify('Invalid colorscheme function: ' . s:colorscheme_func, 'error', {'title': 'nvim-config'})
endif
"}}
"}
diff --git a/lua/plugins.lua b/lua/plugins.lua
index 58e8b7d..ccc01af 100644
--- a/lua/plugins.lua
+++ b/lua/plugins.lua
@@ -95,6 +95,7 @@ require('packer').startup(
use 'sainnhe/gruvbox-material'
use 'shaunsingh/nord.nvim'
use 'NTBBloodbath/doom-one.nvim'
+
-- colorful status line and theme
use 'vim-airline/vim-airline-themes'
use 'vim-airline/vim-airline'
@@ -106,6 +107,9 @@ require('packer').startup(
-- Highlight URLs inside vim
use 'itchyny/vim-highlighturl'
+ -- notification plugin
+ use {'rcarriga/nvim-notify', config = 'vim.notify = require("notify")'}
+
-- For Windows and Mac, we can open an URL in the browser. For Linux, it may
-- not be possible since we maybe in a server which disables GUI.
if (vim.g.is_win == 1) or (vim.g.is_mac == 1) then