Index: tclreadlineCompleter.tcl ================================================================== --- tclreadlineCompleter.tcl +++ tclreadlineCompleter.tcl @@ -1,8 +1,8 @@ # -*- tclsh -*- -# FILE: "/disk01/home/joze/src/tclreadline/tclreadlineCompleter.tcl" -# LAST MODIFICATION: "Wed Sep 15 18:18:13 1999 (joze)" +# FILE: "/home/joze/src/tclreadline/tclreadlineCompleter.tcl" +# LAST MODIFICATION: "Thu Sep 16 02:47:02 1999 (joze)" # (C) 1998, 1999 by Johannes Zellner, # $Id$ # --- # # tclreadline -- gnu readline for tcl @@ -28,11 +28,15 @@ # ================================================================== # TODO: # -# - tcltest is missing +# - tcltest is missing +# - better completion for CompleteListFromList: +# RemoveUsedOptions ... +# - namespace eval fred {... <-- continue with a +# substitution in fred. # # @@ -41,10 +45,88 @@ namespace export \ TryFromList CompleteFromList DisplayHints Rehash \ PreviousWord CommandCompletion RemoveUsedOptions \ HostList ChannelId InChannelId OutChannelId \ Lindex Llength CompleteBoolean + +# set tclreadline::trace to 1, if you +# want to enable explicit trace calls. +# +variable trace + +# set tclreadline::trace_procs to 1, if you +# want to enable tracing every entry to a proc. +# +variable trace_procs + +if {[info exists trace_procs] && $trace_procs} { + ::proc proc {name arguments body} { + ::proc $name $arguments [subst -nocommands { + TraceText [lrange [info level 0] 1 end] + $body + }] + } +} else { ;# !$trace_procs + catch {rename ::tclreadline::proc ""} +} + +if {[info exists trace] && $trace} { + + ::proc TraceReconf {args} { + eval .tclreadline_trace.scroll set $args + .tclreadline_trace.text see end + } + + ::proc AssureTraceWindow {} { + variable trace + if {![info exists trace]} { + return 0 + } + if {!$trace} { + return 0 + } + if {![winfo exists .tclreadline_trace.text]} { + toplevel .tclreadline_trace + text .tclreadline_trace.text \ + -yscrollcommand { tclreadline::TraceReconf } + scrollbar .tclreadline_trace.scroll \ + -orient vertical \ + -command { .tclreadline_trace.text yview } + pack .tclreadline_trace.text -side left -expand yes -fill both + pack .tclreadline_trace.scroll -side right -expand yes -fill y + } else { + raise .tclreadline_trace + } + return 1 + } + + ::proc TraceVar vT { + if {![AssureTraceWindow]} { + return + } + upvar $vT v + if {[info exists v]} { + .tclreadline_trace.text insert end \ + "([lindex [info level -1] 0]) $vT=|$v|\n" + } + # silently ignore unset variables. + } + + ::proc TraceText txt { + if {![AssureTraceWindow]} { + return + } + .tclreadline_trace.text insert end \ + [format {%32s %s} ([lindex [info level -1] 0]) $txt\n] + } + +} else { + ::proc TraceReconf args {} + ::proc AssureTraceWindow args {} + ::proc TraceVar args {} + ::proc TraceText args {} +} #** # TryFromList will return an empty string, if # the text typed so far does not match any of the # elements in list. This might be used to allow @@ -429,21 +511,10 @@ regsub -all -- \" $line {\"} line regsub -all -- \{ $line {\{} line; # \}\} (keep the editor happy) return $line } -proc Trace {varT} { - if {![info exists ::tclreadline::Debug]} {return} - upvar $varT var - if {![info exists var]} { - puts $varT= - } else { - puts $varT=|$var| - } - # puts $var -} - #** # get the word position. # @return the word position # @note will returned modified values. # @sa EventuallyEvaluateFirst @@ -2402,11 +2473,12 @@ } 3 { if {![string length [Lindex $line $pos]]} { return [list \{ {}]; # \} } else { - return [DisplayHints ] + # return [DisplayHints ] + return [BraceOrCommand $text $start $end $line $pos $mod] } } } return "" } @@ -3222,10 +3294,18 @@ return [CompleteFromList ${text} [ToplevelWindows]] } } } } + +proc EventuallyInsertLeadingDot {text fallback} { + if {![string length ${text}]} { + return [list . {}] + } else { + return [DisplayHints $fallback] + } +} #** # TODO: shit. make this better! # @param text, a std completer argument (current word). # @param fullpart, the full text of the current position. @@ -3252,11 +3332,11 @@ # return [list ${pre} {}] } elseif {[regexp ${post} ${text}]} { - # finalize + # finalize, append the post and a space. # set diff \ [expr [CountChar ${fullpart} ${pre}] - [CountChar ${fullpart} ${post}]] for {set i 0} {${i} < ${diff}} {incr i} { append text ${post} @@ -3269,10 +3349,13 @@ } { set left {} set right ${text} } + # TraceVar left + # TraceVar right + # puts stderr \nleft=|$left| # puts stderr \nright=|$right| set exact_matches [MatchesFromList ${right} ${lst}] # TODO this is awkward. Think of making it better! # @@ -3293,11 +3376,11 @@ } return "" } proc complete(bind) {text start end line pos mod} { - switch -- $pos { + switch -- ${pos} { 1 { set widgets [WidgetChildren ${text}] set toplevels [ToplevelWindows] if {[catch {set toplevelClass [winfo class .]}]} { set toplevelClass "" @@ -3307,11 +3390,11 @@ Listbox Menu Menubutton Message Radiobutton Scale Scrollbar Text all } return [CompleteFromList ${text} \ - [concat $toplevels $widgets $toplevelClass $rest]] + [concat ${toplevels} ${widgets} ${toplevelClass} $rest]] } 2 { set modifiers { Alt Control Shift Lock Double Triple B1 B2 B3 B4 B5 Button1 Button2 Button3 Button4 Button5 @@ -3323,39 +3406,55 @@ Circulate Colormap Configure Deactivate Destroy Enter Expose FocusIn FocusOut Gravity Key KeyPress KeyRelease Leave Map Motion MouseWheel Property Reparent Unmap Visibility } - set sequence [concat $modifiers $events] + set sequence [concat ${modifiers} ${events}] return [CompleteListFromList ${text} \ [Lindex $line 2] ${sequence} < - >] } 3 { # return [DisplayHints {