jiangmiao / auto-pairs

Vim plugin, insert or delete brackets, parens, quotes in pair
http://www.vim.org/scripts/script.php?script_id=3599
4.11k stars 373 forks source link

javascript indentation #45

Closed albertosantini closed 11 years ago

albertosantini commented 11 years ago

In javascript with nocindent, the indentation is "wrong".

Firstly without auto-pairs plugin:

// cindent
function () {
    var foo = {
        bar: {

             } // this line is not indented "correctly"
    }
}
// nocindent
function () {
    var foo = {
        bar: {

        } // ok
    }
}

With auto-pairs and nocindent the result is like setting cindent.

I think it is due to '=ko' in line 369:

return "\<ESC>=ko".cmd

https://github.com/jiangmiao/auto-pairs/blob/master/plugin/auto-pairs.vim#L369

Any thought?

Thanks in advance, Alberto

jiangmiao commented 11 years ago

I cannot reproduce the issue in my vim 7.3.409. what's the cinoptions? and I'm afraid it's indent script's bug. indent script should be always correct when trying indent current line.

albertosantini commented 11 years ago

Here the stock 7.3.46.

If I use stock settings for javascript, I mean default cinoptions and cindent, I get the first indentation.

set cinoptions?
cinoptions=j1, J1
set cindent?
cindent

Setting cindent to nocindent I get the second one. Indeed I set in my _vimrc

set nocindent

So far way it is ok.

When I install auto-pairs and type

{<CR>

I get the second case.

jiangmiao commented 11 years ago

Same settings here.

// cindent
function () {
    var foo = {
        bar: {
             } // What's the result when press == or =k at this line in normal mode?
    }
}

the empty line between bar: { and } is removed.

albertosantini commented 11 years ago

Maybe the different result it is due to another settings.

set autoindent
set smartindent

Then I have a mapping:

inoremap <buffer> {<cr> {<cr>}<Esc>O

Of course when I try auto-pairs, I comment out the above mapping.

So in my configuration, when I type {<cr>, I get the correct, for me, indentation.

Pressing == or =k at this line in normal mode I transform:

function () {
    var foo = {
        bar: {
        } // ok with my settings and mapping
    }
}

to

function () {
    var foo = {
        bar: {
             } // with auto-pairs or pressing ==
    }
}

Anyway I am available to any change in my configuration to achieve that result.

Thanks for the support.

jiangmiao commented 11 years ago

I'm sorry I think I won't fix this issue. == behaviour is not part of auto-pairs. It means indent current line. you could try == without auto-pairs and your setting, you will get the same result. the indent should be always correct when trying ==, and for most of situation

foo({|}).bar()

press <CR> at | will cause incorret indentation.

btw: maybe you could try better javascript indenter, https://github.com/jiangmiao/simple-javascript-indenter it should be always indent correctly. and the BriefMode is recommanded.

quangv commented 9 years ago

I believe we have similar problems. Check out my fix on #85