从原始命令中查找重命名的命令
Find renamed command from original command
是否有任何 tcl function/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}
注意:这不会跟踪命令的所有删除。
是否有任何 tcl function/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}
注意:这不会跟踪命令的所有删除。