enhance: improved notices.show_notices (#70)

- Prefer use of lua functions instead of vim.cmd
 - Added buffer and window options
 - Moved from append to appendbufline
This commit is contained in:
CantoroMC 2021-09-27 14:04:54 +02:00 committed by GitHub
parent 20a87ac78c
commit 05d6a13369
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 9 deletions

View File

@ -36,12 +36,22 @@ function M.notice_message_startup()
end
function M.show_notices()
vim.cmd [[
:silent! new
:silent! setl ft=markdown bt=nofile nobuflisted bh=wipe
:silent! nnoremap <silent><buffer> q <cmd>bd<cr>
:silent! normal ggdG
]]
vim.cmd('silent! keepalt split')
local winid = vim.fn.win_getid()
local bufnr = vim.api.nvim_create_buf(false, true)
vim.api.nvim_win_set_buf(winid, bufnr)
vim.wo[winid].winfixheight = true
vim.wo[winid].winfixwidth = true
vim.wo[winid].number = false
vim.wo[winid].foldcolumn = '0'
vim.wo[winid].relativenumber = false
vim.wo[winid].signcolumn = 'no'
vim.bo[bufnr].filetype = 'markdown'
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'q', '<Cmd>bd<CR>', { noremap = true, silent = true })
local ok, _ = pcall(vim.api.nvim_buf_set_name, 0, 'Lualine Notices')
if not ok then
vim.notify('Lualine Notices is already open in another window', vim.log.levels.ERROR, {})
@ -50,9 +60,12 @@ function M.show_notices()
end
local notice = vim.tbl_flatten(persistent_notices)
notice = vim.list_extend(notice, vim.tbl_flatten(notices))
vim.fn.append(0, notice)
vim.api.nvim_win_set_cursor(0, { 1, 0 })
vim.bo.modifiable=false
vim.fn.appendbufline(bufnr, 0, notice)
vim.fn.deletebufline(bufnr, #notice, vim.fn.line('$'))
vim.api.nvim_win_set_cursor(winid, { 1, 0 })
vim.bo[bufnr].modified = false
vim.bo[bufnr].modifiable = false
end
function M.clear_notices()