Merge pull request #260 from ThePrimeagen/fix_buf_with_style

Fix buf with style
This commit is contained in:
ThePrimeagen 2023-02-22 20:00:08 -07:00 committed by GitHub
commit f7040fd0c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 41 deletions

View File

@ -10,8 +10,10 @@ local cache_config = string.format("%s/harpoon.json", data_path)
local M = {} local M = {}
local the_primeagen_harpoon = local the_primeagen_harpoon = vim.api.nvim_create_augroup(
vim.api.nvim_create_augroup("THE_PRIMEAGEN_HARPOON", { clear = true }) "THE_PRIMEAGEN_HARPOON",
{ clear = true }
)
vim.api.nvim_create_autocmd({ "BufLeave, VimLeave" }, { vim.api.nvim_create_autocmd({ "BufLeave, VimLeave" }, {
callback = function() callback = function()
@ -33,7 +35,7 @@ vim.api.nvim_create_autocmd("FileType", {
local working_directory = vim.fn.getcwd() .. "/" local working_directory = vim.fn.getcwd() .. "/"
vim.cmd("vs") vim.cmd("vs")
vim.cmd("e " .. working_directory .. curline) vim.cmd("e " .. working_directory .. curline)
end, { buffer=true, noremap = true, silent = true }) end, { buffer = true, noremap = true, silent = true })
-- horizontal split (control+x) -- horizontal split (control+x)
vim.keymap.set("n", "<C-x>", function() vim.keymap.set("n", "<C-x>", function()
@ -41,7 +43,7 @@ vim.api.nvim_create_autocmd("FileType", {
local working_directory = vim.fn.getcwd() .. "/" local working_directory = vim.fn.getcwd() .. "/"
vim.cmd("sp") vim.cmd("sp")
vim.cmd("e " .. working_directory .. curline) vim.cmd("e " .. working_directory .. curline)
end, { buffer=true, noremap = true, silent = true }) end, { buffer = true, noremap = true, silent = true })
-- new tab (control+t) -- new tab (control+t)
vim.keymap.set("n", "<C-t>", function() vim.keymap.set("n", "<C-t>", function()
@ -49,8 +51,8 @@ vim.api.nvim_create_autocmd("FileType", {
local working_directory = vim.fn.getcwd() .. "/" local working_directory = vim.fn.getcwd() .. "/"
vim.cmd("tabnew") vim.cmd("tabnew")
vim.cmd("e " .. working_directory .. curline) vim.cmd("e " .. working_directory .. curline)
end, { buffer=true, noremap = true, silent = true }) end, { buffer = true, noremap = true, silent = true })
end end,
}) })
--[[ --[[
{ {

View File

@ -7,8 +7,10 @@ local M = {}
local tmux_windows = {} local tmux_windows = {}
if global_config.tmux_autoclose_windows then if global_config.tmux_autoclose_windows then
local harpoon_tmux_group = local harpoon_tmux_group = vim.api.nvim_create_augroup(
vim.api.nvim_create_augroup("HARPOON_TMUX", { clear = true }) "HARPOON_TMUX",
{ clear = true }
)
vim.api.nvim_create_autocmd("VimLeave", { vim.api.nvim_create_autocmd("VimLeave", {
callback = function() callback = function()

View File

@ -205,12 +205,15 @@ function M.nav_file(id)
) )
end end
local old_bufinfo = vim.fn.getbufinfo(old_bufnr)[1] local old_bufinfo = vim.fn.getbufinfo(old_bufnr)
local no_name = old_bufinfo.name == "" if type(old_bufinfo) == "table" and #old_bufinfo >= 1 then
local one_line = old_bufinfo.linecount == 1 old_bufinfo = old_bufinfo[1]
local unchanged = old_bufinfo.changed == 0 local no_name = old_bufinfo.name == ""
if no_name and one_line and unchanged then local one_line = old_bufinfo.linecount == 1
vim.api.nvim_buf_delete(old_bufnr, {}) local unchanged = old_bufinfo.changed == 0
if no_name and one_line and unchanged then
vim.api.nvim_buf_delete(old_bufnr, {})
end
end end
end end

View File

@ -38,14 +38,16 @@ function M.get_os_command_output(cmd, cwd)
end end
local command = table.remove(cmd, 1) local command = table.remove(cmd, 1)
local stderr = {} local stderr = {}
local stdout, ret = Job:new({ local stdout, ret = Job
command = command, :new({
args = cmd, command = command,
cwd = cwd, args = cmd,
on_stderr = function(_, data) cwd = cwd,
table.insert(stderr, data) on_stderr = function(_, data)
end, table.insert(stderr, data)
}):sync() end,
})
:sync()
return stdout, ret, stderr return stdout, ret, stderr
end end

View File

@ -51,8 +51,9 @@ local generate_new_finder = function()
end end
local delete_harpoon_mark = function(prompt_bufnr) local delete_harpoon_mark = function(prompt_bufnr)
local confirmation = local confirmation = vim.fn.input(
vim.fn.input(string.format("Delete current mark(s)? [y/n]: ")) string.format("Delete current mark(s)? [y/n]: ")
)
if if
string.len(confirmation) == 0 string.len(confirmation) == 0
or string.sub(string.lower(confirmation), 0, 1) ~= "y" or string.sub(string.lower(confirmation), 0, 1) ~= "y"
@ -113,23 +114,21 @@ end
return function(opts) return function(opts)
opts = opts or {} opts = opts or {}
pickers pickers.new(opts, {
.new(opts, { prompt_title = "harpoon marks",
prompt_title = "harpoon marks", finder = generate_new_finder(),
finder = generate_new_finder(), sorter = conf.generic_sorter(opts),
sorter = conf.generic_sorter(opts), previewer = conf.grep_previewer(opts),
previewer = conf.grep_previewer(opts), attach_mappings = function(_, map)
attach_mappings = function(_, map) map("i", "<c-d>", delete_harpoon_mark)
map("i", "<c-d>", delete_harpoon_mark) map("n", "<c-d>", delete_harpoon_mark)
map("n", "<c-d>", delete_harpoon_mark)
map("i", "<c-p>", move_mark_up) map("i", "<c-p>", move_mark_up)
map("n", "<c-p>", move_mark_up) map("n", "<c-p>", move_mark_up)
map("i", "<c-n>", move_mark_down) map("i", "<c-n>", move_mark_down)
map("n", "<c-n>", move_mark_down) map("n", "<c-n>", move_mark_down)
return true return true
end, end,
}) }):find()
:find()
end end