mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-13 17:40:25 +00:00
feat(sort of done): Vimeonteuhonteuhon
teu
This commit is contained in:
parent
2374c696d3
commit
8593232cc3
@ -135,6 +135,8 @@ require("harpoon").setup({
|
|||||||
global_settings = {
|
global_settings = {
|
||||||
save_on_toggle = false,
|
save_on_toggle = false,
|
||||||
save_on_change = true,
|
save_on_change = true,
|
||||||
|
nav_last_visited = false,
|
||||||
|
nav_first_in_list = false,
|
||||||
},
|
},
|
||||||
... your other configs ...
|
... your other configs ...
|
||||||
})
|
})
|
||||||
@ -146,6 +148,12 @@ require("harpoon").setup({
|
|||||||
enable this option (on by default) harpoon will not save any changes to your
|
enable this option (on by default) harpoon will not save any changes to your
|
||||||
file. It is very unreliable to save your harpoon on exit (at least that is
|
file. It is very unreliable to save your harpoon on exit (at least that is
|
||||||
what I have found).
|
what I have found).
|
||||||
|
* `nav_last_visited` will open up the last file you visited in harpoon upon
|
||||||
|
VimEnter. If you are using the git-worktree plugin you could listen to the
|
||||||
|
tree switch and execute `require("harpoon.ui").nav_on_open()`
|
||||||
|
* `nav_first_in_list` same as `nav_last_visited` except it will open the first
|
||||||
|
item in the list of marks upon VimEnter or if you call
|
||||||
|
`require("harpoon.ui").nav_on_open()`
|
||||||
|
|
||||||
#### Preconfigured Terminal Commands
|
#### Preconfigured Terminal Commands
|
||||||
These are project specific commands that you wish to execute on the regular.
|
These are project specific commands that you wish to execute on the regular.
|
||||||
|
@ -154,6 +154,8 @@ M.setup = function(config)
|
|||||||
local complete_config = merge_tables({
|
local complete_config = merge_tables({
|
||||||
projects = {},
|
projects = {},
|
||||||
global_settings = {
|
global_settings = {
|
||||||
|
["nav_last_visited"] = false,
|
||||||
|
["nav_first_in_list"] = false,
|
||||||
["save_on_toggle"] = false,
|
["save_on_toggle"] = false,
|
||||||
["save_on_change"] = true,
|
["save_on_change"] = true,
|
||||||
},
|
},
|
||||||
|
@ -140,6 +140,20 @@ M.get_index_of = function(item)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
M.set_last = function()
|
||||||
|
log.trace("set_last()")
|
||||||
|
local mark_idx = M.get_index_of(get_buf_name())
|
||||||
|
if not M.valid_index(mark_idx) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
harpoon.get_mark_config().last = mark_idx
|
||||||
|
end
|
||||||
|
|
||||||
|
M.get_last = function()
|
||||||
|
return harpoon.get_mark_config().last
|
||||||
|
end
|
||||||
|
|
||||||
M.status = function()
|
M.status = function()
|
||||||
log.trace("status()")
|
log.trace("status()")
|
||||||
local idx = M.get_index_of(get_buf_name())
|
local idx = M.get_index_of(get_buf_name())
|
||||||
|
@ -72,6 +72,22 @@ local function get_menu_items()
|
|||||||
return indices
|
return indices
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function navigate(idx)
|
||||||
|
local mark = Marked.get_marked_file(idx)
|
||||||
|
local buf_id = vim.fn.bufnr(mark.filename, true)
|
||||||
|
local set_row = not vim.api.nvim_buf_is_loaded(buf_id)
|
||||||
|
|
||||||
|
vim.api.nvim_set_current_buf(buf_id)
|
||||||
|
if set_row and mark.row and mark.col then
|
||||||
|
vim.cmd(string.format(":call cursor(%d, %d)", mark.row, mark.col))
|
||||||
|
log.debug(string.format(
|
||||||
|
"nav_file(): Setting cursor to row: %d, col: %d",
|
||||||
|
mark.row,
|
||||||
|
mark.col
|
||||||
|
))
|
||||||
|
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
|
||||||
@ -126,6 +142,37 @@ M.on_menu_save = function()
|
|||||||
Marked.set_mark_list(get_menu_items())
|
Marked.set_mark_list(get_menu_items())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
M.nav_on_open = function()
|
||||||
|
local global_config = harpoon.get_global_settings()
|
||||||
|
if global_config.nav_last_visited then
|
||||||
|
M.nav_last_visited()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if global_config.nav_first_in_list then
|
||||||
|
M.nav_first_in_list()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
M.nav_first_in_list = function()
|
||||||
|
local first = Marked.get_index_of(1)
|
||||||
|
if not first then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
navigate(first)
|
||||||
|
end
|
||||||
|
|
||||||
|
M.nav_last_visited = function()
|
||||||
|
local last_mark = Marked.get_last()
|
||||||
|
if not last_mark then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
navigate(last_mark)
|
||||||
|
end
|
||||||
|
|
||||||
M.nav_file = function(id)
|
M.nav_file = function(id)
|
||||||
log.trace("nav_file(): Navigating to", id)
|
log.trace("nav_file(): Navigating to", id)
|
||||||
local idx = Marked.get_index_of(id)
|
local idx = Marked.get_index_of(id)
|
||||||
@ -134,19 +181,7 @@ M.nav_file = function(id)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local mark = Marked.get_marked_file(idx)
|
navigate(idx)
|
||||||
local buf_id = vim.fn.bufnr(mark.filename, true)
|
|
||||||
local set_row = not vim.api.nvim_buf_is_loaded(buf_id)
|
|
||||||
|
|
||||||
vim.api.nvim_set_current_buf(buf_id)
|
|
||||||
if set_row and mark.row and mark.col then
|
|
||||||
vim.cmd(string.format(":call cursor(%d, %d)", mark.row, mark.col))
|
|
||||||
log.debug(string.format(
|
|
||||||
"nav_file(): Setting cursor to row: %d, col: %d",
|
|
||||||
mark.row,
|
|
||||||
mark.col
|
|
||||||
))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.location_window(options)
|
function M.location_window(options)
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
|
" Should we do a lua version?
|
||||||
|
" Challenge they must require harpoon
|
||||||
augroup THE_PRIMEAGEN_HARPOON
|
augroup THE_PRIMEAGEN_HARPOON
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd BufLeave,VimLeave * :lua require('harpoon.mark').store_offset()
|
autocmd BufLeave,VimLeave * :lua require('harpoon.mark').store_offset()
|
||||||
|
autocmd VimEnter * :lua require('harpoon.ui').nav_on_open()
|
||||||
augroup END
|
augroup END
|
||||||
|
Loading…
x
Reference in New Issue
Block a user