mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-14 01:50:27 +00:00
Merge pull request #66 from rudotriton/formatting
formatting with stylua
This commit is contained in:
commit
c2b7ef3d37
5
.stylua.toml
Normal file
5
.stylua.toml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
column_width = 120
|
||||||
|
line_endings = "Unix"
|
||||||
|
indent_type = "Spaces"
|
||||||
|
indent_width = 4
|
||||||
|
quote_style = "AutoPreferDouble"
|
@ -6,7 +6,7 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.reload = function()
|
M.reload = function()
|
||||||
require("plenary.reload").reload_module("harpoon");
|
require("plenary.reload").reload_module("harpoon")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function set_log_level()
|
local function set_log_level()
|
||||||
|
@ -48,7 +48,7 @@ end
|
|||||||
local function merge_tables(...)
|
local function merge_tables(...)
|
||||||
log.trace("_merge_tables()")
|
log.trace("_merge_tables()")
|
||||||
local out = {}
|
local out = {}
|
||||||
for i = 1, select("#",...) do
|
for i = 1, select("#", ...) do
|
||||||
merge_table_impl(out, select(i, ...))
|
merge_table_impl(out, select(i, ...))
|
||||||
end
|
end
|
||||||
return out
|
return out
|
||||||
@ -61,10 +61,10 @@ local function ensure_correct_config(config)
|
|||||||
log.debug("ensure_correct_config(): No config found for:", vim.loop.cwd())
|
log.debug("ensure_correct_config(): No config found for:", vim.loop.cwd())
|
||||||
projects[vim.loop.cwd()] = {
|
projects[vim.loop.cwd()] = {
|
||||||
mark = {
|
mark = {
|
||||||
marks = {}
|
marks = {},
|
||||||
},
|
},
|
||||||
term = {
|
term = {
|
||||||
cmds = {}
|
cmds = {},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@ -72,12 +72,12 @@ local function ensure_correct_config(config)
|
|||||||
local proj = projects[vim.loop.cwd()]
|
local proj = projects[vim.loop.cwd()]
|
||||||
if proj.mark == nil then
|
if proj.mark == nil then
|
||||||
log.debug("ensure_correct_config(): No marks found for", vim.loop.cwd())
|
log.debug("ensure_correct_config(): No marks found for", vim.loop.cwd())
|
||||||
proj.mark = {marks = {}}
|
proj.mark = { marks = {} }
|
||||||
end
|
end
|
||||||
|
|
||||||
if proj.term == nil then
|
if proj.term == nil then
|
||||||
log.debug("ensure_correct_config(): No terminal commands found for", vim.loop.cwd())
|
log.debug("ensure_correct_config(): No terminal commands found for", vim.loop.cwd())
|
||||||
proj.term = {cmds = {}}
|
proj.term = { cmds = {} }
|
||||||
end
|
end
|
||||||
|
|
||||||
local marks = proj.mark.marks
|
local marks = proj.mark.marks
|
||||||
@ -85,7 +85,7 @@ local function ensure_correct_config(config)
|
|||||||
local mark = marks[idx]
|
local mark = marks[idx]
|
||||||
if type(mark) == "string" then
|
if type(mark) == "string" then
|
||||||
mark = {
|
mark = {
|
||||||
filename = mark
|
filename = mark,
|
||||||
}
|
}
|
||||||
marks[idx] = mark
|
marks[idx] = mark
|
||||||
end
|
end
|
||||||
@ -144,15 +144,13 @@ M.setup = function(config)
|
|||||||
c_config = {}
|
c_config = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
local complete_config =
|
local complete_config = merge_tables({
|
||||||
merge_tables(
|
projects = {},
|
||||||
{projects = {} , global_settings = {
|
global_settings = {
|
||||||
["save_on_toggle"] = false,
|
["save_on_toggle"] = false,
|
||||||
["save_on_change"] = true,
|
["save_on_change"] = true,
|
||||||
}},
|
},
|
||||||
expand_dir(c_config),
|
}, expand_dir(c_config), expand_dir(u_config), expand_dir(config))
|
||||||
expand_dir(u_config),
|
|
||||||
expand_dir(config))
|
|
||||||
|
|
||||||
-- There was this issue where the vim.loop.cwd() didn't have marks or term, but had
|
-- There was this issue where the vim.loop.cwd() didn't have marks or term, but had
|
||||||
-- an object for vim.loop.cwd()
|
-- an object for vim.loop.cwd()
|
||||||
@ -191,4 +189,3 @@ end
|
|||||||
M.setup()
|
M.setup()
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
||||||
|
@ -113,10 +113,10 @@ M.get_index_of = function(item)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if type(item) == 'string' then
|
if type(item) == "string" then
|
||||||
local relative_item = utils.normalize_path(item)
|
local relative_item = utils.normalize_path(item)
|
||||||
for idx = 1, M.get_length() do
|
for idx = 1, M.get_length() do
|
||||||
if M.get_marked_file_name(idx) == relative_item then
|
if M.get_marked_file_name(idx) == relative_item then
|
||||||
return idx
|
return idx
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -171,7 +171,7 @@ M.add_file = function(file_name_or_buf_id)
|
|||||||
local found_idx = get_first_empty_slot()
|
local found_idx = get_first_empty_slot()
|
||||||
harpoon.get_mark_config().marks[found_idx] = create_mark(buf_name)
|
harpoon.get_mark_config().marks[found_idx] = create_mark(buf_name)
|
||||||
M.remove_empty_tail(false)
|
M.remove_empty_tail(false)
|
||||||
emit_changed();
|
emit_changed()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- _emit_on_changed == false should only be used internally
|
-- _emit_on_changed == false should only be used internally
|
||||||
@ -328,7 +328,7 @@ M.toggle_file = function(file_name_or_buf_id)
|
|||||||
|
|
||||||
validate_buf_name(buf_name)
|
validate_buf_name(buf_name)
|
||||||
|
|
||||||
if (mark_exists(buf_name)) then
|
if mark_exists(buf_name) then
|
||||||
M.rm_file(buf_name)
|
M.rm_file(buf_name)
|
||||||
print("Mark removed")
|
print("Mark removed")
|
||||||
log.debug("toggle_file(): Mark removed")
|
log.debug("toggle_file(): Mark removed")
|
||||||
@ -356,5 +356,3 @@ M.on = function(event, cb)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local harpoon = require('harpoon')
|
local harpoon = require("harpoon")
|
||||||
local Path = require("plenary.path")
|
local Path = require("plenary.path")
|
||||||
local log = require("harpoon.dev").log
|
local log = require("harpoon.dev").log
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ local function create_terminal()
|
|||||||
|
|
||||||
vim.cmd(":terminal")
|
vim.cmd(":terminal")
|
||||||
local buf_id = vim.fn.bufnr()
|
local buf_id = vim.fn.bufnr()
|
||||||
local term_id = vim.b.terminal_job_id
|
local term_id = vim.b.terminal_job_id
|
||||||
|
|
||||||
if term_id == nil then
|
if term_id == nil then
|
||||||
log.error("_create_terminal(): term_id is nil")
|
log.error("_create_terminal(): term_id is nil")
|
||||||
@ -21,7 +21,7 @@ local function create_terminal()
|
|||||||
|
|
||||||
-- Make sure the term buffer has "hidden" set so it doesn't get thrown
|
-- Make sure the term buffer has "hidden" set so it doesn't get thrown
|
||||||
-- away and cause an error
|
-- away and cause an error
|
||||||
vim.api.nvim_buf_set_option(buf_id, 'bufhidden', 'hide')
|
vim.api.nvim_buf_set_option(buf_id, "bufhidden", "hide")
|
||||||
|
|
||||||
-- Resets the buffer back to the old one
|
-- Resets the buffer back to the old one
|
||||||
vim.api.nvim_set_current_buf(current_id)
|
vim.api.nvim_set_current_buf(current_id)
|
||||||
@ -43,7 +43,7 @@ local function find_terminal(idx)
|
|||||||
|
|
||||||
term_handle = {
|
term_handle = {
|
||||||
buf_id = buf_id,
|
buf_id = buf_id,
|
||||||
term_id = term_id
|
term_id = term_id,
|
||||||
}
|
}
|
||||||
terminals[idx] = term_handle
|
terminals[idx] = term_handle
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
local harpoon = require('harpoon')
|
local harpoon = require("harpoon")
|
||||||
local popup = require('popup')
|
local popup = require("popup")
|
||||||
local Marked = require('harpoon.mark')
|
local Marked = require("harpoon.mark")
|
||||||
local log = require("harpoon.dev").log
|
local log = require("harpoon.dev").log
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
@ -13,12 +13,12 @@ local function create_window()
|
|||||||
local config = harpoon.get_menu_config()
|
local config = harpoon.get_menu_config()
|
||||||
local width = config.width or 60
|
local width = config.width or 60
|
||||||
local height = config.height or 10
|
local height = config.height or 10
|
||||||
local borderchars = config.borderchars or { '─', '│', '─', '│', '╭', '╮', '╯', '╰' }
|
local borderchars = config.borderchars or { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }
|
||||||
local bufnr = vim.api.nvim_create_buf(false, false)
|
local bufnr = vim.api.nvim_create_buf(false, false)
|
||||||
|
|
||||||
local Harpoon_win_id, win = popup.create(bufnr, {
|
local Harpoon_win_id, win = popup.create(bufnr, {
|
||||||
title = 'Harpoon',
|
title = "Harpoon",
|
||||||
highlight = 'HarpoonWindow',
|
highlight = "HarpoonWindow",
|
||||||
line = math.floor(((vim.o.lines - height) / 2) - 1),
|
line = math.floor(((vim.o.lines - height) / 2) - 1),
|
||||||
col = math.floor((vim.o.columns - width) / 2),
|
col = math.floor((vim.o.columns - width) / 2),
|
||||||
minwidth = width,
|
minwidth = width,
|
||||||
@ -26,7 +26,7 @@ local function create_window()
|
|||||||
borderchars = borderchars,
|
borderchars = borderchars,
|
||||||
})
|
})
|
||||||
|
|
||||||
vim.api.nvim_win_set_option(win.border.win_id, 'winhl', 'Normal:HarpoonBorder')
|
vim.api.nvim_win_set_option(win.border.win_id, "winhl", "Normal:HarpoonBorder")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
bufnr = bufnr,
|
bufnr = bufnr,
|
||||||
@ -40,7 +40,7 @@ local function get_menu_items()
|
|||||||
local indices = {}
|
local indices = {}
|
||||||
|
|
||||||
for idx = 1, #lines do
|
for idx = 1, #lines do
|
||||||
local space_location = string.find(lines[idx], ' ')
|
local space_location = string.find(lines[idx], " ")
|
||||||
log.debug("_get_menu_items():", idx, space_location)
|
log.debug("_get_menu_items():", idx, space_location)
|
||||||
|
|
||||||
if space_location ~= nil then
|
if space_location ~= nil then
|
||||||
@ -51,15 +51,13 @@ local function get_menu_items()
|
|||||||
return indices
|
return indices
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
M.toggle_quick_menu = function()
|
M.toggle_quick_menu = function()
|
||||||
log.trace("toggle_quick_menu()")
|
log.trace("toggle_quick_menu()")
|
||||||
if Harpoon_win_id ~= nil and vim.api.nvim_win_is_valid(Harpoon_win_id) then
|
if Harpoon_win_id ~= nil and vim.api.nvim_win_is_valid(Harpoon_win_id) then
|
||||||
local global_config = harpoon.get_global_settings()
|
local global_config = harpoon.get_global_settings()
|
||||||
|
|
||||||
if global_config.save_on_toggle then
|
if global_config.save_on_toggle then
|
||||||
require('harpoon.ui').on_menu_save()
|
require("harpoon.ui").on_menu_save()
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_win_close(Harpoon_win_id, true)
|
vim.api.nvim_win_close(Harpoon_win_id, true)
|
||||||
@ -119,14 +117,14 @@ end
|
|||||||
|
|
||||||
function M.location_window(options)
|
function M.location_window(options)
|
||||||
local default_options = {
|
local default_options = {
|
||||||
relative = 'editor',
|
relative = "editor",
|
||||||
style = 'minimal',
|
style = "minimal",
|
||||||
width = 30,
|
width = 30,
|
||||||
height = 15,
|
height = 15,
|
||||||
row = 2,
|
row = 2,
|
||||||
col = 2,
|
col = 2,
|
||||||
}
|
}
|
||||||
options = vim.tbl_extend('keep', options, default_options)
|
options = vim.tbl_extend("keep", options, default_options)
|
||||||
|
|
||||||
local bufnr = options.bufnr or vim.fn.nvim_create_buf(false, true)
|
local bufnr = options.bufnr or vim.fn.nvim_create_buf(false, true)
|
||||||
local win_id = vim.fn.nvim_open_win(bufnr, true, options)
|
local win_id = vim.fn.nvim_open_win(bufnr, true, options)
|
||||||
@ -147,15 +145,15 @@ function M.notification(text)
|
|||||||
width = 20,
|
width = 20,
|
||||||
height = 2,
|
height = 2,
|
||||||
row = 1,
|
row = 1,
|
||||||
col = win_width - 21
|
col = win_width - 21,
|
||||||
})
|
})
|
||||||
|
|
||||||
vim.api.nvim_buf_set_lines(info.bufnr, 0, 5, false, {"!!! Notification", text})
|
vim.api.nvim_buf_set_lines(info.bufnr, 0, 5, false, { "!!! Notification", text })
|
||||||
vim.api.nvim_set_current_win(prev_win)
|
vim.api.nvim_set_current_win(prev_win)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
bufnr = info.bufnr,
|
bufnr = info.bufnr,
|
||||||
win_id = info.win_id
|
win_id = info.win_id,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -168,13 +166,13 @@ M.nav_next = function()
|
|||||||
local current_index = Marked.get_current_index()
|
local current_index = Marked.get_current_index()
|
||||||
local number_of_items = Marked.get_length()
|
local number_of_items = Marked.get_length()
|
||||||
|
|
||||||
if current_index == nil then
|
if current_index == nil then
|
||||||
current_index = 1
|
current_index = 1
|
||||||
else
|
else
|
||||||
current_index = current_index + 1
|
current_index = current_index + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if (current_index > number_of_items) then
|
if current_index > number_of_items then
|
||||||
current_index = 1
|
current_index = 1
|
||||||
end
|
end
|
||||||
M.nav_file(current_index)
|
M.nav_file(current_index)
|
||||||
@ -185,13 +183,13 @@ M.nav_prev = function()
|
|||||||
local current_index = Marked.get_current_index()
|
local current_index = Marked.get_current_index()
|
||||||
local number_of_items = Marked.get_length()
|
local number_of_items = Marked.get_length()
|
||||||
|
|
||||||
if current_index == nil then
|
if current_index == nil then
|
||||||
current_index = number_of_items
|
current_index = number_of_items
|
||||||
else
|
else
|
||||||
current_index = current_index - 1
|
current_index = current_index - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if (current_index < 1) then
|
if current_index < 1 then
|
||||||
current_index = number_of_items
|
current_index = number_of_items
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -199,4 +197,3 @@ M.nav_prev = function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ local M = {
|
|||||||
data_path = data_path,
|
data_path = data_path,
|
||||||
normalize_path = function(item)
|
normalize_path = function(item)
|
||||||
return Path:new(item):make_relative(vim.loop.cwd())
|
return Path:new(item):make_relative(vim.loop.cwd())
|
||||||
end
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
Loading…
x
Reference in New Issue
Block a user