1

I started a new question on this topic yesterday, and deleted it because I thought I had it solved. No, I'm still confused about exactly how require works. In my situation I have a file calctest.el in a path that load-path sees. Here is the simple file:

(defun calctest ()
  (calc-eval "deg(37@ 26' 36.42\")"))
(provide 'calctest)

Now, if I call (require 'calctest) in the scratch buffer, I get an error:

Required feature `calctest' was not provided". . .

This is even after a successful (load-library "calctest") and a test to see if it is loaded

(calctest) ==>
"37.44345"

But if I do a load-file on calctest.el, then do (require 'calctest) it "sees" it and "loads" it (again?). Why will a require not simply load my calctest? What am I missing here?

2 Answers 2

4

But if I do a load-file on calctest.el, then do (require 'calctest) it "sees" it and "loads" it (again?).

No, the key point is that it doesn't load it.

When you load-file your calctest.el library, the (provide 'calctest) form is evaluated and remembered, which in turn satisfies any subsequent call to (require 'calctest) -- regardless of whether or not it would be able to load that library itself.

require is essentially just a load wrapper which avoids re-loading libraries -- it doesn't care (or even know) whether or not they were originally loaded by another call to require; just whether (provide 'FEATURE) has been evaluated at some point (in which case it loads nothing).

It very much sounds as if your calctest.el wasn't in your load-path when you were originally testing this.

2
  • If I change a library after having done a require on it, I need it reloaded. How can I get require to redo it? Maybe see my similar question here.
    – 147pm
    Commented Dec 7, 2015 at 1:17
  • You can either call unload-feature first, or else simply load it with a non-require function. Personally I'd be disinclined to unload the feature in this instance unless I was testing the FEATURE-unload-function support. load-library or load-file are typically all I need when re-loading modified code.
    – phils
    Commented Dec 7, 2015 at 2:05
1

Why will a require not simply load my calctest? What am I missing here?

Perhaps the path and a restart. require works only if the package is in the load-path. require also does some filename guessing based on the feature name. Restart Emacs may be required to trigger the re-loading.

1
  • I'm probably doing something wrong, but what I don't know. Yes, now it appears to be working -- without needing loads of any sort.
    – 147pm
    Commented Dec 6, 2015 at 19:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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