[Webkit-unassigned] [Bug 16397] Patch to provide rudimentary JavaScript indentation

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Dec 11 13:13:47 PST 2007


http://bugs.webkit.org/show_bug.cgi?id=16397





------- Comment #3 from bfulgham at gmail.com  2007-12-11 13:13 PDT -------
(From update of attachment 17839)
>Index: ChangeLog
>===================================================================
>--- ChangeLog	(revision 28609)
>+++ ChangeLog	(working copy)
>@@ -1,3 +1,9 @@
>+2007-12-10  Brent Fulgham  <bfulgham at gmail.com>
>+
>+        Reviewed by NOBODY (OOPS!).
>+
>+        * Drosera/debugger.js:
>+
> 2007-12-10  Brady Eidson  <beidson at apple.com>
> 
>         Rubberstamped by Sam Weinig
>Index: Drosera/debugger.js
>===================================================================
>--- Drosera/debugger.js	(revision 28609)
>+++ Drosera/debugger.js	(working copy)
>@@ -713,6 +713,61 @@ function syntaxHighlight(code, file)
>         return false;
>     }
> 
>+    function nextNonWSisClosingBrace(currLoc) {
>+        // scan forward.  If the first thing we hit is a closing brace, must decrement indent.
>+        var sz  = ((code.length - currLoc) > 80) ? 80 : code.length - currLoc - 1;
>+        var sub = code.substr(currLoc, sz);
>+        var pat = /\S/;
>+        var pos = sub.search(pat);
>+        if (pos >= 0 && code.charAt(pos + currLoc) == "}") {
>+            return true;
>+        }
>+
>+        return false;
>+    }
>+
>+    var findEOL = /\s*\n/;
>+    var indentLevel = 0;
>+    var indentSize = 4;        // 4 spaces per indent.  Should be configurable!
>+
>+    function indentLine(currLoc, indentLevel) {
>+        var c = code.charAt(currLoc);
>+        var indentCount = 0;
>+
>+        if (nextNonWSisClosingBrace(currLoc)) {
>+            if (indentLevel > 0)
>+                --indentLevel;
>+        }
>+
>+        if (0 == indentLevel)
>+            return currLoc;
>+
>+        while (c == " " || c == "\t" || c == "\n") {
>+            if (indentCount < indentLevel * indentSize) {
>+                if (c == "\t") {
>+                    for (var j = 0; j < indentSize; ++j)
>+                        echoChar(" ");
>+                } else if (c == "\n") {
>+                    echoChar(" ");
>+                } else
>+                    echoChar(c);
>+            }
>+            currLoc++;
>+            c = code.charAt(currLoc);
>+            if (c == "\t")
>+                indentCount += indentSize;
>+            else
>+                indentCount++;
>+        }
>+
>+        while (indentCount < indentLevel * indentSize) { 
>+            echoChar(" ");
>+            indentCount++;
>+        }
>+
>+        return currLoc;
>+    }
>+
>     var result = "";
>     var cPrev = "";
>     var c = "";
>@@ -751,6 +806,8 @@ function syntaxHighlight(code, file)
>             }
>             result += "</span>";
>             echoChar(c);
>+            
>+            i = indentLine(i+1, indentLevel) - 1;
>             continue;
>         } else if (c == "\"" || c == "'") {
>             var instringtype = c;
>@@ -865,6 +922,28 @@ function syntaxHighlight(code, file)
> 
>                 continue;
>             }
>+        } else if (c == "{") {
>+            indentLevel++;
>+            echoChar(c);
>+            echoChar("\n");
>+            i = indentLine(i+1, indentLevel) - 1;
>+            continue;
>+        } else if (c == "}") {
>+
>+            if (cPrev != " " && cPrev != "\t" && cPrev != "\n" && cPrev != ";") {
>+                echoChar("\n");
>+                i = indentLine(i, indentLevel);
>+            }
>+
>+            echoChar(c);
>+            if (indentLevel > 0)
>+                indentLevel--;
>+            continue;
>+       } else if (c == ";") {
>+            echoChar(c);
>+            echoChar("\n");
>+            i = indentLine(i+1, indentLevel) - 1;
>+            continue;
>         }
> 
>         echoChar(c);


-- 
Configure bugmail: http://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the webkit-unassigned mailing list