Code Monkey home page Code Monkey logo

vim-javascript's People

Contributors

amadeus avatar bounceme avatar crusoexia avatar davidchambers avatar dmitrivereshchagin avatar goatslacker avatar iammerrick avatar int3 avatar jeltef avatar jfelchner avatar lencioni avatar mwcz avatar noprompt avatar p-herbert avatar pierreozoux avatar qstrahl avatar rbright avatar remi avatar riobard avatar romgrk avatar rwjblue avatar ryanoasis avatar samirtalwar avatar ukstv avatar utix avatar utyf avatar vitalk avatar wavded avatar wchargin avatar yuezk avatar

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

vim-javascript's Issues

Wrong html indentation with django templates

Hi,

I'm using htmldjango filetype (I guessed it's included in vim by default now) for my django projects. As soon as I started using vim-javascript indentation html indentation is slow and completely wrong. What can I do to fix this?

No syntax highlighting for try/catch block

Hi,

I am not getting syntax highlight for try/catch blocks. I am testing with a new .js file with the following code:

try {
    dataObj = JSON.parse(data);
}
catch (e) {
    return callback(e);
}

Fold comments in with function

I'm trying to get folds to include comments with the function fold, so that:

// Quick unction description
function() {
//...
}

/**

  • Longer description here
    */
    function() { ... }

are folded into

-+- function() { .... } | Longer description here... ------

I know how to set the foldtext, but I'm having trouble overriding the fold definition to include both. I'm new to vimscript and so I'm hunting and pecking on my fork to accomplish this. I haven't had any luck so far, so I thought I'd just post the question because it might be way easier than I think.

Thanks for the module!

features documentation

very correct indentation for javascript

could you give examples of differences between this plugin and the default? also, are you planning on merging this upstream?

make concealing optional

I updated today and was rather bewildered when suddenly various statements were concealed with weird replacements.

That's a /really/ drastic step. Personally I can't imagine why anyone would ever want that but who knows maybe someone else will love it. In any case - you should really make that optional/configurable.

Commit access to all accepted contributors?

Several people have submitted good changes to this project lately. Rather than me continuing to act as gatekeeper, I'd be happy to open up commit rights to everyone who submits an accepted patch. Does anyone have any thoughts either way on the subject?

Regards,
Darrick

Highlighting for javascript templates

Hi,

