refactor(config): nest view settings under view key (#103)
Problem: View-related config fields (`default_view`, `eol_format`, `category_order`, `folding`) are scattered as top-level siblings alongside unrelated fields like `data_path` and `date_syntax`. Solution: Group them under a `view` table with per-view sub-tables: `view.default`, `view.eol_format`, `view.category.order`, `view.category.folding`, and `view.queue` (empty, ready for #100). Update all call sites, tests, and vimdoc.
This commit is contained in:
parent
91cce0a82e
commit
a43f769383
5 changed files with 82 additions and 73 deletions
|
|
@ -440,7 +440,7 @@ end
|
|||
local function apply_extmarks(bufnr, line_meta)
|
||||
local cfg = config.get()
|
||||
local icons = cfg.icons
|
||||
local eol_segments = parse_eol_format(cfg.eol_format or '%c %r %d')
|
||||
local eol_segments = parse_eol_format(cfg.view.eol_format or '%c %r %d')
|
||||
vim.api.nvim_buf_clear_namespace(bufnr, ns_eol, 0, -1)
|
||||
vim.api.nvim_buf_clear_namespace(bufnr, ns_inline, 0, -1)
|
||||
for i, m in ipairs(line_meta) do
|
||||
|
|
@ -578,7 +578,7 @@ function M.render(bufnr)
|
|||
return
|
||||
end
|
||||
|
||||
current_view = current_view or config.get().default_view
|
||||
current_view = current_view or config.get().view.default
|
||||
local view_label = current_view == 'priority' and 'queue' or current_view
|
||||
vim.api.nvim_buf_set_name(bufnr, 'pending://' .. view_label)
|
||||
local all_tasks = _store and _store:active_tasks() or {}
|
||||
|
|
|
|||
|
|
@ -49,22 +49,31 @@
|
|||
---@field next_task? string|false
|
||||
---@field prev_task? string|false
|
||||
|
||||
---@class pending.CategoryViewConfig
|
||||
---@field order? string[]
|
||||
---@field folding? boolean|pending.FoldingConfig
|
||||
|
||||
---@class pending.QueueViewConfig
|
||||
|
||||
---@class pending.ViewConfig
|
||||
---@field default? 'category'|'priority'
|
||||
---@field eol_format? string
|
||||
---@field category? pending.CategoryViewConfig
|
||||
---@field queue? pending.QueueViewConfig
|
||||
|
||||
---@class pending.Config
|
||||
---@field data_path string
|
||||
---@field default_view 'category'|'priority'
|
||||
---@field default_category string
|
||||
---@field date_format string
|
||||
---@field date_syntax string
|
||||
---@field recur_syntax string
|
||||
---@field someday_date string
|
||||
---@field input_date_formats? string[]
|
||||
---@field category_order? string[]
|
||||
---@field drawer_height? integer
|
||||
---@field debug? boolean
|
||||
---@field keymaps pending.Keymaps
|
||||
---@field folding? boolean|pending.FoldingConfig
|
||||
---@field view pending.ViewConfig
|
||||
---@field sync? pending.SyncConfig
|
||||
---@field eol_format? string
|
||||
---@field icons pending.Icons
|
||||
|
||||
---@class pending.config
|
||||
|
|
@ -73,15 +82,20 @@ local M = {}
|
|||
---@type pending.Config
|
||||
local defaults = {
|
||||
data_path = vim.fn.stdpath('data') .. '/pending/tasks.json',
|
||||
default_view = 'category',
|
||||
default_category = 'Todo',
|
||||
date_format = '%b %d',
|
||||
date_syntax = 'due',
|
||||
recur_syntax = 'rec',
|
||||
someday_date = '9999-12-30',
|
||||
eol_format = '%c %r %d',
|
||||
folding = true,
|
||||
category_order = {},
|
||||
view = {
|
||||
default = 'category',
|
||||
eol_format = '%c %r %d',
|
||||
category = {
|
||||
order = {},
|
||||
folding = true,
|
||||
},
|
||||
queue = {},
|
||||
},
|
||||
keymaps = {
|
||||
close = 'q',
|
||||
toggle = '<CR>',
|
||||
|
|
@ -132,7 +146,7 @@ end
|
|||
|
||||
---@return pending.ResolvedFolding
|
||||
function M.resolve_folding()
|
||||
local raw = M.get().folding
|
||||
local raw = M.get().view.category.folding
|
||||
if raw == false then
|
||||
return { enabled = false, foldtext = false }
|
||||
elseif raw == true or raw == nil then
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ function M.category_view(tasks)
|
|||
end
|
||||
end
|
||||
|
||||
local cfg_order = config.get().category_order
|
||||
local cfg_order = config.get().view.category.order
|
||||
if cfg_order and #cfg_order > 0 then
|
||||
local ordered = {}
|
||||
local seen = {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue