monaqa / dial.nvim

enhanced increment/decrement plugin for Neovim.
MIT License
794 stars 12 forks source link

Date pattern like %-m don't work. #64

Closed MasouShizuka closed 1 year ago

MasouShizuka commented 1 year ago

Indefinite length patterns such as %-m and %-d in the date cannot work.

For example, this is setting:

default = {
    augend.date.alias["%-m/%-d"],
},
or
default = {
    augend.date.new {
        pattern = "%-m/%-d",
        default_kind = "day",
        only_valid = true,
        word = false,
    },
},

And this is text:

1/1

Then I can't get the two 1 to increment or decrement.

Patterns without %-m, %-d etc work.

Is there something wrong with my usage?

monaqa commented 1 year ago

Cannot reproduce 🤔 Could you show me a small reproducible vimrc?

MasouShizuka commented 1 year ago

I retested again, and this time commented out all my neovim settings, and it still didn't work, suggesting it had nothing to do with my settings. It was tested on windows before.

Then I copied my settings to neovim in wsl2 and it worked! This is very strange that it doesn't work on windows.

monaqa commented 1 year ago

Is it possible that <C-a> key is being taken by the terminal?

MasouShizuka commented 1 year ago

No. <C-a> works.

The setting is as below:

default = {
    augend.date.alias["%m/%d"],
    augend.date.alias["%-m/%-d"],
},

Then I can change text:

01/01

But I can't change text:

1/1

By the way, both can work in wsl2.

monaqa commented 1 year ago

Could you show me a small, entire, reproducible vimrc?

I don't have a windows environment so I don't think I can reproduce it, but it might give me some clues.

MasouShizuka commented 1 year ago

I just install it with lazy.nvim. Like I said before, I commented out all the other settings to no avail.

If you absolutely need it, here's reproducible code in init.lua:

local plugin_list = {
    {
        "monaqa/dial.nvim",
        config = function()
            vim.keymap.set("n", "<C-a>", require("dial.map").inc_normal(), { silent = true })
            vim.keymap.set("n", "<C-x>", require("dial.map").dec_normal(), { silent = true })
            vim.keymap.set("x", "<C-a>", require("dial.map").inc_visual(), { silent = true })
            vim.keymap.set("x", "<C-x>", require("dial.map").dec_visual(), { silent = true })
            vim.keymap.set("x", "g<C-a>", require("dial.map").inc_gvisual(), { silent = true })
            vim.keymap.set("x", "g<C-x>", require("dial.map").dec_gvisual(), { silent = true })

            local augend = require("dial.augend")
            require("dial.config").augends:register_group {
                default = {
                    augend.date.alias["%m/%d"],
                    augend.date.alias["%-m/%-d"],
                },
            }
        end,
    },
}

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "https://github.com/folke/lazy.nvim.git",
        "--branch=stable", -- latest stable release
        lazypath,
    })
end
vim.opt.rtp:prepend(lazypath)

return require("lazy").setup(plugin_list)
MasouShizuka commented 1 year ago

By the way, my neovim's version is 0.8.3 both on windows and wsl2.

monaqa commented 1 year ago

Thanks. I confirmed that there seems to be no problem with the configuration.

Unfortunately, I still could not reproduce it in my environment (macOS). It seems to be environment-dependent as you say, but I have no idea why.

MasouShizuka commented 1 year ago

I tested some more, hope it helps, as follows:

windows pattern text before cursor text after
%-m/%-d 1/4 1 or 4 1/4
%-d.%-m. 4.1. 4 or 1 4.1.
%Y年%-m月%-d日 2021年1月4日 4 2021年1609804800月1609804800日
%Y年%-m月%-d日 2021年1月4日 1 2021年1612396800月1612396800日
%Y年%-m月%-d日(%ja) 2021年1月4日(月) 4 2021年1609804800月1609804800日(火)
%Y年%-m月%-d日(%ja) 2021年1月4日(月) 1 2021年1612396800月1612396800日(木)
%-y/%m/%d 9/01/04 9 9/01/04
%-H:%-M:%-S 12:2:3 12 or 2 or 3 12:2:3
%-I:%-M:%-S 12:2:3 12 or 2 or 3 12:2:3

Among them, the result of %Y年%-m月%-d日 is very abnormal.

By the way, wsl2 pattern text before cursor text after
%-m/%-d 1/4 4 1/5
%-m/%-d 1/4 1 2/4
%-d.%-m. 4.1. 4 5.1.
%-d.%-m. 4.1. 1 4.2.
%Y年%-m月%-d日 2021年1月4日 4 2021年1月5日
%Y年%-m月%-d日 2021年1月4日 1 2021年2月4日
%Y年%-m月%-d日(%ja) 2021年1月4日(月) 4 2021年1月5日(火)
%Y年%-m月%-d日(%ja) 2021年1月4日(月) 1 2021年2月4日(木)
%-y/%m/%d 9/01/04 9 10/01/04
%-H:%-M:%-S 12:2:3 12 13:2:3
%-H:%-M:%-S 12:2:3 2 12:3:3
%-H:%-M:%-S 12:2:3 3 12:2:4
%-I:%-M:%-S 12:2:3 12 1:2:3
%-I:%-M:%-S 12:2:3 2 12:3:3
%-I:%-M:%-S 12:2:3 3 12:2:4
monaqa commented 1 year ago

@MasouShizuka Thank you for the further research. It is very helpful.

With some help, we finally found the cause: some os.date results seem to be different on Windows than others. (Thank you, @yuys13 !) I have created a PR (#65) to fix the issue. Could you try this?

MasouShizuka commented 1 year ago
Now the test result is: pattern text before cursor text after
%-m/%-d 1/4 1 1/5
%-m/%-d 1/4 4 2/4
%-d.%-m. 4.1. 4 5.1.
%-d.%-m. 4.1. 1 4.2.
%Y年%-m月%-d日 2021年1月4日 4 2021年1月5日
%Y年%-m月%-d日 2021年1月4日 1 2021年2月4日
%Y年%-m月%-d日(%ja) 2021年1月4日(月) 4 2021年1月5日(火)
%Y年%-m月%-d日(%ja) 2021年1月4日(月) 1 2021年2月4日(木)
%-y/%m/%d 9/01/04 9 9/01/04
%-H:%-M:%-S 12:2:3 12 or 2 or 3 12:2:3
%-I:%-M:%-S 12:2:3 12 or 2 or 3 12:2:3

Looks like %-y didn't fix it, and %-H, %-I, %-M, %-S didn't work

MasouShizuka commented 1 year ago

Oh, augend.date.alias["%-H:%-M:%-S"] doesn't work, but

augend.date.new {
    pattern = "%-H:%-M:%-S",
    default_kind = "day",
    only_valid = true,
    word = false,
},

work.

monaqa commented 1 year ago

I fixed about the %-y. Date alias "%-H:%-M:%-S" does not exist, so please try examples such as:

dial_config.augends:register_group {
    default = {
        augend.date.new {
            pattern = "%-H:%-M:%-S",
            default_kind = "sec",
            only_valid = false,
        },
        augend.date.new {
            pattern = "%-I:%-M",
            default_kind = "min",
            only_valid = false,
        },
    },
}
MasouShizuka commented 1 year ago

I roughly tested it, it should be fine.

monaqa commented 1 year ago

Okay, I'll merge #65 and close this issue. Feel free to reopen this / create a new issue if you encounter strange behavior.