3

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.

  • Have you tried expand-file-name? – npostavs Apr 26 '17 at 19:49
  • 1
    You could also try load-file instead. – John Kitchin Apr 26 '17 at 23:04
5

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

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.