Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vim-coffescript autocommand #42

Closed
jandob opened this issue Jan 7, 2014 · 15 comments
Closed

vim-coffescript autocommand #42

jandob opened this issue Jan 7, 2014 · 15 comments

Comments

@jandob
Copy link

jandob commented Jan 7, 2014

I'm using

https://github.com/kchmck/vim-coffee-script.git

and want to apply vim-jsbeautify to the scratch compile buffer
from my vimrc:

augroup CoffeeBufNew
         au!
         autocmd User CoffeeCompile,CoffeeWatch call JsBeautify()
augroup END

When i type ":CoffeeCompile" i get the following error:

Error detected while processing function JsBeautify..Beautifier:
line   54:
E684: list index out of range: 0
E116: Invalid arguments for function setline
Error detected while processing function JsBeautify..Beautifier..<SNR>92_setNumberOfNonSpaceCharactersBeforeCursor:
line    2:
E121: Undefined variable: line
E116: Invalid arguments for function setpos

It seems like the plugin tries to save the cursor position but there is none.

Any help appreciated!

@maksimr
Copy link
Owner

maksimr commented Jan 7, 2014

Can you post settings for vim-coffee-script and example of file in which you run CoffeeCompile.
Thanks!

@jandob
Copy link
Author

jandob commented Jan 7, 2014

minimal example:
vimrc:

NeoBundle 'einars/js-beautify'
NeoBundle 'maksimr/vim-jsbeautify'
    let g:jsbeautify_file = fnameescape(fnamemodify(expand("<sfile>"), ":h")."/bundle/js-beautify/beautify.js")
NeoBundle 'kchmck/vim-coffee-script'
      augroup CoffeeBufNew
         au!
         autocmd User CoffeeCompile,CoffeeWatch call JsBeautify()
      augroup END

test.coffee:

n = 42

running CoffeeCompile results in the mentioned errror.
Can you reproduce this?

@maksimr
Copy link
Owner

maksimr commented Jan 7, 2014

Thanks! Yes

@maksimr maksimr closed this as completed in 005110a Jan 7, 2014
@maksimr
Copy link
Owner

maksimr commented Jan 7, 2014

Fix error. But it because compiled file don't has content when calling JsBeautify

@jandob
Copy link
Author

jandob commented Jan 8, 2014

Thanks, it works now!
for anyone trying to do the same - i had to tweak the autocommmand a little bit

augroup CoffeeBufUpdate
         au!
         "beautify output
         autocmd User CoffeeCompile,CoffeeWatch set modifiable | call JsBeautify() | set nomodifiable
         "stay inside source buffer
         autocmd User CoffeeCompile,CoffeeRun exec bufwinnr(b:coffee_src_buf) 'wincmd w'
augroup END

@maksimr
Copy link
Owner

maksimr commented Jan 8, 2014

👍

@tispratik
Copy link

Am getting the same error when am trying to beautify a javascript file using :call JsBeautify(). I do not use augroup in my vimrc. Has anyone been able to fix the issue?

@maksimr
Copy link
Owner

maksimr commented Feb 20, 2014

@tispratik can you describe test case?

It reproduce if run vim only with vim-jsbeautify?

@maksimr maksimr reopened this Feb 20, 2014
@tispratik
Copy link

Reproduction steps:

  1. Open a new buffer
  2. Paste some json string
  3. Set file type as javascript :set ft=javascript
  4. Beautify. :call JsBeautify()

Interestingly, it does not happen if i skip step number 3

screen shot 2014-02-20 at 10 04 46 am

@tispratik
Copy link

Also i noticed that it only happens if i have a blank line at the top.
screen shot 2014-02-20 at 10 07 36 am

If i delete that blank line and then beautify, this error does not occur.

@maksimr
Copy link
Owner

maksimr commented Feb 20, 2014

Ok! Big Thanks!

@maksimr
Copy link
Owner

maksimr commented Feb 20, 2014

Yup!
The error is associated with the position of the cursor.

If put cursor on first blank line then we get erro

@maksimr
Copy link
Owner

maksimr commented Feb 20, 2014

Move issue to #47

@maksimr maksimr closed this as completed Feb 20, 2014
@tispratik
Copy link

Thanks for your help @maksimr. Am beginning on vim and glad to get so much responsiveness from awesome people like yourself :)

@maksimr
Copy link
Owner

maksimr commented Feb 20, 2014

@tispratik Thanks!)

No problems)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants