Search code examples
emacscompiler-warningsflycheck

use-package with config: function might not be available at runtime


I like using use-package for Emacs. Among other things, I have the following in my configuration file:

(use-package proced
  :ensure t
  :config
  (proced-toggle-auto-update 1)
  (general-define-key
    :keymaps 'proced-mode-map
    "j"   'next-line
    "k"   'previous-line))

Flycheck warns that the function proced-toggle-auto-update might not be available at run time. However, the documentation of use-package states that all forms following config: are evaluated after the package is loaded. Is this flycheck warning a false positive then?


Solution

  • If you know the function will be available at runtime, eg. the package will have been loaded (since that function is not autoloaded), then you can let the compiler know by declaring the function, eg.

    (declare-function proced-toggle-auto-update "proced")
    

    I don't use use-package but presumably the package will have been loaded given the documentation you cite, so yes, this would be a false positive.

    In other circumstances you could explicitly autoload a function as well and let the compiler know,

    (autoload 'proced-toggle-auto-update "proced")
    

    These actions assume the library "proced" is on your load-path, eg. (featurep 'proced) is non-nil.