1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00

Use nvim-notify for showing messages

This commit is contained in:
jdhao 2021-08-05 01:56:13 +08:00
parent 4d3c038cb5
commit c4d050e99d
6 changed files with 14 additions and 27 deletions

View File

@ -11,7 +11,11 @@ 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
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 return
endif endif

View File

@ -145,25 +145,3 @@ 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

View File

@ -32,7 +32,8 @@ augroup END
" https://github.com/vim/vim/issues/4379 " https://github.com/vim/vim/issues/4379
augroup non_utf8_file_warn augroup non_utf8_file_warn
autocmd! 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 augroup END
" Automatically reload the file if it is changed outside of Nvim, see " 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. " https://vi.stackexchange.com/a/20397/15292.
augroup auto_read augroup auto_read
autocmd! 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 autocmd FocusGained,CursorHold * if getcmdwintype() == '' | checktime | endif
augroup END augroup END

View File

@ -102,7 +102,7 @@ inoremap <expr> <s-tab> pumvisible() ? "\<c-p>" : "\<s-tab>"
" Edit and reload init.vim quickly " Edit and reload init.vim quickly
nnoremap <silent> <leader>ev :<C-U>tabnew $MYVIMRC <bar> tcd %:h<cr> 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> 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. " Reselect the text that has just been pasted, see also https://stackoverflow.com/a/4317090/6064933.
nnoremap <expr> <leader>v printf('`[%s`]', getregtype()[0]) nnoremap <expr> <leader>v printf('`[%s`]', getregtype()[0])

View File

@ -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) if has_key(s:my_theme_dict, s:theme)
execute 'call ' . s:colorscheme_func execute 'call ' . s:colorscheme_func
else 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 endif
"}} "}}
"} "}

View File

@ -95,6 +95,7 @@ require('packer').startup(
use 'sainnhe/gruvbox-material' use 'sainnhe/gruvbox-material'
use 'shaunsingh/nord.nvim' use 'shaunsingh/nord.nvim'
use 'NTBBloodbath/doom-one.nvim' use 'NTBBloodbath/doom-one.nvim'
-- colorful status line and theme -- colorful status line and theme
use 'vim-airline/vim-airline-themes' use 'vim-airline/vim-airline-themes'
use 'vim-airline/vim-airline' use 'vim-airline/vim-airline'
@ -106,6 +107,9 @@ require('packer').startup(
-- Highlight URLs inside vim -- Highlight URLs inside vim
use 'itchyny/vim-highlighturl' 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 -- 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. -- 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 if (vim.g.is_win == 1) or (vim.g.is_mac == 1) then