diff --git a/Preferences/Indent.tmPreferences b/Preferences/Indent.tmPreferences index b0245b7..657b1d6 100644 --- a/Preferences/Indent.tmPreferences +++ b/Preferences/Indent.tmPreferences @@ -9,28 +9,28 @@ settings decreaseIndentPattern - (?x)^ \s* (?!//|/\*) - # (nothing |( string | no parens/string )++ | (no parens? (nested parens ) no parens?)+ ) Close - ( (?: |( (?<str> (?<!\\)'(\\'|[^'])*+' | (?<!\\)"(\\"|[^"])*+" | (?<!\\)/(\\/|[^/])*+/) | (?<noS>[^\[\]'"/]++) )++ | (\g<noS>? (?<squar> \[ (?: \g<str> | \g<noS> | \g<squar> )* \] ) \g<noS>? )++ ) \] - | (?: |( \g<str> | (?<noR>[^\(\)'"/]++) )++ | (\g<noR>? (?<round> \( (?: \g<str> | \g<noR> | \g<round> )* \) ) \g<noR>? )++ ) \) - | (?: |( \g<str> | (?<noC>[^\{\}'"/]++) )++ | (\g<noC>? (?<curly> \{ (?: \g<str> | \g<noC> | \g<curly> )* \} ) \g<noC>? )++ ) \} - | \b(?:case|default)\b + (?x)^ + # ( Blank |Comments | (No Paren | String) | String | (Nested Parens ) )*+ Close Yes *+ + (?> (?<yesS> (?!.) |//.*+|/\*((?!\*/).)++(\*/|$)|(^)((?!/\*).)*(\*/)| (?<noS>[^\[\]'"/]) | (?<str> '(\\'|[^'])*+' | "(\\"|[^"])*+" | /(\\/|[^/])*+/) | (?<squar> \[ \g<yesS>*+ \] ) )*+ \] \g<yesS>*+ + | (?<yesR> (?!.) |//.*+|/\*((?!\*/).)++(\*/|$)|(^)((?!/\*).)*(\*/)| (?<noR>[^\(\)'"/]) | \g<str> | (?<round> \( \g<yesR>*+ \) ) )*+ \) \g<yesR>*+ + | (?<yesC> (?!.) |//.*+|/\*((?!\*/).)++(\*/|$)|(^)((?!/\*).)*(\*/)| (?<noC>[^\{\}'"/]) | \g<str> | (?<curly> \{ \g<yesC>*+ \} ) )*+ \} \g<yesC>*+ + | \s* (?!//|/\*) \b(?:case|default)\b (\g<str> | \g<noC> | \g<noC>? \g<curly> \b<noC>?)++ (?!\}) $ ) increaseIndentPattern - (?x)^ \s* (?!//|/\*)([^\s].*)? - # Open (nothing |( string | no parens/string )++ | (no parens? (nested parens ) no parens?)+ ) - ( \[ (?: |( (?<str> (?<!\\)'(\\'|[^'])*+' | (?<!\\)"(\\"|[^"])*+" | (?<!\\)/(\\/|[^/])*+/) | (?<noS>[^\[\]'"/]++) )++ | (\g<noS>? (?<squar> \[ (?: \g<str> | \g<noS> | \g<squar> )* \] ) \g<noS>? )++ ) - | \( (?: |( \g<str> | (?<noR>[^\(\)'"/]++) )++ | (\g<noR>? (?<round> \( (?: \g<str> | \g<noR> | \g<round> )* \) ) \g<noR>? )++ ) - | \{ (?: |( \g<str> | (?<noC>[^\{\}'"/]++) )++ | (\g<noC>? (?<curly> \{ (?: \g<str> | \g<noC> | \g<curly> )* \} ) \g<noC>? )++ ) - | \b(?:case|default)\b + (?x)^ + # Yes *+ Open ( Blank |Comments | (No Paren | String) | String | (Nested Parens ) )*+ + (?> \g<yesS>*+ \[ (?<yesS> (?!.) |//.*+|/\*((?!\*/).)++(\*/|$)|(^)((?!/\*).)*(\*/)| (?<noS>[^\[\]'"/]) | (?<str> '(\\'|[^'])*+' | "(\\"|[^"])*+" | /(\\/|[^/])*+/) | (?<squar> \[ \g<yesS>*+ \] ) )*+ + | \g<yesR>*+ \( (?<yesR> (?!.) |//.*+|/\*((?!\*/).)++(\*/|$)|(^)((?!/\*).)*(\*/)| (?<noR>[^\(\)'"/]) | \g<str> | (?<round> \( \g<yesR>*+ \) ) )*+ + | \g<yesC>*+ \{ (?<yesC> (?!.) |//.*+|/\*((?!\*/).)++(\*/|$)|(^)((?!/\*).)*(\*/)| (?<noC>[^\{\}'"/]) | \g<str> | (?<curly> \{ \g<yesC>*+ \} ) )*+ + | \s* (?!//|/\*)([^\s].*)? \b(?:case|default)\b (\g<str> | \g<noC> | \g<noC>? \g<curly> \b<noC>?)++ (?!\}) )$ indentNextLinePattern ^\s*((if|while|for|switch|else if).*[)]|else)\s*$ unIndentedLinePattern - ^\s*((/\*|\*/\s*$|\ \*).*)?$ + (?x)^ \s* /\* ((?!\*/).)++ $ | ^\s\* | ^\s* \*/\s* $ | ^ \s* $ uuid BC062860-3346-4D3B-8421-C5543F83D11F diff --git a/Syntaxes/JavaScript Basic.tmLanguage b/Syntaxes/JavaScript Basic.tmLanguage index 6ea1386..7d5e1e8 100644 --- a/Syntaxes/JavaScript Basic.tmLanguage +++ b/Syntaxes/JavaScript Basic.tmLanguage @@ -11,19 +11,19 @@ jsx foldingStartMarker - (?x)^ \s* (?!//|/\*)([^\s].*)? - # Open (nothing |( string | no parens/string )++ | (no parens? (nested parens ) no parens?)+ ) - ( \[ (?: |( (?<str> (?<!\\)'(\\'|[^'])*+' | (?<!\\)"(\\"|[^"])*+" | (?<!\\)/(\\/|[^/])*+/) | (?<noS>[^\[\]'"/]++) )++ | (\g<noS>? (?<squar> \[ (?: \g<str> | \g<noS> | \g<squar> )* \] ) \g<noS>? )++ ) - | \( (?: |( \g<str> | (?<noR>[^\(\)'"/]++) )++ | (\g<noR>? (?<round> \( (?: \g<str> | \g<noR> | \g<round> )* \) ) \g<noR>? )++ ) - | \{ (?: |( \g<str> | (?<noC>[^\{\}'"/]++) )++ | (\g<noC>? (?<curly> \{ (?: \g<str> | \g<noC> | \g<curly> )* \} ) \g<noC>? )++ ) + (?x)^ + # Yes *+ Open ( Blank |Comments | (No Paren | String) | String | (Nested Parens ) )*+ + (?> \g<yesS>*+ \[ (?<yesS> (?!.) |//.*+|/\*((?!\*/).)++(\*/|$)|(^)((?!/\*).)*(\*/)| (?<noS>[^\[\]'"/]) | (?<str> '(\\'|[^'])*+' | "(\\"|[^"])*+" | /(\\/|[^/])*+/) | (?<squar> \[ \g<yesS>*+ \] ) )*+ + | \g<yesR>*+ \( (?<yesR> (?!.) |//.*+|/\*((?!\*/).)++(\*/|$)|(^)((?!/\*).)*(\*/)| (?<noR>[^\(\)'"/]) | \g<str> | (?<round> \( \g<yesR>*+ \) ) )*+ + | \g<yesC>*+ \{ (?<yesC> (?!.) |//.*+|/\*((?!\*/).)++(\*/|$)|(^)((?!/\*).)*(\*/)| (?<noC>[^\{\}'"/]) | \g<str> | (?<curly> \{ \g<yesC>*+ \} ) )*+ )$ foldingStopMarker - (?x)^ \s* (?!//|/\*) - # (nothing |( string | no parens/string )++ | (no parens? (nested parens ) no parens?)+ ) Close - ( (?: |( (?<str> (?<!\\)'(\\'|[^'])*+' | (?<!\\)"(\\"|[^"])*+" | (?<!\\)/(\\/|[^/])*+/) | (?<noS>[^\[\]'"/]++) )++ | (\g<noS>? (?<squar> \[ (?: \g<str> | \g<noS> | \g<squar> )* \] ) \g<noS>? )++ ) \] - | (?: |( \g<str> | (?<noR>[^\(\)'"/]++) )++ | (\g<noR>? (?<round> \( (?: \g<str> | \g<noR> | \g<round> )* \) ) \g<noR>? )++ ) \) - | (?: |( \g<str> | (?<noC>[^\{\}'"/]++) )++ | (\g<noC>? (?<curly> \{ (?: \g<str> | \g<noC> | \g<curly> )* \} ) \g<noC>? )++ ) \} - ) + (?x)^ + # ( Blank |Comments | (No Paren | String) | String | (Nested Parens ) )*+ Close Yes *+ + (?> (?<yesS> (?!.) |//.*+|/\*((?!\*/).)++(\*/|$)|(^)((?!/\*).)*(\*/)| (?<noS>[^\[\]'"/]) | (?<str> '(\\'|[^'])*+' | "(\\"|[^"])*+" | /(\\/|[^/])*+/) | (?<squar> \[ \g<yesS>*+ \] ) )*+ \] \g<yesS>*+ + | (?<yesR> (?!.) |//.*+|/\*((?!\*/).)++(\*/|$)|(^)((?!/\*).)*(\*/)| (?<noR>[^\(\)'"/]) | \g<str> | (?<round> \( \g<yesR>*+ \) ) )*+ \) \g<yesR>*+ + | (?<yesC> (?!.) |//.*+|/\*((?!\*/).)++(\*/|$)|(^)((?!/\*).)*(\*/)| (?<noC>[^\{\}'"/]) | \g<str> | (?<curly> \{ \g<yesC>*+ \} ) )*+ \} \g<yesC>*+ + )$ keyEquivalent ^~J name diff --git a/Tests/Javascript Folding & Indent.js b/Tests/Javascript Folding & Indent.js index d3bbdc6..eb5e21e 100644 --- a/Tests/Javascript Folding & Indent.js +++ b/Tests/Javascript Folding & Indent.js @@ -187,58 +187,201 @@ function(){ // Comment }; // Comment -var myObj = { // Comment - label: [1,2,3], // Comment - label: [ // Comment - 1, // Comment - 2, // Comment - 3 // Comment - ], // Comment - label: myArray[ // Comment - 0 // Comment - ], // Comment - label: (statement), // Comment - label: ( // Comment - statement // Comment - ), // Comment - label: myFunction( // Comment - statement // Comment - ), // Comment - label: { // Comment - label:'value' // Comment - }, // Comment - label: function(){ // Comment - statement; // Comment - }, // Comment - label: 0 // Comment -}; // Comment +var myObj = { // Comment + label: [1,2,3], // Comment + label: [ // Comment + 1, // Comment + 2, // Comment + 3 // Comment + ], // Comment + label: myArray[ // Comment + 0 // Comment + ], // Comment + label: (statement), // Comment + label: ( // Comment + statement // Comment + ), // Comment + label: myFunction( // Comment + statement // Comment + ), // Comment + label: { // Comment + label:'value' // Comment + }, // Comment + label: function(){ // Comment + statement; // Comment + }, // Comment + label: 0 // Comment +}; // Comment + + +// ======================== +// = With inline comments = +// ======================== +[1,2,3] /* Comment +*/ +[ /* Comment +*/ + 1, /* Comment +*/ + 2, /* Comment +*/ + 3 /* Comment +*/ +] /* Comment +*/ +myArray[ /* Comment +*/ + 0 /* Comment +*/ +] /* Comment +*/ +(statement) /* Comment +*/ +( /* Comment +*/ + statement /* Comment +*/ +) /* Comment +*/ +myFunction( /* Comment +*/ + statement /* Comment +*/ +) /* Comment +*/ +{ /* Comment +*/ + label:'value' /* Comment +*/ +} /* Comment +*/ +function(){ /* Comment +*/ + statement; /* Comment +*/ +} /* Comment +*/ +[1,2,3]; /* Comment +*/ +[ /* Comment +*/ + 1, /* Comment +*/ + 2, /* Comment +*/ + 3 /* Comment +*/ +]; /* Comment +*/ +myArray[ /* Comment +*/ + 0 /* Comment +*/ +]; /* Comment +*/ +(statement) /* Comment +*/ +( /* Comment +*/ + statement /* Comment +*/ +); /* Comment +*/ +myFunction( /* Comment +*/ + statement /* Comment +*/ +); /* Comment +*/ +{ /* Comment +*/ + label:'value' /* Comment +*/ +}; /* Comment +*/ +function(){ /* Comment +*/ + statement; /* Comment +*/ +}; /* Comment +*/ +var myObj = { /* Comment +*/ + label: [1,2,3], /* Comment +*/ + label: [ /* Comment +*/ + 1, /* Comment +*/ + 2, /* Comment +*/ + 3 /* Comment +*/ + ], /* Comment +*/ + label: myArray[ /* Comment +*/ + 0 /* Comment +*/ + ], /* Comment +*/ + label: (statement), /* Comment +*/ + label: ( /* Comment +*/ + statement /* Comment +*/ + ), /* Comment +*/ + label: myFunction( /* Comment +*/ + statement /* Comment +*/ + ), /* Comment +*/ + label: { /* Comment +*/ + label:'value' /* Comment +*/ + }, /* Comment +*/ + label: function(){ /* Comment +*/ + statement; /* Comment +*/ + }, /* Comment +*/ + label: 0 /* Comment +*/ +}; /* Comment +*/ // ================= // = With Comments = // ================= -[1,2,3] /* Comment */ -[ /* Comment */ - 1, /* Comment */ - 2, /* Comment */ - 3 /* Comment */ -] /* Comment */ -myArray[ /* Comment */ - 0 /* Comment */ -] /* Comment */ -(statement) /* Comment */ -( /* Comment */ - statement /* Comment */ -) /* Comment */ -myFunction( /* Comment */ - statement /* Comment */ -) /* Comment */ -{ /* Comment */ - label:'value' /* Comment */ -} /* Comment */ -function(){ /* Comment */ - statement; /* Comment */ -} /* Comment */ +[1,2,3] /* Comment */ +[ /* Comment */ + 1, /* Comment */ + 2, /* Comment */ + 3 /* Comment */ +] /* Comment */ +myArray[ /* Comment */ + 0 /* Comment */ +] /* Comment */ +(statement) /* Comment */ +( /* Comment */ + statement /* Comment */ +) /* Comment */ +myFunction( /* Comment */ + statement /* Comment */ +) /* Comment */ +{ /* Comment */ + label:'value' /* Comment */ +} /* Comment */ +function(){ /* Comment */ + statement; /* Comment */ +} /* Comment */ // With ; /* Comment */ [1,2,3]; /* Comment */ @@ -267,32 +410,214 @@ function(){ /* Comment */ }; /* Comment */ -// Object /* Comment */ -var myObj = { /* Comment */ - label: [1,2,3], /* Comment */ - label: [ /* Comment */ - 1, /* Comment */ - 2, /* Comment */ - 3 /* Comment */ - ], /* Comment */ - label: myArray[ /* Comment */ - 0 /* Comment */ - ], /* Comment */ - label: (statement), /* Comment */ - label: ( /* Comment */ - statement /* Comment */ - ), /* Comment */ - label: myFunction( /* Comment */ - statement /* Comment */ - ), /* Comment */ - label: { /* Comment */ - label:'value' /* Comment */ - }, /* Comment */ - label: function(){ /* Comment */ - statement; /* Comment */ - }, /* Comment */ - label: 0 /* Comment */ -}; /* Comment */ +// Object /* Comment */ +var myObj = { /* Comment */ + label: [1,2,3], /* Comment */ + label: [ /* Comment */ + 1, /* Comment */ + 2, /* Comment */ + 3 /* Comment */ + ], /* Comment */ + label: myArray[ /* Comment */ + 0 /* Comment */ + ], /* Comment */ + label: (statement), /* Comment */ + label: ( /* Comment */ + statement /* Comment */ + ), /* Comment */ + label: myFunction( /* Comment */ + statement /* Comment */ + ), /* Comment */ + label: { /* Comment */ + label:'value' /* Comment */ + }, /* Comment */ + label: function(){ /* Comment */ + statement; /* Comment */ + }, /* Comment */ + label: 0 /* Comment */ +}; /* Comment */ + + +// ================= +// = With Comments = +// ================= +/* Comment */ [1,2,3] +/* Comment */ [ + /* Comment */ 1, + /* Comment */ 2, + /* Comment */ 3 +/* Comment */ ] +/* Comment */ myArray[ + /* Comment */ 0 +/* Comment */ ] +/* Comment */ (statement) +/* Comment */ ( + /* Comment */ statement +/* Comment */ ) +/* Comment */ myFunction( + /* Comment */ statement +/* Comment */ ) +/* Comment */ { + /* Comment */ label:'value' +/* Comment */ } +/* Comment */ function(){ + /* Comment */ statement; +/* Comment */ } + +/* Comment */ // With ; +/* Comment */ [1,2,3]; +/* Comment */ [ + /* Comment */ 1, + /* Comment */ 2, + /* Comment */ 3 +/* Comment */ ]; +/* Comment */ myArray[ + /* Comment */ 1, + /* Comment */ 2, + /* Comment */ 3 +/* Comment */ ]; +/* Comment */ (statement) +/* Comment */ ( + /* Comment */ statement +/* Comment */ ); +/* Comment */ myFunction( + /* Comment */ statement +/* Comment */ ); +/* Comment */ { + /* Comment */ label:'value' +/* Comment */ }; +/* Comment */ function(){ + /* Comment */ statement; +/* Comment */ }; + +/* Comment */ // Object +/* Comment */ var myObj = { + /* Comment */ label: [1,2,3], + /* Comment */ label: [ + /* Comment */ 1, + /* Comment */ 2, + /* Comment */ 3 + /* Comment */ ], + /* Comment */ label: myArray[ + /* Comment */ 0 + /* Comment */ ], + /* Comment */ label: (statement), + /* Comment */ label: ( + /* Comment */ statement + /* Comment */ ), + /* Comment */ label: myFunction( + /* Comment */ statement + /* Comment */ ), + /* Comment */ label: { + /* Comment */ label:'value' + /* Comment */ }, + /* Comment */ label: function(){ + /* Comment */ statement; + /* Comment */ }, + /* Comment */ label: 0 +/* Comment */ }; + + +// No Fold; No Indent +function(){/* { */} +myArray = [/* [ */] +myFunction(/* ( */) +// No Fold; No Indent +function(){/* } */} +myArray = [/* ] */] +myFunction(/* ) */) +// No Fold; No Indent + + +/* Comment {*/ function(){/* { */} +/* Comment [*/ myArray = [/* [ */] +/* Comment (*/ myFunction(/* ( */) +// No Fold; No Indent +/* Comment }*/ function(){/* } */} +/* Comment ]*/ myArray = [/* ] */] +/* Comment )*/ myFunction(/* ) */) +// No Fold; No Indent + + +/* Comment {*/ function(){ + // Fold; Indent +} +/* Comment [*/ myArray = [ + // Fold; Indent +] +/* Comment (*/ myFunction( + // Fold; Indent +) +// No Fold; No Indent +/* Comment }*/ function(){ + // Fold; Indent +} +/* Comment ]*/ myArray = [ + // Fold; Indent +] +/* Comment )*/ myFunction( + // Fold; Indent +) +// No Fold; No Indent + + +/* Comment +}*/ function(){ + // Fold; Indent +} +/* Comment +]*/ myArray = [ + // Fold; Indent +] +/* Comment +)*/ myFunction( + // Fold; Indent +) +// No Fold; No Indent + + +/* Comment +{*/ function(){} +/* Comment +[*/ myArray = [] +/* Comment +(*/ myFunction() +// No Fold; No Indent +/* Comment +}*/ function(){} +/* Comment +]*/ myArray = [] +/* Comment +)*/ myFunction() +// No Fold; No Indent + + +function(){/* } */ + // Fold; Indent +/*{*/} +myArray = [/* ] */ + // Fold; Indent +/*[*/] +myFunction(/* ) */ + // Fold; Indent +/*(*/) +// No Fold; No Indent + + +function(){/* } + */// Fold; Indent + /*{ +*/} +myArray = [/* ] + */// Fold; Indent + /*[ +*/] +myFunction(/* ) + */// Fold; Indent + /*( +*/) +// No Fold; No Indent + // ============== @@ -473,6 +798,18 @@ switch () // = Strings = // =========== +// No Fold; No Indent +myFunction("" + statement; // Fold; Indent +"") +// No Fold; No Indent +myArray = ["", + statement; // Fold; Indent +""] +// No Fold; No Indent +function(){"" + statement; // Fold; Indent +""} // No Fold; No Indent myFunction(")" statement; // Fold; Indent @@ -700,6 +1037,17 @@ myFunction(/{ }/) myFunction(/{\/}/) +{/ +// No Fold; No Indent +}/ +{' +// No Fold; No Indent +}' +{" +// No Fold; No Indent +}" + + // ============ // = Comments = // ============ @@ -714,6 +1062,16 @@ myFunction(/{\/}/) // No Fold; No Indent // } +0 // myFunction( +0 // No Fold; No Indent +0 // ) +0 // myArray = [ +0 // No Fold; No Indent +0 // ] +0 // function(){ +0 // No Fold; No Indent +0 // } + function(){ some_function(); @@ -753,4 +1111,3 @@ function(){ '}\'{' -