Version 8 of info complete

Updated 2011-11-14 20:33:50 by dkf
info complete command

Returns 1 if command is a complete Tcl command in the sense of having no unclosed quotes, braces, brackets or array element names, If the command doesn't appear to be complete then 0 is returned. This command is typically used in line-oriented input environments to allow users to type in commands that span multiple lines; if the command isn't complete, the script can delay evaluating it until additional lines have been typed to complete the command.

RS: Could it be that info complete can be used generally to check whether a string can be parsed as a list? I used to use

 expr {![catch {llength $x}]}

for that purpose...

The answer: "no". It is possible for a string to be "info complete" but not be a list. To wit:

  % set foo "{this is a test}{more stuff}"
  {this is a test}{more stuff}
  % llength $foo
  list element in braces followed by "{more" instead of space
  % info complete $foo
  1

AMG: It seems odd to me that [info complete] doesn't return false when its argument has a trailing backslash (or an odd number of trailing backslashes), since that's normally used to signify that the command is continued onto the next line. An interactive shell relying on [info complete] likely has to implement its own check for trailing backslashes, e.g.:

proc complete {script} {
    expr {[info complete $script] && [regexp {(?:^|[^\\])(?:\\\\)*$} $script]}
}