rep.tcl

# file: rep.tcl
# purpose: provide read-eval-print loop for newLISP
# correspondending with rep.lsp

package require Tk
destroy .rep
toplevel .rep
wm title .rep "Read Eval Print -- newLISP"

tk appname rep

pack\
 [text .rep.t -font {Mono -15} -undo yes -wrap none\
   -width 40 -height 10 -yscrollcommand ".rep.v set"]\
 -expand yes -fill both -side left

pack\
  [scrollbar .rep.v -orient vertical -command ".rep.t yview"]\
 -side left -fill y

proc newLISP line {
  puts "(respond $line)"
}

proc println result {
  # aufgerufen aus newLISP heraus
  .rep.t mark set insert end
  .rep.t insert insert [lindex [list $result] 0]\n
  after idle .rep.t see insert
}

bind .rep.t  [list apply [list win {
      #
      # Teile die Benutzereingabe an newLISP mit:
      #
      if {[$win tag ranges sel] eq {}} then {
        set line [$win get {insert linestart} {insert lineend}]
      } else {
        set line [$win get sel.first sel.last]
      }
      # puts "(respond $line)"
      newLISP $line
      $win mark set insert end
      $win insert insert \n
    }] %W]
bind .rep.t  +break
bind .rep.t  continue

# eof

4.10.2022