Testing out a tasks folder for a custom plugin
This commit is contained in:
42
Tasks.md
42
Tasks.md
@ -1,22 +1,42 @@
|
||||
# Tasks and Todos
|
||||
|
||||
## Client 1
|
||||
- [ ] Research SSO issues - 04-09-2025
|
||||
- [ ] Reach out to engineering - 04-09-2025
|
||||
|
||||
### Tasks
|
||||
- [ ] Update thati - 01-05-2025
|
||||
|
||||
### In Progress
|
||||
- [-] text - 04-08-2025
|
||||
|
||||
### Completed
|
||||
- [X] Research SSO issues - 04-09-2025
|
||||
- [X] Update this! - 04-10-2025
|
||||
- [X] text - 01-01-2024
|
||||
- [X] Reach out to engineering - 04-09-2025
|
||||
|
||||
## Client 2
|
||||
- [ ] Music and Opera - 07-09-2024
|
||||
- [ ] Buy a clarinet - 02-04-2025
|
||||
|
||||
### Tasks
|
||||
- [ ] Buy a clarinet - 02-04-2025
|
||||
|
||||
## Client 1
|
||||
- [ ] text - 04-08-2025
|
||||
- [] text - 01-01-2024
|
||||
### Completed
|
||||
- [X] Music and Opera - 07-09-2024
|
||||
|
||||
## Client 3
|
||||
- [] text - 04-09-2025
|
||||
- [] text - 04-10-2025
|
||||
|
||||
Client 2
|
||||
- [ ] Do this thing - 04-09-2025
|
||||
### Tasks
|
||||
- [ ] text - 04-09-2025
|
||||
- [ ] text - 04-10-2025
|
||||
|
||||
### Completed
|
||||
- [X] Do this thing - 04-09-2025
|
||||
|
||||
## Client 4
|
||||
|
||||
### Tasks
|
||||
- [ ] text
|
||||
- [ ] less - 04-10-2025
|
||||
|
||||
### Completed
|
||||
- [X] more test - 04-10-2025
|
||||
|
||||
|
||||
87
lua/markdown_organizer/init.lua
Normal file
87
lua/markdown_organizer/init.lua
Normal file
@ -0,0 +1,87 @@
|
||||
local M = {}
|
||||
|
||||
-- Function to determine fold level for each line
|
||||
local function fold_completed_tasks(lnum)
|
||||
local line = vim.fn.getline(lnum)
|
||||
|
||||
-- Check if the line contains a completed task
|
||||
if line:match("%- %[X%]") then
|
||||
return ">1" -- Start a fold at level 1
|
||||
end
|
||||
|
||||
return "0" -- No fold
|
||||
end
|
||||
|
||||
-- Function to hide completed tasks using foldexpr
|
||||
function M.hide_completed()
|
||||
local count = 0
|
||||
local pattern = "%- %[X%]" -- Pattern to match completed tasks: "- [X]"
|
||||
|
||||
-- Get all lines in the current buffer
|
||||
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
|
||||
|
||||
-- Count completed tasks
|
||||
for _, line in ipairs(lines) do
|
||||
if line:match(pattern) then
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
|
||||
-- If no completed tasks found, notify and return
|
||||
if count == 0 then
|
||||
vim.notify("No completed tasks found", vim.log.levels.INFO)
|
||||
return
|
||||
end
|
||||
|
||||
-- Save current folding settings
|
||||
local old_foldmethod = vim.wo.foldmethod
|
||||
local old_foldexpr = vim.wo.foldexpr
|
||||
|
||||
-- Set up folding based on expression
|
||||
vim.wo.foldmethod = "expr"
|
||||
vim.wo.foldexpr = "v:lua.require'markdown_organizer'.fold_expr(v:lnum)"
|
||||
|
||||
-- Close all folds to hide completed tasks
|
||||
vim.cmd("normal! zM")
|
||||
|
||||
-- Notify user of how many tasks were hidden
|
||||
vim.notify("Hidden " .. count .. " completed tasks", vim.log.levels.INFO)
|
||||
|
||||
-- Add autocmd to restore original folding settings when leaving buffer
|
||||
vim.api.nvim_create_autocmd("BufLeave", {
|
||||
buffer = 0,
|
||||
callback = function()
|
||||
vim.wo.foldmethod = old_foldmethod
|
||||
vim.wo.foldexpr = old_foldexpr
|
||||
end,
|
||||
once = true
|
||||
})
|
||||
end
|
||||
|
||||
-- Expose the fold expression function to be used by foldexpr
|
||||
function M.fold_expr(lnum)
|
||||
return fold_completed_tasks(lnum)
|
||||
end
|
||||
|
||||
-- Function to restore normal folding
|
||||
function M.show_completed()
|
||||
-- Reset folding settings to default
|
||||
vim.wo.foldmethod = "manual"
|
||||
vim.wo.foldexpr = "0"
|
||||
|
||||
-- Open all folds
|
||||
vim.cmd("normal! zR")
|
||||
|
||||
vim.notify("Showing all tasks", vim.log.levels.INFO)
|
||||
end
|
||||
|
||||
-- Register the commands
|
||||
vim.api.nvim_create_user_command("HideCompleted", function()
|
||||
M.hide_completed()
|
||||
end, {})
|
||||
|
||||
vim.api.nvim_create_user_command("ShowCompleted", function()
|
||||
M.show_completed()
|
||||
end, {})
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user