From 83572cc15ba2e741e58bd8d8d222b06ec8d0e256 Mon Sep 17 00:00:00 2001 From: siduck Date: Thu, 15 Sep 2022 07:51:13 +0530 Subject: [PATCH] move tabufline related functions to ui repo --- lua/core/mappings.lua | 20 ++++++------- lua/core/utils.lua | 67 ------------------------------------------- lua/plugins/init.lua | 2 +- 3 files changed, 11 insertions(+), 78 deletions(-) diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index 0abf7fd..3d9df51 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -59,14 +59,6 @@ M.general = { -- new buffer ["b"] = { " enew ", "new buffer" }, - - -- close buffer + hide terminal buffer - ["x"] = { - function() - require("core.utils").close_buffer() - end, - "close buffer", - }, }, t = { [""] = { termcodes "", "escape terminal mode" } }, @@ -92,20 +84,28 @@ M.tabufline = { -- cycle through buffers [""] = { function() - require("core.utils").tabuflineNext() + require("nvchad_ui.tabufline").tabuflineNext() end, "goto next buffer", }, [""] = { function() - require("core.utils").tabuflinePrev() + require("nvchad_ui.tabufline").tabuflinePrev() end, "goto prev buffer", }, -- pick buffers via numbers [""] = { " TbufPick ", "Pick buffer" }, + + -- close buffer + hide terminal buffer + ["x"] = { + function() + require("nvchad_ui.tabufline").close_buffer() + end, + "close buffer", + }, }, } diff --git a/lua/core/utils.lua b/lua/core/utils.lua index 6c23977..b74278b 100644 --- a/lua/core/utils.lua +++ b/lua/core/utils.lua @@ -1,18 +1,6 @@ local M = {} -local api = vim.api - local merge_tb = vim.tbl_deep_extend -M.close_buffer = function(bufnr) - if vim.bo.buftype == "terminal" then - vim.cmd(vim.bo.buflisted and "set nobl | enew" or "hide") - else - bufnr = bufnr or api.nvim_get_current_buf() - require("core.utils").tabuflinePrev() - vim.cmd("confirm bd" .. bufnr) - end -end - M.load_config = function() local config = require "core.default_config" local chadrc_exists, chadrc = pcall(require, "custom.chadrc") @@ -201,59 +189,4 @@ M.packer_sync = function(...) end end -M.bufilter = function() - local bufs = vim.t.bufs or nil - - if not bufs then - return {} - end - - for i = #bufs, 1, -1 do - if not vim.api.nvim_buf_is_valid(bufs[i]) then - table.remove(bufs, i) - end - end - - return bufs -end - -M.tabuflineNext = function() - local bufs = M.bufilter() or {} - - for i, v in ipairs(bufs) do - if api.nvim_get_current_buf() == v then - vim.cmd(i == #bufs and "b" .. bufs[1] or "b" .. bufs[i + 1]) - break - end - end -end - -M.tabuflinePrev = function() - local bufs = M.bufilter() or {} - - for i, v in ipairs(bufs) do - if api.nvim_get_current_buf() == v then - vim.cmd(i == 1 and "b" .. bufs[#bufs] or "b" .. bufs[i - 1]) - break - end - end -end - --- closes tab + all of its buffers -M.closeAllBufs = function(action) - local bufs = vim.t.bufs - - if action == "closeTab" then - vim.cmd "tabclose" - end - - for _, buf in ipairs(bufs) do - M.close_buffer(buf) - end - - if action ~= "closeTab" then - vim.cmd "enew" - end -end - return M diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 52710ac..1cc7f82 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -195,7 +195,7 @@ local plugins = { ["folke/which-key.nvim"] = { disable = true, module = "which-key", - keys = { "", "\"", "'", "`" }, + keys = { "", '"', "'", "`" }, config = function() require "plugins.configs.whichkey" end,