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

Multibyte pair \( and \) causing errors. #71

Closed
HawkinsT opened this issue Nov 24, 2022 · 4 comments
Closed

Multibyte pair \( and \) causing errors. #71

HawkinsT opened this issue Nov 24, 2022 · 4 comments
Labels
bug Something isn't working status:Confirmed

Comments

@HawkinsT
Copy link

HawkinsT commented Nov 24, 2022

OS Arch Linux
What vim? (+ version) Neovim 0.8 and 0.9.0-dev

Autopairs config (if applicable):

let g:AutoPairsCompatibleMaps = 0
let g:AutoPairsMapBS = 1    " This is required for some reason otherwise <BS> is not set; not sure why as it's apparently the default value and this and packer are the only plugins I'm loading
let g:AutoPairs = autopairs#AutoPairsDefine([
    \ {'open': '\\left(', 'close': '\right)', 'filetype': 'tex'},
    \ {'open': '\\(', 'close': '\)', 'filetype': 'tex'},
    \ {'open': '\\[', 'close': '\]', 'filetype': 'tex'}])

Describe the bug
I'm using the above multibyte pairs for latex. \[ and \left( work fine and are just here for comparison. \( also works fine and creates the associated \) pair, however if I then hit backspace I get the warning:

Error detected while processing function autopairs#AutoPairsDelete:
line 16:
E55: Unmatched \)

then

Error detected while processing function autopairs#AutoPairsDelete[41] .. autopairs#Strings#matchend:
line 1:
E55: Unmatched \)

However the deletion works (it just deletes one byte so I end up with \|\) where | is the cursor position). Deleting the other three bytes now also results in these same two errors being repeated three more times.

As another scenario, after creating the matched pairs \(|\) if I hit <CR> I get the error:

Error detected while processing function autopairs#Keybinds#IgnoreInsertEnter[3] .. autopairs#AutoPairsReturn:
line 18:
E55: Unmatched \)

and then the CR happens so I end up with:

\(
|\)

instead of

\(
|
\)

as happens with, e.g. ( and ).

Since this doesn't happen with the matched pairs \[|\] or \left(|\right) my assumption is it's some screwy regex related to #53. I've tested this on all three branches and an otherwise blank config (except for bootstrapping packer and loading auto-pairs with the above settings) and all have this issue.

@HawkinsT HawkinsT added bug Something isn't working status:Triage labels Nov 24, 2022
@LunarWatcher
Copy link
Owner

It is indeed screwy regex. AutoPairsBackspace doesn't properly escape close:

let a = matchstr(rest_of_line, '^\v\s*\V' .. close)

For comparison, this is from AutoPairsInsert, which is fine:

let m = matchstr(afterline, '^\v\s*\zs\V' .. escape(close, '\'))

The problem is that I use \V to "disable" regex constructs, so to use a group, you'd have to use \(\). This is where the bad escape comes in. The escape method transforms \) to \\), which is interpreted as the literal \) rather than as a regex group.

As for the enter problem, same cause, in theory. Missing escape. Weird thing though, it doesn't error out for me (admittedly in Vim). I don't understand why, but I mean, if I can fix it anyway, it doesn't really matter.

I really need to revisit a large part of the pattern matching. I'll make a hotfix for the errors (or try anyway), but if that doesn't fix return, that's a wontfix until #53 is fixed (which I've been putting off because of Other Stuff:tm:, but no time like the present I suppose)

@HawkinsT
Copy link
Author

Many thanks for your quick response (and continued work on auto-pairs)! I'll await your hotfix and report back; let me know if you'd like me to test anything else related to this.

LunarWatcher added a commit that referenced this issue Nov 24, 2022
@LunarWatcher
Copy link
Owner

Hotfix pushed; confirmation it also works in neovim would be great!

LunarWatcher added a commit that referenced this issue Nov 24, 2022
@HawkinsT
Copy link
Author

I can confirm that BS and CR now work as expected in Neovim also. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working status:Confirmed
Projects
None yet
Development

No branches or pull requests

2 participants