I was wondering what issue cc074c3 fixes. (I'm not at all versed in vim syntax highlighting)
This commit has broken some of the syntax highlighting for my html files.

I use underscore.js templates within my html files and they are usually wrapped within a script tag.
For example,

<script id="widget_template" type="text/template">
blah blah blah
</script>

Commit cc074c3 has broken that highlighting and I was wondering if there was perhaps a way I could fix it?

Cheers,
Xianyi

Indent correctly multiple variable assigns.

Your proposed vim indent script doesn't indent correctly the following block:
var fs = require('fs'),
path = require('path');

Which it indent to:
var fs = require('fs'),
path = require('path');

Feature Request: Function Argument Syntax Highlighting

A feature I would like in this syntax plugin would be to highlight both the parenthesis on function declaration and arguments individually.

See example here:

example

I have however managed to get parenthesis isolated outside of function declaration.

My edits to the syntax file are as follows: (probably a major hack, I am no expert in this)
amadeus@4c84029

Note, I would still like to keep arguments passed in on a function call separate from this.

Any help would be much appreciated.

Syntax file adjusts folding settings

The syntax file adjusts 'foldmethod' and 'foldlevel', which is way out line with what a syntax file should be adjusting.

I realize the repo is merely vendoring a syntax file from a different maintainer, but I am reporting it here anyways because it's unfortunate I can't use such an awesome indenting algorithm without being subjected to such a huge regression.

How to replace the default parenthesis-aligned indent with a regular one?

Is there a way to replace the default parenthesis-aligned line continuation indenting with a regular 1-indent per continuation?

While the parenthesis-alignment may look nice occasionally, it makes the code very irregular, sharp, wastes a lot of space with longer function names, doesn't work with tabs and kills bunnies.

That is, instead of:

function(1,
         2)

get

function(1,
  2)

JSDoc indentation is broken?

Type /, *, <CR>, <CR>, <CR>, /, and result is:

/*
 *
 */

It seems good, but type /, *, *, <CR>, <CR>, <CR>, /, and result is

/**
*
    */

It seems wrong.

Is the problem happen on only my vim?

Changing an indent size

Many jQuery plugins use 8 spaces instead of 2.
Is there any way to change an indent size using this plugin?
Its seems like a:

autocmd Filetype javascript setlocal ts=8 sts=8 sw=8

is being ignored since i use your plugin.

thanks

multiline var statements not indented

I'm trying to follow the rules that JSLint has, and something like

var a=b,
    c,
    d;

gets indented as

var a=b,
c,
d;

which JSLint doesn't like.

I may also be doing something wrong of course.

Commit 4dee33f79486b8 breaks indentation

The indentation is broken for any code proceeding a mutline var.

Here is an auto indented example:

function foo(d){
  return d;
}

var x = 1,
    b = 2;

function foo(d){
return d;
}
  {
  a: true,
      b: false,
  }

multiline function calls confuse the indenter

sometimes I have several longish arguments/expressions to a function call so I want to break the function call into something like (manually formatted):

fun( longish_argument,
     some_expression() * 2.0 + x - 130.0,
     nested_function_call( indent_me,
                           thanks ),
     still_more_arguments);

the following is formatted with 'gg=G' with vim-javascript indenter:

/*
* the arguments below are short to make a more readable test case, but the
* point of this formatting is to be able to break function calls with long
* arguments...
*/

fun(1,
    2,
    3);
    // doesn't return
    fun(1,
        2,
        3
       );
       // doesn't either
       fun(
         1,
         2,
         3);
         // again
         fun(
           1,
           2,
           3
         ); 
         // this is the only one working, but even it breaks in some contexts

         switch(foo) {
           case 1:
             here(
               1,
           2, // why????
           );
           here(
             1,
             2,
             3
           ); // seems recovered, but it's misindented
           break;
           case 2:
             here(
               1,
           2
           ); // so it breaks after each case
           break;
         }

I'd be happy to help changing the indenter, but I'm lost in the script, could you explain the logic behind it?

indentation bug: array of objects inside object

First, I want to say great job on this indent script, as it works great nearly all the time. I did encounter a bug with this particular data structure:

var data = {
  arrayOfObjects: [
    {
    key: "value"
  }
  ]
}

Notice that the key: "value" line and following brace are off by one indentation level.

No syntax highlighting for curly and square braces?

Is it just me, or does the syntax highlighting included here not highlight curly and square braces?

The stock JS syntax file in Vim highlights the curly and square braces (but not normal parenthesis) fine - I figured this one would too!

Tested with both gVim and console vim with solarized and ir_black color schemes.

Commit 2e97915441ca breaks indentation

I spent some time tracking down the specific change tonight that is impacting my indentation, and it looks like it was part of commit 2e97915 - specifically the change to s:syng_multiline.

Here is an example of JS that demonstrates the broken indentation:

function test() {
    // A comment
    "some code";
}

If you put your cursor on the "some code"; line and hit O to start a new line above the code, and below the comment, you get an indent of 3 spaces, rather than the tab I would expect. This behavior is consistent when expandtab is on or off, and my shiftwidth, tabstop, and softtabstop are all at 4. If I go to add code after the "some code"; line, everything is fine and the indent is okay.

Additionally, my default formatoptions look to be croql when I'm in a JS file, but even if I clear those out entirely so that there are no format options, I still see this behavior (and the removal of r means you can reproduce it by being on the comment line and hitting o to create a new line).

I would submit a pull request to fix this, but honestly I don't know enough about vimscript at this point to understand why it was changed to just comment\c instead of the full JS comment pieces that are defined. I do see the notes on commit 2f39355 which explain that it's using more generic and shorter patterns, but at least for the comments, it seems to be introducing a problem, and I would politely request that the change for comments be reverted, unless someone better (such as @drslump who authored the original change) has any insights as to why the above example is breaking.

I've been hunting down what happened for a couple of weeks now and just learned about git bisect, and so I was able to bisect it down to this commit, and then given that the commit was small, I tested undoing it line by line. It really is just this one line. Not sure why that would fail here.

Thank you kindly for your consideration! I hope this bug report is sufficient. :)

