Skip to content

Commit

Permalink
feat: dot repeat support (#35)
Browse files Browse the repository at this point in the history
* fix: prevent list recalculation when toggling checkbox in normal mode

* the list recal adds a space buffer for some reason

* feat: dot repeat support
  • Loading branch information
gaoDean authored Dec 22, 2022
1 parent aaadfa9 commit f600383
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
14 changes: 10 additions & 4 deletions lua/autolist/auto.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ local function modify(prev, pattern)
return utils.get_ordered_add(matched, 1)
end

function M.new_before()
M.new(true)
end

function M.new(O_pressed)
if fn.line(".") <= 0 then return end
local prev_line = fn.getline(fn.line(".") - 1)
Expand Down Expand Up @@ -107,8 +111,7 @@ function M.new(O_pressed)
utils.reset_cursor_column()
return
end
if not before
and config.colon.indent_raw
if config.colon.indent_raw
and prev_line:match(pat_colon)
then
utils.set_current_line(config.colon.preferred .. " " .. fn.getline("."):gsub("^%s*", "", 1))
Expand Down Expand Up @@ -146,6 +149,11 @@ function M.indent(direction)
end
end


function M.normal_recal()
M.recal()
end

-- recalculates the current list scope
function M.recal(override_start_num, reset_list)
-- the var base names: list and line
Expand Down Expand Up @@ -217,13 +225,11 @@ function M.invert()
if filled == true then
-- replace current line's empty checkbox with filled checkbox
fn.setline(".", (cur_line:gsub(checkbox_filled_pat, checkbox_empty, 1)))
check_recal("invert")
return
-- it is a checkbox, but not empty
elseif filled == false then
-- replace current line's filled checkbox with empty checkbox
fn.setline(".", (cur_line:gsub(checkbox_empty_pat, checkbox_filled, 1)))
check_recal("invert")
return
end
end
Expand Down
14 changes: 8 additions & 6 deletions lua/autolist/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@ local default_config = {
},
},
normal_mappings = {
new = {
"o",
"O+(true)",
},
recal = {
new = { "o" },
new_before = { "O" },
normal_recal = {
"dd",
"p"
},
Expand Down Expand Up @@ -102,7 +100,11 @@ local function setmap(func, mappings, ft, mode)
else
map = map .. " " .. map -- execute the mapping
end
au("Filetype", ft, mode .. " <buffer> " .. map .. "<cmd>lua require('autolist')." .. func .. "(" .. args .. ")<cr>")
if mode == 'inoremap' then
au("Filetype", ft, mode .. " <buffer> " .. map .. "<cmd>lua require('autolist')." .. func .. "(" .. args .. ")<cr>")
else
au("Filetype", ft, mode .. " <buffer> " .. map .. "<cmd>lua vim.o.operatorfunc=\"v:lua.require'autolist'." .. func .. "\"<cr><cmd>normal! g@g@<cr> ")
end
end
end

Expand Down

0 comments on commit f600383

Please sign in to comment.