8

Let's say I have my own elisp code in ~/bin/hello.el.

The ~/.emacs file has the following code to run hello.el at startup.

(add-to-list 'load-path "~/bin/elisp")
(require 'hello)

But, I get the following error message.

Warning (initialization): An error occurred while loading `/Users/smcho/.emacs':

error: Required feature `hello' was not provided

What's wrong with this?

Community
  • 1
  • 1
prosseek
  • 182,215
  • 215
  • 566
  • 871
  • Incidentally, you might consider reorganizing your code: instead of a ~/.emacs, Emacs will automatically find and load ~/.emacs.d/init.el, so you can put all your elisp inside ~/.emacs.d. – sanityinc Jul 28 '10 at 09:17
  • @sanityinc : It's different from my understanding. Could you check this? – prosseek Jul 28 '10 at 13:10
  • Yes, it's different, but I'm not sure in which way you mean. Here's my config (with *no* ~/.emacs), in case it helps: http://github.com/purcell/emacs.d – sanityinc Jul 28 '10 at 18:42

3 Answers3

16

Does hello.el provide hello? It should start with (provide 'hello). See the elisp manual. Does (load "hello.el") work?

deinst
  • 18,402
  • 3
  • 47
  • 45
  • (provide 'hello) should be added for the first line of the elisp code. Thanks. – prosseek Jul 28 '10 at 01:55
  • What's the difference between (require) and (load)? – prosseek Jul 28 '10 at 01:56
  • (load) loads the file. (require) loads a feature when it is used. A file can provide more than one feature, but I do not think that the code in the file is evaluated until the feature is used (don't quote me on the exact semantics). Require is essentially saying I'm going to need this, figure out where it is and have it ready if I need it. – deinst Jul 28 '10 at 02:00
  • 3
    Actually the convention is that (provide 'feature) should be the last line of an Emacs Lisp source file... – Bozhidar Batsov Jul 28 '10 at 08:54
3

You have to put something like that in your LISP code:

(provide 'hello)

Vlad
  • 9,180
  • 5
  • 48
  • 67
1

If you added ~/bin/elisp to your load-path, then Emacs won't find a file in ~/bin. In this case, Emacs would try to load ~/bin/elisp/hello.el, and if it can't find that, then it will look for a file named hello.elc or hello.el (in that order) in the other parts of your load-path.

Also, as others have mentioned, hello.el needs to have a (provide 'hello) in it (typically at the end).

haxney
  • 3,358
  • 4
  • 30
  • 31