mirror of
https://github.com/ThePrimeagen/harpoon
synced 2024-09-16 21:44:02 +02:00
feat(filename): Filename is now an object with row-col offset
This commit is contained in:
parent
7e6711fc0e
commit
1158df026f
7 changed files with 85 additions and 34 deletions
|
@ -2,6 +2,8 @@
|
||||||
This is still beta. We are getting there, but its not as fast as I would like.
|
This is still beta. We are getting there, but its not as fast as I would like.
|
||||||
Therefore APIs are subject to change.
|
Therefore APIs are subject to change.
|
||||||
|
|
||||||
|
![Harpoon](harpoon.png)
|
||||||
|
|
||||||
# harpoon
|
# harpoon
|
||||||
The goal of Harpoon is to get you where you want with the fewest keystrokes.
|
The goal of Harpoon is to get you where you want with the fewest keystrokes.
|
||||||
|
|
||||||
|
|
1
TODO.md
1
TODO.md
|
@ -1,6 +1,5 @@
|
||||||
### Manage A Mark 1.0
|
### Manage A Mark 1.0
|
||||||
* Logo
|
* Logo
|
||||||
* linexcol offset in saved file
|
|
||||||
* floating term / split term
|
* floating term / split term
|
||||||
* TODO: Fill me in, that one really important thing....
|
* TODO: Fill me in, that one really important thing....
|
||||||
* README.md
|
* README.md
|
||||||
|
|
BIN
harpoon.png
Normal file
BIN
harpoon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2 MiB |
|
@ -76,7 +76,15 @@ local function ensure_correct_config(config)
|
||||||
|
|
||||||
local marks = proj.mark.marks
|
local marks = proj.mark.marks
|
||||||
for idx = 1, #marks do
|
for idx = 1, #marks do
|
||||||
marks[idx] = utils.normalize_path(marks[idx])
|
local mark = marks[idx]
|
||||||
|
if type(mark) == "string" then
|
||||||
|
mark = {
|
||||||
|
filename = mark
|
||||||
|
}
|
||||||
|
marks[idx] = mark
|
||||||
|
end
|
||||||
|
|
||||||
|
marks[idx].filename = utils.normalize_path(mark.filename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ local function filter_empty_string(list)
|
||||||
local next = {}
|
local next = {}
|
||||||
for idx = 1, #list do
|
for idx = 1, #list do
|
||||||
if list[idx] ~= "" then
|
if list[idx] ~= "" then
|
||||||
table.insert(next, list[idx])
|
table.insert(next, list[idx].filename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ local function get_buf_name(id)
|
||||||
|
|
||||||
local idx = M.get_index_of(id)
|
local idx = M.get_index_of(id)
|
||||||
if M.valid_index(idx) then
|
if M.valid_index(idx) then
|
||||||
return harpoon.get_mark_config().marks[idx]
|
return M.get_marked_file_name(idx)
|
||||||
end
|
end
|
||||||
--
|
--
|
||||||
-- not sure what to do here...
|
-- not sure what to do here...
|
||||||
|
@ -31,11 +31,17 @@ local function get_buf_name(id)
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
|
|
||||||
local function mark_exists(buf_name)
|
local function create_mark(filename)
|
||||||
local marks = harpoon.get_mark_config().marks
|
return {
|
||||||
|
filename = filename,
|
||||||
|
row = 0,
|
||||||
|
col = 0,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local function mark_exists(buf_name)
|
||||||
for idx = 1, M.get_length() do
|
for idx = 1, M.get_length() do
|
||||||
if marks[idx] == buf_name then
|
if M.get_marked_file_name(idx) == buf_name then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -56,11 +62,10 @@ M.get_index_of = function(item)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local config = harpoon.get_mark_config()
|
|
||||||
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 config.marks[idx] == relative_item then
|
if M.get_marked_file_name(idx) == relative_item then
|
||||||
return idx
|
return idx
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -89,8 +94,12 @@ M.status = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
M.valid_index = function(idx)
|
M.valid_index = function(idx)
|
||||||
local config = harpoon.get_mark_config()
|
if idx == nil then
|
||||||
return idx ~= nil and config.marks[idx] ~= nil and config.marks[idx] ~= ""
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local file_name = M.get_marked_file_name(idx)
|
||||||
|
return file_name ~= nil and file_name ~= ""
|
||||||
end
|
end
|
||||||
|
|
||||||
M.add_file = function(file_name_or_buf_id)
|
M.add_file = function(file_name_or_buf_id)
|
||||||
|
@ -103,16 +112,17 @@ M.add_file = function(file_name_or_buf_id)
|
||||||
|
|
||||||
validate_buf_name(buf_name)
|
validate_buf_name(buf_name)
|
||||||
|
|
||||||
local config = harpoon.get_mark_config()
|
|
||||||
for idx = 1, M.get_length() do
|
for idx = 1, M.get_length() do
|
||||||
if config.marks[idx] == "" then
|
local filename = M.get_marked_file_name(idx)
|
||||||
config.marks[idx] = buf_name
|
if filename == "" then
|
||||||
|
harpoon.get_mark_config().marks[idx] = create_mark(filename)
|
||||||
|
|
||||||
M.remove_empty_tail()
|
M.remove_empty_tail()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(config.marks, buf_name)
|
table.insert(harpoon.get_mark_config().marks, create_mark(buf_name))
|
||||||
M.remove_empty_tail()
|
M.remove_empty_tail()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -120,24 +130,32 @@ M.remove_empty_tail = function()
|
||||||
local config = harpoon.get_mark_config()
|
local config = harpoon.get_mark_config()
|
||||||
|
|
||||||
for i = M.get_length(), 1, -1 do
|
for i = M.get_length(), 1, -1 do
|
||||||
if config.marks[i] ~= "" then
|
local filename = M.get_marked_file_name(i)
|
||||||
|
if filename ~= "" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if config.marks[i] == "" then
|
if filename == "" then
|
||||||
table.remove(config.marks, i)
|
table.remove(config.marks, i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
M.store_offset = function()
|
M.store_offset = function()
|
||||||
local buf_name = get_buf_name()
|
local ok, res = pcall(function()
|
||||||
local idx = M.get_index_of(buf_name)
|
local buf_name = get_buf_name()
|
||||||
if not M.valid_index(idx) then
|
local idx = M.get_index_of(buf_name)
|
||||||
return
|
if not M.valid_index(idx) then
|
||||||
end
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local line = vim.api.nvim_eval("line('.')");
|
local row, col = vim.api.nvim_eval("line('.')");
|
||||||
|
end)
|
||||||
|
|
||||||
|
if not ok then
|
||||||
|
-- TODO: Developer logs?
|
||||||
|
print("M.store_offset#pcall failed:", res)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
M.rm_file = function(file_name_or_buf_id)
|
M.rm_file = function(file_name_or_buf_id)
|
||||||
|
@ -148,7 +166,7 @@ M.rm_file = function(file_name_or_buf_id)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
harpoon.get_mark_config().marks[idx] = ""
|
harpoon.get_mark_config().marks[idx] = create_mark("")
|
||||||
M.remove_empty_tail()
|
M.remove_empty_tail()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -156,8 +174,17 @@ M.clear_all = function()
|
||||||
harpoon.get_mark_config().marks = {}
|
harpoon.get_mark_config().marks = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
M.get_marked_file = function(idx)
|
--- ENTERPRISE PROGRAMMING
|
||||||
return harpoon.get_mark_config().marks[idx]
|
M.get_marked_file = function(idxOrName)
|
||||||
|
if type(idxOrName) == "string" then
|
||||||
|
idxOrName = M.get_index_of(idxOrName)
|
||||||
|
end
|
||||||
|
return harpoon.get_mark_config().marks[idxOrName]
|
||||||
|
end
|
||||||
|
|
||||||
|
M.get_marked_file_name = function(idx)
|
||||||
|
local mark = harpoon.get_mark_config().marks[idx]
|
||||||
|
return mark and mark.filename
|
||||||
end
|
end
|
||||||
|
|
||||||
M.get_length = function()
|
M.get_length = function()
|
||||||
|
@ -174,11 +201,11 @@ M.set_current_at = function(idx)
|
||||||
config.marks[current_idx] = ""
|
config.marks[current_idx] = ""
|
||||||
end
|
end
|
||||||
|
|
||||||
config.marks[idx] = buf_name
|
config.marks[idx] = create_mark(buf_name)
|
||||||
|
|
||||||
for i = 1, M.get_length() do
|
for i = 1, M.get_length() do
|
||||||
if not config.marks[i] then
|
if not config.marks[i] then
|
||||||
config.marks[i] = ""
|
config.marks[i] = create_mark("")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -188,17 +215,32 @@ M.to_quickfix_list = function()
|
||||||
local file_list = filter_empty_string(config.marks)
|
local file_list = filter_empty_string(config.marks)
|
||||||
local qf_list = {}
|
local qf_list = {}
|
||||||
for idx = 1, #file_list do
|
for idx = 1, #file_list do
|
||||||
|
local mark = M.get_marked_file(idx)
|
||||||
qf_list[idx] = {
|
qf_list[idx] = {
|
||||||
text = string.format("%d: %s", idx, file_list[idx]),
|
text = string.format("%d: %s", idx, file_list[idx]),
|
||||||
filename = file_list[idx],
|
filename = mark.filename,
|
||||||
|
row = mark.row,
|
||||||
|
col = mark.col,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
vim.fn.setqflist(qf_list)
|
vim.fn.setqflist(qf_list)
|
||||||
end
|
end
|
||||||
|
|
||||||
M.set_mark_list = function(new_list)
|
M.set_mark_list = function(new_list)
|
||||||
|
|
||||||
local config = harpoon.get_mark_config()
|
local config = harpoon.get_mark_config()
|
||||||
|
|
||||||
|
for k, v in pairs(new_list) do
|
||||||
|
if type(v) == "string" then
|
||||||
|
local mark = M.get_marked_file(v)
|
||||||
|
if not mark then
|
||||||
|
mark = create_mark(v)
|
||||||
|
end
|
||||||
|
|
||||||
|
new_list[k] = mark
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
config.marks = new_list
|
config.marks = new_list
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ local Path = require("plenary.path")
|
||||||
local M = {}
|
local M = {}
|
||||||
local terminals = {}
|
local terminals = {}
|
||||||
|
|
||||||
function create_terminal()
|
local function create_terminal()
|
||||||
local current_id = vim.fn.bufnr()
|
local current_id = vim.fn.bufnr()
|
||||||
|
|
||||||
vim.cmd(":terminal")
|
vim.cmd(":terminal")
|
||||||
|
|
|
@ -20,7 +20,7 @@ function create_window()
|
||||||
return win_info
|
return win_info
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_menu_items()
|
local function get_menu_items()
|
||||||
local lines = vim.api.nvim_buf_get_lines(bufh, 0, -1, true)
|
local lines = vim.api.nvim_buf_get_lines(bufh, 0, -1, true)
|
||||||
local indices = {}
|
local indices = {}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ M.toggle_quick_menu = function()
|
||||||
bufh = win_info.bufnr
|
bufh = win_info.bufnr
|
||||||
|
|
||||||
for idx = 1, Marked.get_length() do
|
for idx = 1, Marked.get_length() do
|
||||||
local file = Marked.get_marked_file(idx)
|
local file = Marked.get_marked_file_name(idx)
|
||||||
if file == "" then
|
if file == "" then
|
||||||
file = "(empty)"
|
file = "(empty)"
|
||||||
end
|
end
|
||||||
|
@ -77,12 +77,12 @@ M.on_menu_save = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
M.nav_file = function(id)
|
M.nav_file = function(id)
|
||||||
idx = Marked.get_index_of(id)
|
local idx = Marked.get_index_of(id)
|
||||||
if not Marked.valid_index(idx) then
|
if not Marked.valid_index(idx) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local buf_id = vim.fn.bufnr(Marked.get_marked_file(idx))
|
local buf_id = vim.fn.bufnr(Marked.get_marked_file_name(idx))
|
||||||
|
|
||||||
if vim.api.nvim_win_is_valid(buf_id) then
|
if vim.api.nvim_win_is_valid(buf_id) then
|
||||||
vim.api.nvim_win_close(win_id)
|
vim.api.nvim_win_close(win_id)
|
||||||
|
|
Loading…
Reference in a new issue