Skip to content

Commit fd9cb7f

Browse files
committed
summary as a ranged tag
1 parent 6fece15 commit fd9cb7f

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

lua/neorg/modules/core/summary/module.lua

+28-5
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,19 @@ module.load = function()
116116
end
117117
end)
118118
local result = {}
119-
local prefix = string.rep("*", heading_level)
119+
local prefix = string.rep(" ", heading_level)
120120

121121
for category, data in vim.spairs(categories) do
122-
table.insert(result, prefix .. " " .. category)
123-
122+
if #result > 0 then
123+
table.insert(result, "")
124+
end
125+
table.insert(result, prefix .. "#cat " .. category)
124126
for _, datapoint in ipairs(data) do
125127
table.insert(
126128
result,
127129
table.concat({
128-
" - {:$",
130+
prefix,
131+
" {:$",
129132
datapoint.norgname,
130133
":}[",
131134
neorg.lib.title(datapoint.title),
@@ -200,7 +203,27 @@ module.on_event = function(event)
200203
return
201204
end
202205

203-
vim.api.nvim_buf_set_lines(buffer, event.cursor_position[1], event.cursor_position[1], true, generated)
206+
-- surround with a ranged tag
207+
table.insert(generated, 1, "|group summary")
208+
table.insert(generated, "|end")
209+
210+
local start_line = event.cursor_position[1]
211+
local end_line = start_line
212+
-- find * replace an existing ranged tag
213+
local node_line_below = ts.get_first_node_on_line(buffer, start_line)
214+
if node_line_below and node_line_below:type() == "_paragraph_break" then
215+
-- allow for a line break between heading and tag
216+
node_line_below = ts.get_first_node_on_line(buffer, start_line+1)
217+
end
218+
if node_line_below and node_line_below:type() == "ranged_tag" then
219+
start_line, _ = node_line_below:start()
220+
end_line, _ = node_line_below:end_()
221+
end_line = end_line + 1
222+
else
223+
neorg.utils.notify(node_line_below:type())
224+
end
225+
226+
vim.api.nvim_buf_set_lines(buffer, start_line, end_line, true, generated)
204227
end
205228
end
206229

0 commit comments

Comments
 (0)