load-file
needs an absolute file name. If you don't give it an absolute path, it will have to generate one based on the current buffer's default-directory
which isn't going to be what you want:
$ cd /
$ emacs -Q --batch --eval "(load-file \"foo.el\")"
Cannot open load file: No such file or directory, /foo.el
$ cd /tmp
$ emacs -Q --batch --eval "(load-file \"foo.el\")"
Cannot open load file: No such file or directory, /tmp/foo.el
I thought emacs would look in emacs home directory (~/.emacs.d/) to find files.
You don't want that either. Emacs will not look in ~/.emacs.d
by default when loading lisp files (and see Warning message about load-path. or https://stackoverflow.com/q/24779041 regarding the fact that Emacs will complain if you try to make it do so).
In code, you would usually use either (load "foo")
or (require 'foo)
to load a foo.el[c]
library with Emacs looking for it in the directories listed in the load-path
variable.
I suggest reading:
- C-hig
(emacs)Lisp Libraries
- C-hig
(elisp)How Programs Do Loading
- C-hf
require