home *** CD-ROM | disk | FTP | other *** search
- !!Script
- // Copyright ⌐ 1997-1998 - Modelworks Software
- // @Modified build 287 cm19990409 - added endLine parameter to CleanupMultilineComment
- /**
- @Event: onPostReformat~is called to allow custom modifications
- after a file has been reformatted. This script is called after
- the normal reformat has been completed. This implementation
- just cleans up multiline comments by aligning all '*' in a
- muliline comment that uses a '*' at the begining of each line.
- @EndTool:
- @Summary: onPostReformat~is called to adjust formatting
- */
-
- var gOutput = getOutput();
-
- function DoCommand()
- {
- var editor = getActiveEditor();
- if (editor)
- {
- OnEvent(editor);
- editor.setActive("PostReformat");
- }
- }
-
- function OnEvent(editor)
- {
- var startCommentData = editor.findFirst("<%", 0, 0);
- while (startCommentData && startCommentData.found)
- {
- //gOutput.writeLine("Start = " + startCommentData.startLineIndex);
- var endCommentData = editor.findFirst("%>", startCommentData.startLineIndex, startCommentData.startCharIndex);
- if (endCommentData && endCommentData.found)
- {
- if (endCommentData.startLineIndex > startCommentData.startLineIndex)
- {
- var nextLine = CleanupMultilineComment(editor,
- startCommentData.startLineIndex, endCommentData.startLineIndex); //cm19990409
- startCommentData = editor.findFirst("<%", nextLine, 0);
- }
- else
- {
- startCommentData = editor.findFirst("/*", endCommentData.startLineIndex+1, 0);
- }
-
- //gOutput.writeLine("End = " + endCommentData.startLineIndex);
- }
- else
- {
- break;
- }
- }
- return true;
- }
-
- var gFirstRegExp = /(\s*\/\*)/;
- var gInnerRegExp = /(\s*\*)/;
-
- function CleanupMultilineComment(editor, startLine, endLine) //cm19990409
- {
- var indentLevel = editor.getIndentLevel(startLine);
- var lineData = editor.copy(startLine);
- if (gFirstRegExp.exec(lineData))
- {
- var length = RegExp.$1.length;
- startLine += 1;
- editor.setIndentLevel(startLine, indentLevel);
- lineData = editor.copy(startLine);
- while (gInnerRegExp.exec(lineData) && startLine <= endLine)
- {
- var commentIndent = RegExp.$1.length;
- if (commentIndent < length)
- {
- editor.replace(" ", startLine, commentIndent-1, startLine, commentIndent-1);
- }
- startLine += 1;
- lineData = editor.copy(startLine);
- }
- }
- else
- {
- startLine += 1;
- }
- return startLine;
- }
-
-
- !!/Script
-
-