home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-18 | 6.4 KB | 171 lines | [TEXT/ALFA] |
-
- if {$startingUp} {
- #================================================================================
- addMode Java javaMenu {*.java *.j} javaMenu
- set javaMenu "•140"
- addMenu javaMenu
- set modeMenus(Java) {javaMenu}
- return
- }
-
-
-
- newModeVar Java elecColon {1} 1
- newModeVar Java elecRBrace {1} 1
- newModeVar Java leftFillColumn {3} 0
- newModeVar Java prefixString {//} 0
- newModeVar Java electricSemi {1} 1
- newModeVar Java elecLBrace {1} 1
- newModeVar Java elecElse {1} 1
- newModeVar Java wordWrap {0} 1
- newModeVar Java funcExpr {^[^ \t\(#\r/@].*\(.*\)$} 0
- newModeVar Java parseExpr {\b([_:\w]+)\s*\(} 0
- newModeVar Java wordBreak {\w+} 0
- newModeVar Java wordBreakPreface {\W} 0
- newModeVar Java electricTab {0} 1
- newModeVar Java autoMark 0 1
- newModeVar Java stringColor green 0
- newModeVar Java commentColor red 0
- newModeVar Java keywordColor blue 0
-
- regModeKeywords -e {//} -b {/*} {*/} -c $JavamodeVars(commentColor) -k $JavamodeVars(keywordColor) -s $JavamodeVars(stringColor) Java {
- abstract boolean break byte byvalue case catch char class const continue
- default do double else extends false final finally float for goto if
- implements import instanceof int interface long native new null package
- private protected public return short static super switch synchronized this
- threadsafe throw transient true try void while }
-
-
-
- proc javaMenu {} {}
-
- menu -n $javaMenu -p javaMenuProc {
- "/S<U<OswitchToCompiler"
- "(-"
- "/K<U<OcompileFile"
- }
-
-
- proc javaMenuProc {menu item} {
- switch $item {
- switchToCompiler {launchForeAppl Javc}
- compileFile {launchForeAppl Javc; sendOpenEvent -n 'Javc' [car [winNames -f]]}
- }
- }
-
-
- # My version of JavaMarkFile. First revision, April 1996.
- # Jim Menard, jimm@io.com
- proc JavaMarkFile {} {
- # Sorry, but globals are a lot easier than using "upvar" in subroutines
- global markArray
- global classStartPositions
- global classNames
-
- unset markArray
-
- # Look for class definitions first
- set markExpr {^[ \t]*([A-Za-z_][A-Za-z0-9_]*[ \t]+)*class[ \t]+[A-Za-z_][A-Za-z0-9_]*[ \t\r]([A-Za-z_][A-Za-z0-9_.]*[ \t]+)*\{}
- set wordExpr {class[ \t]+([A-Za-z_][A-Za-z0-9_]*)}
- set commands {
- set markArray([concat $word "class"]) $markPos
- # Remember mark position and name separately so we can call
- # getClassFromPos() later.
- lappend classStartPositions $markPos
- lappend classNames $word
- }
- searchAndDestroy $markExpr $wordExpr $commands 0
-
- # The following regular expression is overly restrictive. After the open
- # paren, I disallow semicolons. That avoids finding lines like
- # throw new FooException(arg);
- # which is good, but unfortunately also avoids finding lines like
- # public int foo(arg) // comment with semi;
- #
- # It doesn't find constructors without a "public", "private", or other phrase
- # before the method name since it requires at least one word before the
- # method name. They are special-cased below. I did that so function calls,
- # "if" statements, and the like wouldn't be found.
- set markExpr {^[ \t]*([A-Za-z_][A-Za-z0-9_]*[ \t]+)+[A-Za-z_][A-Za-z0-9_]*[ \t\r]*\([^;]+$}
- set wordExpr {([A-Za-z_][A-Za-z0-9_]*)[ \t]*\(}
- set commands {
- if {$className == $word} {
- set markArray([concat $className "constructor"]) $markPos
- } else {
- set markArray($className::$word) $markPos
- }
- }
- searchAndDestroy $markExpr $wordExpr $commands 1
-
- # One more time; let's go back for constructors with no modifiers.
- set markExpr {^[ \t]*[A-Z][A-Za-z0-9_]*[ \t\r]*\([^;]+$}
- set wordExpr {([A-Z][A-Za-z0-9_]*)[ \t]*\(}
- set commands {
- if {$className == $word} {
- set markArray([concat $className "constructor"]) [lineStart [expr $start - 1]]
- }
- }
- searchAndDestroy $markExpr $wordExpr $commands 1
-
- if {[info exists markArray]} {
- foreach f [lsort -ignore [array names markArray]] {
- set next [nextLineStart $markArray($f)]
- if {[string length $f] > 35} { set f "[string range $f 0 31]..." }
- setNamedMark "${f}" "$markArray($f)" $next $next
- }
- }
- }
-
- # Start at top of file and find text that matches markExpr. Clean it up and
- # use wordExpr to find the word we want. Execute commands.
- proc searchAndDestroy {markExpr wordExpr commands needClassName} {
- global markArray
- global classStartPositions
- global classNames
-
- set pos 0
- while {![catch {search -s -f 1 -r 1 -m 0 -i 0 "$markExpr" $pos} res]} {
- set start [lindex $res 0]
- set end [expr [lindex $res 1] + 1]
- set thistext [getText $start $end]
- if {$needClassName} {
- set className [getClassFromPos $start $classStartPositions $classNames]
- }
- # regexp doesn't like carriage returns or tabs
- regsub -all "\r" $thistext " " thistext
- regsub -all "\t" $thistext " " thistext
- # If the open paren was the last character on the line, the selected text
- # included the last carriage return as well. Trim this off now that it is
- # changed into a space.
- set thistext [string trimright $thistext]
- if {[regexp $wordExpr $thistext dummy word]} {
- set markPos [lineStart [expr $start - 1]]
- eval $commands
- }
- set pos $end
- }
- }
-
- # Given a file position, find the class definition in which it resides.
- # There's got to be an easier way than passing two separate lists. I tried
- # fooling around with markArray(), but don't know Tcl well enough to use
- # it instead.
- proc getClassFromPos {pos classStartPositions classNames} {
- set nClasses [llength $classStartPositions]
- for {set i [expr $nClasses - 1]} {$i >= 0} {set i [expr $i - 1]} {
- if {[lindex $classStartPositions $i] <= $pos} {
- return [lindex $classNames $i]
- }
- }
- return ""
- }
-
-
- bind '\{' <s> electricLeft Java
- bind '\;' electricSemi Java
- bind '\}' <s> electricRight Java
- bind '\;' <z> ordSemi Java
-
- insertMenu $javaMenu
-
-