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
@ -50,7 +49,7 @@ local function terms()
map("t", m.esc_termmode, "<C-\\><C-n>", opt) map("t", m.esc_termmode, "<C-\\><C-n>", opt)
-- hide a term from within terminal mode -- hide a term from within terminal mode
map("t", m.esc_hide_termmode, "<C-\\><C-n> :lua require('utils').close_buffer() <CR>", opt) map("t", m.esc_hide_termmode, "<C-\\><C-n> :lua require('utils').close_buffer() <CR>", opt)
-- pick a hidden term -- pick a hidden term
map("n", m.pick_term, ":Telescope terms <CR>", opt) map("n", m.pick_term, ":Telescope terms <CR>", opt)
-- Open terminals -- Open terminals

View File

@ -27,7 +27,7 @@ opt.fillchars = { eob = " " }
-- Numbers -- Numbers
opt.number = options.number opt.number = options.number
opt.numberwidth = options.numberwidth opt.numberwidth = options.numberwidth
opt.relativenumber = options.relativenumber opt.relativenumber = options.relativenumber
-- Indenline -- Indenline
opt.expandtab = options.expandtab opt.expandtab = options.expandtab

View File

@ -5,7 +5,7 @@ local present, bufferline = pcall(require, "bufferline")
if not present then if not present then
return return
end end
bufferline.setup { bufferline.setup {
options = { options = {
offsets = { { filetype = "NvimTree", text = "", padding = 1 } }, offsets = { { filetype = "NvimTree", text = "", padding = 1 } },
@ -25,23 +25,23 @@ bufferline.setup {
mappings = true, mappings = true,
always_show_bufferline = true, always_show_bufferline = true,
custom_filter = function(buf_number) custom_filter = function(buf_number)
-- Func to filter out our managed/persistent split terms -- Func to filter out our managed/persistent split terms
local present_type, type = pcall(function() local present_type, type = pcall(function()
return vim.api.nvim_buf_get_var(buf_number, "term_type") return vim.api.nvim_buf_get_var(buf_number, "term_type")
end) end)
if present_type then if present_type then
if type == "vert" then if type == "vert" then
return false return false
elseif type == "hori" then elseif type == "hori" then
return false return false
else else
return true return true
end end
else else
return true return true
end end
end, end,
}, },
highlights = { highlights = {
fill = { fill = {

View File

@ -10,7 +10,7 @@ M.term_picker = function(opts)
pickers = require "telescope.pickers" pickers = require "telescope.pickers"
finders = require "telescope.finders" finders = require "telescope.finders"
previewers = require "telescope.previewers" previewers = require "telescope.previewers"
make_entry = require "telescope.make_entry" make_entry = require "telescope.make_entry"
actions = require "telescope.actions" actions = require "telescope.actions"
action_state = require "telescope.actions.state" action_state = require "telescope.actions.state"
@ -19,26 +19,25 @@ M.term_picker = function(opts)
else else
error "Cannot find telescope!" error "Cannot find telescope!"
end end
local filter = vim.tbl_filter local filter = vim.tbl_filter
local local_utils = require "utils" local local_utils = require "utils"
-- buffer number and name -- buffer number and name
local bufnr = vim.api.nvim_get_current_buf() local bufnr = vim.api.nvim_get_current_buf()
local bufname = vim.api.nvim_buf_get_name(bufnr) local bufname = vim.api.nvim_buf_get_name(bufnr)
local bufnrs = filter(function(b) local bufnrs = filter(function(b)
local present_type, type = pcall(function() local present_type, type = pcall(function()
return vim.api.nvim_buf_get_var(b, "term_type") return vim.api.nvim_buf_get_var(b, "term_type")
end) end)
if not present_type then if not present_type then
-- let's only terms that we created -- let's only terms that we created
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
@ -59,22 +58,22 @@ M.term_picker = function(opts)
return vim.fn.getbufinfo(a)[1].lastused > vim.fn.getbufinfo(b)[1].lastused return vim.fn.getbufinfo(a)[1].lastused > vim.fn.getbufinfo(b)[1].lastused
end) end)
end end
local buffers = {} local buffers = {}
local default_selection_idx = 1 local default_selection_idx = 1
for _, bufnr in ipairs(bufnrs) do for _, bufnr in ipairs(bufnrs) do
local flag = bufnr == vim.fn.bufnr "" and "%" or (bufnr == vim.fn.bufnr "#" and "#" or " ") local flag = bufnr == vim.fn.bufnr "" and "%" or (bufnr == vim.fn.bufnr "#" and "#" or " ")
if opts.sort_lastused and not opts.ignore_current_buffer and flag == "#" then if opts.sort_lastused and not opts.ignore_current_buffer and flag == "#" then
default_selection_idx = 2 default_selection_idx = 2
end end
local element = { local element = {
bufnr = bufnr, bufnr = bufnr,
flag = flag, flag = flag,
info = vim.fn.getbufinfo(bufnr)[1], info = vim.fn.getbufinfo(bufnr)[1],
} }
if opts.sort_lastused and (flag == "#" or flag == "%") then if opts.sort_lastused and (flag == "#" or flag == "%") then
local idx = ((buffers[1] ~= nil and buffers[1].flag == "%") and 2 or 1) local idx = ((buffers[1] ~= nil and buffers[1].flag == "%") and 2 or 1)
table.insert(buffers, idx, element) table.insert(buffers, idx, element)
@ -82,12 +81,12 @@ M.term_picker = function(opts)
table.insert(buffers, element) table.insert(buffers, element)
end end
end end
if not opts.bufnr_width then if not opts.bufnr_width then
local max_bufnr = math.max(unpack(bufnrs)) local max_bufnr = math.max(unpack(bufnrs))
opts.bufnr_width = #tostring(max_bufnr) opts.bufnr_width = #tostring(max_bufnr)
end end
pickers.new(opts, { pickers.new(opts, {
prompt_title = "Terminal buffers", prompt_title = "Terminal buffers",
finder = finders.new_table { finder = finders.new_table {
@ -103,24 +102,24 @@ M.term_picker = function(opts)
actions.close(prompt_bufnr) actions.close(prompt_bufnr)
local buf = entry.bufnr local buf = entry.bufnr
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)
-- TODO buffer checks/error detection (make sure we do get a buf) -- TODO buffer checks/error detection (make sure we do get a buf)
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

@ -36,39 +36,39 @@ end
M.close_buffer = function(bufexpr, force) M.close_buffer = function(bufexpr, force)
-- This is a modification of a NeoVim plugin from -- This is a modification of a NeoVim plugin from
-- Author: ojroques - Olivier Roques -- Author: ojroques - Olivier Roques
-- Src: https://github.com/ojroques/nvim-bufdel -- Src: https://github.com/ojroques/nvim-bufdel
-- (Author has okayed copy-paste) -- (Author has okayed copy-paste)
-- 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
} }
-- ---------------- -- ----------------
-- Helper functions -- Helper functions
-- ---------------- -- ----------------
-- Switch to buffer 'buf' on each window from list 'windows' -- Switch to buffer 'buf' on each window from list 'windows'
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
@ -78,68 +78,68 @@ M.close_buffer = function(bufexpr, force)
-- ---------------- -- ----------------
-- End helper functions -- End helper functions
-- ---------------- -- ----------------
local buf = vim.fn.bufnr() local buf = vim.fn.bufnr()
if vim.fn.buflisted(buf) == 0 then -- exit if buffer number is invalid if vim.fn.buflisted(buf) == 0 then -- exit if buffer number is invalid
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
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)
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)
-- TODO this scope is error prone, make resilient -- TODO this scope is error prone, make resilient
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