Improve indentation of multi line statements

Indenting this works as expected

app = connect().
  use(connect.favicon()).
  use(connect.logger()).
  use(connect.static(app.root + '/public')).
  listen(app.port);

this doesn't.

app = connect()
  .use(connect.favicon())
  .use(connect.logger())
  .use(connect.static(app.root + '/public'))
  .listen(app.port);

Can someone point me in the right direction so I can fix it?

multiline function calls confuse the indenter (re-open Issue #4)

I ran into the same problem submitted by @artm in Issue #4, which was accidentally closed. I don't have permission to re-open the issue, so I've copy-n-pasted it below. Thanks!

sometimes I have several longish arguments/expressions to a function call so I want to break the function call into something like (manually formatted):

fun( longish_argument,
     some_expression() * 2.0 + x - 130.0,
     nested_function_call( indent_me,
                           thanks ),
     still_more_arguments);

the following is formatted with 'gg=G' with vim-javascript indenter:

/*
* the arguments below are short to make a more readable test case, but the
* point of this formatting is to be able to break function calls with long
* arguments...
*/

fun(1,
    2,
    3);
    // doesn't return
    fun(1,
        2,
        3
       );
       // doesn't either
       fun(
         1,
         2,
         3);
         // again
         fun(
           1,
           2,
           3
         ); 
         // this is the only one working, but even it breaks in some contexts

         switch(foo) {
           case 1:
             here(
               1,
           2, // why????
           );
           here(
             1,
             2,
             3
           ); // seems recovered, but it's misindented
           break;
           case 2:
             here(
               1,
           2
           ); // so it breaks after each case
           break;
         }

I'd be happy to help changing the indenter, but I'm lost in the script, could you explain the logic behind it?

Regular Expression Syntax Issue

The following snippet causes syntax highlighting to be broken:

function foo(){
  return /['"]/;
}
var s = 'asdf';

The quotes in the regular expression seem to be interpreted as the beginning of a string literal.

couple indentation issues (switch statements and multiline strings)

I noticed a couple indentation issues.

switch(test){
    case 1:
        alert('hi');
    break;
    case 2:
        case 3:
            default:
}

In this example break isn't aligned with case, it seems only the first line gets indented properly. Also case 3 and default get indented in when they should be all the same indent level.

var test = '\
hello world \
and goodbye \
\';

In this example, nothing gets indented. It would either be nice to indent one level or indent up to the quote (').

I don't know if I'm up to vim par to tackle these but definitely welcome them and am willing to test.

an improvement to the formatting code

Hey, i've made some changes to the following line, haven't installed git yet, so i just made the change and hope that you will merge it in.

The case is as follows:
var y = a / b / c; // will identify / b / as regular expression, which is just wrong
I've modified it so that only this will be identified:
var y = / a /;

The relevant line change and comment is as follows:
"regexp, basically only regexp after '= *' will be matched, to prevent
"matching complex math expressions with multiple ''s. 'hs=e' will not
"highlight the '=', 'hs=e+1' will not highlight '= ', etc.

syntax region javaScriptRegexpString start=+= */\(\*\|/\)\@!+hs=e skip=+\\\\\|\\/+ end=+/[gim]\{,3}+ contains=javaScriptSpecial,@htmlPreproc oneline

Don't override foldmethod

Hello,

I really like this plugin, but I have thing that annoys me about it, which is that it ALWAYS sets a foldmethod. Wouldn't it be better to check if a foldmethod is already set, and if so not do anything?

Just my $0,02.

Thanks,
Chiel

Very slow

Adding vim-javascript had a major performance impact on vim. Turning it off and removing it made the slowness in using vim go away. I can't be sure but I think it may even have led to vim crashing. The default vim support for JavaScript is not very good, but this is very slow at parsing large JavaScript files. I'm using an ivy-bridge Macbook Retina with SSD.

> 80-columns line - syntax alignment problem.

With that snippet, no problem:

function foo(one, two, three, four, five, six, seven, eight, night, ten) {
  var syntax = "bug";
}

With the following one -> bug bug. The line is long, so I put a after the "ten" parameter (80-columns rule). The variable syntax is not correctly indented :(

function foo(one, two, three, four, five, six, seven, eight, night, ten,
             eleven, twelve) {
               var syntax = "bug";
}

Lost indent on second multiline /* comment block within 1+ indent scopes

When opening a multiline /* comment block within an indented scope, the next line doesn't maintain the same indent level.

In insert mode (cursor denoted as _):

function() {
    function() {
        /*_
    }
}

Pressing <Enter> now yields:

function() {
    function() {
        /*
 * _
    }
}

Instead, it should be:

function() {
    function() {
        /*
         * _
    }
}

Settings:

" vim:set sw=4 sts=4 ts=4 et:

Hash closed on same line it's opened shouldn't de-indent

I'm working through some backbone.js examples, and there's a chunk like:

var Target = Backbone.Model.extend({
  promptColor: function() {
    var cssColor = prompt("Please enter a CSS color:");
    this.set({color: cssColor}); #problem line
  }
});

But the line marked "problem line" de-indents when I type the closing curly to close off that hash, so it ends up as:

var Target = Backbone.Model.extend({
  promptColor: function() {
    var cssColor = prompt("Please enter a CSS color:");
  this.set({color: cssColor}); #hey what am I doing back here?
  }
});

I could break the hash up over several lines, and it does what you'd expect:

var Target = Backbone.Model.extend({
  promptColor: function() {
    var cssColor = prompt("Please enter a CSS color:");
    this.set({
      color: cssColor
    });
  }
});

But now I've got three lines of code instead of one.

Increment and decrement ("++","--") treated as binary operators

Judging from the indent behaviour it seems the increment and decrement operators are treated like binary operators (or a binary operator followed by a unary operator).

For example,

a++
b

becomes

a++
    b

I spent two minutes looking at the code and I believe s:continuation_regex and possibly also s:msl_regex should be altered so they do not match "++" and "--". I do not have a solution.

setlocal iskeyword+=$ applied to php filetypes

My knowledge of plugin development is limited but I've tried to work a solution out before posting this issue:

After digging around, I've discovered that Vim, by default, sources syntax/html.vim which, by default, sources syntax/javascript.vim when you edit a PHP document. This isn't actually a problem except for line 28 of syntax/javascript.vim: setlocal iskeyword+=$

This messes with my workflow when I'm coding as my muscle memory sees $ differently depending on whether I'm working on Javascript or PHP. I tried to figure out a way of fixing the issue and I think I got it to work. I removed setlocal iskeyword+=$ from syntax/javascript.vim and moved it to a new file ftplugin/javascript.vim based on a recommendation from freenode#vim.

This worked for me when I tested a JS file and a PHP file but when editing JS in an HTML file, it doesn't. While I don't tend to work with JS that is inline in HTML, I can understand that others may possibly want to. To work around this, I duplicated ftplugin/javascript.vim to ftplugin/html.vim and the functionality was restored when editing JS within HTML.

I do have a local clone with my changes applied that I can push to Github for you to check out and test; I don't know if it's too trivial for you to verify based upon my explanation above. When I get some spare time at the office, I can push it up and either leave a link here or just do a pull request.

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.