pangloss / vim-javascript

Vastly improved Javascript indentation and syntax support in Vim.
http://www.vim.org/scripts/script.php?script_id=4452
3.8k stars 358 forks source link

Honour cino W also when opening brace at the end #1114

Closed elmart closed 6 years ago

elmart commented 6 years ago

I have vim-javascript installed, and this in my .vimrc: set cinoptions+=(0,m1,)100,W1s,j1,J1. With that, I get the desired:

object.method(argument1,
              argument2);

and

object.method(
  argument1,
  argument2
});

But there's one specific combination, very common in javascript, where I want the following:

object.method({
  field1: value1,
  ...
});

while I get the following with the above config:

object.method({
              field1: value1,
              ...
});

This is, I want to chain after ( only if there are arguments, but making the exception if the last character is {, in which case I want next line indented one tabstop with respecto to the enclosing context. Is that possible? I've tried myself a lot, but I can't find a way.

bounceme commented 6 years ago

aight, will implement. thanks for describing

bounceme commented 6 years ago

~couldnt you just set cino+=w1 ?~

bounceme commented 6 years ago

1112

bounceme commented 6 years ago

let g:javascript_indent_W_pat = '[^[:blank:]{[]'

elmart commented 6 years ago

Tried and the case ending in {works ok. But now I get this when only parens are used:

someFunction(
  arg1,
  ...
  )

instead of

someFunction(
  arg1,
  ...
)

This is, the closing parens alingment is not as before.

BTW, what is the empty character class [] for, in let g:javascript_indent_W_pat = '[^[:blank:]{[]'? It shouldn't match anything, should it?

bounceme commented 6 years ago

maybe i messed up https://github.com/pangloss/vim-javascript/pull/1112/files#diff-564c1f6e79518959361f7ad8a86f5792R90 somehow. otherwise it def shouldnt be affecting lines starting with ) . [^[:blank:]{[] is one character class like [^[{[:blank:]] and includes the [ character ( if you want that exception too )

elmart commented 6 years ago

[^[:blank:]{[] is one character class like [^[{[:blank:]] and includes the [ character ( if you want that exception too )

Ah, you're right. I didn't see the first bracket was still unclosed when reaching the third [.

elmart commented 6 years ago

I saw you had commited to master, so I started using it again. But I'm sorry to say it seems we didn't test this enough, as I'm having all kinds of weird behaviour now. First time after installing, it seems to work ok. But once you quit vim and open it again, many strange things happen. Will produce a better error report once I come back from holidays.

bounceme commented 6 years ago

no problem, will fix any issues

elmart commented 6 years ago

After your last changes in #1118, everything seems fine. Closing by now. Will reopen if something wrong detected later.

elmart commented 6 years ago

Hi again. Just a question: What would the definition for javascript_indent_W_pat be? I mean, now I wanted to also apply cino W when last character in line is >, so that snippets like

array.map(item =>
  item.field
)

also get the right indent. As javascript_indent_W_pat='[^[:blank:]{[]' was working ok for me, I thought that could be done just adding '>' in the pattern, this is, javascript_indent_W_pat='[^[:blank:]{[>]', but that doesn't seem to work. So I guess I'm misinterpreting what javascript_indent_W_pat is for. Could you explain, please?

bounceme commented 6 years ago

it is for the first character, (or regex), after {

adding > is like {>

elmart commented 6 years ago

I think you mean (, not {. Right?

bounceme commented 6 years ago

oh, yes