Closed dmalyuta closed 2 years ago
Why do you guys compile init.el while using use-package?
Is one not supposed to compile init.el
when using use-package
? Is that functionality not possible?
of course it's possible, I'm asking of curiosity, since to my experience it doesn't speed up loading at all, so I can't imagine why one may want to do it
I guess my question is more out of curiosity for why this error comes up, and whether it is a symptom of me doing something wrong in my init.el
Does
(eval-when-compile
(require 'use-package))
help?
Works for me, at least from dired
If I use the following init.el
:
;; MELPA
(require 'package)
(setq package-enable-at-startup nil)
(setq package-check-signature nil)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(add-to-list 'package-archives '("elpy" . "https://jorgenschaefer.github.io/packages/"))
;; boostrap 'use-package'
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(eval-when-compile
(require 'use-package))
(use-package windmove
;; move cursor between windows
:demand
:bind
(("C-<left>" . windmove-left)
("C-<right>" . windmove-right)
("C-<up>" . windmove-up)
("C-<down>" . windmove-down)))
Then I get the following byte compilation error:
$ emacs --batch --eval '(byte-compile-file "init.el")'
In toplevel form:
init.el:13:13:Error: Cannot open load file: No such file or directory, use-package
Please see @a13 comment.
Does
(eval-when-compile (require 'use-package))
help?
I did add the suggested statement in my last reply... There is an error Cannot open load file
, like I posted.
Looks like a load-path
issue
It seems the issue goes away if I compile from inside Emacs using M-x byte-compile-init-dir
. How come the terminal version then isn't working?
Fri Aug 28 11:13:11 BST 2020
init.el:13:13:Error: Cannot open load file: No such file or directory, use-package
As @a13 mentioned, use-package
is not found in your load-path
.
To show this, add the following before the eval-when-compile
expression:
(message "current load-path: %s" load-path)
and run emacs --batch -l init.el
You'll see that use-package
is not in the load-path
.
To include it, (package-initialize)
needs to be run.
Include this in the eval-when
expression:
(eval-when-compile
(package-initialize)
(require 'use-package))
There should be no problems now when running the batch command.
As others have explained, this is a load-path
issue. If use-package was installed with package-install
, things should work automatically. If using an older version, try adding (package-initialize)
to your init file.
The beginning of my
~/.emacs.d/init.el
file looks like this:I am trying to byte compile my
init.el
file. I execute the following in the terminal, sinde the~/.emacs.d/
directory:The output is:
Basically, the very first key binding definition fails... and there is also some sort of warning about a free variable. How do I properly byte-compile the
init.el
file - even for the above very simple example (imagine there's nothing else to theinit.el
file)?