Bram Moolenaar wrote:
> Hari Kumar wrote:
>
> > Vim uses cindent for JS files which works in general nicely. There are
> > a few cases where this does not work correctly. F.e.
> >
> > var a = {
> >     b: 1,
> >     c: "hello"
> > }
> >
> > cindent would align b: 1 to col 0 and indent c: "hello" by shiftwidth.
> > This is because of how it treats labels in C. The attached fix avoids
> > this by using another 'cindentoption' value 'J' so that such lines
> > could be treated differently if the file is a JS file. This also sets
> > the 'j' option used by Java files in order to handle anonymous
> > functions in JS.  Further it changes how a 'case' label is determined,
> > to suit JS also.
> >
> > I've tested this fix with JS & C source code and it seems working for me.
> >
> > Review is appreciated,
>
> Good to see this patch.
>
Thanks for taking a look.

> Since you know about this stuff, can you become the maintainer of the
> javascript indent plugin?  If so then please update the header of the
> file.
>
My vim script skills aren't any good :) What I want to try is to fix
the indenting issues in the cindent code itself.

I found one more case where the indenting is wrong. The JS code is:

window.addEventListener("load", function()
   {
         if (1)
         {
            // do something
         }
         else
         {
            // something else
         }
   },
false);

The 'j' flag in 'cino' helps a bit but the inner 'if' block will be
incorrectly indented. I tried to find the cause but without much
success. All I could figure out was that it was using the line with
the open parenthesis as the scope and then somehow gets confused with
the brace following the if.. and would indent it on col 0. It would be
great if this issue could be fixed.

> Instead of changing all calls to cin_iscase(), it's easier to rename
> cin_iscase() to cin_iscase_js(), add the extra argument, and create a
> new cin_iscase() that calls cin_iscase_js(arg, FALSE).
>
Right, but wouldn't that create an overhead of an additional function
call? (Maybe I am not understanding the suggestion correctly)

/harig

-- 
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