Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
33
Task/History-variables/Tcl/history-variables-1.tcl
Normal file
33
Task/History-variables/Tcl/history-variables-1.tcl
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# Define the history machinery
|
||||
proc histvar {varName operation} {
|
||||
upvar 1 $varName v ___history($varName) history
|
||||
switch -- $operation {
|
||||
start {
|
||||
set history {}
|
||||
if {[info exist v]} {
|
||||
lappend history $v
|
||||
}
|
||||
trace add variable v write [list histvar.write $varName]
|
||||
trace add variable v read [list histvar.read $varName]
|
||||
}
|
||||
list {
|
||||
return $history
|
||||
}
|
||||
undo {
|
||||
set history [lrange $history 0 end-1]
|
||||
}
|
||||
stop {
|
||||
unset history
|
||||
trace remove variable v write [list histvar.write $varName]
|
||||
trace remove variable v read [list histvar.read $varName]
|
||||
}
|
||||
}
|
||||
}
|
||||
proc histvar.write {key varName args} {
|
||||
upvar 1 $varName v ___history($key) history
|
||||
lappend history $v
|
||||
}
|
||||
proc histvar.read {key varName args} {
|
||||
upvar 1 $varName v ___history($key) history
|
||||
set v [lindex $history end]
|
||||
}
|
||||
13
Task/History-variables/Tcl/history-variables-2.tcl
Normal file
13
Task/History-variables/Tcl/history-variables-2.tcl
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# Enable history for foo
|
||||
histvar foo start
|
||||
set foo {a b c d}
|
||||
set foo 123
|
||||
set foo "quick brown fox"
|
||||
puts $foo
|
||||
puts foo-history=[join [histvar foo list] ", "]
|
||||
puts $foo
|
||||
histvar foo undo
|
||||
puts $foo
|
||||
histvar foo undo
|
||||
puts $foo
|
||||
histvar foo stop
|
||||
Loading…
Add table
Add a link
Reference in a new issue