23

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 ?

Sibi
  • 3,603
  • 2
  • 22
  • 35
  • 2
    What part of [the documentation for this](https://www.gnu.org/software/emacs/manual/html_node/elisp/How-Programs-Do-Loading.html#How-Programs-Do-Loading) 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 09 '14 at 02:15
  • See also the Emacs manual, node [Lisp Libraries](http://www.gnu.org/software/emacs/manual/html_node/emacs/Lisp-Libraries.html). – Drew Mar 24 '17 at 23:19

2 Answers2

24

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)
Malabarba
  • 22,878
  • 6
  • 78
  • 163
shosti
  • 5,048
  • 26
  • 33
10

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).

Stefan
  • 26,154
  • 3
  • 46
  • 84
  • 2
    :D Your answer exactly explains the suggestions in [*The GNU Emacs FAQ*](https://www.gnu.org/software/emacs/manual/html_node/efaq/Evaluating-Emacs-Lisp-code.html): “You can use `M-x` `load-file` to have Emacs evaluate all the Lisp forms in a file. (To do this **from Lisp** use the function `load` **instead**.)” – shynur Feb 17 '23 at 22:09