mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-14 01:50:27 +00:00
Merge pull request #90 from anott03/fnToAPI
moving from vim.fn to vim.api where possible
This commit is contained in:
commit
1c98945c68
@ -157,7 +157,13 @@ M.setup = function(config)
|
|||||||
["save_on_toggle"] = false,
|
["save_on_toggle"] = false,
|
||||||
["save_on_change"] = true,
|
["save_on_change"] = true,
|
||||||
},
|
},
|
||||||
}, expand_dir(c_config), expand_dir(u_config), expand_dir(config))
|
}, expand_dir(
|
||||||
|
c_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()
|
||||||
|
@ -21,10 +21,12 @@ local function emit_changed()
|
|||||||
end
|
end
|
||||||
|
|
||||||
for idx, cb in pairs(callbacks["changed"]) do
|
for idx, cb in pairs(callbacks["changed"]) do
|
||||||
log.trace(string.format(
|
log.trace(
|
||||||
"_emit_changed(): Running callback #%d for 'changed'",
|
string.format(
|
||||||
idx
|
"_emit_changed(): Running callback #%d for 'changed'",
|
||||||
))
|
idx
|
||||||
|
)
|
||||||
|
)
|
||||||
cb()
|
cb()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -56,7 +58,7 @@ end
|
|||||||
local function get_buf_name(id)
|
local function get_buf_name(id)
|
||||||
log.trace("_get_buf_name():", id)
|
log.trace("_get_buf_name():", id)
|
||||||
if id == nil then
|
if id == nil then
|
||||||
return utils.normalize_path(vim.fn.bufname())
|
return utils.normalize_path(vim.api.nvim_buf_get_name(0))
|
||||||
elseif type(id) == "string" then
|
elseif type(id) == "string" then
|
||||||
return utils.normalize_path(id)
|
return utils.normalize_path(id)
|
||||||
end
|
end
|
||||||
@ -72,17 +74,19 @@ local function get_buf_name(id)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function create_mark(filename)
|
local function create_mark(filename)
|
||||||
local cursor_pos = vim.fn.getcurpos()
|
local cursor_pos = vim.api.nvim_win_get_cursor(0)
|
||||||
log.trace(string.format(
|
log.trace(
|
||||||
"_create_mark(): Creating mark at row: %d, col: %d for %s",
|
string.format(
|
||||||
cursor_pos[2],
|
"_create_mark(): Creating mark at row: %d, col: %d for %s",
|
||||||
cursor_pos[4],
|
cursor_pos[1],
|
||||||
filename
|
cursor_pos[2],
|
||||||
))
|
filename
|
||||||
|
)
|
||||||
|
)
|
||||||
return {
|
return {
|
||||||
filename = filename,
|
filename = filename,
|
||||||
row = cursor_pos[2],
|
row = cursor_pos[1],
|
||||||
col = cursor_pos[3],
|
col = cursor_pos[2],
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -102,7 +106,10 @@ end
|
|||||||
local function validate_buf_name(buf_name)
|
local function validate_buf_name(buf_name)
|
||||||
log.trace("_validate_buf_name():", buf_name)
|
log.trace("_validate_buf_name():", buf_name)
|
||||||
if buf_name == "" or buf_name == nil then
|
if buf_name == "" or buf_name == nil then
|
||||||
log.error("_validate_buf_name(): Not a valid name for a mark,", buf_name)
|
log.error(
|
||||||
|
"_validate_buf_name(): Not a valid name for a mark,",
|
||||||
|
buf_name
|
||||||
|
)
|
||||||
error("Couldn't find a valid file name to mark, sorry.")
|
error("Couldn't find a valid file name to mark, sorry.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -111,8 +118,12 @@ end
|
|||||||
M.get_index_of = function(item)
|
M.get_index_of = function(item)
|
||||||
log.trace("get_index_of():", item)
|
log.trace("get_index_of():", item)
|
||||||
if item == nil then
|
if item == nil then
|
||||||
log.error("get_index_of(): Function has been supplied with a nil value.")
|
log.error(
|
||||||
error("You have provided a nil value to Harpoon, please provide a string rep of the file or the file idx.")
|
"get_index_of(): Function has been supplied with a nil value."
|
||||||
|
)
|
||||||
|
error(
|
||||||
|
"You have provided a nil value to Harpoon, please provide a string rep of the file or the file idx."
|
||||||
|
)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -144,9 +155,9 @@ M.status = function(bufnr)
|
|||||||
log.trace("status()")
|
log.trace("status()")
|
||||||
local buf_name
|
local buf_name
|
||||||
if bufnr then
|
if bufnr then
|
||||||
buf_name = vim.fn.bufname(bufnr)
|
buf_name = vim.api.nvim_buf_get_name(bufnr)
|
||||||
else
|
else
|
||||||
buf_name = vim.fn.bufname()
|
buf_name = vim.api.nvim_buf_get_name(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
local norm_name = utils.normalize_path(buf_name)
|
local norm_name = utils.normalize_path(buf_name)
|
||||||
@ -218,14 +229,16 @@ M.store_offset = function()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local cursor_pos = vim.fn.getcurpos()
|
local cursor_pos = vim.api.nvim_win_get_cursor(0)
|
||||||
log.debug(string.format(
|
log.debug(
|
||||||
"store_offset(): Stored row: %d, col: %d",
|
string.format(
|
||||||
cursor_pos[2],
|
"store_offset(): Stored row: %d, col: %d",
|
||||||
cursor_pos[3]
|
cursor_pos[1],
|
||||||
))
|
cursor_pos[2]
|
||||||
harpoon.get_mark_config().marks[idx].row = cursor_pos[2]
|
)
|
||||||
harpoon.get_mark_config().marks[idx].col = cursor_pos[3]
|
)
|
||||||
|
harpoon.get_mark_config().marks[idx].row = cursor_pos[1]
|
||||||
|
harpoon.get_mark_config().marks[idx].col = cursor_pos[2]
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if not ok then
|
if not ok then
|
||||||
@ -355,7 +368,7 @@ end
|
|||||||
|
|
||||||
M.get_current_index = function()
|
M.get_current_index = function()
|
||||||
log.trace("get_current_index()")
|
log.trace("get_current_index()")
|
||||||
return M.get_index_of(vim.fn.bufname())
|
return M.get_index_of(vim.api.nvim_buf_get_name(0))
|
||||||
end
|
end
|
||||||
|
|
||||||
M.on = function(event, cb)
|
M.on = function(event, cb)
|
||||||
|
@ -9,10 +9,10 @@ local function create_terminal(create_with)
|
|||||||
create_with = ":terminal"
|
create_with = ":terminal"
|
||||||
end
|
end
|
||||||
log.trace("_create_terminal(): Init:", create_with)
|
log.trace("_create_terminal(): Init:", create_with)
|
||||||
local current_id = vim.fn.bufnr()
|
local current_id = vim.api.nvim_get_current_buf()
|
||||||
|
|
||||||
vim.cmd(create_with)
|
vim.cmd(create_with)
|
||||||
local buf_id = vim.fn.bufnr()
|
local buf_id = vim.api.nvim_get_current_buf()
|
||||||
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
|
||||||
@ -68,7 +68,7 @@ M.sendCommand = function(idx, cmd, ...)
|
|||||||
|
|
||||||
if cmd then
|
if cmd then
|
||||||
log.debug("sendCommand:", cmd)
|
log.debug("sendCommand:", cmd)
|
||||||
vim.fn.chansend(term_handle.term_id, string.format(cmd, ...))
|
vim.api.nvim_chan_send(term_handle.term_id, string.format(cmd, ...))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -105,14 +105,18 @@ M.toggle_quick_menu = function()
|
|||||||
":lua require('harpoon.ui').select_menu_item()<CR>",
|
":lua require('harpoon.ui').select_menu_item()<CR>",
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
vim.cmd(string.format(
|
vim.cmd(
|
||||||
"autocmd BufWriteCmd <buffer=%s> :lua require('harpoon.ui').on_menu_save()",
|
string.format(
|
||||||
Harpoon_bufh
|
"autocmd BufWriteCmd <buffer=%s> :lua require('harpoon.ui').on_menu_save()",
|
||||||
))
|
Harpoon_bufh
|
||||||
vim.cmd(string.format(
|
)
|
||||||
"autocmd BufModifiedSet <buffer=%s> set nomodified",
|
)
|
||||||
Harpoon_bufh
|
vim.cmd(
|
||||||
))
|
string.format(
|
||||||
|
"autocmd BufModifiedSet <buffer=%s> set nomodified",
|
||||||
|
Harpoon_bufh
|
||||||
|
)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
M.select_menu_item = function()
|
M.select_menu_item = function()
|
||||||
@ -142,11 +146,13 @@ M.nav_file = function(id)
|
|||||||
vim.api.nvim_buf_set_option(buf_id, "buflisted", true)
|
vim.api.nvim_buf_set_option(buf_id, "buflisted", true)
|
||||||
if set_row and mark.row and mark.col then
|
if set_row and mark.row and mark.col then
|
||||||
vim.cmd(string.format(":call cursor(%d, %d)", mark.row, mark.col))
|
vim.cmd(string.format(":call cursor(%d, %d)", mark.row, mark.col))
|
||||||
log.debug(string.format(
|
log.debug(
|
||||||
"nav_file(): Setting cursor to row: %d, col: %d",
|
string.format(
|
||||||
mark.row,
|
"nav_file(): Setting cursor to row: %d, col: %d",
|
||||||
mark.col
|
mark.row,
|
||||||
))
|
mark.col
|
||||||
|
)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -161,8 +167,8 @@ function M.location_window(options)
|
|||||||
}
|
}
|
||||||
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.api.nvim_create_buf(false, true)
|
||||||
local win_id = vim.fn.nvim_open_win(bufnr, true, options)
|
local win_id = vim.api.nvim_open_win(bufnr, true, options)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
bufnr = bufnr,
|
bufnr = bufnr,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user