8

I have test code that wants to require some utility code in the same directory. I would prefer to not update the load-path, as most of the time, I do not want me or any other user who has checked out this code to be looking in this directory.

It seemed that (require 'utils "./utils.el") should work, but this gives me an error:

file-remote-p: Cannot open load file: No such file or directory, ./utils.el

Is there a better way than something like

(let ((load-path (append (list (file-name-directory (buffer-file-name))))
                         load-path)))
    (require 'utils))

I also cannot specify an absolute path, as the path may be different when other users check out the repository.

Troy Daniels
  • 487
  • 2
  • 13

1 Answers1

11

Like John Kitchin pointed out, load-file does what you want. For example:

(setq my-utils-file "utils.el")
(load-file 
  (expand-file-name my-utils-file
                    (file-name-directory (buffer-file-name))))
Heikki
  • 2,961
  • 11
  • 18