3

With the following init file, emacs chokes on the first line:

bash-4.3$ pwd
/Users/sean/.emacs.d

bash-4.3$ cat init.el 
(require 'use-package)
(use-package package)

bash-4.3$ emacs --version | head -n 1
GNU Emacs 24.4.1

However, when I run emacs 'normally' (with this init file) and perform the require manually, it succeeds. Why would this happen? What can I do to fix it that won't have me changing load-paths every time I update use-package?


It is interesting to note that, by specifying the load manually, no errors are reported:

bash-4.3$ emacs --batch -L init.el

However, starting emacs interactively shows the issue.

Drew
  • 75,699
  • 9
  • 109
  • 225
Sean Allred
  • 6,861
  • 16
  • 85
  • Not clear. You are changing the recipe on the fly here, so it's hard to answer you. And now you mention that you are **updating** library `use-package`? So this is not the ordinary `use-package.el`? Where is it? For `require` to work, the library needs to be in your `load-path` - that's the problem, AFAICT. – Drew Oct 26 '14 at 18:10
  • @Drew I'm sorry if I was unclear; I have in the past been seemingly forced to update load-paths by hand when I update packages with `package.el`. (Org goes from version `20140101` to `20140201`, for instance.) I obviously do not want to be updating my initialization file every time one of these updates occurs. This *is* the ordinary `use-package.el`, just thinking ahead to when it will be updated upstream :) – Sean Allred Oct 26 '14 at 18:15
  • Agreed, this is a duplicate. Unfortunately, I can't vote yet. – Sean Allred Oct 26 '14 at 18:23

2 Answers2

7

It is package.el (with package-initialize) that adds the subdirectories of .emacs.d/elpa to your load path; these are not loaded automatically. Since use-package is in this directory, emacs doesn't see it until it encounters (package-initialize).

(package-initialize)
(require 'use-package)

It would appear that (package-initialize) is called sometime after the initialization file has been loaded. More information on the initialization sequence can be found in the manual:


@Drew pointed out in a comment that

… now that there is package-enable-at-startup, with t as the default value, package-initialize does get called after loading your init file.

Sean Allred
  • 6,861
  • 16
  • 85
0

Library use-package.el is not in your load-path.

The -l command-line option expects a file name, not a library name. You need to use option -L.

See:

Drew
  • 75,699
  • 9
  • 109
  • 225
  • 1
    True, but this doesn't really answer the question. Start emacs interactively, then. – Sean Allred Oct 26 '14 at 17:57
  • How does it not answer the question? Did you try using `-L` and specifying the directory for `use-package.el`? Or did you try specifying the *absolute* file name for it with `-l`? – Drew Oct 26 '14 at 18:03
  • The question wasn't truly about `--batch` usage, it was about *interactive* usage. It's absolutely true that `use-package.el` isn't in my `load-path` when it processes `require`, but why does my `load-path` change before and after emacs processes my `init` file? Shouldn't it be calling `normal-top-level-add-subdirs-to-load-path` *before* it processes my initialization file, or is that done with `package-initialize`? – Sean Allred Oct 26 '14 at 18:08
  • It is done with `package-initialize` (as you have since found out). Or by updating `load-path` in your init file or using command-line option `-L` or in other code you load. Emacs doesn't guess where some library you `require` might be located. That's what `load-path` is for. – Drew Oct 26 '14 at 18:12
  • Yes, I understand that :) I just misunderstood the initialization sequence. I was lucky enough to come on to the emacs boat *after* `package.el` was distributed with it, so it's always had that essence of 'it just works'; I never stopped to think about *when* it was configured (i.e. which forms allow it) to work. Even after four years, I'm still learning :) – Sean Allred Oct 26 '14 at 18:15
  • All of this means that, somewhere *after* the init file has been loaded, `(package-initialize)` is called. That's the piece of information that lets the whole situation make sense. – Sean Allred Oct 26 '14 at 18:16
  • You say: *somewhere* ***after*** *the init file has been loaded, `(package-initialize)` is called.* No, you can invoke `(package-initialize)` in your init file. That's what people usually do. – Drew Oct 26 '14 at 18:21
  • 1
    OK, yes, now that there is `package-enable-at-startup`, with `t` as the default value, `package-initialize` does get called after loading your init file. But you can also call it yourself, in the init file. – Drew Oct 26 '14 at 18:25
  • Sorry again for all the confusion :) – Sean Allred Oct 26 '14 at 18:26