Skip to content

Commit

Permalink
Merge pull request #2 from rrossmiller/send-update-event
Browse files Browse the repository at this point in the history
Send update event
  • Loading branch information
rrossmiller authored Dec 18, 2023
2 parents 826d14a + b1cb28f commit 1f66a6c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ I have a plan to fix this.
## 🛠️ Roadmap
- [x] read and write todos in buffer from/to a file
- [x] project/repo-level vs global todo
- [x] sync the instances/open windows (rpc)
- [x] update the window whenever any todo window/file was updated
- [x] only update the window if the underlying file was updated
- [ ] fancy icons marking doneness?
- change a prefix of a line to mean that the todo is done and the style of the line should change to reflect that
- [ ] sync the instances/open windows (rpc)
14 changes: 14 additions & 0 deletions lua/tasklist/health.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
M = {}

function M.check()
vim.health.start("Checking that fswatch is installed")
local ok = vim.fn.executable("fswatch")
-- make sure setup function parameters are ok
if ok ~= 0 then
vim.health.ok("Setup is correct")
else
vim.health.error("fswatch is not installed or missing from path")
end
end

return M
31 changes: 25 additions & 6 deletions lua/tasklist/init.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
-- much of the credit goes to: https://dev.to/2nit/how-to-write-neovim-plugins-in-lua-5cca
-- also folke's https://github.com/folke/persistence.nvim
-- also gpt 3.5
local config = require("tasklist.config")
local api = vim.api
local buf, win
local win_open = false
local global_todo = true
local suffix = ".todo"

local M = {}

local function update_buffer(chan_id, data, name)
-- https://neovim.io/doc/user/channel.html#on_stdout
local fname = 'todo' .. suffix
if not global_todo then
fname = M.get_proj_name() .. suffix
end
if vim.api.nvim_buf_is_valid(buf) and data[1]:find(fname) then
local content = M.read_content()
vim.api.nvim_buf_set_lines(buf, 0, -1, false, content)
end
end

function M.setup(opts)
config.setup(opts)
-- vim.api.nvim_create_user_command("TasklistToggleGlobal", function(cmd) M.toggle_window() end)
-- vim.api.nvim_create_user_command("TasklistToggleProject", function(cmd) M.toggle_proj_window() end)

vim.api.nvim_create_autocmd("VimLeavePre", {
group = vim.api.nvim_create_augroup("todo_content", { clear = true }),
Expand All @@ -23,6 +36,12 @@ function M.setup(opts)
end
end,
})

local pth = config.options.dir .. "/*.todo"
-- update window whenever todo list is updated
vim.fn.jobstart("fswatch -x +i " .. pth, {
on_stdout = update_buffer,
})
end

function M.open_window()
Expand Down Expand Up @@ -68,9 +87,9 @@ function M.open_window()
end

function M.read_content()
local fname = 'todo'
local fname = 'todo' .. suffix
if not global_todo then
fname = M.get_proj_name()
fname = M.get_proj_name() .. suffix
end
local f = io.open(config.options.dir .. fname, 'r')
local lines = {}
Expand All @@ -90,9 +109,9 @@ end

function M.save_todos()
-- write buffer to todofile
local fname = 'todo'
local fname = 'todo' .. suffix
if not global_todo then
fname = M.get_proj_name()
fname = M.get_proj_name() .. suffix
end
local file = io.open(config.options.dir .. fname, 'w')
if not file then
Expand Down

0 comments on commit 1f66a6c

Please sign in to comment.