Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutolistRecalculate does not function correctly on indented ordered lists. #82

Open
CabalCrow opened this issue Nov 12, 2023 · 1 comment

Comments

@CabalCrow
Copy link

Tested in a markdown file:
AutolistRecalculate does not recalculate correctly ordered list if it lacks the first element.
For example

1. list
2. list
3. list

if the 3. element of the list is indented & then AutolistRecalculate is used this is the list I get:

1. list
2. list
    3. list

instead of:

1. list
2. list
    1. list

Indenting back into an indent level where you have a 1. (or any other first element of an ordered list) & then using AutolistRecalculate does work correctly, example:

1. list
2. list
3. list
    1. list
    2. list
        5. list 

You can indent the last element of the list either to the first level (which will recalculate to 4) or the second level (which would recalculate to 3).
However if the 1. is missing on the second level it won't recalculate the whole second level from its first element like it would on the initial indent, example:

1. list
    2. list
        5. list 

if we indent back into the second level with the final element:

1. list
    2. list
    3. list 

instead of:

1. list
    1. list
    2. list 

Also using AutolistCycleNext (or prev) on an indended order list with missing first element (the same type of list where recalculate does not work correctly on) does nothing at all. Also treesitter does not colour that list (it colours the list in which those commands function correctly) so don't know if that could be related.

This is my config:

{
        "gaoDean/autolist.nvim",
        ft = {
            "markdown",
            "text",
            "tex",
            "plaintex",
            "norg",
        },
        config = function()
            require("autolist").setup()

            vim.keymap.set("i", "<c-t>", "<c-t><cmd>AutolistRecalculate<cr>") -- an example of using <c-t> to indent
            vim.keymap.set("i", "<c-d>", "<c-d><cmd>AutolistRecalculate<cr>") -- an example of using <c-t> to indent
            vim.keymap.set("i", "<CR>", "<CR><cmd>AutolistNewBullet<cr>")
            vim.keymap.set("n", "o", "o<cmd>AutolistNewBullet<cr>")
            vim.keymap.set("n", "O", "O<cmd>AutolistNewBulletBefore<cr>")
            vim.keymap.set("n", "<CR>", "<cmd>AutolistToggleCheckbox<cr><CR>")

            -- cycle list types with dot-repeat
            vim.keymap.set("i", "<c-tab>", require("autolist").cycle_next_dr, { expr = true })
	    vim.keymap.set("i", "<c-s-tab>", require("autolist").cycle_prev_dr, { expr = true })
            vim.keymap.set("n", "<leader>an", require("autolist").cycle_next_dr, { expr = true })
            vim.keymap.set("n", "<leader>ap", require("autolist").cycle_prev_dr, { expr = true })

            -- functions to recalculate list on edit
            vim.keymap.set("n", ">>", ">><cmd>AutolistRecalculate<cr>")
            vim.keymap.set("n", "<<", "<<<cmd>AutolistRecalculate<cr>")
            vim.keymap.set("n", "nn", "dd<cmd>AutolistRecalculate<cr>")
            vim.keymap.set("n", "<leader>n", "dd<cmd>AutolistRecalculate<cr>")
            vim.keymap.set("n", "<leader><backspace>", "\"_dd<cmd>AutolistRecalculate<cr>")
            vim.keymap.set("n", "<backspace>n", "\"_dd<cmd>AutolistRecalculate<cr>")
            vim.keymap.set("n", "<backspace><backspace>", "\"_dd<cmd>AutolistRecalculate<cr>")
            vim.keymap.set("v", "n", "d<cmd>AutolistRecalculate<cr>")
            vim.keymap.set("v", "<backspace>", "\"_d<cmd>AutolistRecalculate<cr>")
        end,
    },

I've tested both with keymaps & the actual command (AutolistRecalculate) via the command mode :.

@alichtman
Copy link

I can reproduce this issue. It also breaks on unordered lists:

- Item 1
- Item 2
- Item 3

If you're in insert mode on Item 3 and press <C-t>, you get:

- Item 1
- Item 2
    - Item 3

instead of

- Item 1
- Item 2
    * Item 3

I'm using lazy.nvim with the following config:

local filetypes = {
    "markdown",
    "text",
    "tex",
    "gitcommit",
    "scratch",
    "jrnl",
}
return {
    "gaoDean/autolist.nvim",
    ft = filetypes,
    config = function()
        local autolist = require('autolist')

        autolist.setup({
            colon = { indent_raw = false },
        })

        local opts = { buffer = true }

        local function set_keymaps()
            vim.keymap.set('i', '<CR>', '<CR><cmd>AutolistNewBullet<CR>', { buffer = true })
            vim.keymap.set('n', 'o', 'o<cmd>AutolistNewBullet<CR>', { buffer = true })
            vim.keymap.set('n', 'O', 'O<cmd>AutolistNewBulletBefore<CR>', { buffer = true })

            -- cycle list types with dot-repeat
            -- vim.keymap.set("n", "<leader>cn", require("autolist").cycle_next_dr, { expr = true })
            -- vim.keymap.set("n", "<leader>cp", require("autolist").cycle_prev_dr, { expr = true })

            -- functions to recalculate list on edit
            vim.keymap.set("i", "<C-t>", "<c-t><cmd>AutolistRecalculate<CR>")
            vim.keymap.set("i", "<C-d>", "<c-d><cmd>AutolistRecalculate<CR>")
            vim.keymap.set("n", ">>", ">><cmd>AutolistRecalculate<CR>")
            vim.keymap.set("n", "<<", "<<<cmd>AutolistRecalculate<CR>")
            vim.keymap.set("n", "dd", "dd<cmd>AutolistRecalculate<CR>")
            vim.keymap.set("v", "d", "d<cmd>AutolistRecalculate<CR>")
        end

        local augroup = vim.api.nvim_create_augroup('Autolist', {})
        vim.api.nvim_create_autocmd('FileType', {
            pattern = filetypes,
            group = augroup,
            callback = set_keymaps,
        })

        -- Set the keymaps the firs time autolist.nvim gets lazy-loaded
        set_keymaps()
    end
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants