Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Emacs Lisp function is to `require` as `autoload` is to `load`?

Tags:

emacs

elisp

I am trying to program GNU Emacs 23 to issue require commands lazily, on demand, instead of up front in my .emacs file. If I wanted to delay the execution of a load command, I could use autoload. But require and load take different sorts of arguments.

Is there a predefined function that does for require the same job that autoload does for load? And if not, what tools would people recommend that I use to roll my own?

like image 840
Norman Ramsey Avatar asked Jan 06 '14 15:01

Norman Ramsey


1 Answers

There is not difference between require and load with regards to autoload. require is just a frontend to load, which more or less comes down to:

(defun require (feature &optional filename noerror)
  (unless (featurep feature)
    (let ((filename (or filename (symbol-name feature))))
      (load filename noerror))))

As you can see, the symbol name given to require is equal to the filename given to load. As a matter of fact, the first (require 'foo) evaluated in an Emacs session is equivalent to (load "foo").

Thus, you can just use (auto-load 'foo-function "foo") for foo-function from the library foo, that you can load with (require 'foo).

like image 161
lunaryorn Avatar answered Sep 28 '22 02:09

lunaryorn