英文:
In tclsh, [tab] will automatically execute the defined proc (with tclreadline)
问题
以下是您要翻译的部分:
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?"
英文:
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?
答案1
得分: 1
这部分内容的中文翻译如下:
原来,tclreadline
的内置完成处理程序执行脚本定义的过程来搜索子命令或合奏命令。然而,在存在捕获所有 args
的情况下,这只会在此“完成”尝试期间执行该过程:
观察:
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
目前,避免只在形式参数规范中使用“args”的过程。您可能想要提交一个问题报告。应该正确处理“args”情况。(我的直觉是完成服务应该只使用“info”内省来查找过程,而不是探索子命令或合奏命令,只有在像cget、configure等命令需要执行时才需要。)
英文:
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.)
答案2
得分: 0
根据 @mrcalvin 的回答,我尝试通过完成自动完成函数来解决这个问题,而且成功了!
对于 proc test [tab] 将不再执行它。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论