Posted to tcl by Poor Yorick at Wed Feb 05 02:49:43 GMT 2014view raw

  1. #! /bin/env tclsh
  2.  
  3. proc alias {alias target} {
  4. set fulltarget [uplevel [list namespace which $target]]
  5. namespace eval [namespace qualifiers $fulltarget] \
  6. [list namespace export [namespace tail $fulltarget]]
  7. set newcmd [namespace eval [info cmdcount] [string map [
  8. list @{alias} [list $alias] @{fulltarget} [list $fulltarget] ] {
  9. namespace import @{fulltarget}
  10. rename [namespace tail @{fulltarget}] @{alias}
  11. ::namespace export @{alias}
  12. ::namespace which @{alias}
  13. }]]
  14. uplevel [list namespace import $newcmd]
  15. uplevel [list trace add command $fulltarget delete [list apply [list {stash args} {
  16. namespace delete [namespace qualifiers $stash]
  17. }] $newcmd]]
  18. }
  19.  
  20. proc proc1 args {}
  21. alias newproc proc1
  22. proc proc1 {} {}
  23.