Hello,
I have a tcl extension that logs all commands entered by the user in
interactive mode into a replay script. The idea is that the user will
be able to source the replay script. This works nicely as long as
the commands entered in interactive mode are spelled out completely.
However, in interactive mode, auto-completion allows the user to enter
abbreviated (but unambiguous) commands, but logging these results in
a replay script that cannot be sourced because tcl_interactive is 0 in
non-interactive mode.
My question is if there is a Tcl function/utility that can auto-
complete a command string entered by the user?
For example:
user enters:
pu [lind [lis a b c] 0]
replay script should contain:
puts [lindex [list a b c] 0]
Thanks,
Soren Soe.
|
|
0
|
|
|
|
Reply
|
stsoe
|
9/23/2010 6:38:47 PM |
|
On Sep 23, 12:38=A0pm, stsoe <st...@gonsoe.com> wrote:
> Hello,
>
> I have a tcl extension that logs all commands entered by the user in
> interactive mode into a replay script. =A0The idea is that the user will
> be able to source the replay script. =A0 =A0This works nicely as long as
> the commands entered in interactive mode are spelled out completely.
> However, in interactive mode, auto-completion allows the user to enter
> abbreviated (but =A0unambiguous) commands, but logging these results in
> a replay script that cannot be sourced because tcl_interactive is 0 in
> non-interactive mode.
>
> My question is if there is a Tcl function/utility that can auto-
> complete a command string entered by the user?
> For example:
>
> user enters:
> pu [lind [lis a b c] 0]
>
> replay script should contain:
> puts [lindex [list a b c] 0]
>
> Thanks,
> Soren Soe.
While I'm not familiar with a command or extension to auto-complete a
command string, it seems to me that you could accomplish your
objective using some [unknown] magic, along the following lines:
rename unknown _original_unknown
proc unknown {args} {
set command [lsearch -all -inline -glob [info commands] [lindex
$args 0]*]
if {[llength $command] =3D=3D 1} {
return [uplevel 1 [list $command {*}[lrange $args 1 end]]]
} else {
return [uplevel 1 [list _original_unknown {*}$args]]
}
}
|
|
0
|
|
|
|
Reply
|
Aric
|
9/23/2010 7:42:51 PM
|
|