home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / mutt / autoload.mut < prev    next >
Lisp/Scheme  |  1988-10-05  |  2KB  |  45 lines

  1.   ;; autoload.mut : Delayed file loading.
  2.   ;; Autoloading files means files are not loaded until they are used.  This
  3.   ;;   can result in smaller init files and faster startup times.
  4.   ;; (autoload function-name file-name)
  5.   ;;   When function-name is called, file-name is loaded and a call is again
  6.   ;;     made to function-name.  file-name MUST have redefined function-name
  7.   ;;     (or you will find your self in a infinite loop).
  8.   ;; (autoload-with-keypress file-name)
  9.   ;;   Same as autoload but the key that called the function is redone.
  10.   ;;   file-name MUST rebind the key or you will load forever.
  11.   ;;   You would use this function over autoload when several keys are bound
  12.   ;;     to functions rebound in file-name.
  13.   ;; Notes:
  14.   ;;   The function that calls autoload MUST be late bound else autoload
  15.   ;;     will be called every time the function is called.  bind-to-key is
  16.   ;;     always later bound.  For function calls use:
  17.   ;;     (floc "function-to-be-autoloaded" args) or
  18.   ;;     (floc "function-to-be-autoloaded" ()) if no args.
  19.   ;;   Autoloaded functions can take arguments - the args after fcn-name and
  20.   ;;     file-name are passed to the autoloaded function (if they are
  21.   ;;     passed to autoload:  use (push-args) or push them explictly).
  22.   ;; Examples:
  23.   ;;   (defun foo { (floc "bar" 1 "two" 3) })
  24.   ;;   (defun bar { (autoload "bar" "bar.mco" (push-args 0)) })
  25.   ;;    Whenever foo or bar is called, bar.mco will loaded and bar called.
  26.   ;;      If foo is called, bar is called with the arg list: 1 "two" 3.
  27.   ;; C Durland
  28.  
  29. (defun
  30.   autoload (string fcn-name file-name) HIDDEN
  31.   {
  32.     (if (load file-name)
  33.       (floc (fcn-name) (push-args 2))
  34.       (msg "autoload: Could not load " file-name)
  35.     )
  36.   }
  37.   autoload-with-keypress (string file-name) HIDDEN
  38.   {
  39.     (if (load file-name)
  40.       (exe-key (key-pressed))
  41.       (msg "autoload: Could not load " file-name)
  42.     )
  43.   }
  44. )
  45.