Add support for external html docs
[maxima.git] / interfaces / xmaxima / Tkmaxima / Bindings.tcl
blob2bd3774a9df8c1c968d3f9271ee6a59f25a2af85
1 # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
3 # $Id: Bindings.tcl,v 1.10 2007-03-23 00:05:06 villate Exp $
5 ###### Bindings.tcl ######
6 ############################################################
7 # Netmath Copyright (C) 1998 William F. Schelter #
8 # For distribution under GNU public License. See COPYING. #
9 ############################################################
11 global NCtextHelp
12 set NCtextHelp [mc "
13 Bindings:
14 <Return> This sends the current expression (ie where the insert
15 cursor is) for evaluation.
16 <Linefeed> (Control-j) This inserts a newline, and is useful
17 for entering multiline input.
18 <Control-k> Kills the current line and puts it in kill ring.
19 Successive control-k's append their output together.
20 <Control-y> Yank out the last kill, Meta-y cycles through previous
21 kills.
22 <Control-g> Interrupts the current computation.
23 <Alt-p> Gets the previous input in the history of inputs; if the
24 first input is reached, it proceeds to the last input. If
25 some characters are written before clicking on Alt-p, only
26 history items containing those characters will be considered.
27 <Alt-n> Gets the next input in the history of inputs; if the end is
28 reached, it proceeds to the first input. If some characters
29 are written before clicking on Alt-n, only history items
30 containing those characters will be considered.
31 <Alt-s> Print again the Maxima input prompt.
34 proc vMAXSetCNTextBindings {w} {
35 # Prevent deleting output fields with BackSpace key
36 bind CNtext <Key-BackSpace> {
37 if {[lsearch [%W tag names [%W index insert-1c]] output] >= 0} break
40 # Disable default keyboard bindings in output fields
41 bind CNtext <Key> {
42 if {[lsearch [%W tag names [%W index insert]] output] >= 0} break
45 # Keep only default bindings for the cursor movement keys
46 foreach Key {<Left> <Right> <Up> <Down> <Next> <Prior> <Home> <End>
47 <Shift-Left> <Shift-Right> <Shift-Up> <Shift-Down> <Shift-Home>
48 <Shift-End> <Control-Shift-Home> <Control-Shift-End>
49 <Control-a> <Control-b> <Control-e> <Control-f> <Control-n> <Control-p>
50 <Control-Home> <Control-End> <Meta-less> <Meta-greater> <Meta-b>
51 <Meta-f>} {
52 bind CNtext $Key "# nothing"
55 # The "Return" key is bound to command evaluation, except in output tags
56 bind CNtext <Return> {
57 if {[lsearch [%W tag names [%W index insert]] output] >= 0} {
58 break
59 } else {
60 CMeval %W
61 break
65 # Special keys (see NCtextHelp above for explanation)
66 bind CNtext <Control-g> "CMinterrupt %W "
67 bind CNtext <Control-G> "CMinterrupt %W "
68 bind CNtext <Control-u> "CNclearinput %W "
69 bind CNtext <Control-U> "CNclearinput %W "
70 bind CNtext "\)" "CNblinkMatchingParen %W %A"
71 bind CNtext "\]" "CNblinkMatchingParen %W %A"
72 bind CNtext "\}" "CNblinkMatchingParen %W %A"
73 bind CNtext <Control-j> "tkTextInsert %W %A ; openMathAnyKey %W %K %A"
74 bind CNtext <Control-J> "tkTextInsert %W %A ; openMathAnyKey %W %K %A"
75 bind CNtext <Alt-p> "CNpreviousInput $w -1"
76 bind CNtext <Alt-P> "CNpreviousInput $w -1"
77 bind CNtext <Alt-n> "CNpreviousInput $w 1"
78 bind CNtext <Alt-N> "CNpreviousInput $w 1"
79 bind CNtext <Alt-s> {sendMaxima %W ":s\n" }
80 bind CNtext <Alt-S> {sendMaxima %W ":s\n" }
81 bind CNtext <Control-Key-c> {tk_textCopy %W ;break}
82 bind CNtext <Control-Key-C> {tk_textCopy %W ;break}
83 bind CNtext <Control-Key-x> {tk_textCut %W ;break}
84 bind CNtext <Control-Key-X> {tk_textCut %W ;break}
85 bind CNtext <Control-Key-v> {tk_textPaste %W ;break}
86 bind CNtext <Control-Key-V> {tk_textPaste %W ;break}
90 global maxima_priv
91 set maxima_priv(doublek) 0
93 bind OpenMathText <Control-Key-k><Control-Key-k> {
94 set maxima_priv(doublek) 1
96 bind OpenMathText <Control-Key-K><Control-Key-K> {
97 set maxima_priv(doublek) 1
100 global maxima_priv
101 if {0} {
102 # xmaxima should not be binding the Text class
103 if {! [info exists maxima_priv(bindings_added) ] } {
104 bind Text <Control-Key-k> "+openMathControlK %W"
105 bind Text <B3-Motion> [bind Text <B2-Motion>]
106 bind Text <Button-3> [bind Text <Button-2>]
108 set maxima_priv(bindings_added) 1
110 } else {
111 bind OpenMathText <Control-Key-k> "+openMathControlK %W"
112 bind OpenMathText <Control-Key-K> "+openMathControlK %W"
116 #mike - I'm decreeing windows Cut/Copy/Paste conventions for
117 # keybindings, and will preobably reserve Alt-key for menu shortcuts.
119 bind OpenMathText <Control-Key-y> "OpenMathYank %W 0; break"
120 bind OpenMathText <Alt-Key-y> "OpenMathYank %W 1; break"
121 bind OpenMathText <Meta-Key-y> "OpenMathYank %W 1; break"
123 # put the clipboard paste on Control-Shift-y
124 # event add <<Paste>> <Control-Shift-y>
126 # Copy
127 bind OpenMathText <Alt-Key-w> {
128 pushCommand %W SaveSelection ""
129 if { "[selection own -displayof %W]" == "%W"} {
130 pushl [saveText %W sel.first sel.last] killRing
131 selection clear -displayof %W
135 bind OpenMathText <Key> {openMathAnyKey %W %K %A}
136 bind OpenMathText <Alt-Key> {openMathAnyKey %W %K ALT_%A}
138 # stop the double button click word selection in openMathText..
139 bind OpenMathText <Double-Button-1> { break; }
140 bind OpenMathText <Control-c><Key-e> {doInvoke %W insert ; break}
142 # ok - mark
143 bind OpenMathText <Control-Key-space> {
144 pushCommand %W SetAnchor ""
145 %W mark set anchor insert
149 #-----------------------------------------------------------------
151 # binding -- push the current selection on the killRing, and
152 # if there is no selection, push the region between the anchor and
153 # the point.
154 # Results:
156 # Side Effects:
158 #----------------------------------------------------------------
161 bind OpenMathText <Control-Key-w> {
162 pushCommand %W OpenMathTextCut ""
163 # in the first case the <<Cut>> event on Text will delete the selection.
164 if { [catch { pushl [saveText %W sel.first sel.last] killRing } ] } {
165 catch {
166 set range [getRange %W anchor insert]
167 pushl [eval saveText %W $range] killRing
168 eval %W delete $range
175 proc openMathAnyKey { win keysym s } {
176 # puts "$win `$keysym' `$s'"
177 if { "$s" != "" } {
178 pushCommand $win openMathAnyKey [list $win $keysym $s]
181 if { "$s" != "" && [doInsertp [$win tag names insert]]
182 && ("$s" == "$keysym" || [regexp -- "\[\n\t \x04\b\x7f\]" "$s" junk] )} {
183 setModifiedFlag $win insert
187 #mike this code is impenetrable:
188 proc OpenMathYank {win level} {
189 global maxima_priv
190 #puts "doing OpenMathYank $win $level"
191 if { $level == 0 } {
192 set maxima_priv(currentwin) $win
193 pushCommand $win OpenMathYank [list $win $level]
194 set maxima_priv(point) insert
195 $win mark set beforeyank insert
196 $win mark gravity beforeyank left
197 eval [peekl killRing "" ]
198 } elseif { ![info exists maxima_priv(lastcom,$win)]} {
199 #mike this case was not forseen in the code below and
200 # it always occurs on the first Yank if nothing has benn Killed
201 } elseif { [catch {
202 set last $maxima_priv(lastcom,$win)
203 set m [lindex [lindex $last 1] 1]
204 incr m
205 if { [lindex $last 0] == "OpenMathYank" && \
206 "$maxima_priv(currentwin)" == "$win" && \
207 "$maxima_priv(point)" == "insert"} {
208 set doit 1
209 } else {
210 #mike the following was missing, and its
211 # lack was obscurred by the catch
212 set doit 0
214 } err] || "$doit" == "0"} {
215 pushCommand $win Error ""
216 } else {
217 set res [peekl killRing _none_ [expr {$m + 1}]]
218 if { "$res" == "_none_" } {
219 # this will cause to cycle
220 set m 0
221 } else {
222 $win delete beforeyank insert
223 eval $res
225 pushCommand $win OpenMathYank [list $win $m]
227 catch {$win see insert}
230 proc saveText { win args } {
232 if {[catch {$win index [lindex $args 1 ]} endregion]} {return ""}
234 set tags [ldelete sel [$win tag names]]
235 set prev [lindex $args 0]
237 if { "$prev" == "" } {set prev 0.0 }
238 if { "$endregion" == "" } {set endregion end}
240 set allar($prev) 1
241 set allar($endregion) 1
242 foreach v $tags {
243 set ranges [tagRanges $win $v $prev $endregion]
244 foreach {begin end} $ranges {
245 lappend start($begin) $v
246 lappend stop($end) $v
247 set allar($begin) 1
248 set allar($end) 1
252 proc __comp { a b} " return \[$win compare \$a > \$b \] "
253 set all [lsort -command __comp [array names allar]]
254 set result ""
255 foreach v $all {
256 append result "Tins [list [array names currentTags]] [quoteBraces [$win get $prev $v]]\n"
257 set prev $v
260 if { [info exists start($v)] } {
262 foreach u $start($v) { set currentTags($u) 1}
265 if { [info exists stop($v)] } {
267 foreach u $stop($v) { unset currentTags($u) }
272 #puts -nonewline "..deleting{$stop($v)} giving {$currentTags}"
274 # puts ">>"
277 return $result
282 proc openMathControlK { win } {
283 global maxima_priv
284 if { $maxima_priv(doublek) != 0 } {
285 set now [popl killRing ""]
286 } else {
287 set now ""
289 set maxima_priv(doublek) 0
290 if { [$win compare insert == "insert lineend" ] } {
291 if { [$win compare insert < end] } {
292 append now "\nTins {[ldelete sel [$win tag names insert]]} {\n}"
293 } } else {
294 append now "\n[saveText $win insert {insert lineend}]"
296 pushl $now killRing