From accf7ef4efb405f2ec11408b7781a1619cfcc574 Mon Sep 17 00:00:00 2001 From: Aaron Hallaert Date: Wed, 10 Nov 2021 09:32:47 +0100 Subject: [PATCH] Change project_key to function --- lua/harpoon/init.lua | 14 +++++--------- lua/harpoon/utils.lua | 39 ++++++++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/lua/harpoon/init.lua b/lua/harpoon/init.lua index b1d7d02..172dfa9 100644 --- a/lua/harpoon/init.lua +++ b/lua/harpoon/init.lua @@ -50,7 +50,7 @@ local function mark_config_key() if HarpoonConfig.mark_branch then return utils.branch_key() else - return utils.project_key + return utils.project_key() end end @@ -72,9 +72,7 @@ local function ensure_correct_config(config) mark_config_key() ) projects[mark_config_key()] = { - mark = { - marks = {}, - }, + mark = { marks = {} }, term = { cmds = {}, }, @@ -102,9 +100,7 @@ local function ensure_correct_config(config) for idx, mark in pairs(marks) do if type(mark) == "string" then - mark = { - filename = mark, - } + mark = { filename = mark } marks[idx] = mark end @@ -197,7 +193,7 @@ function M.refresh_projects_b4update() cache_config ) -- save current runtime version of our project config for merging back in later - local cwd = vim.loop.cwd() + local cwd = mark_config_key() local current_p_config = { projects = { [cwd] = ensure_correct_config(HarpoonConfig).projects[cwd], @@ -241,7 +237,7 @@ end function M.get_term_config() log.trace("get_term_config()") - return ensure_correct_config(HarpoonConfig).projects[utils.project_key].term + return ensure_correct_config(HarpoonConfig).projects[utils.project_key()].term end function M.get_mark_config() diff --git a/lua/harpoon/utils.lua b/lua/harpoon/utils.lua index cd897d8..6bf6510 100644 --- a/lua/harpoon/utils.lua +++ b/lua/harpoon/utils.lua @@ -4,17 +4,22 @@ local Job = require("plenary.job") local M = {} -local project_key = vim.loop.cwd() -M.project_key = project_key -M.branch_key = vim.loop.cwd() M.data_path = data_path -function M.mark_config_key() - return string.gsub(vim.loop.cwd() .. '-' .. vim.fn.system('git branch --show-current'), "\n", "") +function M.project_key() + return vim.loop.cwd() +end + +function M.branch_key() + return string.gsub( + vim.loop.cwd() .. "-" .. vim.fn.system("git branch --show-current"), + "\n", + "" + ) end function M.normalize_path(item) - return Path:new(item):make_relative(M.branch_key) + return Path:new(item):make_relative(M.project_key()) end function M.get_os_command_output(cmd, cwd) @@ -24,20 +29,24 @@ function M.get_os_command_output(cmd, cwd) end local command = table.remove(cmd, 1) local stderr = {} - local stdout, ret = Job:new({ - command = command, - args = cmd, - cwd = cwd, - on_stderr = function(_, data) - table.insert(stderr, data) - end - }):sync() + local stdout, ret = Job + :new({ + command = command, + args = cmd, + cwd = cwd, + on_stderr = function(_, data) + table.insert(stderr, data) + end, + }) + :sync() return stdout, ret, stderr end function M.split_string(str, delimiter) local result = {} - for match in (str .. delimiter):gmatch("(.-)" .. delimiter) do table.insert(result, match) end + for match in (str .. delimiter):gmatch("(.-)" .. delimiter) do + table.insert(result, match) + end return result end