Index: TODO ================================================================== --- TODO +++ TODO @@ -1,10 +1,10 @@ /* ================================================================== FILE: "/diska/home/joze/src/tclreadline/TODO" - LAST MODIFICATION: "Thu Sep 2 04:06:52 1999 (joze)" + LAST MODIFICATION: "Mon Sep 6 08:44:35 1999 (joze)" (C) 1998, 1999 by Johannes Zellner, $Id$ --- tclreadline -- gnu readline for tcl @@ -33,16 +33,13 @@ verwenden, um nur eine begrenze Zahl zu schreiben. + wenn nur ein array Element von a vorliegt, wird trotzdem nur auf $a( completed. --> ändern. - + custom completers: - prüfen, ob ein completer für eine Funktion da ist ... - z.B.: `set' könnte für alle Variblennamen completen. - + history_expansion mit (z.B. !$). + ist $bla das erste Wort eines Befehls, so sollte vor der completion die Variable ersetzt werden, um den completer herauszufinden. + den script completern den level mitgeben ? + Index: tclreadlineSetup.tcl.in ================================================================== --- tclreadlineSetup.tcl.in +++ tclreadlineSetup.tcl.in @@ -1,8 +1,8 @@ #!/usr/locanl/bin/tclsh # FILE: "/diska/home/joze/src/tclreadline/tclreadlineSetup.tcl.in" -# LAST MODIFICATION: "Sat Sep 4 07:35:09 1999 (joze)" +# LAST MODIFICATION: "Mon Sep 6 08:50:52 1999 (joze)" # (C) 1998, 1999 by Johannes Zellner, # $Id$ # --- # # tclreadline -- gnu readline for tcl @@ -334,11 +334,12 @@ return ${part} } proc SubCmd {start line} { set depth 0 - for {set i $start} {$i > 0} {incr i -1} { + # puts stderr SubCmd + for {set i $start} {$i >= 0} {incr i -1} { set c [string index $line $i] if {{;} == $c} { incr i; # discard command break character return [list [expr $start - $i] [string range $line $i end]] } elseif {{]} == $c} { @@ -409,20 +410,31 @@ regsub -all -- \" $line {\"} line regsub -all -- \{ $line {\{} line; # \}\} (keep the editor happy) return $line } +#** +# get the word position. +# @return the word position +# @note will returned modified values. +# @sa EventuallyEvaluateFirst +# @date Sep-06-1999 +# # % p # % bla put $b # % put $b # part == put # start == 0 # end == 3 # line == "put $b" # [PartPosition] should return 0 # -proc PartPosition {part start end line} { +proc PartPosition {partT startT endT lineT} { + + upvar $partT part $startT start $endT end $lineT line + EventuallyEvaluateFirst part start end line + # puts stderr "(PartPosition) line\[start\]=[string index $line $start]" # puts stderr "(PartPosition) part=|$part|" incr start -1 if {"\"" == [string index $line $start]} { incr start -1 @@ -637,10 +649,46 @@ set namespaces "" } } return [string trim "${matches} ${namespaces}"] } + +#** +# check, if the first argument starts with a '[' +# and must be evaluated before continuing. +# NOTE: eventually modifies all arguments. +# DATE: Sep-06-1999 +# +proc EventuallyEvaluateFirst {partT startT endT lineT} { + # return; # disabled + upvar $partT part $startT start $endT end $lineT line + set line [string trim ${line}] + + set char [string index ${line} 0] + if {{[} != ${char} && {$} != ${char}} {return} + + set pos 0 + while {-1 != [set idx [string first {]} ${line} ${pos}]]} { + set cmd [string range ${line} 0 ${idx}] + if {[info complete ${cmd}]} { + break; + } + set pos [expr ${idx} + 1] + } + + if {![info exists cmd]} {return} + if {![info complete ${cmd}]} {return} + set cmd [string range ${cmd} 1 [expr [string length ${cmd}] - 2]] + set rest [string range ${line} [expr ${idx} + 1] end] + + if {[catch [list set result [string trim [eval ${cmd}]]]]} {return} + + set line ${result}${rest} + set diff [expr [string length ${result}] - ([string length ${cmd}] + 2)] + incr start ${diff} + incr end ${diff} +} # if the line entered so far is # % puts $b # part == $b # start == 5 @@ -701,21 +749,20 @@ } elseif {"" != [set sub [SubCmd $start $line]]} { set new_start [lindex $sub 0] set new_end [expr $end - ($start - $new_start)] set new_line [lindex $sub 1] # puts stderr "(SubCmd) $new_start $new_end $new_line" - return \ - [ScriptCompleter $part $new_start $new_end $new_line] - } elseif {0 == \ - [set pos [PartPosition $part $start $end $line]]} { + return [ScriptCompleter $part $new_start $new_end $new_line] + } elseif {0 == [set pos [PartPosition part start end line]]} { # puts stderr "(PartPosition) $part $start $end $line" # set matches [array names known_cmds "[string trim ${part}]*"] set all [CommandCompletion ${part}] #puts \nmatches=$matches\n return [Format $all $part] } else { # try to use $pos further ... + # puts stderr |$line| if {"." == [string index [lindex ${line} 0] 0]} { set alias WIDGET } else { set alias [lindex [QuoteQuotes ${line}] 0] } @@ -1690,11 +1737,13 @@ forget - parent { return [AttemptFromList ${mod} $space_matches] } code { return "" } current {} export { return [MenuFromList ${mod} -clear ?pattern?] } - import { return [MenuFromList ${mod} -force] } + import { + return [MenuFromList ${mod} "-force $space_matches"] + } origin { if {![llength ${mod}]} { return } } qualifiers - tail { if {![llength ${mod}]} { return } } which { return [MenuFromList ${mod} { -command -variable }] } @@ -1709,13 +1758,13 @@ eval { if {![llength ${mod}]} { return ?arg? } } inscope { if {![llength ${mod}]} { return ?arg? } } parent {} code {} current {} - export { return [MenuFromList ${mod} ?pattern?] } + export - forget - - import { if {![llength ${mod}]} { return ?pattern? } } + import { return [Menu ?pattern?] } origin {} qualifiers {} tail {} which { return [MenuFromList $text { -command -variable }] } @@ -2086,11 +2135,11 @@ return "" } proc complete(update) {text start end line pos mod} { if {1 == $pos && ![llength ${mod}]} { - return ?idletasks? + return idletasks } return "" } proc complete(uplevel) {text start end line pos mod} { @@ -2230,11 +2279,11 @@ #puts \nprev=|$prev| #puts switches=|$options(switches)| #puts found=[lsearch -exact ${prev} $options(switches)] if {-1 != [set found [lsearch -exact $options(switches) ${prev}]]} { if {![llength ${mod}]} { - return [lindex $options(value) ${found}] + return [list "[lindex $options(value) ${found}]"] } } else { return [AttemptFromList ${mod} $options(switches)] } }