6 Byte-compiling your init file

Some users might want to byte-compile their init file to make Emacs startup faster. This is not recommended in most cases, as the speed-up is usually too small to be worth it, and it can lead to confusion if the byte-compiled files are out-of-date. If you still want to do it, this chapter explains how to do that.

use-package always loads every library that it can while a file is being byte-compiled. This helps silence spurious warnings about unknown variables and functions.

However, there are times when this is just not enough. For those times, use the :defines and :functions keywords to introduce dummy variable and function declarations solely for the sake of silencing byte-compiler warnings. For example:

(use-package texinfo
  :defines texinfo-section-list
  :commands texinfo-mode
  :init
  (add-to-list 'auto-mode-alist '("\\.texi$" . texinfo-mode)))

If you need to silence a missing function warning, you can use :functions:

(use-package ruby-mode
  :mode "\\.rb\\'"
  :interpreter "ruby"
  :functions inf-ruby-keys
  :config
  (defun my-ruby-mode-hook ()
    (require 'inf-ruby)
    (inf-ruby-keys))
  (add-hook 'ruby-mode-hook 'my-ruby-mode-hook))

Normally, use-package will load each package at compile time before compiling the configuration, to ensure that any necessary symbols are in scope to satisfy the byte-compiler. At times this can cause problems, since a package may have special loading requirements, and all that you want to use use-package for is to add a configuration to the eval-after-load hook. In such cases, use the :no-require keyword:

(use-package foo
  :no-require t
  :config
  (message "Evaluate this immediately after loading `foo'"))