diff --git a/README.md b/README.md index 9518e4f..f7ca83f 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/lua/tasklist/health.lua b/lua/tasklist/health.lua new file mode 100644 index 0000000..2ee51b1 --- /dev/null +++ b/lua/tasklist/health.lua @@ -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 diff --git a/lua/tasklist/init.lua b/lua/tasklist/init.lua index 46c98a6..78ccbfa 100644 --- a/lua/tasklist/init.lua +++ b/lua/tasklist/init.lua @@ -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 }), @@ -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() @@ -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 = {} @@ -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