1 # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
3 # $Id: NConsole.tcl,v 1.10 2006-12-04 10:45:46 villate Exp $
5 ###### NConsole.tcl ######
6 ############################################################
7 # Netmath Copyright (C) 1998 William F. Schelter #
8 # For distribution under GNU public License. See COPYING. #
9 ############################################################
12 proc mkConsole
{ fr program
} {
16 pack $fr -expand 1 -fill both
18 label [set msg
$fr.
label] -height 1 -relief sunken
\
19 -textvariable maxima_priv
(load_rate
)
21 oset
$w program
$program
24 bind $w <Configure
> "resizeSubPlotWindows $w %w %h"
26 $w tag configure input
-foreground blue
27 # -relief sunken -borderwidth 1
28 bindtags $w [linsert [bindtags $w] 1 CNtext OpenMathText
]
32 if { ![regexp -- $maxima_priv(sticky
) input
] } {
33 append maxima_priv
(sticky
) {|^input
$}
37 $w mark gravity lastStart left
38 pack $w -side top
-expand 1 -fill both
39 pack $msg -side bottom
-expand 0 -fill x
43 proc CNinterrupt
{ w
} {
44 sendInterrupt
[oget
$w program
]
47 proc CNclearinput
{ w
} {
48 if { [$w compare lastStart
< insert
] } {
49 pushl
"[saveText $w lastStart insert ]" killRing
50 $w delete lastStart insert
55 proc CNinsertPrompt
{ w
} {
56 set prompt
[oget
$w prompt
]
57 $w mark
set insert end
58 if { [$w compare insert
> "insert linestart"] } {
61 $w insert insert
"$prompt" prompt
62 $w mark
set lastStart
[$w index
"end -1char"]
64 #puts [$w dump -all "[$w index end] -2 lines" end]
68 linkLocal
$w inputs inputIndex
70 if { [$w compare insert
< lastStart
] } {
71 set this
[thisRange
$w input insert
]
72 if { "$this" != "" } {
73 set code
[eval $w get
$this]
74 set prev
[string trimright
[$w get lastStart end
] \n]
76 $w delete lastStart end
77 $w insert lastStart
$code input
80 set expr [string trimright
[$w get lastStart end
] \n]
81 $w tag add input lastStart end
83 set inputIndex
[expr {[llength $inputs] - 1}]
85 #puts "sendind <$expr>"
86 set res
[sendOneWait
[oget
$w program
] $expr]
87 message "received result"
90 if { ![regexp \n $res] } {
95 if { [regexp "\{plot\[23\]d" $res] } {
98 if { ![info exists counter
] } {set counter
0}
99 set name
$w.plot
[oset
$w counter
[expr {1 + [oget
$w counter
]}]]
100 eval plot2dData
$name $res [getDimensions
$w $name]
102 set view
[ShowPlotWindow
$w $name "$e $e" "$e $e" ""]
103 append view
" -1 line"
105 $w insert end
$res "$tag result"
110 if { [info exists view
] } {$w yview
$view }
111 if { "$prev" != "" } {$w insert insert
$prev}
114 proc CNpreviousInput
{ w direction
} {
115 linkLocal
$w inputIndex matching
116 if { [catch {makeLocal
$w inputs
}] } { return }
117 if { [$w compare insert
< lastStart
] } { return }
119 set last
[lindex [peekLastCommand
$w] 1]
120 if { ("[lindex $last 2]" != "ALT_p" && "[lindex $last 2]" != "ALT_n") ||
\
121 ![info exists inputIndex
] } {
122 set inputIndex
[expr {$direction < 0 ?
[llength $inputs] : -1}]
123 set matching
[string trim
[$w get lastStart end
] " \n"]
125 if {[info exists
$matching]} {
126 lappend inputs
$matching
128 set n
[llength $inputs]
130 set matchRegexp
"[quoteForRegexp $matching]"
131 while {[incr j
] <= $n } {
132 set inputIndex
[expr {($inputIndex + $direction+ $n)%$n}]
133 # [string match "$matching*" [lindex $inputs $inputIndex]]
134 if { [regexp -- $matchRegexp [lindex $inputs $inputIndex]] } {
135 $w delete lastStart end
136 $w insert insert
[lindex $inputs $inputIndex]
143 proc CNblinkMatchingParen
{ win ch
} {
144 $win tag delete blink
145 if { [string first
$ch "\}\)\]"] >= 0 } {
146 set tem
[$win get
"@0,0" "insert"]
147 set ind
[matchingParen
$tem]
148 if { "$ind" != "" } {
149 set ind
[expr {[string length
$tem] - $ind}]
150 catch { after cancel
[oget
$win blinkAfter
] }
151 set i
[$win index
"insert -$ind chars"]
152 $win tag add blink
"$i" "$i +1char"
153 $win tag configure blink
-foreground red
154 oset
$win blinkAfter
[after 1000 $win tag delete blink
]
161 #-----------------------------------------------------------------
163 # matchingParen -- Return index of STRING which a close paren
164 # would match if added to end.
169 #----------------------------------------------------------------
171 proc matchingParen
{ s1
} {
173 set ind
[string length
$s]
175 regsub -all "\[\01\02\]" $s x s
176 regsub -all "\[\]\}\)\]" $s "\01c" s
177 regsub -all "\[\[\{\(\]" $s "\01o" s
178 set lis
[split $s \01]
180 while { [incr n
-1] > 0 } {
181 set v
[lindex $lis $n]
182 incr ind
-[string length
$v]
183 set c
[string index
$v 0]
195 ## endsource nconsole.tcl