Hari G wrote:

> On Feb 1, 7:02 pm, Bram Moolenaar <b...@moolenaar.net> wrote:
> > Audrius wrote:
> > > 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.
> >
> > Yes, it looks different from the example for J1.
> > Hari?
> >
> 
> Yes. The fixes that are currently included in Vim only resolve a part
> of indentation issues with JavaScript using cindent. I had submitted
> another patch (see 
> http://groups.google.com/group/vim_dev/browse_thread/thread/5e3c91a11cae07a7
> ) which fixes some of these issues. At present I've a fix (locally)
> that seem to work in most cases but still buggy with code that has
> random braces within comments and those not within braces (which is
> valid in JavaScript). Since it changes a lot of the get_c_indent
> function, I am quite not sure I've not broken C/C++ indenting. Bram,
> should I submit it as a patch?

Make sure to run the tests, there is a test for C indenting.

I could include a patch, but I rather have one where you are confident
it works well!

-- 
hundred-and-one symptoms of being an internet addict:
182. You may not know what is happening in the world, but you know
     every bit of net-gossip there is.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Raspunde prin e-mail lui