auto-pairs icon indicating copy to clipboard operation
auto-pairs copied to clipboard

Parentheses indentation conflict with vim-javascript plugin

Open madox2 opened this issue 9 years ago • 9 comments

When using this plugin together with vim-javascript, indentation of parentheses is wrong after new line. I have following js code:

function render() {
  return (|)
}

After pressing ENTER:

function render() {
  return (
    |
)
}

Notice that last parenthesis is not indented.

Also see https://github.com/pangloss/vim-javascript/issues/663

madox2 avatar Oct 10 '16 18:10 madox2

+1 same issue here

valerybugakov avatar Dec 25 '16 12:12 valerybugakov

I've got

function render() {
    return (
    |
    )
}

expected:

function render() {
    return (
        |
    )
}

The issue happens only for parens, for braces everything is ok

dderg avatar Apr 16 '17 12:04 dderg

+1 same here

heydemoura avatar May 16 '17 23:05 heydemoura

+1 same here. Anybody has solution????

u10root avatar Jan 28 '18 15:01 u10root

+1 same here

tony40508 avatar Aug 18 '19 18:08 tony40508

Is there a solution for this?

nschurmann avatar Aug 02 '21 07:08 nschurmann

Lunarwatcher/auto-pairs#26 Lunarwatcher/auto-pairs#27 (tl;dr: fix your indent config)

LunarWatcher avatar Aug 02 '21 08:08 LunarWatcher

Thanks @LunarWatcher , I forgot to mention that this only happens when writing javascript in a file that contains JSX (it can be a .js or .jsx) and inside a function or class method. Here's a screenshot. If I use something different than vim polyglot then it works fine. Screen Shot 2021-08-02 at 9 42 03 PM

nschurmann avatar Aug 02 '21 09:08 nschurmann

The second TL;DR: on this topic is that auto-pairs doesn't actually do what the docs promise, in terms of:

Input: (|)   <cr> at |
Output: (
    |
)

Because it has to respect a number of systems. In practice, all it does is <CR>=ko (or enter, format one up, create and jump into insert mode on the line under).

As a consequence, bad indent functions does make auto-pairs "misbehave" in the sense that it doesn't do what the docs promise, but it does respect how Vim was configured. And to be clear, polyglot isn't the only way out. It too can have bugs - use whatever plugin works for your use, or write an indentexpr if you know how and have some time to kill (or just because you want to). Having a language-portable way to do what the docs promise without relying on the indentexpr for the language to work like it should, though, is a lot harder to implement than it is to use indentexprs. (in theory, anyway. I've tried and failed to do that in a way that just works regardless of the indentexpr and other style options - and that was even prior to accounting for spaces and tabs)

LunarWatcher avatar Aug 02 '21 10:08 LunarWatcher