Hi,

I was exploring the possibility to use cindent for JavaScript code
indentation, because all the indent plugins I've tried so far make me
unhappy.  I've found that it works pretty well (except for array
literals spanning multiple lines, though I'll try to fix it using
indentexpr similar to how it's done in indent/java.vim), but I believe
I've stumbled upon a bug.  At least it doesn't work as advertised in
documentation.

To reproduce the problem you'll need the following files:

$ cat > test.vim <<EOF
set nocompatible

set tabstop=8
set softtabstop=4
set shiftwidth=4
set expandtab

set nolisp
set noautoindent
set nosmartindent
set indentexpr=

set cindent
set cinoptions=j1,J1
EOF

$ cat > test.js <<EOF
var bar = {
    foo: {
        that: this,
        some: ok,
    },
    "bar": {
        a : 2,
        b: "123abc",
        x: 4,
        "y": 5
    }
}
EOF

The code snippet above is taken from :h javascript-indenting
documentation.  But when I run

  $ vim -u test.vim --noplugin test.js

and do gg=G, I get the following:

var bar = {
    foo: {
             that: this,
             some: ok,
         },
    "bar": {
        a : 2,
        b: "123abc",
        x: 4,
        "y": 5
    }
}

Notice that when the name in object literal is string ("bar":), the
indentation of its value object literal is correct, but if the name is
identifier (foo:), then the following three lines look wrong.

I went through :h cinoptions-values, but none of them looked like they
could interfere with cinoptions=J1 in this case.  Either I'm missing
something important here (some settings) or cindent doesn't work how it
should according to :h javascript-indenting example.

I'm using vim 7.3.094 from slackware-current.

-- 
Audrius Kažukauskas

Attachment: pgprKpTYStJjk.pgp
Description: PGP signature

Raspunde prin e-mail lui