2023-12-27 20:31:31 +01:00
|
|
|
local M = {}
|
|
|
|
local header_regex = "^(#+) (.+)"
|
|
|
|
|
2023-12-28 12:44:41 +01:00
|
|
|
M.headerControl = function(action)
|
2023-12-27 22:03:28 +01:00
|
|
|
local current_line = vim.api.nvim_get_current_line()
|
|
|
|
local row = vim.api.nvim_win_get_cursor(0)[1]
|
2023-12-27 20:31:31 +01:00
|
|
|
|
2023-12-27 22:03:28 +01:00
|
|
|
if current_line:match(header_regex) then
|
2023-12-28 12:44:41 +01:00
|
|
|
if action == "promote" then
|
|
|
|
if current_line:match("^# (.+)") then
|
|
|
|
vim.notify("You can't promote this header anymore")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
vim.api.nvim_buf_set_text(0, row - 1, 0, row - 1, 1, { "" })
|
|
|
|
elseif action == "demote" then
|
|
|
|
if current_line:match("^###### (.+)") then
|
|
|
|
vim.notify("You can't demote this header anymore")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
vim.api.nvim_buf_set_text(0, row - 1, 0, row - 1, 0, { "#" })
|
2023-12-27 20:31:31 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-12-28 12:44:41 +01:00
|
|
|
-- M.promote = function()
|
|
|
|
-- local current_line = vim.api.nvim_get_current_line()
|
|
|
|
-- local row = vim.api.nvim_win_get_cursor(0)[1]
|
|
|
|
--
|
|
|
|
-- if current_line:match(header_regex) then
|
|
|
|
-- if current_line:match("^# (.+)") then
|
|
|
|
-- vim.notify("You can't promote this header anymore")
|
|
|
|
-- else
|
|
|
|
-- vim.api.nvim_buf_set_text(0, row - 1, 0, row - 1, 1, { "" })
|
|
|
|
-- end
|
|
|
|
-- end
|
|
|
|
-- end
|
|
|
|
--
|
|
|
|
-- M.demote = function()
|
|
|
|
-- local current_line = vim.api.nvim_get_current_line()
|
|
|
|
-- local row = vim.api.nvim_win_get_cursor(0)[1]
|
|
|
|
--
|
|
|
|
-- if current_line:match(header_regex) then
|
|
|
|
-- if current_line:match("^###### (.+)") then
|
|
|
|
-- vim.notify("You can't demote this header anymore")
|
|
|
|
-- else
|
|
|
|
-- vim.api.nvim_buf_set_text(0, row - 1, 0, row - 1, 0, { "#" })
|
|
|
|
-- end
|
|
|
|
-- end
|
|
|
|
-- end
|
2023-12-27 20:31:31 +01:00
|
|
|
|
|
|
|
return M
|