mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-14 01:50:27 +00:00
moving from vim.fn to vim.api where possible
vim.fn functions are vimsciprt, while vim.api functions are lua, so api functions tend to perform better
This commit is contained in:
parent
65d1b43428
commit
a0f33c9a37
@ -56,7 +56,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 +72,17 @@ 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(string.format(
|
||||||
"_create_mark(): Creating mark at row: %d, col: %d for %s",
|
"_create_mark(): Creating mark at row: %d, col: %d for %s",
|
||||||
|
cursor_pos[1],
|
||||||
cursor_pos[2],
|
cursor_pos[2],
|
||||||
cursor_pos[4],
|
|
||||||
filename
|
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
|
||||||
|
|
||||||
@ -144,9 +144,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 +218,14 @@ 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(string.format(
|
||||||
"store_offset(): Stored row: %d, col: %d",
|
"store_offset(): Stored row: %d, col: %d",
|
||||||
cursor_pos[2],
|
cursor_pos[1],
|
||||||
cursor_pos[3]
|
cursor_pos[2]
|
||||||
))
|
))
|
||||||
harpoon.get_mark_config().marks[idx].row = cursor_pos[2]
|
harpoon.get_mark_config().marks[idx].row = cursor_pos[1]
|
||||||
harpoon.get_mark_config().marks[idx].col = cursor_pos[3]
|
harpoon.get_mark_config().marks[idx].col = cursor_pos[2]
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if not ok then
|
if not ok then
|
||||||
@ -313,7 +313,8 @@ M.to_quickfix_list = function()
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
log.debug("to_quickfix_list(): qf_list:", qf_list)
|
log.debug("to_quickfix_list(): qf_list:", qf_list)
|
||||||
vim.fn.setqflist(qf_list)
|
-- Does this only work when there is an LSP attached to the buffer?
|
||||||
|
vim.lsp.util.set_qflist(qf_list)
|
||||||
end
|
end
|
||||||
|
|
||||||
M.set_mark_list = function(new_list)
|
M.set_mark_list = function(new_list)
|
||||||
@ -355,7 +356,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
|
||||||
|
|
||||||
|
@ -161,8 +161,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