echasnovski / mini.nvim

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

mini.ai: errors when using \ or CTRL-J or CTRL-M as key of textobject #841

Closed thomaswuhoileong closed 2 months ago

thomaswuhoileong commented 2 months ago

Contributing guidelines

Module(s)

mini.ai

Description

Using \ or CTRL-J or CTRL-M as the key for a textobject leads to the error due to invalid lua syntax. The reason is that, in the return statement of H.expr_textobject(), when tobj_id is '\\', it is not escaped when substituted in the expression, and when tobj_id is '\n' or '\r', the linebreak makes the expression incomplete.

Neovim version

0.9.5

Steps to reproduce

1) Open nvim 2) Load mini.ai (by :lua require 'mini.ai'.setup {}<CR>) 3) Type va<Bslash> or va<C-J> or va<CR>

Expected behavior

No error due to invalid lua syntax should occur. Either the corresponding textobject is searched for or a message rejecting the usage of such keys is shown.

Actual behavior

The error message E5107: Error loading lua [string ":lua"]:1: <message> is shown (where <message> depends on the key and mini.ai configuration).

thomaswuhoileong commented 2 months ago

There is also the same problem in H.expr_motion() which causes the same error when typing g[<Bslash> etc.

echasnovski commented 2 months ago

Thanks for the issue!

Yes, I can reproduce. And if \ is a reasonable case, I am not sure supporting <C-xxx> keys is a good idea if it needs some dark magic to be done. I'll take a look.

echasnovski commented 2 months ago

The case of \ should now be fixed on latest main. Also the list of allowed characters for textobject id is now better clarified as "alphanumeric, punctuation, space, or tab", so <C-J> (which is \n) and <C-M> (which is \r) are now correctly not supported (with message).