home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 September (IDG) / Sep99.iso / Shareware World / Utilities / Text Processing / Alpha / Tcl / Modes / browserMode.tcl < prev    next >
Encoding:
Text File  |  1999-03-18  |  4.8 KB  |  179 lines  |  [TEXT/ALFA]

  1. #=============================================================================
  2. # Browser mode.
  3. # Alpha cannot do batch searches without this file
  4. #=============================================================================
  5.  
  6. alpha::mode Brws 1.0.2 dummyBrws 
  7.  
  8. Bind '\r'    gotoMatch  Brws
  9. Bind enter    gotoMatch  Brws
  10. ascii 0x3      gotoMatch  Brws
  11. Bind down     downBrowse Brws
  12. Bind up     upBrowse   Brws
  13. Bind 'n' <z>    downBrowse Brws
  14. Bind 'p' <z>    upBrowse   Brws
  15. ascii 0x20    downBrowse Brws
  16. ascii 0x8    upBrowse   Brws
  17. # this was below.  do we need it?
  18. Bind 'c' <Cz>    gotoMatch
  19.  
  20. proc dummyBrws {} {}
  21.  
  22. proc upBrowse {} {
  23.     set limit [nextLineStart [nextLineStart [minPos]]]
  24.     if {[pos::compare [getPos] > $limit]} {
  25.     set limit [pos::math [getPos] - 1]
  26.     }
  27.     select [lineStart $limit] [nextLineStart $limit]
  28. }
  29.  
  30. proc downBrowse {} {
  31.     set pos [getPos]
  32.     if {[pos::compare $pos < [nextLineStart [minPos]]]} {
  33.     set pos [nextLineStart [minPos]]
  34.     }
  35.     if {[pos::compare [nextLineStart $pos] != [maxPos]]} {
  36.     select [nextLineStart $pos] [nextLineStart [nextLineStart $pos]]
  37.     }
  38. }
  39.  
  40. proc nextPrevMatch {{dir 1} {wname "*Batch Find*"}} {
  41.     set wins [winNames]
  42.     set res [lsearch $wins $wname]
  43.     if {$res < 0} {
  44.     set res [lsearch -regexp $wins {\*.*\*}]
  45.     if {$res < 0} return
  46.     }
  47.     set win [lindex $wins $res]
  48.     bringToFront $win
  49.     if {$dir} {
  50.     downBrowse
  51.     } else {
  52.     upBrowse
  53.     }
  54.     gotoMatch
  55.     dispErr $win
  56. }
  57.  
  58. proc nextMatch {{wname "*Batch Find*"}} {
  59.     nextPrevMatch 1 $wname
  60. }
  61.  
  62. proc prevMatch {{wname "*Batch Find*"}} {
  63.     nextPrevMatch 0 $wname
  64. }
  65.  
  66. proc dispErr {{win "* Compiler Errors *"}} {
  67.     if {[string length $win]} {
  68.     set text [getText -w $win [getPos -w $win] [selEnd -w $win]]
  69.     if {[regexp {(Line.*)∞} $text dummy sub]} {
  70.         message "$sub"
  71.     }
  72.     }
  73. }
  74.         
  75.  
  76. ##############################################################################
  77. #  To be used in the windows created by "matchingLines" or by batch searches.
  78. #
  79. #  With the cursor positioned in a line corrsponding to a match, 
  80. #  go back and select the line in the original file that 
  81. #  generated this match.  (Like emacs 'Occur' functionality)
  82. #
  83. #  97-08-01 Now doesn't ask if you want a new copy of windows with <n>.
  84. #           Wrap dialog also skipped.
  85. proc gotoMatch {} {
  86.     if {[string match "*MAILBOX*" [win::CurrentTail]]} {
  87.     mailGotoMatch
  88.     return
  89.     }
  90.     global tileHeight tileWidth tileTop tileLeft tileHeight \
  91.       errorHeight errorDisp tileMargin
  92.     set text [getText [lineStart [getPos]] \
  93.       [pos::math [nextLineStart [getPos]] - 1]]
  94.     set ind1 [string first "∞" $text]
  95.     set ind2 [string last "∞" $text]
  96.     if {$ind1 == $ind2} {
  97.     set fname [string trim [string range $text $ind1 end] {∞}]
  98.     set msg ""
  99.     } else {
  100.     set fname [string trim [string range $text $ind1 $ind2] {∞}]
  101.     set msg [string trim [string range $text $ind2 end] {∞}]
  102.     }
  103.     
  104.     set top $tileTop
  105.     set geo [getGeometry]
  106.     if {([lindex $geo 0] != $tileLeft) || ([lindex $geo 1] != $top) \
  107.       || ([lindex $geo 3] != $errorHeight) } {
  108.     moveWin $tileLeft $top
  109.     sizeWin $tileWidth $errorHeight
  110.     }
  111.     set mar $tileMargin
  112.     incr top [expr {$errorHeight + $mar}]
  113.     if {[file exists $fname]} {
  114.     edit -c -w -g $tileLeft $top $tileWidth $errorDisp $fname
  115.     set geo [getGeometry]
  116.     if {([lindex $geo 0] != $tileLeft) || ([lindex $geo 1] != $top) \
  117.       || ([lindex $geo 2] != $tileWidth) || ([lindex $geo 3] != $errorDisp) } {
  118.         sizeWin $tileWidth $errorDisp
  119.         moveWin $tileLeft $top
  120.     }
  121.     } else {
  122.     if {![string match "*Link*" \
  123.       [getText [minPos] [nextLineStart [minPos]]]]} {
  124.         alertnote "File \" $fname \" not found." 
  125.     }
  126.     return
  127.     }
  128.     if {[regexp {Line ([0-9]+):} $text dummy line]} {
  129.     set pos [rowColToPos $line 0]
  130.     select $pos [nextLineStart $pos]
  131.     }
  132.     message $msg
  133. }
  134.  
  135. set lastMatchingLines ""
  136.  
  137. proc matchingLines {{reg ""} {for 1} {ign 1} {word 0} {regexp 1}} {
  138.     global lastMatchingLines
  139.     
  140.     if {![string length $reg] && \
  141.       [catch {prompt "Regular expression:" $lastMatchingLines} reg]} return
  142.     set lastMatchingLines $reg
  143.     if {![string length $reg]} return
  144.     if {!$regexp} {
  145.     set reg [quote::Regfind $reg]
  146.     }
  147.     if {$word} {
  148.     set reg "^.*\\b$reg\\b.*$"
  149.     } else {
  150.     set reg "^.*$reg.*$"
  151.     }
  152.     set pos [expr {$for ? [minPos] : [getPos]}]
  153.     set fileName [stripNameCount [win::Current]]
  154.     set matches 0
  155.     set lines {}
  156.     while {![catch {search -s -f 1 -r 1 -i $ign -- $reg $pos} mtch]} {
  157.     regsub -all "\t" [eval getText $mtch] "  " text
  158.     append lines "\r" [format "Line %d: " \
  159.       [lindex [posToRowCol [lindex $mtch 0]] 0]] \
  160.       $text \
  161.       "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\
  162.       \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t∞$fileName"
  163.     set pos [lindex $mtch 1]
  164.     incr matches
  165.     }
  166.     if {$matches} {
  167.     grepsToWindow {* Matching Lines *} \
  168.       [format "%d matching lines (<cr> to go to match)\r-----" $matches] \
  169.       $lines "\r"
  170.     } else {
  171.     beep
  172.     message "No matches found."
  173.     }
  174. }
  175.  
  176.  
  177.  
  178.