From 05d6a13369bcb606f4e60aeb43e685a1b699a746 Mon Sep 17 00:00:00 2001 From: CantoroMC <62297689+CantoroMC@users.noreply.github.com> Date: Mon, 27 Sep 2021 14:04:54 +0200 Subject: [PATCH] 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 --- lua/lualine/utils/notices.lua | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/lua/lualine/utils/notices.lua b/lua/lualine/utils/notices.lua index 4b8701e..e059805 100644 --- a/lua/lualine/utils/notices.lua +++ b/lua/lualine/utils/notices.lua @@ -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 q bd - :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', 'bd', { 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()