17

I went through the documentation of both the function but they don't seem to shed much information. What is the actual difference between them apart from the fact that load is a built-in function in C source code whereas load-file is an interactive list compiled function.

What is the recommended function to use in init.el since both seem to be doing the same job ?

  • 2
    What part of the documentation for this was not clear in this regard? Consider reporting the doc problem, if you really think there is one: M-x report-emacs-bug. As @shosti says, and as the doc clearly indicates, load-file "does not use load-path, and does not append suffixes", for two important differences. – Drew Nov 9 '14 at 2:15
  • See also the Emacs manual, node Lisp Libraries. – Drew Mar 24 '17 at 23:19
14

There are several ways to load Lisp files in Emacs:

  1. load-file takes a literal filename (relative or absolute) and loads the code. Example: (load-file "/usr/local/share/site-lisp/foo.el")
  2. load is like load-file, except that it is more flexible--you can leave out the extension and it will automatically load the "elc" or "el" file as appropriate.
    It also looks into the load-path directories.
    Example: (load "foo") (if "foo.el" is in the current directory or in the load-path").
  3. load-library is an interactive interface for load.
  4. require is similar to load, except it prevents the file from being loaded more than once (it also requires a corresponding provide statement at the end of the file in question). Example: (require 'foo)
  • 3
    Your require example is a load example. ;-) – Drew Nov 9 '14 at 2:10
  • The load-file example uses load. :) – itsjeyd Nov 9 '14 at 9:57
  • 2
    Sorry to say 2 and 3 were wrong. :-) load does look into the load-path. – Malabarba Nov 10 '14 at 11:51
  • @Malabarba Oops, you're right, thanks for the correction. That is more confusing than I thought. – shosti Nov 10 '14 at 15:58
8

load-file and load-library are commands for interactive use (where the main difference is in the initial content of the prompt).

load is the underlying function to use when you write Elisp (such as in your .emacs).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.