use-package icon indicating copy to clipboard operation
use-package copied to clipboard

byte-compiling reference to free variables using defines and functions seems to not be working

Open kirk86 opened this issue 6 years ago • 6 comments

So, I have the following code in my init:

(use-package undo-tree
  :defines undo-tree-visualizer-selection-mode
  :commands undo-tree-mode
  :ensure t
  :config
  (global-undo-tree-mode t))

I still get these at byte compilation time image

As you can see both undo-tree-mode and undo-tree-visualizer-selection-mode are still there. I still can't wrap my head around what is the proper usage of :defines and :functions is there an order of precedence? Do the :defines and :functions have to come before :ensure? Can they be used together with :ensure? The examples in the readme didn't help me much (maybe I'm too stupid to understand how is this working).

kirk86 avatar Oct 15 '19 11:10 kirk86

I have the same issue. The :functions does not work for me. Instead I add something like (declare-function undo-tree-mode "undo-tree") to my :config block to fix the warning. I typically get this warning for functions provided by the package that I use in the :config block.

willbush avatar May 03 '20 02:05 willbush

same issue here, any update? @jwiegley

tshu-w avatar Aug 12 '20 01:08 tshu-w

There should be no order dependence of this sort, since keywords are always processed in these same order. In cases like this, I would suggest expanding the macro to see why things aren't behaving as you'd expect. The use of :functions for example should expand to using declare-function, at least when byte-compile-current-file is bound and non-nil.

jwiegley avatar Aug 12 '20 03:08 jwiegley

@jwiegley yes, this is because my byte-compile-current-file is nil. But I wonder how to suppress flycheck warning? should I set byte-compile-current-file to t or use declare-function rather than :functions

tshu-w avatar Aug 12 '20 06:08 tshu-w

Well, certainly using declare-function can't hurt. :functions is only there for convenience.

jwiegley avatar Aug 12 '20 19:08 jwiegley

@jwiegley Thx your reply.

tshu-w avatar Aug 13 '20 10:08 tshu-w