;; autoload.kl
;; an error-corrector to automagically load undefined variables & funcs
;; error corr can return:
;; :nil nothing done
;; :true nothing done, but bypass rest
;; <expr> make error return normally <expr>

(if (not (boundp 'autoload:corrector))
  (put *error-correctors* -1 'autoload:corrector)
)

(defun autoload:corrector (errorcode &rest data &aux
    (variable (getn data 0))		;the undefined symbol triggering error
    (result :nil)
    (*load-extensions* '(".kl"))
  )
  (if (or (= errorcode 'Errors:UndefinedVariable)
      (= errorcode 'Errors:UndefinedFunction)
    )
    (if (and (typep variable Atom)
	(find-file variable)
      )
      (progn
	(load variable)
	(if (boundp variable) (setq result (eval variable)))
      )
    )
  )
  result
)

