Skip to content

Commit

Permalink
Merge pull request #7 from desdic/20240327dev
Browse files Browse the repository at this point in the history
feat: Add toggle, next and prev
  • Loading branch information
desdic authored Mar 29, 2024
2 parents 5d56ca1 + fedf8fc commit f5a40b9
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 102 deletions.
10 changes: 10 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- Enable cache
cache = true

std = luajit
codes = true

-- Global objects
read_globals = {
"vim",
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Example using the lazy plugin manager
keymap("n", "<Leader>f]", function() marlin.move_up() end, { desc = "move up" })
keymap("n", "<Leader>f[", function() marlin.move_down() end, { desc = "move down" })
keymap("n", "<Leader>fs", function() marlin.sort() end, { desc = "sort" })
keymap("n", "<Leader>fn", function() marlin.next() end, { desc = "open next index" })
keymap("n", "<Leader>fp", function() marlin.prev() end, { desc = "open previous index" })
keymap("n", "<Leader><Leader>", function() marlin.toggle() end, { desc = "toggle cur/last open index" })

for index = 1,4 do
keymap("n", "<Leader>"..index, function() marlin.open(index) end, { desc = "goto "..index })
Expand Down
15 changes: 10 additions & 5 deletions lua/marlin/callbacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,29 @@
-- Module definition ==========================================================
local callbacks = {}

local vim_api_nvim_tabpage_list_wins = vim.api.nvim_tabpage_list_wins
local vim_api_nvim_win_get_buf = vim.api.nvim_win_get_buf
local vim_api_nvim_set_current_win = vim.api.nvim_set_current_win
local vim_api_nvim_set_current_buf = vim.api.nvim_set_current_buf

---@param bufnr number buffer id
callbacks.change_buffer = function(bufnr, _)
vim.api.nvim_set_current_buf(bufnr)
vim_api_nvim_set_current_buf(bufnr)
end

---@param bufnr number buffer id
callbacks.use_split = function(bufnr, _)
local wins = vim.api.nvim_tabpage_list_wins(0)
local wins = vim_api_nvim_tabpage_list_wins(0)
for _, win in ipairs(wins) do
local winbufnr = vim.api.nvim_win_get_buf(win)
local winbufnr = vim_api_nvim_win_get_buf(win)

if winbufnr == bufnr then
vim.api.nvim_set_current_win(win)
vim_api_nvim_set_current_win(win)
return
end
end

vim.api.nvim_set_current_buf(bufnr)
vim_api_nvim_set_current_buf(bufnr)
end

return callbacks
23 changes: 13 additions & 10 deletions lua/marlin/datafile.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
local M = {}

local uv = vim.loop

M.read_config = function(datafile)
if vim.fn.filereadable(datafile) ~= 0 then
local fd = io.open(datafile, "r")
if fd then
local content = fd:read("*a")
io.close(fd)
return vim.fn.json_decode(content)
end
local fd = uv.fs_open(datafile, "r", 438)
if fd then
local stat = uv.fs_fstat(fd)
local data = uv.fs_read(fd, stat.size, 0)
uv.fs_close(fd)
return vim.fn.json_decode(data)
end
return {}
end
Expand All @@ -19,6 +20,7 @@ M.save_data = function(opts, project, localdata)
end
return
end

local data = M.read_config(opts.datafile)
data[project] = localdata

Expand All @@ -28,14 +30,15 @@ M.save_data = function(opts, project, localdata)
end

local content = vim.fn.json_encode(data)
local fd = io.open(opts.datafile, "w")

local fd = uv.fs_open(opts.datafile, "w", 438)
if not fd then
vim.notify("Unable to open " .. opts.datafile .. " for write")
return
end

fd:write(content)
io.close(fd)
uv.fs_write(fd, content)
uv.fs_close(fd)
end

return M
Loading

0 comments on commit f5a40b9

Please sign in to comment.