Git Product home page Git Product logo

vim-jsbeautify's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-jsbeautify's Issues

Error with pathogen#helptags

In my .vimrc I have this line:

call pathogen#helptags()

And when I load vim I am getting this error on startup:

Error detected while processing function pathogen#helptags:
line    4:
E151: No match: /home/kpauli/.vim/bundle/vim-jsbeautify/doc/*
Press ENTER or type command to continue

The doc folder does have contents, though:

kpauli@ubuntu-vm:~$ ls /home/kpauli/.vim/bundle/vim-jsbeautify/doc
en  ru

I am new to vim. let me know if there is more information you need.

cannot format the other file

when I open some file with Vim at the first time, then format it, it works all right

$ vim index.html

call HtmlBeautify()

But when I open other file like this:

:o main.js

call JsBeautify()

nothing happened, this file cannot format at all.

then I close vim and open the js file with vim, it works all right.

then I open the html file, nothing happened.

It seems that this plugin cannot format the other file in vim, any solution?

How to configure to use tabs?

Good Afternoon!

I am new vim plugins and was excited to discover a JS beautify plugin. I have set it up but cannot configure it to use tabs.

I have installed the plugin, and can launch it as follows:

image

This works.

It is presently formatting the javascript using spaces. I would like to format using tabs. I tried creating an .editorconfig file inside my home directory but it isn't being picked up. The editor config file looks like this:

[**.js]
indent_style = tab

[**.css]
indent_style = tab

[**.html]
indent_style = tab
max_char = 78
brace_style = expand

Any hints on how to debug this? Would really like to get this working with tabs.

Thanks,
Jake


Env Info:

Windows Running Git Bash
Vim 7.4
Installed vim-jsbeautify using pathogen

Having trouble installing.

I've followed the installation instructions exactly (using Pathogen) about 5 times now, and simply can't get the plugin to work. When I run ":call JsBeautify()", it does nothing (also returns no error).

Could you give me some tips for debugging what might be wrong?

Wrong path to beautify.js

I tried installing via Vundle:

Here is what is in my .vimrc:

Bundle 'maksimr/vim-jsbeautify'
Bundle 'einars/js-beautify'

" set path to js-beautify file

let s:rootDir = fnamemodify(expand("<sfile>"), ":h")
let g:jsbeautify_file = fnameescape(s:rootDir."/bundle/js-beautify/beautify.js")
let g:htmlbeautify_file = fnameescape(s:rootDir."/bundle/js-beautify/beautify-html.js")
let g:cssbeautify_file = fnameescape(s:rootDir."/bundle/js-beautify/beautify-css.js")

When I :call JsBeautify(), I get the wrong path to beautify.js:
Error: ENOENT, no such file or directory '/home/shaun/bundle/js-beautify/beautify.js'

My guess is that s:rootDir isn't expanding to the right place?

Setting it manually to let s:rootDir = "/home/shaun/.vim" works.

Read local .editorconfig files starting from current working directory and move up to Root

Let's say current working directory is /var/lib/project

it should read the following .editorconfig files in order:

  1. /var/lib/project/.editorconfig
  2. /var/lib/.editorconfig
  3. /var/.editorconfig
  4. /.editorconfig
  5. ~/.editorconfig
  6. $VIM/.editorconfig

giving the highest priority to the current working directory's editor config file.
Thus, whatever is written in /var/lib/project/.editorconfig should override any other editorconfig files for the duplicate options.

This will help localizing different editor config settings for each project.

Cannot find module beautify.js

When i run the command ':call JsBeautify' in vim, i got the following error message:
module.js:340
throw err;
^
Error: Cannot find module '/Users/ares/vim-ide/.vim/bundle/vim-jsbeautify/plugin/lib/js/lib/beautify.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at load (/Users/ares/vim-ide/.vim/bundle/vim-jsbeautify/plugin/beautify.min.js:1:1164)
at /Users/ares/vim-ide/.vim/bundle/vim-jsbeautify/plugin/beautify.min.js:1:1509
at Object. (/Users/ares/vim-ide/.vim/bundle/vim-jsbeautify/plugin/beautify.min.js:1:1756)
at Object. (/Users/ares/vim-ide/.vim/bundle/vim-jsbeautify/plugin/beautify.min.js:1:1785)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)

I don't have the 'lib/js/lib/beautify.js' on my file system. When i clone your git repo, the lib folder is not included.

Add available options to editconfig

It would be great if we had the options we can set documented. I want to be able to set the "Break lines on chained methods" configuration.

REQ: non plugin-manager instructions

not sure if i'm alone, but i don't use plugin managers and simply drop the .vim file in ~/.vim/plugin/

but this one merrits some install instructions as you have extra files that are non-obvious, such the js file and the options one.

Support for Json files as well

They can go through the same beautification as .js files, but need to be read from either [*] or [*.json] section in the editorconfig

Initial Run Error

I installed your plugin using pathogen and used the suggested .vimrc settings listed below.

let g:jsbeautify = {'indent_size': 3, 'indent_char': '\t'}
let g:htmlbeautify = {'indent_size': 3, 'indent_char': ' ', 'max_char': 78, 'brace_style': 'expand', 'unformatted': ['a', 'sub', 'sup', 'b', 'i', 'u']}
let g:cssbeautify = {'indent_size': 3, 'indent_char': ' '}
"map <c-f> :call JsBeautify()<cr>
autocmd FileType javascript noremap <buffer>  <c-f> :call JsBeautify()<cr>
autocmd FileType html noremap <buffer> <c-f> :call HtmlBeautify()<cr>
autocmd FileType css noremap <buffer> <c-f> :call CSSBeautify()<cr>

I have Node.js installed under the alias node. When I hit <c-f> I get the below error message printed in the buffer:

node.js:134
      throw e; // process.nextTick error, or 'error' event on first tick

 TypeError: undefined is not a function
     at CALL_NON_FUNCTION (native)   
     at ~/.vim/bundle/vim-jsbeautify/plugin/beautify-min.js:1:854
     at Object.<anonymous> (~/.vim/bundle/vim-jsbeautify/plugin/beautify-min.js:1:960)
     at Object.<anonymous> (~/.vim/bundle/vim-jsbeautify/plugin/beautify-min.js:1:971)
     at Module._compile (module.js:402:26)
     at Object..js (module.js:408:10)
     at Module.load (module.js:334:31)
     at Function._load (module.js:293:12)
     at Array.<anonymous> (module.js:421:10)
     at EventEmitter._tickCallback (node.js:126:26)

If I manually type :call JsBeautify() I get the same result as above; but typing :call JsBeautify(0,$) returns no error, but also doesn't load any formatting.

What did I do wrong? Is this error due to my method of installation?

E117: Unknown function: JsBeautify

This is probably a newbie question, but when I follow the installation instructions and try to run beautiful I get the message

E117: Unknown function: JsBeautify

This is my .vimrc

  1 set number
  2 set expandtab
  3 set tabstop=4
  4 set shiftwidth=4
  5 syntax on
  6 
  7 ".vimrc
  8 
  9 " map <c-f> :call JsBeautify()<cr>
 10 " or
 11 autocmd FileType javascript noremap <buffer>  <c-f> :call JsBeautify()<cr>
 12 " for html
 13 autocmd FileType html noremap <buffer> <c-f> :call HtmlBeautify()<cr>
 14 " for css or scss
 15 autocmd FileType css noremap <buffer> <c-f> :call CSSBeautify()<cr>

and the bundle is here:
/Users/<me>/.vim/bundle/vim-jsbeautify

Any help would be appreciated...

Windows NodeJS + Cygwin Vim

Not sure how many people fall into this bucket, but I had some trouble getting this to work in Cygwin because the Windows node.exe doesn't like the paths. I stuck some lines in

~/.vim/bundle/vim-jsbeautify/plugin/beautifier.vim (starting after line 403)

let beautify_absolute_path_windows = fnameescape(system("cygpath -w ".s:plugin_Root_directory."/beautify.min.js"))
let tmp_file_Beautifier_arg_windows = fnameescape(system("cygpath -w ".tmp_file_Beautifier_arg))
let path_Beautifier_arg_windows = fnameescape(system("cygpath -w ".path_Beautifier_arg))

let result = system(engine." ".beautify_absolute_path_windows." --js_arguments ".tmp_file_Beautifier_arg_windows." ".opts_Beautifier_arg." ".path_Beautifier_arg_windows)

That worked for me. Not sure how to test within the script if this is the scenario, but just in case there's some other Cygwin Vim user with the Windows NodeJS, there you go.

vim-coffescript autocommand

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!

array elements on new line each

Nice, that you added options in the new version! But is there an option for js to put the content of arrays into a new line?
So instead of:

['a', 'b', 'c', 'd']

New line each:

[
    'a',
    'b',
    'c',
    'd'
]

Thanks!

default nodejs problem

I use nodejs for jsbeautify, but in some Linux os, such as my ubuntu 14.04, node is another software instead of nodejs, I can link nodejs as node, but add nodejs for default maybe a better solution. like:

  let engine = get(opts, 'bin', 'node')
  " Some Linux has node(not nodejs)
  " so apt-get install will get nodejs
  if !executable(engine)
      let engine = get(opts, 'bin', 'nodejs')
  endif

error on run: ReferenceError: arguments is not defined

I had try to run vim-jsbeautify with v8 (d8)

and got error

/home/bor/.vim/bundle/vim-jsbeautify/plugin/beautify.min.js:1: ReferenceError: arguments is not defined
ath)}).apply(this,typeof process=="object"&&process.argv.splice(3)||arguments)
                                                                    ^
ReferenceError: arguments is not defined
    at /home/bor/.vim/bundle/vim-jsbeautify/plugin/beautify.min.js:1:1311

setup

".editorconfig

root = true

[**.js]
bin=d8
indent_style = space
indent_size = 4
$ d8 
V8 version 3.14.5.3 [console: dumb]

Please help me to solve this issue.

HtmlBeautify() adding extra newline

When formatting html files it keeps adding extra newlines at the end of the file.

Calling a format on this input:

  1 <html>
  2
  3 </html>

Produces:

  1 <html>
  2
  3 </html>
  4

More calls to the format function will keep increasing the number of extra lines.
I've tried to update to the latest version (my previous version was cloned in the beginning of December). Both these versions has this issue.

Tab Indentation

There does not appear to be a way to set the indentation style to tabs using .editorconfig.

sample .vimrc configuration

It would probably be a good idea to change the jsbeautify configuration to not default to 4 \t indents, so changing it to something like this:

 let g:jsbeautify = {'indent_size': 1, 'indent_char': '\t'}

Multiplies indentation tabs

Hi,

I would like to have tabstop=softtabstop=shiftwidth=4 and run this plugin to format my JavaScript file. The .editorconfig settings to achieve that should be:

[**.js]
indent_style = tab
tab_width=4
indent_size = tab

However in this case the plugin uses 4 tabs for every level of indentation. I expect it to use only 1.
With this .editorconfig:

[**.js]
indent_style = tab
tab_width=4
indent_size = 1

It works properly, uses only 1 tab for indentation and sets tabstop=4, however in this case shiftwidth and softtabstop are both set to 1.

My understanding is that the ts, st, sw values are managed by the editorconfig plugin and this plugin does the formatting. That means that the first setting should work and the plugin shouldn't multiply the tabs.

indent_size not respected

Seems that the indent_size value in .editorconfig is not respected when running JSBeautify. It always defaults to 4. Node 1.10.14 and jsbeautify 1.4.0

Error with detection position of cursor

Get error if we have file with first blank line
, set position cursor on first line and call JsBeautify()

Error detected while processing function JsBeautify..Beautifier..<SNR>63_setNumberOfNonSpaceCharactersBeforeCursor:

Related:
#42

Install instruction on windows 7?

Do I need to install any node module in order to use this plugin?

I got the follow error when i format the code:
module.js:340
throw err;
^
Error: Cannot find module 'C:\Users\Gilbert'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)

My "home" should be 'C:\Users\Gilbert Wong' instead.
And I've tried to symlink to just 'Gilbert' but didn't work.

BTW, in the source it seems "vimfiles/" is not one of the places the ".editorconfig" will be looked for. Any plan to support this?

Please help. Thanks.

Edit file only if necessary

I've added the following line to my .vimrc which runs JsBeautify every time I save a file:

au BufWritePre *.{js} :call JsBeautify()

Most of the time JsBeautify doesn't have any effect but replaces the whole content of the file leaving an extra step in the undo history. It should only edit the content of a file if there is a change.

intent_size of 2 not respected

Hi,

I have the following editorconfig:

root = true                                                                                                                                                                                                                                                                                                                   

[**.js]                                                                                                                                                                                                                                                                                                                       
;vim:path=~/.vim/bundle/js-beautify/beautify.js                                                                                                                                                                                                                                                                               
indent_size = 2                                                                                                                                                                                                                                                                                                               
jslint_happy = 1                                                                                                                                                                                                                                                                                                              
keep_array_indentation = 1                                                                                                                                                                                                                                                                                                    
space_before_conditional = 1                                                                                                                                                                                                                                                                                                  
break_chained_methods = 1                                                                                                                                                                                                                                                                                                     
indent_style = space                                                                                                                                                                                                                                                                                                          

[**.css]                                                                                                                                                                                                                                                                                                                      
;vim:path=~/.vim/bundle/js-beautify/beautify-css.js                                                                                                                                                                                                                                                                           
indent_style = space                                                                                                                                                                                                                                                                                                          
indent_size = 2                                                                                                                                                                                                                                                                                                               

[**.html]                                                                                                                                                                                                                                                                                                                     
;vim:path=~/.vim/bundle/js-beautify/beautify-html.js                                                                                                                                                                                                                                                                          
unformatted = ['a', 'sub', 'sup', 'b', 'i', 'u']                                                                                                                                                                                                                                                                              
indent_style = space                                                                                                                                                                                                                                                                                                          
indent_size = 2                                                                                                                                                                                                                                                                                                               
max_char = 80                                                                                                                                                                                                                                                                                                                 
brace_style = expand 

And the ident_size of 2 is not respected (always set to 4) with the latest version. Any idea why? I have installed /js-beautify as a separated bundle.

can't beautify anymore :/

/Users/jojoyuji/dotfiles/vim/bundle/vim-jsbeautify/plugin/beautify-min.js:1
tf-8")}}();(function(a,c,d){var e={indent_size:4,indent_char:" "},a=f(a),c=c&&
^
TypeError: undefined is not a function
at /Users/jojoyuji/dotfiles/vim/bundle/vim-jsbeautify/plugin/beautify-min.js:1:810
at Object. (/Users/jojoyuji/dotfiles/vim/bundle/vim-jsbeautify/plugin/beautify-min.js:1:865)
at Object. (/Users/jojoyuji/dotfiles/vim/bundle/vim-jsbeautify/plugin/beautify-min.js:1:875)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3

It was working so far... What's going on?

JsBeautify() is ignoring .editorconfig

I have tried my .editorconfig in both my ~/ dir and ~/.vim/ but it still is ignored. When I invoke :call JsBeautify() it uses 4 spaces instead of 2.

Here is my .editorconfig

root = true

[**.js]
indent_style = space
indent_size = 2

[**.css]
indent_style = space
indent_size = 2

[**.html]
indent_style = space
indent_size = 2
max_char = 78
brace_style = expand

Bug with 'indention' in js-beautify 1.3.2

Bug with indention in new version js-beautify

Expected:

    (["foo", "bar"] ).each(function(i) {
        return i;
    });

Output:

    (["foo", "bar"]).each(function(i) {
            return i;
        });

JS and CSS Beautify destructively add new lines when in <script> and <style> tags.

Say I have this CSS:

<style type="text/css" media="screen">
    p {        margin:10px 0;    }    .hide {        display:none;    }
</style>
line 1
line 2
line 3
line 4
line 5

If I visually select inside the tag and do :call CSSBeautify("'<","'>") it out puts this:

<style type="text/css" media="screen">
    p {
        margin:10px 0;
    }
    .polarity {
        display:none;
    }
line 5

If I visually select the whole tag, this is the output:

<style type="text/css" media="screen"> p {
    margin:10px 0;
}
.polarity {
    display:none;
}
</style>
line 5

It shouldn't destroy lines 1-4. It also does this with <script> tags. I will be looking into this issue myself when I have the time. Will send PR if I find anything.

Formatting error

After the range beautifier commit 89b2ca3, formatting this code produces an error:

1 function() {
2 }
Error detected while processing function JsBeautify..Beautifier:
line   60:
E16: Invalid range: 2,$g/.*/d

Detected an unknown function

When i open gvim, an unknown function detected on the startup

Error detected while processing ~/.vim/bundle/vim-jsbeautify/plugin/beautifier.vim:
line  326:
E117: Unknown function: editorconfig#AddNewHook    

Did I missing something?

*I installed your plugin using vundle

HTML prettify failed

the prettified result is not so satisfying, in which the most annoying is there are spaces between html tags, like this:

< html >

wonder how to configure this or is this a bug?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.