echasnovski / mini.nvim

Library of 40+ independent Lua modules improving overall Neovim (version 0.8 and higher) experience with minimal effort
MIT License
4.74k stars 179 forks source link

Unicode pairs #833

Closed prescientmoon closed 4 months ago

prescientmoon commented 4 months ago

Contributing guidelines

Module(s)

mini.ai

Description

I tried passing v = { "%b⟨⟩", "^.().*().$" } to custom_textobjects, but div (and other similar commands) always fail to find anything to match.

Neovim version

0.9.5

Steps to reproduce

Load the following config

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or 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)

require("lazy").setup({
    {
        "echasnovski/mini.ai",
        opts = { custom_textobjects = { v = { "%b⟨⟩", "^.().*().$" } } },
    },
})

For convenience, here's a string of text you can check the keybind on ⟨abc⟩

Expected behavior

No response

Actual behavior

(mini.ai) No textobject "iv" found covering region within 50 lines and `search_method = 'cover_or_next'`.
echasnovski commented 4 months ago

Thanks for the issue!

Matching in 'mini.ai' is done with Lua patterns. The %b special pattern item does not seem to work with multibyte characters. You can check it by executing :=string.find('⟨abc⟩', "%b⟨⟩"), which will print nil indicating that no match is found. In turn, plain <> works: =string.find('<abc>', "%b<>") gives 1, 5.

Closing as not not supported by Lua patterns.

prescientmoon commented 4 months ago

Thanks for the issue!

Matching in 'mini.ai' is done with Lua patterns. The %b special pattern item does not seem to work with multibyte characters. You can check it by executing :=string.find('⟨abc⟩', "%b⟨⟩"), which will print nil indicating that no match is found. In turn, plain <> works: =string.find('<abc>', "%b<>") gives 1, 5.

Closing as not not supported by Lua patterns.

Bonus question: any idea why using ⟨.-⟩ for the unbalanced version always removes the brackets, even when using div? Could it be that the "inside" still deletes all but one byte of the bracket or something similar? Would I have to use something different for the second argument (other than ^.().*().$)

echasnovski commented 4 months ago

Bonus question: any idea why using ⟨.-⟩ for the unbalanced version always removes the brackets, even when using div? Could it be that the "inside" still deletes all but one byte of the bracket or something similar? Would I have to use something different for the second argument (other than ^.().*().$)

I would need more information with actual examples of textobject spec, text before, taken steps, and text after.

prescientmoon commented 4 months ago

I would need more information with actual examples of textobject spec, text before, taken steps, and text after.

For the textobject v = { "⟨.-⟩", "^.().*().$" } and the text ⟨abc⟩, positioning the cursor on the b and pressing div will delete the entire string.

echasnovski commented 4 months ago

For the textobject v = { "⟨.-⟩", "^.().*().$" } and the text ⟨abc⟩, positioning the cursor on the b and pressing div will delete the entire string.

This is because both "⟨" and "⟩" are multibyte characters, while "." in Lua pattern matches a single byte character. Using { '⟨.-⟩', '^⟨().*()⟩$' } as specification should solve this.