home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 September (IDG) / Sep99.iso / Shareware World / Utilities / Text Processing / Alpha / Tcl / Packages / smarterSource.tcl < prev    next >
Encoding:
Text File  |  1999-04-13  |  4.3 KB  |  106 lines  |  [TEXT/ALFA]

  1. ## -*-Tcl-*- (install)
  2.  # ###################################################################
  3.  #  Vince's Additions - an extension package for Alpha
  4.  # 
  5.  #  FILE: "smarterSource.tcl"
  6.  #                                    created: 18/10/95 {6:00:07 pm} 
  7.  #                                last update: 13/4/1999 {8:23:18 pm} 
  8.  #  
  9.  #  Files in PREFS are passed through unchanged.  Simplified proc.
  10.  #  Interacts ok with package rebuilding.
  11.  # ##################################################################
  12.  ##
  13.  
  14. ## 
  15.  # VMD May'95-Oct'97: <darley@fas.harvard.edu>
  16.  # 
  17.  # Changed default directory to the the alpha preferences directory. 
  18.  # Changed extension to '+' rather than 'bullet' (option-8) because of
  19.  # ascii transmission problems - lots of people have a non-working version
  20.  # of this file.
  21.  # 
  22.  # Passes through 'tclIndex(x)' and 'prefs.tcl' unchanged.
  23.  # 
  24.  # Renamed this file to 'smarterSource.tcl', originally just to
  25.  # differentiate it from the old crippled versions.
  26.  # 
  27.  # IMPORTANT: Fixed the script so that it works with path names containing
  28.  # spaces.  Changed all 'uplevel #0' to 'uplevel 1'.
  29.  # 
  30.  ##
  31.  
  32. #############################################################################
  33. # BASED UPON 'smartSource.tcl':
  34. #
  35. # Copyright 1994, Robert Browning (osiris@cs.utexas.edu): This code is made 
  36. # freely available to anyone who can find a use for it. Consider it part of my
  37. # thanks to all those who have contributed to the freeware and shareware base.
  38. # (Especially Pete Keheler, without which this code would be pretty useless).
  39. # === Modifications by Vince, May 1995 ===
  40. #############################################################################
  41.  
  42. alpha::extension smarterSource 0.1.3 {
  43. if {![string length [info commands __ssource]]} {
  44.  
  45. lunion varPrefs(Files) tclExtensionsFolder
  46. # location in which smarterSource looks for extension files
  47. newPref earlyfolder tclExtensionsFolder "$PREFS"
  48.  
  49.     rename source __ssource
  50. }
  51. ;proc source {filename} {
  52.     global tclExtensionsFolder PREFS
  53.     set justName [file tail "$filename"]
  54.     # we don't want to over-ride these files
  55.     if { [lsearch -exact {tclIndex tclIndexx prefs.tcl} $justName] != -1 \
  56.       || [string match [file join ${PREFS} *${justName}] $filename] } {
  57.     return [uplevel 1 [list __ssource $filename]] 
  58.     }
  59.     
  60.     set overrideFile [file join ${tclExtensionsFolder} ${justName}]
  61.     if {[file exists $overrideFile]} {
  62.     set returnVal [uplevel 1 [list __ssource $overrideFile]]
  63.     } else {
  64.     set returnVal [uplevel 1 [list __ssource $filename]]
  65.     }
  66.     
  67.     set extensionFiles [glob -nocomplain \
  68.       "[file root $overrideFile]+*[file extension ${justName}]"]
  69.     
  70.     foreach extensionFile $extensionFiles {
  71.     set returnVal [uplevel 1 [list __ssource $extensionFile]]
  72.     }
  73.     return "$returnVal" 
  74. }
  75. # end package block
  76. } help {
  77.     This package implements a replacement source command. It is intended to help
  78.     make the process of augmenting Alpha's code base with your own changes less
  79.     awkward, especially in the face of program updates. It also makes it so
  80.     that you no longer have to source files containing procedures that you want
  81.     to override in your UserStartup file.
  82.     
  83.     Basically, you designate a directory to contain your files. Then
  84.     any time Alpha is instructed to source a file named filename.tcl, it will
  85.     first look in the directory you have designated, and if there is a file of
  86.     the identical name there (i.e. filename.extension) it will source that file
  87.     instead of the original one specified. If there are any files named
  88.     filename+*.extension it will source those in the order returned by glob after
  89.     either the original filename.extension or the replacement has been sourced.
  90.     
  91.     For example, if your TclExtensions directory contains files named
  92.     latex+1.tcl and latex+2.tcl, then whenever you try to open a latex file
  93.     Alpha will first source the standard latex.tcl file, then latex+1.tcl, then
  94.     latex+2.tcl. If there was also a file named latex.tcl in the TclExtensions
  95.     directory then that file would be sourced in place of the standard
  96.     latex.tcl, then latex+1.tcl, then latex+2.tcl.
  97.     
  98.     You may just want to use filename+.extension for a single extension file.
  99.     
  100.     Note that latex+10.tcl would be sourced _before_ latex+9.tcl, so you
  101.     may wish to use latex+01.tcl ... latex+99.tcl to make things clearer.
  102. }
  103.  
  104.