Use-package: void variable error while using byte-compiled init files

Created on 12 Mar 2017  路  3Comments  路  Source: jwiegley/use-package

Hi,

I was trying to changing my init files into use-package forms, and everything was fine.
Then I was thinking of speeding up the loading process by byte compiling every file under "~/.emacs.d/settings" directory (the directory I place all the init files), so I did.
However I got a problem while loading some .elc file, "emacs --debug-init" gives:

Debugger entered--Lisp error: (void-variable personal-keybindings)
  add-to-list(personal-keybindings (("C-/") undo-tree-undo undo))

This is strange because if I load .el instead of .elc then everything works.
Also if I use the old require-and-define-key way instead of use-package, the problem disappears.

I am using snippet below to automatically load my file:

(mapc 'load (directory-files "~/.emacs.d/settings/" t "^[a-zA-Z0-9].*.elc$"))

Code snippet that causes the problem:

(use-package undo-tree
  :init
  ;; Show diffs when browsing through the undo tree
  (setq undo-tree-visualizer-diff t)
  ;; Don't show relative times in the undo tree visualizer
  (setq undo-tree-visualizer-timestamps nil)
  ;; Don't save history to a file
  (setq undo-tree-auto-save-history nil)

  :bind 
  ("C-/" . undo-tree-undo)
  ("C-?" . undo-tree-redo)
  ("C-x u" . undo-tree-visualize))

  :config (global-undo-tree-mode))

This problem only appears iff both use-package and byte compiled init files are used.

Any idea?

Most helpful comment

Try adding (require 'bind-key) to your init file.

In uncompiled code, using the use-package macro will autoload use-package which also loads bind-key. But when you compile, the expansion of the macro doesn't need to load use-package, so it never gets loaded. Perhaps the use-package macro should add (require 'bind-key) to its expansion?

All 3 comments

Try adding (require 'bind-key) to your init file.

In uncompiled code, using the use-package macro will autoload use-package which also loads bind-key. But when you compile, the expansion of the macro doesn't need to load use-package, so it never gets loaded. Perhaps the use-package macro should add (require 'bind-key) to its expansion?

Oops. I am stupid.

I forgot to add (require 'use-package) to my .emacs file (which is the
first one to be loaded).

After adding that line before loading other init files, everything
works!

You made my day! Thanks! :-D

P.S. Question will be closed.

Danny

On 2017-03-12 16:01, Noam Postavsky notifications@github.com wrote:

Try adding (require 'bind-key) to your init file.

In uncompiled code, using the use-package macro will autoload use-package which also loads bind-key. But when you compile, the expansion of the macro doesn't need to load use-package, so it never gets loaded. Perhaps the use-package macro should add (require 'bind-key) to its expansion?

Adding "(require 'use-package)" before loading other init files solved the problem.
It was caused by lacking loading of use-package.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jtecca picture jtecca  路  9Comments

kpbochenek picture kpbochenek  路  8Comments

davep picture davep  路  6Comments

ghost picture ghost  路  14Comments

cswarth picture cswarth  路  5Comments