tree-wide: Format files

ugh why do people don't push formatted stuff
This commit is contained in:
Akianonymus 2021-08-19 13:58:07 +05:30 committed by siduck76
parent 6224ed6283
commit e3f0429a72
5 changed files with 69 additions and 71 deletions

View file

@ -41,7 +41,6 @@ map("n", miscMap.copywhole_file, ":%y+<CR>", opt)
-- toggle numbers -- toggle numbers
map("n", miscMap.toggle_linenr, ":set nu!<CR>", opt) map("n", miscMap.toggle_linenr, ":set nu!<CR>", opt)
-- terminals -- terminals
local function terms() local function terms()
local m = user_map.terms local m = user_map.terms

View file

@ -38,7 +38,6 @@ M.term_picker = function(opts)
return false return false
end end
-- if 1 ~= vim.fn.buflisted(b) then -- if 1 ~= vim.fn.buflisted(b) then
-- return false -- return false
-- end -- end
@ -113,14 +112,14 @@ M.term_picker = function(opts)
if chad_term then if chad_term then
if type == "wind" then if type == "wind" then
-- swtich to term buff & show in bufferline -- swtich to term buff & show in bufferline
vim.cmd(string.format('b %d | setlocal bl', buf)) vim.cmd(string.format("b %d | setlocal bl", buf))
-- vim.cmd('startinsert') TODO fix this -- vim.cmd('startinsert') TODO fix this
elseif type == "vert" then elseif type == "vert" then
vim.cmd(string.format('vsp #%d', buf)) vim.cmd(string.format("vsp #%d", buf))
-- vim.cmd('startinsert') TODO fix this -- vim.cmd('startinsert') TODO fix this
elseif type == "hori" then elseif type == "hori" then
-- TODO change 15 to a chad config var number -- TODO change 15 to a chad config var number
vim.cmd(string.format('15 sp #%d ', buf)) vim.cmd(string.format("15 sp #%d ", buf))
-- vim.cmd('startinsert') TODO fix this -- vim.cmd('startinsert') TODO fix this
end end
end end

View file

@ -42,7 +42,7 @@ M.close_buffer = function(bufexpr, force)
-- Options -- Options
local opts = { local opts = {
next = 'cycle', -- how to retrieve the next buffer next = "cycle", -- how to retrieve the next buffer
quit = false, -- exit when last buffer is deleted quit = false, -- exit when last buffer is deleted
--TODO make this a chadrc flag/option --TODO make this a chadrc flag/option
} }
@ -55,20 +55,20 @@ M.close_buffer = function(bufexpr, force)
local function switch_buffer(windows, buf) local function switch_buffer(windows, buf)
local cur_win = vim.fn.winnr() local cur_win = vim.fn.winnr()
for _, winid in ipairs(windows) do for _, winid in ipairs(windows) do
vim.cmd(string.format('%d wincmd w', vim.fn.win_id2win(winid))) vim.cmd(string.format("%d wincmd w", vim.fn.win_id2win(winid)))
vim.cmd(string.format('buffer %d', buf)) vim.cmd(string.format("buffer %d", buf))
end end
vim.cmd(string.format('%d wincmd w', cur_win)) -- return to original window vim.cmd(string.format("%d wincmd w", cur_win)) -- return to original window
end end
-- Select the first buffer with a number greater than given buffer -- Select the first buffer with a number greater than given buffer
local function get_next_buf(buf) local function get_next_buf(buf)
local next = vim.fn.bufnr('#') local next = vim.fn.bufnr "#"
if opts.next == 'alternate' and vim.fn.buflisted(next) == 1 then if opts.next == "alternate" and vim.fn.buflisted(next) == 1 then
return next return next
end end
for i = 0, vim.fn.bufnr('$') - 1 do for i = 0, vim.fn.bufnr "$" - 1 do
next = (buf + i) % vim.fn.bufnr('$') + 1 -- will loop back to 1 next = (buf + i) % vim.fn.bufnr "$" + 1 -- will loop back to 1
if vim.fn.buflisted(next) == 1 then if vim.fn.buflisted(next) == 1 then
return next return next
end end
@ -84,13 +84,13 @@ M.close_buffer = function(bufexpr, force)
return return
end end
if #vim.fn.getbufinfo({buflisted = 1}) < 2 then if #vim.fn.getbufinfo { buflisted = 1 } < 2 then
if opts.quit then if opts.quit then
-- exit when there is only one buffer left -- exit when there is only one buffer left
if force then if force then
vim.cmd('qall!') vim.cmd "qall!"
else else
vim.cmd('confirm qall') vim.cmd "confirm qall"
end end
return return
end end
@ -101,20 +101,20 @@ M.close_buffer = function(bufexpr, force)
if chad_term then if chad_term then
-- Must be a window type -- Must be a window type
vim.cmd(string.format('setlocal nobl', buf)) vim.cmd(string.format("setlocal nobl", buf))
vim.cmd('enew') vim.cmd "enew"
return return
end end
-- don't exit and create a new empty buffer -- don't exit and create a new empty buffer
vim.cmd('enew') vim.cmd "enew"
vim.cmd('bp') vim.cmd "bp"
end end
local next_buf = get_next_buf(buf) local next_buf = get_next_buf(buf)
local windows = vim.fn.getbufinfo(buf)[1].windows local windows = vim.fn.getbufinfo(buf)[1].windows
-- force deletion of terminal buffers to avoid the prompt -- force deletion of terminal buffers to avoid the prompt
if force or vim.fn.getbufvar(buf, '&buftype') == 'terminal' then if force or vim.fn.getbufvar(buf, "&buftype") == "terminal" then
local chad_term, type = pcall(function() local chad_term, type = pcall(function()
return vim.api.nvim_buf_get_var(buf, "term_type") return vim.api.nvim_buf_get_var(buf, "term_type")
end) end)
@ -123,23 +123,23 @@ M.close_buffer = function(bufexpr, force)
if chad_term then if chad_term then
if type == "wind" then if type == "wind" then
-- hide from bufferline -- hide from bufferline
vim.cmd(string.format('%d bufdo setlocal nobl', buf)) vim.cmd(string.format("%d bufdo setlocal nobl", buf))
-- swtich to another buff -- swtich to another buff
-- TODO switch to next bufffer, this works too -- TODO switch to next bufffer, this works too
vim.cmd('BufferLineCycleNext') vim.cmd "BufferLineCycleNext"
else else
local cur_win = vim.fn.winnr() local cur_win = vim.fn.winnr()
-- we can close this window -- we can close this window
vim.cmd(string.format('%d wincmd c', cur_win)) vim.cmd(string.format("%d wincmd c", cur_win))
return return
end end
else else
switch_buffer(windows, next_buf) switch_buffer(windows, next_buf)
vim.cmd(string.format('bd! %d', buf)) vim.cmd(string.format("bd! %d", buf))
end end
else else
switch_buffer(windows, next_buf) switch_buffer(windows, next_buf)
vim.cmd(string.format('silent! confirm bd %d', buf)) vim.cmd(string.format("silent! confirm bd %d", buf))
end end
-- revert buffer switches if user has canceled deletion -- revert buffer switches if user has canceled deletion
if vim.fn.buflisted(buf) == 1 then if vim.fn.buflisted(buf) == 1 then