从原始命令中查找重命名的命令



有没有tcl函数/proc/api可以用来获取所有重命名的命令?

我的意思是:

假设有人在包含的文件中的某个地方写下以下语句:

rename -force command tmp_command

在这一行之后,没有"command"的命令,相反,"tmp_command"是新命令。

如果我在需要的地方只有"command"名称,我如何才能重命名命令"tmp_command"。

Tcl不记得它为您所做的重命名,但您可以通过跟踪对rename的调用来创建自己的重命名(在左侧,这样您就只能跟踪成功的调用(:

trace add execution rename leave rememberRename
proc rememberRename {cmd code args} { # see the docs for the full list of callback arguments
if {$code == 0} {
lappend ::renames [lrange $cmd 1 end]
}
}
# demo code
proc foo x y
rename foo bar
rename bar grill
rename grill foo
puts $renames
# {foo bar} {bar grill} {grill foo}

注意:这不会跟踪命令的所有删除

最新更新