LunarWatcher / auto-pairs

Vim plugin, insert or delete brackets, parentheses, and quotes in pairs
MIT License
173 stars 6 forks source link

Confused about MultiLineClose #77

Closed joshfrench closed 1 year ago

joshfrench commented 1 year ago

OS: MacOS 13

What vim? (+ version) nvim v0.9.0-dev-2417

Reproduced in other variants of Vim? (Optional): Reproduced on nvim 0.8

Autopairs config (if applicable): happens with an empty config as well as with vim.g.AutoPairsMultiLineClose = 1

Describe the bug Not sure if this is a bug or expected behavior, I think I'm mostly confused about how MultiLineClose is supposed to work -- my use-case may not be a close, per se? I've reproduced this in Fennel as well as TreeSitter query files, so it may just be a lisp-y thing.

Given this expression, where | is the cursor:

(
  |)

If I insert (, I get this:

(
  ()

which is now unbalanced. The same is true if there's whitespace between the cursor and the closing ). Is there a way to configure auto-pairs to correctly generate a full pair instead of treating the final ) as already unbalanced? BackInsert doesn't insert the correct ) either, fwiw.

LunarWatcher commented 1 year ago

which is now unbalanced

Yes, because that isn't what MultiLineClose is for. If you have

{
|
}

And press }, you'll get

{

}|

Rather than

{
}|
}

And only if there's whitespace. The docs probably need an update to clarify what it's for. I remember it having been more specific, but guess that changed at some point. /shrug

Is there a way to configure auto-pairs to correctly generate a full pair instead of treating the final ) as already unbalanced?

No. What you're asking for is an overall balance check for a file, and that requires semantic information auto-pairs doesn't have, and can't easily access. Keeping track of it requires parsing the entire file with an understanding of constructs like comments and strings, and that's a parser

BackInsert doesn't insert the correct ) either, fwiw.

BackInsert is exclusively for flymode. It isn't designed for anything else, and is barely hooked up as-is (flymode isn't recommended or maintained)

joshfrench commented 1 year ago

That all makes sense, thanks for the explainer. FWIW I've been using this fork since at least 2021 and I haven't found an alternate that can compare, thanks for all your work!