Loading ...
Sorry, an error occurred while loading the content.

Re: Possible cindent bug when using cinoptions=J1

Expand Messages
  • Bram Moolenaar
    ... 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! --
    Message 1 of 6 , Feb 2, 2011
    • 0 Attachment
      Hari G wrote:

      > On Feb 1, 7:02 pm, Bram Moolenaar <B...@...> 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 -- Bram@... -- 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
    • Matt Schulkind
      I have run across a related problem, though not the exact same one while trying to modify the objc indentation to work for ^{} blocks. The J1 option seems to
      Message 2 of 6 , Apr 4, 2011
      • 0 Attachment
        I have run across a related problem, though not the exact same one while trying to modify the objc indentation to work for ^{} blocks. The J1 option seems to be pretty much exactly what I want, and it works for the most part, but I uncovered this problem:

        class Foo
        {
          public void bar() {
            object.add(new ChangeListener() {
              public void stateChanged(ChangeEvent e) {
                foo =
              bar;
              }
            });
          }
        }

        Notice how the 'bar;' is actually outdented from the 'foo =' line, even though with my vimrc, it should be 4 spaces indented from 'foo ='.

        Hari,
        If I'm going to chase this bug, is there a branch/patch that you suggest starting from? I don't want make changes to the same code that you've already changed heavily elsewhere.

        --
        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
      • Matt Schulkind
        I just realized that I mispoke here, I m actually trying to use the j1 option, NOT the J1 option. The rest still applies though. Perhaps if I m chasing a j1
        Message 3 of 6 , Apr 4, 2011
        • 0 Attachment
          I just realized that I mispoke here, I'm actually trying to use the j1 option, NOT the J1 option. The rest still applies though. Perhaps if I'm chasing a j1 bug though, I won't be touching the same code?

          --
          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
        Your message has been successfully submitted and would be delivered to recipients shortly.