From 148d7ee9f34ec805f8928060841fac5cfb6e2de6 Mon Sep 17 00:00:00 2001 From: Thomas Aylott Date: Mon, 4 Aug 2008 14:34:18 -0400 Subject: [PATCH] =?UTF-8?q?NEW=20Advanced=20Folding=20and=20Indent=20patte?= =?UTF-8?q?rns!=20Added=20switch=E2=80=A6case=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Preferences/Indent.tmPreferences | 35 ++++++ Preferences/JavaScript Indent.tmPreferences | 21 ---- Syntaxes/JavaScript Basic.tmLanguage | 20 ++-- Tests/Javascript Folding & Indent.js | 123 +++++++++++++++++--- 4 files changed, 149 insertions(+), 50 deletions(-) create mode 100644 Preferences/Indent.tmPreferences delete mode 100644 Preferences/JavaScript Indent.tmPreferences diff --git a/Preferences/Indent.tmPreferences b/Preferences/Indent.tmPreferences new file mode 100644 index 0000000..684085a --- /dev/null +++ b/Preferences/Indent.tmPreferences @@ -0,0 +1,35 @@ + + + + + name + Indent + scope + source.js + settings + + decreaseIndentPattern + (?x)^ \s* (?!//|/\*) + # (nothing | ( string | no parens )+ | (no parens? (nested parens ) no parens?)+ ) Close + ( (?: | ( (?<str> '(\\'|[^'])*+' | "(\\"|[^"])*+" | /(\\/|[^/])*+/) | (?<noR>[^\[\]'"/]++) )++ | (\g<noR>? (?<round> \[ (?: \g<str> | \g<noR> | \g<round> )* \] ) \g<noR>? )++ ) \] + | (?: | ( \g<str> | (?<noS>[^\(\)'"/]++) )++ | (\g<noS>? (?<squar> \( (?: \g<str> | \g<noS> | \g<squar> )* \) ) \g<noS>? )++ ) \) + | (?: | ( \g<str> | (?<noC>[^\{\}'"/]++) )++ | (\g<noC>? (?<curly> \{ (?: \g<str> | \g<noC> | \g<curly> )* \} ) \g<noC>? )++ ) \} + | \b(?:case|default)\b .*$# [^;]*$ + ) + increaseIndentPattern + (?x)^ \s* (?!//|/\*)([^\s].*)? + # Open (nothing | ( string | no parens )+ | (no parens? (nested parens ) no parens?)+ ) + ( \[ (?: | ( (?<str> '(\\'|[^'])*+' | "(\\"|[^"])*+" | /(\\/|[^/])*+/) | (?<noR>[^\[\]'"/]++) )++ | (\g<noR>? (?<round> \[ (?: \g<str> | \g<noR> | \g<round> )* \] ) \g<noR>? )++ ) + | \( (?: | ( \g<str> | (?<noS>[^\(\)'"/]++) )++ | (\g<noS>? (?<squar> \( (?: \g<str> | \g<noS> | \g<squar> )* \) ) \g<noS>? )++ ) + | \{ (?: | ( \g<str> | (?<noC>[^\{\}'"/]++) )++ | (\g<noC>? (?<curly> \{ (?: \g<str> | \g<noC> | \g<curly> )* \} ) \g<noC>? )++ ) + | \b(?:case|default)\b .*# [^;]* + )$ + indentNextLinePattern + ^\s*((if|while|for|switch|else if).*[)]|else)\s*$ + unIndentedLinePattern + ^\s*((/\*|\*/\s*$|\ \*).*)?$ + + uuid + BC062860-3346-4D3B-8421-C5543F83D11F + + diff --git a/Preferences/JavaScript Indent.tmPreferences b/Preferences/JavaScript Indent.tmPreferences deleted file mode 100644 index 1ace8e8..0000000 --- a/Preferences/JavaScript Indent.tmPreferences +++ /dev/null @@ -1,21 +0,0 @@ - - - - - name - JavaScript Indent - scope - source.js - settings - - decreaseIndentPattern - ^((.*\*/)?\s*(\}|\))([^{]*\{)?([;,]?\s*|\.[^{]*|\s*\)[;\s]*)$|\s*[}]while.*$) - increaseIndentPattern - ^(\/(?!\/)|[^\/])*((\{[^}"']*|\([^)"']*)|\=\s*)$ - indentNextLinePattern - ^\s*((if|while|for|switch|else if).*[)]|else)\s*$ - - uuid - BC062860-3346-4D3B-8421-C5543F83D11F - - diff --git a/Syntaxes/JavaScript Basic.tmLanguage b/Syntaxes/JavaScript Basic.tmLanguage index 988d0f9..d588fc3 100644 --- a/Syntaxes/JavaScript Basic.tmLanguage +++ b/Syntaxes/JavaScript Basic.tmLanguage @@ -11,18 +11,18 @@ jsx foldingStartMarker - (?x)^ \s* ([^\s].*)? - # Open (nothing | no parens | (no parens? (nested parens ) no parens?)+ ) - ( \[ (?: | (?<noR>[^\[\]]++) | (\g<noR>? (?<round> \[ (?: \g<noR> | \g<round> )* \] ) \g<noR>? )++ ) - | \( (?: | (?<noS>[^\(\)]++) | (\g<noS>? (?<squar> \( (?: \g<noS> | \g<squar> )* \) ) \g<noS>? )++ ) - | \{ (?: | (?<noC>[^\{\}]++) | (\g<noC>? (?<curly> \{ (?: \g<noC> | \g<curly> )* \} ) \g<noC>? )++ ) + (?x)^ \s* (?!//|/\*)([^\s].*)? + # Open (nothing | ( string | no parens )+ | (no parens? (nested parens ) no parens?)+ ) + ( \[ (?: | ( (?<str> '(\\'|[^'])*+' | "(\\"|[^"])*+" | /(\\/|[^/])*+/) | (?<noR>[^\[\]'"/]++) )++ | (\g<noR>? (?<round> \[ (?: \g<str> | \g<noR> | \g<round> )* \] ) \g<noR>? )++ ) + | \( (?: | ( \g<str> | (?<noS>[^\(\)'"/]++) )++ | (\g<noS>? (?<squar> \( (?: \g<str> | \g<noS> | \g<squar> )* \) ) \g<noS>? )++ ) + | \{ (?: | ( \g<str> | (?<noC>[^\{\}'"/]++) )++ | (\g<noC>? (?<curly> \{ (?: \g<str> | \g<noC> | \g<curly> )* \} ) \g<noC>? )++ ) )$ foldingStopMarker - (?x)^ \s* - # (nothing | no parens | (no parens? (nested parens ) no parens?)+ ) Close - ( (?: | (?<noR>[^\[\]]++) | (\g<noR>? (?<round> \[ (?: \g<noR> | \g<round> )* \] ) \g<noR>? )++ ) \] - | (?: | (?<noS>[^\(\)]++) | (\g<noS>? (?<squar> \( (?: \g<noS> | \g<squar> )* \) ) \g<noS>? )++ ) \) - | (?: | (?<noC>[^\{\}]++) | (\g<noC>? (?<curly> \{ (?: \g<noC> | \g<curly> )* \} ) \g<noC>? )++ ) \} + (?x)^ \s* (?!//|/\*) + # (nothing | ( string | no parens )+ | (no parens? (nested parens ) no parens?)+ ) Close + ( (?: | ( (?<str> '(\\'|[^'])*+' | "(\\"|[^"])*+" | /(\\/|[^/])*+/) | (?<noR>[^\[\]'"/]++) )++ | (\g<noR>? (?<round> \[ (?: \g<str> | \g<noR> | \g<round> )* \] ) \g<noR>? )++ ) \] + | (?: | ( \g<str> | (?<noS>[^\(\)'"/]++) )++ | (\g<noS>? (?<squar> \( (?: \g<str> | \g<noS> | \g<squar> )* \) ) \g<noS>? )++ ) \) + | (?: | ( \g<str> | (?<noC>[^\{\}'"/]++) )++ | (\g<noC>? (?<curly> \{ (?: \g<str> | \g<noC> | \g<curly> )* \} ) \g<noC>? )++ ) \} ) keyEquivalent ^~J diff --git a/Tests/Javascript Folding & Indent.js b/Tests/Javascript Folding & Indent.js index b8803fb..7d9791a 100644 --- a/Tests/Javascript Folding & Indent.js +++ b/Tests/Javascript Folding & Indent.js @@ -26,6 +26,7 @@ Documentation Comment (idiom) * officia deserunt mollit anim id est laborum. */ + // nothing [1,2,3] @@ -325,35 +326,45 @@ function(){ function(){ statement }; function(){ statement }; myFunction() myFunction( + // Fold; Indent );myFunction myFunction((0) + // Fold; Indent );myFunction myFunction(something() + // Fold; Indent ) myFunction(()something + // Fold; Indent ) myFunction((something) + // Fold; Indent ) myFunction(something(something)something + // Fold; Indent something(something)something) myFunction(something()() + // Fold; Indent ) myFunction(()something() + // Fold; Indent ) myFunction((something)() + // Fold; Indent ) myFunction(()something()(something)()something() + // Fold; Indent ) @@ -362,6 +373,22 @@ myFunction(()something()(something)()something() // = Special = // =========== switch (statement){ +case 'label': + statement; + break; +case 'label': + statement; + break; +case 'label': + statement; + break; +default: + statement; +} + +function(){ + + switch (statement){ case 'label': statement; break; @@ -373,8 +400,20 @@ switch (statement){ break; default: statement; + } + + switch (statement){ + case 'label': statement; break; + case 'label': statement; break; + case 'label': statement; break; + default: statement; + } + } + + + // No fold if (statement) statement; @@ -382,13 +421,26 @@ if (statement) statement; if (statement){ - statement;} +statement;} // Fold if (statement){ statement; } +if () + statement; +else if () + statement; +else + statement; +while () + statement; +for () + statement; +switch () + statement; + // =========== // = Strings = @@ -396,75 +448,75 @@ if (statement){ // No Fold; No Indent myFunction(")" - // Fold; Indent + statement; // Fold; Indent "(") // No Fold; No Indent myArray = ["]", - // Fold; Indent + statement; // Fold; Indent "["] // No Fold; No Indent function(){"}" - // Fold; Indent + statement; // Fold; Indent "{"} // No Fold; No Indent myFunction("\")" - // Fold; Indent + statement; // Fold; Indent "\"(") // No Fold; No Indent myArray = ["\"]", - // Fold; Indent + statement; // Fold; Indent "\"["] // No Fold; No Indent function(){"\"}" - // Fold; Indent + statement; // Fold; Indent "\"{"} // No Fold; No Indent myFunction(')' - // Fold; Indent + statement; // Fold; Indent '(') // No Fold; No Indent myArray = [']', - // Fold; Indent + statement; // Fold; Indent '['] // No Fold; No Indent function(){'}' - // Fold; Indent + statement; // Fold; Indent '{'} // No Fold; No Indent myFunction('\')' - // Fold; Indent + statement; // Fold; Indent '\'(') // No Fold; No Indent myArray = ['\']', - // Fold; Indent + statement; // Fold; Indent '\'['] // No Fold; No Indent function(){'\'}' - // Fold; Indent + statement; // Fold; Indent '\'{'} // No Fold; No Indent myFunction(/)/ - // Fold; Indent + statement; // Fold; Indent /(/) // No Fold; No Indent myArray = [/]/, - // Fold; Indent + statement; // Fold; Indent /[/] // No Fold; No Indent function(){/}/ - // Fold; Indent + statement; // Fold; Indent /{/} // No Fold; No Indent myFunction(/\/)/ - // Fold; Indent + statement; // Fold; Indent /\/(/) // No Fold; No Indent myArray = [/\/]/, - // Fold; Indent + statement; // Fold; Indent /\/[/] // No Fold; No Indent function(){/\/}/ - // Fold; Indent + statement; // Fold; Indent /\/{/} // No Fold; No Indent @@ -506,3 +558,36 @@ myFunction('\' ) ') myFunction(/ \) /) myFunction(/\/\) /) + +// ============ +// = Comments = +// ============ + +// myFunction( +// No Fold; No Indent +// ) +// myArray = [ +// No Fold; No Indent +// ] +// function(){ +// No Fold; No Indent +// } + + +function(){ + some_function(); + +/* ignore_first(); + ignore_second(); +*/ + + more_functions(); +} + + +"" +'' +() +[] +{} +