Reputation: 87
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?
Upvotes: 2
Views: 146
Reputation: 87
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.
Upvotes: 0
Reputation: 3434
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.)
Upvotes: 1