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

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