mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-13 17:40:25 +00:00
feat(polar): mutex is about to bork me
This commit is contained in:
parent
7a9ef73961
commit
4e16fc9026
@ -1,3 +1,7 @@
|
||||
# WARNING
|
||||
This is still beta. We are getting there, but its not as fast as I would like.
|
||||
Therefore APIs are subject to change.
|
||||
|
||||
# harpoon
|
||||
The goal of Harpoon is to get you where you want with the fewest keystrokes.
|
||||
|
||||
|
@ -1,28 +1,47 @@
|
||||
local terminals = require("harpoon.terminal")
|
||||
local manage = require("harpoon.manage-a-mark")
|
||||
local terminals = require("harpoon.term")
|
||||
local manage = require("harpoon.mark")
|
||||
local cwd = cwd or vim.loop.cwd()
|
||||
local config_path = vim.fn.stdpath("config")
|
||||
local terminal_config = string.format("%s/harpoon-terminal.json", config_path)
|
||||
local data_path = vim.fn.stdpath("data")
|
||||
local user_terminal_config = string.format("%s/harpoon-terminal.json", config_path)
|
||||
local cache_terminal_config = string.format("%s/harpoon-terminal.json", data_path)
|
||||
|
||||
local M = {}
|
||||
|
||||
function expand_dir(projects)
|
||||
local expanded_config = {}
|
||||
for k in pairs(projects) do
|
||||
local expanded_path = Path.new(k):expand()
|
||||
projects[expanded_path] = projects[k]
|
||||
end
|
||||
end
|
||||
|
||||
-- 1. saved. Where do we save?
|
||||
M.setup = function(config)
|
||||
function read_terminal_config()
|
||||
return vim.fn.json_decode(Path:new(terminal_config):read())
|
||||
function read_terminal_config(config)
|
||||
return vim.fn.json_decode(Path:new(config):read())
|
||||
end
|
||||
|
||||
-- TODO: Merge the configs instead of falling back
|
||||
if not config then
|
||||
local ok, res = pcall(read_terminal_config)
|
||||
if ok then
|
||||
config = res
|
||||
else
|
||||
config = {}
|
||||
end
|
||||
config = {}
|
||||
end
|
||||
|
||||
terminals.setup(config)
|
||||
manage.setup(config)
|
||||
local ok, user_config = pcall(read_terminal_config, user_terminal_config)
|
||||
local ok2, cache_config = pcall(read_terminal_config, data_terminal_config)
|
||||
|
||||
if not ok then
|
||||
user_config = {}
|
||||
end
|
||||
|
||||
if not ok2 then
|
||||
cache_config = {}
|
||||
end
|
||||
|
||||
local complete_config =
|
||||
vim.tbl_deep_extend("force", {}, cache_config, user_config, config)
|
||||
|
||||
terminals.setup(complete_config)
|
||||
manage.setup(complete_config)
|
||||
end
|
||||
|
||||
return M
|
||||
|
@ -2,16 +2,34 @@ local Path = require('plenary.path')
|
||||
|
||||
local M = {}
|
||||
|
||||
harpoon_win_id = nil
|
||||
harpoon_bufh = nil
|
||||
|
||||
local cwd = cwd or vim.loop.cwd()
|
||||
local data_path = vim.fn.stdpath("data")
|
||||
local mark_config = {}
|
||||
|
||||
cwd = cwd:gsub("/", "_")
|
||||
|
||||
local file_name = string.format("%s/%s.cache", data_path, cwd)
|
||||
|
||||
--[[
|
||||
{
|
||||
projects = {
|
||||
["/path/to/director"] = {
|
||||
term = {
|
||||
cmds = {
|
||||
}
|
||||
... is there antyhnig that could be options?
|
||||
},
|
||||
mark = {
|
||||
marks = {
|
||||
}
|
||||
... is there antyhnig that could be options?
|
||||
}
|
||||
}
|
||||
},
|
||||
... high level settings
|
||||
}
|
||||
--]]
|
||||
|
||||
function get_id_or_current_buffer(id)
|
||||
if id == nil then
|
||||
return vim.fn.bufname(vim.fn.bufnr())
|
||||
@ -36,6 +54,18 @@ function hydrate_from_cache()
|
||||
return {}, {}
|
||||
end
|
||||
|
||||
M.setup = function(config)
|
||||
if not config.projects[cwd] then
|
||||
mark_config = {}
|
||||
else
|
||||
mark_config = config.projects[cwd].mark
|
||||
end
|
||||
end
|
||||
|
||||
M.get_config = function()
|
||||
return mark_config
|
||||
end
|
||||
|
||||
M.save = function()
|
||||
Path:new(file_name):write(vim.fn.json_encode(marked_files), 'w')
|
||||
end
|
||||
@ -201,8 +231,5 @@ M.get_length = function()
|
||||
return #marked_files
|
||||
end
|
||||
|
||||
M.setup = function()
|
||||
end
|
||||
|
||||
return M
|
||||
|
@ -3,9 +3,8 @@ local cwd = cwd or vim.loop.cwd()
|
||||
|
||||
local M = {}
|
||||
|
||||
harpoon_terminal_config = { }
|
||||
harpoon_terminals = {}
|
||||
harpoon_init = false
|
||||
local terminal_config = { }
|
||||
local terminals = {}
|
||||
|
||||
function create_terminal()
|
||||
local current_id = vim.fn.bufnr()
|
||||
@ -38,26 +37,39 @@ lua require("harpoon").setup({
|
||||
--]]
|
||||
|
||||
function getCmd(idx)
|
||||
local commandSet = harpoon_terminal_config[cwd]
|
||||
local commandSet = terminal_config[cwd]
|
||||
if not commandSet then
|
||||
return nil
|
||||
end
|
||||
return commandSet[idx]
|
||||
end
|
||||
|
||||
M.setup = function(config)
|
||||
|
||||
local expanded_config = {}
|
||||
for k in pairs(config.terminal) do
|
||||
local expanded_path = Path.new(k):expand()
|
||||
expanded_config[expanded_path] = config.terminal[k]
|
||||
--[[
|
||||
{
|
||||
projects: {
|
||||
"/path/to/dir": {
|
||||
term: {
|
||||
cmds: string[],
|
||||
... top level settings .. (we don't have)
|
||||
}
|
||||
mark: {
|
||||
marks: string[], // very skept -- has odd behavior
|
||||
... top level settings .. (we don't have)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--]]
|
||||
M.setup = function(config)
|
||||
if not config.projects[cwd] then
|
||||
terminal_config = {}
|
||||
else
|
||||
terminal_config = config.projects[cwd].term
|
||||
end
|
||||
|
||||
harpoon_terminal_config = expanded_config or {}
|
||||
end
|
||||
|
||||
M.gotoTerminal = function(idx)
|
||||
local term_handle = harpoon_terminals[idx]
|
||||
local term_handle = terminals[idx]
|
||||
|
||||
if not term_handle then
|
||||
local buf_id, term_id = create_terminal()
|
||||
@ -68,18 +80,18 @@ M.gotoTerminal = function(idx)
|
||||
buf_id = buf_id,
|
||||
term_id = term_id
|
||||
}
|
||||
harpoon_terminals[idx] = term_handle
|
||||
terminals[idx] = term_handle
|
||||
end
|
||||
|
||||
vim.api.nvim_set_current_buf(term_handle.buf_id)
|
||||
end
|
||||
|
||||
M.sendCommand = function(idx, cmd)
|
||||
local term_handle = harpoon_terminals[idx]
|
||||
local term_handle = terminals[idx]
|
||||
|
||||
if not term_handle then
|
||||
M.gotoTerminal(idx)
|
||||
term_handle = harpoon_terminals[idx]
|
||||
term_handle = terminals[idx]
|
||||
end
|
||||
|
||||
if type(cmd) == "number" then
|
@ -1,5 +1,5 @@
|
||||
-- TODO: Harpooned
|
||||
local Marker = require('harpoon.manage-a-mark')
|
||||
local Marker = require('harpoon.mark')
|
||||
local eq = assert.are.same
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
local Path = require('plenary.path')
|
||||
local float = require('plenary.window.float')
|
||||
local Marked = require('harpoon.manage-a-mark')
|
||||
local Marked = require('harpoon.mark')
|
||||
|
||||
local factorw = 0.42069
|
||||
local factorh = 0.69420
|
||||
|
@ -1,5 +1,5 @@
|
||||
augroup THE_PRIMEAGEN_HARPOON
|
||||
autocmd!
|
||||
autocmd VimLeave * :lua require('harpoon.manage-a-mark').save()
|
||||
autocmd BufLeave * :lua require('harpoon.manage-a-mark').store_offset()
|
||||
autocmd VimLeave * :lua require('harpoon.mark').save()
|
||||
autocmd BufLeave * :lua require('harpoon.mark').store_offset()
|
||||
augroup END
|
||||
|
Loading…
x
Reference in New Issue
Block a user