2
my_tcl 7 % proc test args {puts "wwwww"} 
my_tcl 8 % test [tab]wwwww
wwwww
[tab]
wwwww
wwwww

.gitignore README.md .vscode/  ...

my_tcl 8 % test 

After two tabs the proc runs four times and then returns to the position before the tab. How should I avoid this problem?

piper
  • 79
  • 4
  • I *suspect* it is looking for information it can use to do autocompletion with (by a specific kind of error message), but isn't getting it. But I don't know. (There isn't a general grammar that it can use instead.) – Donal Fellows Apr 13 '23 at 11:27
  • Is this `tclreadline`'s bundled `tclshrl` running? – mrcalvin Apr 14 '23 at 20:16

2 Answers2

1

It turns out that tclreadline's built-in completion handler executes script-defined procs to search for sub- or ensemble commands. However, in presence of the catch-all args, this will simply execute the proc during this "completion" attempt:

Watch:

tclsh8.6 [/tmp] proc test {a b c} {puts "www"}
tclsh8.6 [/tmp] test[TAB] 
<a>
tclsh8.6 [/tmp] proc test {args} {puts "www"}
tclsh8.6 [/tmp] test[TAB] www
www

For now, avoid procs with only "args" in their formal parameter spec. You might want to file a ticket . The "args" case should be handled properly. (My gut feeling is that the completion service should only use "info" introspection for procs, without exploring for sub- or ensemble commands, with execution only necessary for commands like cget, configure etc.)

mrcalvin
  • 3,291
  • 12
  • 18
0

Based on @mrcalvin's answer, I tried to solve this problem by completing the auto-completion function, and it worked!

namespace eval tclreadline { proc complete(test) {text start end line pos mod} {return} }

For proc test [tab] will no longer execute it.

piper
  • 79
  • 4